List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:com.rackspacecloud.client.cloudfiles.sample.FilesCopy.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);//from w w w. j a v a2s .c o m CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); if (line.hasOption("file") && line.hasOption("folder")) { System.err.println("Can not use both -file and -folder on the command line at the same time."); System.exit(-1); } //if (line.hasOption("file") && line.hasOption("folder")) if (line.hasOption("download")) { if (line.hasOption("folder")) { String localFolder = FilenameUtils.normalize(line.getOptionValue("folder")); String containerName = null; if (StringUtils.isNotBlank(localFolder)) { File localFolderObj = new File(localFolder); if (localFolderObj.exists() && localFolderObj.isDirectory()) { if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName)) { System.err.println( "You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(ontainerName)) } else { System.err.println( "You must provide the -container for a copy operation to work as expected."); System.exit(-1); } System.out.println("Downloading all objects from: " + containerName + " to local folder: " + localFolder); getContainerObjects(localFolderObj, containerName); } else { if (!localFolderObj.exists()) { System.err.println("The local folder: " + localFolder + " does not exist. Create it first and then run this command."); } if (!localFolderObj.isDirectory()) { System.err.println( "The local folder name supplied : " + localFolder + " is not a folder !"); } System.exit(-1); } } } System.exit(0); } //if (line.hasOption("download")) if (line.hasOption("folder")) { String containerName = null; String folderPath = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName)) { System.err.println("You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(containerName)) } else { System.err.println("You must provide the -container for a copy operation to work as expected."); System.exit(-1); } folderPath = line.getOptionValue("folder"); if (StringUtils.isNotBlank(folderPath)) { File folder = new File(FilenameUtils.normalize(folderPath)); if (folder.isDirectory()) { if (line.hasOption("z")) { System.out.println("Zipping: " + folderPath); System.out.println("Nested folders are ignored !"); File zipedFolder = zipFolder(folder); String mimeType = FilesConstants.getMimetype(ZIPEXTENSION); copyToCreateContainerIfNeeded(zipedFolder, mimeType, containerName); } else { File[] files = folder.listFiles(); for (File f : files) { String mimeType = FilesConstants .getMimetype(FilenameUtils.getExtension(f.getName())); System.out.println("Uploading :" + f.getName() + " to " + folder.getName()); copyToCreateContainerIfNeeded(f, mimeType, containerName); System.out.println( "Upload :" + f.getName() + " to " + folder.getName() + " completed."); } } } else { System.err.println("You must provide a valid folder value for the -folder option !"); System.err.println("The value provided is: " + FilenameUtils.normalize(folderPath)); System.exit(-1); } } } //if (line.hasOption("folder")) if (line.hasOption("file")) { String containerName = null; String fileNamePath = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName) || containerName.indexOf('/') != -1) { System.err.println("You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(containerName)) } else { System.err.println("You must provide the -container for a copy operation to work as expected."); System.exit(-1); } fileNamePath = line.getOptionValue("file"); if (StringUtils.isNotBlank(fileNamePath)) { String fileName = FilenameUtils.normalize(fileNamePath); String fileExt = FilenameUtils.getExtension(fileNamePath); String mimeType = FilesConstants.getMimetype(fileExt); File file = new File(fileName); if (line.hasOption("z")) { logger.info("Zipping " + fileName); if (!file.isDirectory()) { File zippedFile = zipFile(file); mimeType = FilesConstants.getMimetype(ZIPEXTENSION); copyTo(zippedFile, mimeType, containerName); zippedFile.delete(); } } //if (line.hasOption("z")) else { logger.info("Uploading " + fileName + "."); if (!file.isDirectory()) copyTo(file, mimeType, containerName); else { System.err.println( "The path you provided is a folder. For uploading folders use the -folder option."); System.exit(-1); } } } //if (StringUtils.isNotBlank(file)) else { System.err.println("You must provide a valid value for the file to upload !"); System.exit(-1); } } //if (line.hasOption("file")) } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (FilesAuthorizationException err) { logger.fatal("FilesAuthorizationException : Failed to login to your account !" + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch (FilesAuthorizationException err) catch (Exception err) { logger.fatal("IOException : " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.mosso.client.cloudfiles.sample.FilesCopy.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);/* w w w . j av a 2 s . c om*/ CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); if (line.hasOption("file") && line.hasOption("folder")) { System.err.println("Can not use both -file and -folder on the command line at the same time."); System.exit(-1); } //if (line.hasOption("file") && line.hasOption("folder")) if (line.hasOption("download")) { if (line.hasOption("folder")) { String localFolder = FilenameUtils.normalize(line.getOptionValue("folder")); String containerName = null; if (StringUtils.isNotBlank(localFolder)) { File localFolderObj = new File(localFolder); if (localFolderObj.exists() && localFolderObj.isDirectory()) { if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName)) { System.err.println( "You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(ontainerName)) } else { System.err.println( "You must provide the -container for a copy operation to work as expected."); System.exit(-1); } System.out.println("Downloading all objects from: " + containerName + " to local folder: " + localFolder); getContainerObjects(localFolderObj, containerName); } else { if (!localFolderObj.exists()) { System.err.println("The local folder: " + localFolder + " does not exist. Create it first and then run this command."); } if (!localFolderObj.isDirectory()) { System.err.println( "The local folder name supplied : " + localFolder + " is not a folder !"); } System.exit(-1); } } } System.exit(0); } //if (line.hasOption("download")) if (line.hasOption("folder")) { String containerName = null; String folderPath = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName)) { System.err.println("You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(containerName)) } else { System.err.println("You must provide the -container for a copy operation to work as expected."); System.exit(-1); } folderPath = line.getOptionValue("folder"); if (StringUtils.isNotBlank(folderPath)) { File folder = new File(FilenameUtils.normalize(folderPath)); if (folder.isDirectory()) { if (line.hasOption("z")) { System.out.println("Zipping: " + folderPath); System.out.println("Nested folders are ignored !"); File zipedFolder = zipFolder(folder); String mimeType = FilesConstants.getMimetype(ZIPEXTENSION); copyToCreateContainerIfNeeded(zipedFolder, mimeType, containerName); } else { File[] files = folder.listFiles(); for (File f : files) { String mimeType = FilesConstants .getMimetype(FilenameUtils.getExtension(f.getName())); System.out.println("Uploading :" + f.getName() + " to " + folder.getName()); copyToCreateContainerIfNeeded(f, mimeType, containerName); System.out.println( "Upload :" + f.getName() + " to " + folder.getName() + " completed."); } } } else { System.err.println("You must provide a valid folder value for the -folder option !"); System.err.println("The value provided is: " + FilenameUtils.normalize(folderPath)); System.exit(-1); } } } //if (line.hasOption("folder")) if (line.hasOption("file")) { String containerName = null; String fileNamePath = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); if (!StringUtils.isNotBlank(containerName) || containerName.indexOf('/') != -1) { System.err.println("You must provide a valid value for the Container to upload to !"); System.exit(-1); } //if (!StringUtils.isNotBlank(containerName)) } else { System.err.println("You must provide the -container for a copy operation to work as expected."); System.exit(-1); } fileNamePath = line.getOptionValue("file"); if (StringUtils.isNotBlank(fileNamePath)) { String fileName = FilenameUtils.normalize(fileNamePath); String fileExt = FilenameUtils.getExtension(fileNamePath); String mimeType = FilesConstants.getMimetype(fileExt); File file = new File(fileName); if (line.hasOption("z")) { logger.info("Zipping " + fileName); if (!file.isDirectory()) { File zippedFile = zipFile(file); mimeType = FilesConstants.getMimetype(ZIPEXTENSION); copyTo(zippedFile, mimeType, containerName); zippedFile.delete(); } } //if (line.hasOption("z")) else { logger.info("Uploading " + fileName + "."); if (!file.isDirectory()) copyTo(file, mimeType, containerName); else { System.err.println( "The path you provided is a folder. For uploading folders use the -folder option."); System.exit(-1); } } } //if (StringUtils.isNotBlank(file)) else { System.err.println("You must provide a valid value for the file to upload !"); System.exit(-1); } } //if (line.hasOption("file")) } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (FilesAuthorizationException err) { logger.fatal("FilesAuthorizationException : Failed to login to your account !" + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch (FilesAuthorizationException err) catch (IOException err) { logger.fatal("IOException : " + err); System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:org.objectrepository.MessageConsumerDaemon.java
/** * main/*from www.ja v a2s . co m*/ * <p/> * Accepts one folder as argument: -messageQueues * That folder ought to contain one or more folders ( or symbolic links ) to the files * The folder has the format: [foldername] or [foldername].[maxTasks] * MaxTasks is to indicate the total number of jobs being able to run. * * long * * @param argv */ public static void main(String[] argv) { if (instance == null) { final Properties properties = new Properties(); if (argv.length > 0) { for (int i = 0; i < argv.length; i += 2) { try { properties.put(argv[i], argv[i + 1]); } catch (ArrayIndexOutOfBoundsException arr) { System.out.println("Missing value after parameter " + argv[i]); System.exit(-1); } } } else { log.fatal("Usage: pmq-agent.jar -messageQueues [queues] -heartbeatInterval [interval in ms]\n" + "The queues is a folder that contains symbolic links to the startup scripts."); System.exit(-1); } if (log.isInfoEnabled()) { log.info("Arguments set: "); for (String key : properties.stringPropertyNames()) { log.info("'" + key + "'='" + properties.getProperty(key) + "'"); } } if (!properties.containsKey("-messageQueues")) { log.fatal("Expected case sensitive parameter: -messageQueues"); System.exit(-1); } final File messageQueues = new File((String) properties.get("-messageQueues")); if (!messageQueues.exists()) { log.fatal("Cannot find folder for messageQueues: " + messageQueues.getAbsolutePath()); System.exit(-1); } if (messageQueues.isFile()) { log.fatal( "-messageQueues should point to a folder, not a file: " + messageQueues.getAbsolutePath()); System.exit(-1); } long heartbeatInterval = 600000; if (properties.containsKey("-heartbeatInterval")) { heartbeatInterval = Long.parseLong((String) properties.get("heartbeatInterval")); } String identifier = null; if (properties.containsKey("-id")) { identifier = (String) properties.get("-id"); } else if (properties.containsKey("-identifier")) { identifier = (String) properties.get("-identifier"); } final File[] files = messageQueues.listFiles(); final String[] scriptNames = (properties.containsKey("-startup")) ? new String[] { properties.getProperty("-startup") } : new String[] { "/startup.sh", "\\startup.bat" }; final List<Queue> queues = new ArrayList<Queue>(); for (File file : files) { final String name = file.getName(); final String[] split = name.split("\\.", 2); final String queueName = split[0]; for (String scriptName : scriptNames) { final String shellScript = file.getAbsolutePath() + scriptName; final int maxTask = (split.length == 1) ? 1 : Integer.parseInt(split[1]); log.info("Candidate mq client for " + queueName + " maxTasks " + maxTask); if (new File(shellScript).exists()) { final Queue queue = new Queue(queueName, shellScript, false); queue.setCorePoolSize(1); queue.setMaxPoolSize(maxTask); queue.setQueueCapacity(1); queues.add(queue); break; } else { log.warn("... skipping, because no startup script found at " + shellScript); } } } if (queues.size() == 0) { log.fatal("No queue folders seen in " + messageQueues.getAbsolutePath()); System.exit(-1); } // Add the system queue queues.add(new Queue("Connection", null, true)); getInstance(queues, identifier, heartbeatInterval).run(); } System.exit(0); }
From source file:org.yardstickframework.report.jfreechart.JFreeChartGraphPlotter.java
/** * @param cmdArgs Arguments.//from w ww. j ava 2s . com */ public static void main(String[] cmdArgs) { try { JFreeChartGraphPlotterArguments args = new JFreeChartGraphPlotterArguments(); JCommander jCommander = jcommander(cmdArgs, args, "<graph-plotter>"); if (args.help()) { jCommander.usage(); return; } if (args.inputFolders().isEmpty()) { errorHelp("Input folders are not defined."); return; } List<String> inFoldersAsString = args.inputFolders(); List<File> inFolders = new ArrayList<>(inFoldersAsString.size()); for (String folderAsString : inFoldersAsString) inFolders.add(new File(folderAsString).getAbsoluteFile()); for (File inFolder : inFolders) { if (!inFolder.exists()) { errorHelp("Folder does not exist: " + inFolder.getAbsolutePath()); return; } } List<List<List<File>>> benchFolders = new ArrayList<>(); for (File inFolder : inFolders) { File[] dirs0 = inFolder.listFiles(); if (dirs0 == null || dirs0.length == 0) continue; List<File> dirs = new ArrayList<>(Arrays.asList(dirs0)); Collections.sort(dirs, FILE_NAME_COMP); boolean multipleDrivers = false; for (File f : dirs) { if (f.isFile() && MULTIPLE_DRIVERS_MARKER_FILE.equals(f.getName())) { multipleDrivers = true; break; } } List<List<File>> mulDrvFiles = new ArrayList<>(); if (multipleDrivers) { for (File f : dirs) { List<File> files = getFiles(f); if (files != null) mulDrvFiles.add(files); } } else { List<File> files = getFiles(inFolder); if (files != null) mulDrvFiles.add(files); } benchFolders.add(mergeMultipleDriverLists(mulDrvFiles)); } if (benchFolders.isEmpty()) { errorHelp("Input folders are empty or have invalid structure: " + inFoldersAsString); return; } String outputFolder = outputFolder(inFolders); JFreeChartGenerationMode mode = args.generationMode(); if (mode == COMPOUND) processCompoundMode(outputFolder, benchFolders, args); else if (mode == COMPARISON) processComparisonMode(outputFolder, benchFolders, args); else if (mode == STANDARD) processStandardMode(benchFolders, args); else errorHelp("Unknown generation mode: " + args.generationMode()); } catch (ParameterException e) { errorHelp("Invalid parameter.", e); } catch (Exception e) { errorHelp("Failed to execute graph generator.", e); } }
From source file:DIA_Umpire_Quant.DIA_Umpire_Quant.java
/** * @param args the command line arguments *//*from ww w .j a va 2 s . c om*/ public static void main(String[] args) throws FileNotFoundException, IOException, Exception { System.out.println( "================================================================================================="); System.out.println("DIA-Umpire quantitation with targeted re-extraction analysis (version: " + UmpireInfo.GetInstance().Version + ")"); if (args.length != 1) { System.out.println( "command format error, it should be like: java -jar -Xmx10G DIA_Umpire_Quant.jar diaumpire_quant.params"); return; } try { ConsoleLogger.SetConsoleLogger(Level.INFO); ConsoleLogger.SetFileLogger(Level.DEBUG, FilenameUtils.getFullPath(args[0]) + "diaumpire_quant.log"); } catch (Exception e) { } try { Logger.getRootLogger().info("Version: " + UmpireInfo.GetInstance().Version); Logger.getRootLogger().info("Parameter file:" + args[0]); BufferedReader reader = new BufferedReader(new FileReader(args[0])); String line = ""; String WorkFolder = ""; int NoCPUs = 2; String UserMod = ""; String Combined_Prot = ""; String InternalLibID = ""; String ExternalLibPath = ""; String ExternalLibDecoyTag = "DECOY"; boolean DefaultProtFiltering = true; boolean DataSetLevelPepFDR = false; float ProbThreshold = 0.99f; float ExtProbThreshold = 0.99f; float Freq = 0f; int TopNPep = 6; int TopNFrag = 6; float MinFragMz = 200f; String FilterWeight = "GW"; float MinWeight = 0.9f; float RTWindow_Int = -1f; float RTWindow_Ext = -1f; TandemParam tandemPara = new TandemParam(DBSearchParam.SearchInstrumentType.TOF5600); HashMap<String, File> AssignFiles = new HashMap<>(); boolean InternalLibSearch = false; boolean ExternalLibSearch = false; boolean ExportSaint = false; boolean SAINT_MS1 = false; boolean SAINT_MS2 = true; HashMap<String, String[]> BaitList = new HashMap<>(); HashMap<String, String> BaitName = new HashMap<>(); HashMap<String, String[]> ControlList = new HashMap<>(); HashMap<String, String> ControlName = new HashMap<>(); //<editor-fold defaultstate="collapsed" desc="Reading parameter file"> while ((line = reader.readLine()) != null) { line = line.trim(); Logger.getRootLogger().info(line); if (!"".equals(line) && !line.startsWith("#")) { //System.out.println(line); if (line.equals("==File list begin")) { do { line = reader.readLine(); line = line.trim(); if (line.equals("==File list end")) { continue; } else if (!"".equals(line)) { File newfile = new File(line); if (newfile.exists()) { AssignFiles.put(newfile.getAbsolutePath(), newfile); } else { Logger.getRootLogger().info("File: " + newfile + " does not exist."); } } } while (!line.equals("==File list end")); } if (line.split("=").length < 2) { continue; } String type = line.split("=")[0].trim(); String value = line.split("=")[1].trim(); switch (type) { case "TargetedExtraction": { InternalLibSearch = Boolean.parseBoolean(value); break; } case "InternalLibSearch": { InternalLibSearch = Boolean.parseBoolean(value); break; } case "ExternalLibSearch": { ExternalLibSearch = Boolean.parseBoolean(value); break; } case "Path": { WorkFolder = value; break; } case "path": { WorkFolder = value; break; } case "Thread": { NoCPUs = Integer.parseInt(value); break; } case "Fasta": { tandemPara.FastaPath = value; break; } case "Combined_Prot": { Combined_Prot = value; break; } case "DefaultProtFiltering": { DefaultProtFiltering = Boolean.parseBoolean(value); break; } case "DecoyPrefix": { if (!"".equals(value)) { tandemPara.DecoyPrefix = value; } break; } case "UserMod": { UserMod = value; break; } case "ProteinFDR": { tandemPara.ProtFDR = Float.parseFloat(value); break; } case "PeptideFDR": { tandemPara.PepFDR = Float.parseFloat(value); break; } case "DataSetLevelPepFDR": { DataSetLevelPepFDR = Boolean.parseBoolean(value); break; } case "InternalLibID": { InternalLibID = value; break; } case "ExternalLibPath": { ExternalLibPath = value; break; } case "ExtProbThreshold": { ExtProbThreshold = Float.parseFloat(value); break; } case "RTWindow_Int": { RTWindow_Int = Float.parseFloat(value); break; } case "RTWindow_Ext": { RTWindow_Ext = Float.parseFloat(value); break; } case "ExternalLibDecoyTag": { ExternalLibDecoyTag = value; if (ExternalLibDecoyTag.endsWith("_")) { ExternalLibDecoyTag = ExternalLibDecoyTag.substring(0, ExternalLibDecoyTag.length() - 1); } break; } case "ProbThreshold": { ProbThreshold = Float.parseFloat(value); break; } case "ReSearchProb": { //ReSearchProb = Float.parseFloat(value); break; } case "FilterWeight": { FilterWeight = value; break; } case "MinWeight": { MinWeight = Float.parseFloat(value); break; } case "TopNFrag": { TopNFrag = Integer.parseInt(value); break; } case "TopNPep": { TopNPep = Integer.parseInt(value); break; } case "Freq": { Freq = Float.parseFloat(value); break; } case "MinFragMz": { MinFragMz = Float.parseFloat(value); break; } //<editor-fold defaultstate="collapsed" desc="SaintOutput"> case "ExportSaintInput": { ExportSaint = Boolean.parseBoolean(value); break; } case "QuantitationType": { switch (value) { case "MS1": { SAINT_MS1 = true; SAINT_MS2 = false; break; } case "MS2": { SAINT_MS1 = false; SAINT_MS2 = true; break; } case "BOTH": { SAINT_MS1 = true; SAINT_MS2 = true; break; } } break; } // case "BaitInputFile": { // SaintBaitFile = value; // break; // } // case "PreyInputFile": { // SaintPreyFile = value; // break; // } // case "InterationInputFile": { // SaintInteractionFile = value; // break; // } default: { if (type.startsWith("BaitName_")) { BaitName.put(type.substring(9), value); } if (type.startsWith("BaitFile_")) { BaitList.put(type.substring(9), value.split("\t")); } if (type.startsWith("ControlName_")) { ControlName.put(type.substring(12), value); } if (type.startsWith("ControlFile_")) { ControlList.put(type.substring(12), value.split("\t")); } break; } //</editor-fold> } } } //</editor-fold> //Initialize PTM manager using compomics library PTMManager.GetInstance(); if (!UserMod.equals("")) { PTMManager.GetInstance().ImportUserMod(UserMod); } //Check if the fasta file can be found if (!new File(tandemPara.FastaPath).exists()) { Logger.getRootLogger().info("Fasta file :" + tandemPara.FastaPath + " cannot be found, the process will be terminated, please check."); System.exit(1); } //Check if the prot.xml file can be found if (!new File(Combined_Prot).exists()) { Logger.getRootLogger().info("ProtXML file: " + Combined_Prot + " cannot be found, the export protein summary table will be empty."); } LCMSID protID = null; //Parse prot.xml and generate protein master list given an FDR if (Combined_Prot != null && !Combined_Prot.equals("")) { protID = LCMSID.ReadLCMSIDSerialization(Combined_Prot); if (!"".equals(Combined_Prot) && protID == null) { protID = new LCMSID(Combined_Prot, tandemPara.DecoyPrefix, tandemPara.FastaPath); ProtXMLParser protxmlparser = new ProtXMLParser(protID, Combined_Prot, 0f); //Use DIA-Umpire default protein FDR calculation if (DefaultProtFiltering) { protID.RemoveLowLocalPWProtein(0.8f); protID.RemoveLowMaxIniProbProtein(0.9f); protID.FilterByProteinDecoyFDRUsingMaxIniProb(tandemPara.DecoyPrefix, tandemPara.ProtFDR); } //Get protein FDR calculation without other filtering else { protID.FilterByProteinDecoyFDRUsingLocalPW(tandemPara.DecoyPrefix, tandemPara.ProtFDR); } protID.LoadSequence(); protID.WriteLCMSIDSerialization(Combined_Prot); } Logger.getRootLogger().info("Protein No.:" + protID.ProteinList.size()); } HashMap<String, HashMap<String, FragmentPeak>> IDSummaryFragments = new HashMap<>(); //Generate DIA file list ArrayList<DIAPack> FileList = new ArrayList<>(); File folder = new File(WorkFolder); if (!folder.exists()) { Logger.getRootLogger().info("The path : " + WorkFolder + " cannot be found."); System.exit(1); } for (final File fileEntry : folder.listFiles()) { if (fileEntry.isFile() && (fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzxml") | fileEntry.getAbsolutePath().toLowerCase().endsWith(".mzml")) && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q1.mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q2.mzxml") && !fileEntry.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) { AssignFiles.put(fileEntry.getAbsolutePath(), fileEntry); } if (fileEntry.isDirectory()) { for (final File fileEntry2 : fileEntry.listFiles()) { if (fileEntry2.isFile() && (fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzxml") | fileEntry2.getAbsolutePath().toLowerCase().endsWith(".mzml")) && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q1.mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q2.mzxml") && !fileEntry2.getAbsolutePath().toLowerCase().endsWith("q3.mzxml")) { AssignFiles.put(fileEntry2.getAbsolutePath(), fileEntry2); } } } } Logger.getRootLogger().info("No. of files assigned :" + AssignFiles.size()); for (File fileEntry : AssignFiles.values()) { Logger.getRootLogger().info(fileEntry.getAbsolutePath()); String mzXMLFile = fileEntry.getAbsolutePath(); if (mzXMLFile.toLowerCase().endsWith(".mzxml") | mzXMLFile.toLowerCase().endsWith(".mzml")) { DIAPack DiaFile = new DIAPack(mzXMLFile, NoCPUs); FileList.add(DiaFile); HashMap<String, FragmentPeak> FragMap = new HashMap<>(); IDSummaryFragments.put(FilenameUtils.getBaseName(mzXMLFile), FragMap); Logger.getRootLogger().info( "================================================================================================="); Logger.getRootLogger().info("Processing " + mzXMLFile); if (!DiaFile.LoadDIASetting()) { Logger.getRootLogger().info("Loading DIA setting failed, job is incomplete"); System.exit(1); } if (!DiaFile.LoadParams()) { Logger.getRootLogger().info("Loading parameters failed, job is incomplete"); System.exit(1); } } } LCMSID combinePepID = null; if (DataSetLevelPepFDR) { combinePepID = LCMSID.ReadLCMSIDSerialization(WorkFolder + "combinePepID.SerFS"); if (combinePepID == null) { FDR_DataSetLevel fdr = new FDR_DataSetLevel(); fdr.GeneratePepIonList(FileList, tandemPara, WorkFolder + "combinePepID.SerFS"); combinePepID = fdr.combineID; combinePepID.WriteLCMSIDSerialization(WorkFolder + "combinePepID.SerFS"); } } //process each DIA file for quantification based on untargeted identifications for (DIAPack DiaFile : FileList) { long time = System.currentTimeMillis(); Logger.getRootLogger().info("Loading identification results " + DiaFile.Filename + "...."); //If the LCMSID serialization is found if (!DiaFile.ReadSerializedLCMSID()) { DiaFile.ParsePepXML(tandemPara, combinePepID); DiaFile.BuildStructure(); if (!DiaFile.MS1FeatureMap.ReadPeakCluster()) { Logger.getRootLogger().info("Loading peak and structure failed, job is incomplete"); System.exit(1); } DiaFile.MS1FeatureMap.ClearMonoisotopicPeakOfCluster(); //Generate mapping between index of precursor feature and pseudo MS/MS scan index DiaFile.GenerateClusterScanNomapping(); //Doing quantification DiaFile.AssignQuant(); DiaFile.ClearStructure(); } DiaFile.IDsummary.ReduceMemoryUsage(); time = System.currentTimeMillis() - time; Logger.getRootLogger().info(DiaFile.Filename + " processed time:" + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)))); } //<editor-fold defaultstate="collapsed" desc="Targete re-extraction using internal library"> Logger.getRootLogger().info( "================================================================================================="); if (InternalLibSearch && FileList.size() > 1) { Logger.getRootLogger().info("Module C: Targeted extraction using internal library"); FragmentLibManager libManager = FragmentLibManager.ReadFragmentLibSerialization(WorkFolder, InternalLibID); if (libManager == null) { Logger.getRootLogger().info("Building internal spectral library"); libManager = new FragmentLibManager(InternalLibID); ArrayList<LCMSID> LCMSIDList = new ArrayList<>(); for (DIAPack dia : FileList) { LCMSIDList.add(dia.IDsummary); } libManager.ImportFragLibTopFrag(LCMSIDList, Freq, TopNFrag); libManager.WriteFragmentLibSerialization(WorkFolder); } libManager.ReduceMemoryUsage(); Logger.getRootLogger() .info("Building retention time prediction model and generate candidate peptide list"); for (int i = 0; i < FileList.size(); i++) { FileList.get(i).IDsummary.ClearMappedPep(); } for (int i = 0; i < FileList.size(); i++) { for (int j = i + 1; j < FileList.size(); j++) { RTAlignedPepIonMapping alignment = new RTAlignedPepIonMapping(WorkFolder, FileList.get(i).GetParameter(), FileList.get(i).IDsummary, FileList.get(j).IDsummary); alignment.GenerateModel(); alignment.GenerateMappedPepIon(); } FileList.get(i).ExportID(); FileList.get(i).IDsummary = null; } Logger.getRootLogger().info("Targeted matching........"); for (DIAPack diafile : FileList) { if (diafile.IDsummary == null) { diafile.ReadSerializedLCMSID(); } if (!diafile.IDsummary.GetMappedPepIonList().isEmpty()) { diafile.UseMappedIon = true; diafile.FilterMappedIonByProb = false; diafile.BuildStructure(); diafile.MS1FeatureMap.ReadPeakCluster(); diafile.MS1FeatureMap.ClearMonoisotopicPeakOfCluster(); diafile.GenerateMassCalibrationRTMap(); diafile.TargetedExtractionQuant(false, libManager, 1.1f, RTWindow_Int); diafile.MS1FeatureMap.ClearAllPeaks(); diafile.IDsummary.ReduceMemoryUsage(); diafile.IDsummary.RemoveLowProbMappedIon(ProbThreshold); diafile.ExportID(); Logger.getRootLogger().info("Peptide ions: " + diafile.IDsummary.GetPepIonList().size() + " Mapped ions: " + diafile.IDsummary.GetMappedPepIonList().size()); diafile.ClearStructure(); } diafile.IDsummary = null; System.gc(); } Logger.getRootLogger().info( "================================================================================================="); } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Targeted re-extraction using external library"> //External library search if (ExternalLibSearch) { Logger.getRootLogger().info("Module C: Targeted extraction using external library"); //Read exteranl library FragmentLibManager ExlibManager = FragmentLibManager.ReadFragmentLibSerialization(WorkFolder, FilenameUtils.getBaseName(ExternalLibPath)); if (ExlibManager == null) { ExlibManager = new FragmentLibManager(FilenameUtils.getBaseName(ExternalLibPath)); //Import traML file ExlibManager.ImportFragLibByTraML(ExternalLibPath, ExternalLibDecoyTag); //Check if there are decoy spectra ExlibManager.CheckDecoys(); //ExlibManager.ImportFragLibBySPTXT(ExternalLibPath); ExlibManager.WriteFragmentLibSerialization(WorkFolder); } Logger.getRootLogger() .info("No. of peptide ions in external lib:" + ExlibManager.PeptideFragmentLib.size()); for (DIAPack diafile : FileList) { if (diafile.IDsummary == null) { diafile.ReadSerializedLCMSID(); } //Generate RT mapping RTMappingExtLib RTmap = new RTMappingExtLib(diafile.IDsummary, ExlibManager, diafile.GetParameter()); RTmap.GenerateModel(); RTmap.GenerateMappedPepIon(); diafile.BuildStructure(); diafile.MS1FeatureMap.ReadPeakCluster(); diafile.GenerateMassCalibrationRTMap(); //Perform targeted re-extraction diafile.TargetedExtractionQuant(false, ExlibManager, ProbThreshold, RTWindow_Ext); diafile.MS1FeatureMap.ClearAllPeaks(); diafile.IDsummary.ReduceMemoryUsage(); //Remove target IDs below the defined probability threshold diafile.IDsummary.RemoveLowProbMappedIon(ExtProbThreshold); diafile.ExportID(); diafile.ClearStructure(); Logger.getRootLogger().info("Peptide ions: " + diafile.IDsummary.GetPepIonList().size() + " Mapped ions: " + diafile.IDsummary.GetMappedPepIonList().size()); } } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Peptide and fragment selection"> Logger.getRootLogger().info("Peptide and fragment selection across the whole dataset"); ArrayList<LCMSID> SummaryList = new ArrayList<>(); for (DIAPack diafile : FileList) { if (diafile.IDsummary == null) { diafile.ReadSerializedLCMSID(); diafile.IDsummary.ClearAssignPeakCluster(); //diafile.IDsummary.ClearPSMs(); } if (protID != null) { //Generate protein list according to mapping of peptide ions for each DIA file to the master protein list diafile.IDsummary.GenerateProteinByRefIDByPepSeq(protID, true); diafile.IDsummary.ReMapProPep(); } if ("GW".equals(FilterWeight)) { diafile.IDsummary.SetFilterByGroupWeight(); } else if ("PepW".equals(FilterWeight)) { diafile.IDsummary.SetFilterByWeight(); } SummaryList.add(diafile.IDsummary); } FragmentSelection fragselection = new FragmentSelection(SummaryList); fragselection.freqPercent = Freq; fragselection.MinFragMZ = MinFragMz; fragselection.GeneratePepFragScoreMap(); fragselection.GenerateTopFragMap(TopNFrag); fragselection.GenerateProtPepScoreMap(MinWeight); fragselection.GenerateTopPepMap(TopNPep); //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Writing general reports"> ExportTable export = new ExportTable(WorkFolder, SummaryList, IDSummaryFragments, protID, fragselection); export.Export(TopNPep, TopNFrag, Freq); //</editor-fold> //<editor-fold defaultstate="collapsed" desc="//<editor-fold defaultstate="collapsed" desc="Generate SAINT input files"> if (ExportSaint && protID != null) { HashMap<String, DIAPack> Filemap = new HashMap<>(); for (DIAPack DIAfile : FileList) { Filemap.put(DIAfile.GetBaseName(), DIAfile); } FileWriter baitfile = new FileWriter(WorkFolder + "SAINT_Bait_" + DateTimeTag.GetTag() + ".txt"); FileWriter preyfile = new FileWriter(WorkFolder + "SAINT_Prey_" + DateTimeTag.GetTag() + ".txt"); FileWriter interactionfileMS1 = null; FileWriter interactionfileMS2 = null; if (SAINT_MS1) { interactionfileMS1 = new FileWriter( WorkFolder + "SAINT_Interaction_MS1_" + DateTimeTag.GetTag() + ".txt"); } if (SAINT_MS2) { interactionfileMS2 = new FileWriter( WorkFolder + "SAINT_Interaction_MS2_" + DateTimeTag.GetTag() + ".txt"); } HashMap<String, String> PreyID = new HashMap<>(); for (String samplekey : ControlName.keySet()) { String name = ControlName.get(samplekey); for (String file : ControlList.get(samplekey)) { baitfile.write(FilenameUtils.getBaseName(file) + "\t" + name + "\t" + "C\n"); LCMSID IDsummary = Filemap.get(FilenameUtils.getBaseName(file)).IDsummary; if (SAINT_MS1) { SaintOutput(protID, IDsummary, fragselection, interactionfileMS1, file, name, PreyID, 1); } if (SAINT_MS2) { SaintOutput(protID, IDsummary, fragselection, interactionfileMS2, file, name, PreyID, 2); } } } for (String samplekey : BaitName.keySet()) { String name = BaitName.get(samplekey); for (String file : BaitList.get(samplekey)) { baitfile.write(FilenameUtils.getBaseName(file) + "\t" + name + "\t" + "T\n"); LCMSID IDsummary = Filemap.get(FilenameUtils.getBaseName(file)).IDsummary; if (SAINT_MS1) { SaintOutput(protID, IDsummary, fragselection, interactionfileMS1, file, name, PreyID, 1); } if (SAINT_MS2) { SaintOutput(protID, IDsummary, fragselection, interactionfileMS2, file, name, PreyID, 2); } } } baitfile.close(); if (SAINT_MS1) { interactionfileMS1.close(); } if (SAINT_MS2) { interactionfileMS2.close(); } for (String AccNo : PreyID.keySet()) { preyfile.write(AccNo + "\t" + PreyID.get(AccNo) + "\n"); } preyfile.close(); } //</editor-fold> Logger.getRootLogger().info("Job done"); Logger.getRootLogger().info( "================================================================================================="); } catch (Exception e) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(e)); throw e; } }
From source file:iac.cnr.it.TestSearcher.java
public static void main(String[] args) throws IOException, ParseException { /** Command line parser and options */ CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption(OPT_INDEX, true, "Index path"); options.addOption(OPT_QUERY, true, "The query"); CommandLine cmd = null;/*ww w .ja va 2s .c om*/ try { cmd = parser.parse(options, args); } catch (org.apache.commons.cli.ParseException e) { logger.fatal("Error while parsing command line arguments"); System.exit(1); } /** Check for mandatory options */ if (!cmd.hasOption(OPT_INDEX) || !cmd.hasOption(OPT_QUERY)) { usage(); System.exit(0); } /** Read options */ File casePath = new File(cmd.getOptionValue(OPT_INDEX)); String query = cmd.getOptionValue(OPT_QUERY); /** Check correctness of the path containing an ISODAC case */ if (!casePath.exists() || !casePath.isDirectory()) { logger.fatal("The case directory \"" + casePath.getAbsolutePath() + "\" is not valid"); System.exit(1); } /** Check existance of the info.dat file */ File infoFile = new File(casePath, INFO_FILENAME); if (!infoFile.exists()) { logger.fatal("Can't find " + INFO_FILENAME + " within the case directory (" + casePath + ")"); System.exit(1); } /** Load the mapping image_uuid --> image_filename */ imagesMap = new HashMap<Integer, String>(); BufferedReader reader = new BufferedReader(new FileReader(infoFile)); while (reader.ready()) { String line = reader.readLine(); logger.info("Read the line: " + line); String currentID = line.split("\t")[0]; String currentImgFile = line.split("\t")[1]; imagesMap.put(Integer.parseInt(currentID), currentImgFile); logger.info("ID: " + currentID + " - IMG: " + currentImgFile + " added to the map"); } reader.close(); /** Load all the directories containing an index */ ArrayList<String> indexesDirs = new ArrayList<String>(); for (File f : casePath.listFiles()) { logger.info("Analyzing: " + f); if (f.isDirectory()) indexesDirs.add(f.getAbsolutePath()); } logger.info(indexesDirs.size() + " directories found!"); /** Set-up the searcher */ Searcher searcher = null; try { String[] array = indexesDirs.toArray(new String[indexesDirs.size()]); searcher = new Searcher(array); TopDocs results = searcher.search(query, Integer.MAX_VALUE); ScoreDoc[] hits = results.scoreDocs; int numTotalHits = results.totalHits; System.out.println(numTotalHits + " total matching documents"); for (int i = 0; i < numTotalHits; i++) { Document doc = searcher.doc(hits[i].doc); String path = doc.get(FIELD_PATH); String filename = doc.get(FIELD_FILENAME); String image_uuid = doc.get(FIELD_IMAGE_ID); if (path != null) { //System.out.println((i + 1) + ". " + path + File.separator + filename + " - score: " + hits[i].score); // System.out.println((i + 1) + ". " + path + File.separator + filename + " - image_file: " + image_uuid); System.out.println((i + 1) + ". " + path + File.separator + filename + " - image_file: " + imagesMap.get(Integer.parseInt(image_uuid))); } else { System.out.println((i + 1) + ". " + "No path for this document"); } } } catch (Exception e) { System.err.println("An error occurred: " + e.getMessage()); e.printStackTrace(); } finally { if (searcher != null) searcher.close(); } }
From source file:it.univpm.deit.semedia.musicuri.core.MusicURISearch.java
/** * Identifies the MusicURIReference that most closely matches the given audio file * @param args the audio file to identify *//*from ww w. j a va2 s .com*/ public static void main(String[] args) throws Exception { MusicURISearch engine = new MusicURISearch((Toolset.getCWD() + "db\\"), "MusicURIReferences.db"); // MusicURIDatabase db = new MusicURIDatabase ("C:/Eclipse/workspace/MusicURI/db/", "MusicURIReferences.db"); // MusicURISearch engine = new MusicURISearch (db); //MusicURISearch engine = new MusicURISearch ("D:/10References/", "MusicURIReferences.db"); //***************************************************************************** //************************* F I L E I N P U T *************************** //***************************************************************************** if ((args.length == 1) && (new File(args[0]).exists())) { // get the file's canonical path File givenHandle = new File(args[0]); boolean finalResortIsCombinedDistance = true; String queryAudioCanonicalPath = givenHandle.getCanonicalPath(); System.out.println("Input: " + queryAudioCanonicalPath); PerformanceStatistic tempStat; if (givenHandle.isDirectory()) { File[] list = givenHandle.listFiles(); if (list.length == 0) { System.out.println("Directory is empty"); return; } else { ArrayList allStats = new ArrayList(); File currentFile; int truePositives = 0; int falsePositives = 0; int trueNegatives = 0; int falseNegatives = 0; if (finalResortIsCombinedDistance) System.out.println(" Final resort is combined distance"); else System.out.println(" Final resort is audio signature distance"); for (int i = 0; i < list.length; i++) { currentFile = list[i]; try { if (Toolset.isSupportedAudioFile(currentFile)) { System.out.println("\nIdentifying : " + currentFile.getName()); tempStat = engine.getIdentificationPerformance(new MusicURIQuery(givenHandle), true, true, 0.09f, finalResortIsCombinedDistance); //identify (new MusicURIQuery(currentFile), true, true, 0.09f, finalResortIsCombinedDistance, 1); if (tempStat != null) allStats.add(tempStat); if (tempStat.isTruePositive()) truePositives++; if (tempStat.isFalsePositive()) falsePositives++; if (tempStat.isTrueNegative()) trueNegatives++; if (tempStat.isFalseNegative()) falseNegatives++; System.out.println( "\nTrue Positives : " + truePositives + "/" + allStats.size()); System.out .println("False Positives : " + falsePositives + "/" + allStats.size()); System.out .println("True Negatives : " + trueNegatives + "/" + allStats.size()); System.out .println("False Negatives : " + falseNegatives + "/" + allStats.size()); } } catch (Exception e) { e.printStackTrace(); } } System.out.println("\n\nStatistics for Test Case: " + queryAudioCanonicalPath); engine.mergeStatistics(allStats); } } //end if givenHandle is Directory if (givenHandle.isFile()) { if (Toolset.isSupportedAudioFile(givenHandle)) { //tempStat = engine.getIdentificationPerformance (new MusicURIQuery(givenHandle), true, true, 0.09f, finalResortIsCombinedDistance); tempStat = engine.getIdentificationPerformance(new MusicURIQuery(givenHandle), false, false, 0.09f, false); //identify (new MusicURIQuery(givenHandle), true, true, 0.09f, finalResortIsCombinedDistance, 1); if (tempStat != null) { System.out.println("\nIdentification completed"); //tempStat.printStatistics(); ArrayList allStats = new ArrayList(); allStats.add(tempStat); engine.mergeStatistics(allStats); } else System.out.println("Error in identification "); } } } //end if else { System.err.println("MusicURISearch"); System.err.println("Usage: java it.univpm.deit.semedia.musicuri.core.MusicURISearch {unknown.mp3}"); } }
From source file:edu.msu.cme.rdp.seqmatch.cli.SeqMatchMain.java
public static void main(String[] args) throws Exception { if (args.length == 0) { System.err.println("USAGE: SeqMatchMain [train|seqmatch] <args>"); return;//from w ww . java 2 s . c om } String cmd = args[0]; args = Arrays.copyOfRange(args, 1, args.length); if (cmd.equals("train")) { if (args.length != 2) { System.err.println("USAGE: train <reference sequences> <trainee_out_file_prefix>" + "\nMultiple trainee output files might be created, each containing maximum " + Trainee.MAX_NUM_SEQ + " sequences"); return; } File refSeqs = new File(args[0]); File traineeFileOut = new File(args[1]); //maybe more than 1 trainee files need to be created, depending on the number of seqs CreateMultiMatchFromFile.getMultiTrainee(refSeqs, traineeFileOut); } else if (cmd.equals("seqmatch")) { File refFile = null; File queryFile = null; HashMap<String, String> descMap = new HashMap<String, String>(); PrintStream out = new PrintStream(System.out); int knn = 20; float minSab = .5f; try { CommandLine line = new PosixParser().parse(options, args); if (line.hasOption("knn")) { knn = Integer.parseInt(line.getOptionValue("knn")); } if (line.hasOption("sab")) { minSab = Float.parseFloat(line.getOptionValue("sab")); } if (line.hasOption("desc")) { descMap = readDesc(new File(line.getOptionValue("desc"))); } if (line.hasOption("outFile")) { out = new PrintStream(new File(line.getOptionValue("outFile"))); } args = line.getArgs(); if (args.length != 2) { throw new Exception("Unexpected number of command line arguments"); } refFile = new File(args[0]); queryFile = new File(args[1]); } catch (Exception e) { new HelpFormatter().printHelp("seqmatch <refseqs | trainee_file_or_dir> <query_file>\n" + " trainee_file_or_dir is a single trainee file or a directory containing multiple trainee files", options); System.err.println("Error: " + e.getMessage()); return; } SeqMatch seqmatch = null; if (refFile.isDirectory()) { // a directory of trainee files List<SeqMatch> engineList = new ArrayList<SeqMatch>(); for (File f : refFile.listFiles()) { if (!f.isHidden()) { TwowaySeqMatch match = new TwowaySeqMatch(new SeqMatchEngine(new StorageTrainee(f))); engineList.add(match); } } seqmatch = new MultiTraineeSeqMatch(engineList); } else { // a single fasta file or trainee file if (SeqUtils.guessFileFormat(refFile) == SequenceFormat.UNKNOWN) { seqmatch = CLISeqMatchFactory.trainTwowaySeqMatch(new StorageTrainee(refFile)); } else { seqmatch = CreateMultiMatchFromFile.getMultiMatch(refFile); } } out.println("query name\tmatch seq\torientation\tS_ab score\tunique oligomers\tdescription"); SeqReader reader = new SequenceReader(queryFile); Sequence seq; while ((seq = reader.readNextSequence()) != null) { SeqMatchResultSet resultSet = seqmatch.match(seq, knn); for (SeqMatchResult result : resultSet) { char r = '+'; if (result.isReverse()) { r = '-'; } if (result.getScore() > minSab) { out.println(seq.getSeqName() + "\t" + result.getSeqName() + "\t" + r + "\t" + result.getScore() + "\t" + resultSet.getQueryWordCount() + "\t" + descMap.get(result.getSeqName())); } } } out.close(); } else { throw new IllegalArgumentException("USAGE: SeqMatchMain [train|seqmatch] <args>"); } }
From source file:ca.uqac.info.Job.Launcher.JobLauncher.java
public static void main(final String[] args) { // Parse command line arguments Options options = setupOptions();// www . j ava 2 s . c om CommandLine c_line = setupCommandLine(args, options); String batFolder = ""; String outFolderStr = ""; File folderBat = null; File[] listOfFiles = null; String files = ""; String username = ""; String password = ""; String recipient = ""; String message = ""; boolean emailOpt = false; GoogleMail Gmail = null; if (c_line.hasOption("e")) { emailOpt = Boolean.parseBoolean(c_line.getOptionValue("email")); } if (emailOpt == true) { Gmail = new GoogleMail(); } // boolean nextJob = true; if (c_line.hasOption("h")) { showUsage(options); System.exit(ERR_OK); } //Contains a bat folder if (c_line.hasOption("b")) { batFolder = c_line.getOptionValue("BatFolder"); } else { System.err.println("No Bat Folder in Arguments"); System.exit(ERR_ARGUMENTS); } //Contains a Output folder if (c_line.hasOption("o")) { outFolderStr = c_line.getOptionValue("OutputFolder"); } else { System.err.println("No Output Folder in Arguments"); System.exit(ERR_ARGUMENTS); } //Use the email option if (emailOpt == true) { //Contains the username if (c_line.hasOption("username")) { username = c_line.getOptionValue("u"); } else { System.err.println("No username in Arguments"); System.exit(ERR_ARGUMENTS); } //Contains the password if (c_line.hasOption("password")) { password = c_line.getOptionValue("p"); } else { System.err.println("No password in Arguments"); System.exit(ERR_ARGUMENTS); } //Contains the recipient Email if (c_line.hasOption("recipientEmail")) { recipient = c_line.getOptionValue("r"); } else { System.err.println("No recipient Email in Arguments"); System.exit(ERR_ARGUMENTS); } } folderBat = new File(batFolder); listOfFiles = folderBat.listFiles(); File outFolder = new File(outFolderStr); //Make sure to test all of the files for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { files = listOfFiles[i].getName(); String outName = outFolderStr + "\\Results_" + files + ".txt"; message = outName; //Make sure to use only the bat files if (files.endsWith(".bat") || files.endsWith(".Bat")) { try { String StartDay = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").format(new Date()); long timeBefore = new Date().getTime(); int exitStatus = launchJob(listOfFiles[i].getAbsolutePath(), outName, outFolder); long timeAfter = new Date().getTime(); String EndDay = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").format(new Date()); long timeLaunch = timeAfter - timeBefore; if (exitStatus != 0)// An error arrived in the job launch { message += " exitStatus : " + exitStatus; message += " \n Total : " + timeLaunch + " ms"; message += " \n Start : " + StartDay; message += "\n End : " + EndDay; //Send the email to tell the launch job status sendEmail(Gmail, emailOpt, username, password, recipient, "Error :" + files, message); } else // Every things is fine { message += " \n Total : " + timeLaunch + " ms"; message += " \n Start : " + StartDay; message += "\n End : " + EndDay; //Send the email to tell the launch job status sendEmail(Gmail, emailOpt, username, password, recipient, files + " Done !!!", message); } } catch (Exception e) { //Send a email for the error from the launch of the job sendEmail(Gmail, emailOpt, username, password, recipient, "Error :" + files, "Launch Job and/or SMTP error !!!"); e.printStackTrace(); } } // if files .bat } // if isFile } // For listOfFiles }
From source file:fr.inria.edelweiss.kgdqp.core.CentralizedInferrencing.java
public static void main(String args[]) throws ParseException, EngineException, InterruptedException, IOException { List<String> endpoints = new ArrayList<String>(); String queryPath = null;//ww w.j av a 2 s .co m boolean rulesSelection = false; File rulesDir = null; File ontDir = null; ///////////////// Graph graph = Graph.create(); QueryProcess exec = QueryProcess.create(graph); Options options = new Options(); Option helpOpt = new Option("h", "help", false, "print this message"); // Option queryOpt = new Option("q", "query", true, "specify the sparql query file"); // Option endpointOpt = new Option("e", "endpoint", true, "a federated sparql endpoint URL"); Option versionOpt = new Option("v", "version", false, "print the version information and exit"); Option rulesOpt = new Option("r", "rulesDir", true, "directory containing the inference rules"); Option ontOpt = new Option("o", "ontologiesDir", true, "directory containing the ontologies for rules selection"); // Option locOpt = new Option("c", "centralized", false, "performs centralized inferences"); Option dataOpt = new Option("l", "load", true, "data file or directory to be loaded"); // Option selOpt = new Option("s", "rulesSelection", false, "if set to true, only the applicable rules are run"); // options.addOption(queryOpt); // options.addOption(endpointOpt); options.addOption(helpOpt); options.addOption(versionOpt); options.addOption(rulesOpt); options.addOption(ontOpt); // options.addOption(selOpt); // options.addOption(locOpt); options.addOption(dataOpt); String header = "Corese/KGRAM rule engine experiment command line interface"; String footer = "\nPlease report any issue to alban.gaignard@cnrs.fr, olivier.corby@inria.fr"; CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("kgdqp", header, options, footer, true); System.exit(0); } if (cmd.hasOption("o")) { rulesSelection = true; String ontDirPath = cmd.getOptionValue("o"); ontDir = new File(ontDirPath); if (!ontDir.isDirectory()) { logger.warn(ontDirPath + " is not a valid directory path."); System.exit(0); } } if (!cmd.hasOption("r")) { logger.info("You must specify a path for inference rules directory !"); System.exit(0); } if (cmd.hasOption("l")) { String[] dataPaths = cmd.getOptionValues("l"); for (String path : dataPaths) { Load ld = Load.create(graph); ld.load(path); logger.info("Loaded " + path); } } if (cmd.hasOption("v")) { logger.info("version 3.0.4-SNAPSHOT"); System.exit(0); } String rulesDirPath = cmd.getOptionValue("r"); rulesDir = new File(rulesDirPath); if (!rulesDir.isDirectory()) { logger.warn(rulesDirPath + " is not a valid directory path."); System.exit(0); } // Local rules graph initialization Graph rulesG = Graph.create(); Load ld = Load.create(rulesG); if (rulesSelection) { // Ontology loading if (ontDir.isDirectory()) { for (File o : ontDir.listFiles()) { logger.info("Loading " + o.getAbsolutePath()); ld.load(o.getAbsolutePath()); } } } // Rules loading if (rulesDir.isDirectory()) { for (File r : rulesDir.listFiles()) { logger.info("Loading " + r.getAbsolutePath()); ld.load(r.getAbsolutePath()); } } // Rule engine initialization RuleEngine ruleEngine = RuleEngine.create(graph); ruleEngine.set(exec); ruleEngine.setOptimize(true); ruleEngine.setConstructResult(true); ruleEngine.setTrace(true); StopWatch sw = new StopWatch(); logger.info("Federated graph size : " + graph.size()); logger.info("Rules graph size : " + rulesG.size()); // Rule selection logger.info("Rules selection"); QueryProcess localKgram = QueryProcess.create(rulesG); ArrayList<String> applicableRules = new ArrayList<String>(); sw.start(); String rulesSelQuery = ""; if (rulesSelection) { rulesSelQuery = pertinentRulesQuery; } else { rulesSelQuery = allRulesQuery; } Mappings maps = localKgram.query(rulesSelQuery); logger.info("Rules selected in " + sw.getTime() + " ms"); logger.info("Applicable rules : " + maps.size()); // Selected rule loading for (Mapping map : maps) { IDatatype dt = (IDatatype) map.getValue("?res"); String rule = dt.getLabel(); //loading rule in the rule engine // logger.info("Adding rule : "); // System.out.println("-------"); // System.out.println(rule); // System.out.println(""); // if (! rule.toLowerCase().contains("sameas")) { applicableRules.add(rule); ruleEngine.addRule(rule); // } } // Rules application on distributed sparql endpoints logger.info("Rules application (" + applicableRules.size() + " rules)"); ExecutorService threadPool = Executors.newCachedThreadPool(); RuleEngineThread ruleThread = new RuleEngineThread(ruleEngine); sw.reset(); sw.start(); // ruleEngine.process(); threadPool.execute(ruleThread); threadPool.shutdown(); //monitoring loop while (!threadPool.isTerminated()) { // System.out.println("******************************"); // System.out.println(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); // System.out.println("Rule engine running for " + sw.getTime() + " ms"); // System.out.println("Federated graph size : " + graph.size()); System.out.println(sw.getTime() + " , " + graph.size()); Thread.sleep(5000); } logger.info("Federated graph size : " + graph.size()); // logger.info(Util.jsonDqpCost(QueryProcessDQP.queryCounter, QueryProcessDQP.queryVolumeCounter, QueryProcessDQP.sourceCounter, QueryProcessDQP.sourceVolumeCounter)); // TripleFormat f = TripleFormat.create(graph, true); // f.write("/tmp/gAll.ttl"); }