List of usage examples for java.lang String endsWith
public boolean endsWith(String suffix)
From source file:net.securnetwork.itebooks.downloader.EbookDownloader.java
/** * Program main method./*from w ww . j av a 2s . c o m*/ * * @param args the program arguments */ public static void main(String[] args) { if (validateArguments(args)) { int start = MIN_EBOOK_INDEX; int end = getLastEbookIndex(); String destinationFolder = null; // Check if resume mode if (args.length == 1 && args[0].equals(RESUME_ARG)) { start = Integer.parseInt(prefs.get(LAST_SAVED_EBOOK_PREF, MIN_EBOOK_INDEX - 1 + "")) + 1; //$NON-NLS-1$ destinationFolder = prefs.get(OUTPUT_FOLDER_PREF, null); } else { destinationFolder = getDestinationFolder(args); } if (destinationFolder == null) { System.err.println(Messages.getString("EbookDownloader.NoDestinationFolderFound")); //$NON-NLS-1$ return; } else { // Possibly fix the destination folder path destinationFolder = destinationFolder.replace("\\", "/"); if (!destinationFolder.endsWith("/")) { destinationFolder += "/"; } prefs.put(OUTPUT_FOLDER_PREF, destinationFolder); } if (args.length == 3) { start = getStartIndex(args); end = getEndIndex(args); } try { for (int i = start; i <= end; i++) { String ebookPage = BASE_EBOOK_URL + i + SLASH; Source sourceHTML = new Source(new URL(ebookPage)); List<Element> allTables = sourceHTML.getAllElements(HTMLElementName.TABLE); Element detailsTable = allTables.get(0); // Try to build an info bean for the ebook String bookTitle = EbookPageParseUtils.getTitle(detailsTable); if (bookTitle != null) { EbookInfo ebook = createEbookInfo(bookTitle, i, detailsTable); String filename = destinationFolder + Misc.getValidFilename(ebook.getTitle(), ebook.getSubTitle(), ebook.getYear(), ebook.getFileFormat()); System.out.print(MessageFormat.format(Messages.getString("EbookDownloader.InfoDownloading"), //$NON-NLS-1$ new Object[] { ebook.getSiteId() })); try { URL ebookPageURL = new URL(ebook.getDownloadLink()); HttpURLConnection con = (HttpURLConnection) ebookPageURL.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Referer", ebookPage); InputStream conIS = con.getInputStream(); FileUtils.copyInputStreamToFile(conIS, new File(filename)); System.out.println(Messages.getString("EbookDownloader.DownloadingOK")); //$NON-NLS-1$ prefs.put(LAST_SAVED_EBOOK_PREF, i + ""); //$NON-NLS-1$ conIS.close(); } catch (Exception e) { System.out.println(Messages.getString("EbookDownloader.DownloadingKO")); //$NON-NLS-1$ } } } } catch (Exception e) { System.err.println(Messages.getString("EbookDownloader.FatalError")); //$NON-NLS-1$ e.printStackTrace(); } } else { printHelp(); } }
From source file:main.Driver.java
/** * The path to a properties file which will supply parameter values for the tests should be passed in as argument 0 to main. * The test that will be run is determined by the value of 'test_type' in the properties file, and each of the tests have their own properties: * 'encode+decode' - Encode and decode the given leadsheet with the autoencoder, writing the result to a leadsheet file. * Params: // www. ja v a 2 s . co m * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * name_generator_connectome={the path to the connectome which the name generator will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded and decoded} * * output_folder={the path to the output folder which the result leadsheet file will be written in} * * 'encode+write_queue' - Encode the given leadsheet with the autoencoder, then write the encoded feature queue to a queue file. * Params: * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded} * * queue_folder={the path to the output folder which the result queue file will be written in} * * 'encode+write_queue+decode' - Encode the given leadsheet with the autoencoder, write the encoded feature queue to a queue file, and then write the result leadsheet to a leadsheet file. * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * name_generator_connectome={the path to the connectome which the name generator will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded and decoded} * * queue_folder={the path to the output folder which the result queue file will be written in} * * output_folder={the path to the output folder which the result leadsheet file will be written in} * 'create_feature_property_vector' - Given a corpus folder of leadsheets, construct a vector consisting of property analysis values for each feature in the corpus data * * input_corpus_folder={the path to the corpus folder containing all leadsheets to analyze} * * feature_size={the size (in time steps) of each feature} * * feature_properties_path={the path to write the generated vector file to (the file will be a csv file containing all the values in left-to-right order} * * feature_property={the type of feature property to analyze - current options are 'rest', 'sustain', articulate' (these return ratios of time steps with the given property to the total time steps in the feature). * 'compile_feature_queue_matrix' - Given a corpus folder of feature queues, construct a matrix of all feature vectors and write it as a csv file * * queue_folder={the path to the folder containing all queue files to compile} * * feature_matrix_path={the path to write the result csv file to} * 'generate_from_feature_queue_matrix' - Given a matrix of feature vectors, load the autoencoder with a queue of those features and decode from it, writing the result leadsheet to a file * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * reference_leadsheet={the path to the leadsheet we will take the chord sequence from (and loop it to match the length of the feature queue)} * * feature_queue_matrix_path={the path to the feature queue matrix file we will decode from} * * output_file_path={the path to the file we will write our result leadsheet to} * * (optional) song_title={the song title to write in the leadsheet file - by default this is "Generation from Feature Matrix {path of the feature matrix}"} * * feature_size={the size (in time steps) of features} * 'population_trade' - Given a leadsheet file, split it into sections of a specified size, and between sections, generate a response that plays off of a population of previously encoded feature queues * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded and traded with} * * output_folder={the path to the output folder which the result leadsheet file will be written in} * * trading_part_size={the size (in time steps) of each trading part. The input leadsheet will be split into sections of this size, and trading responses will be generated in between.} * * interpolation_variance={a random value between zero and this will be added to the interpolation_min at each trading section to calculate the interpolation of the recently encoded queue towards the queue population before decoding the trading response} * * interpolation_min={the minimum ratio of interpolation at each trading section} * * herding_strength={the maximum strength of the herding operation at each section (all queues in the population are interpolated a random amount towards the most recent queue)} * * mutation_strength={the maximum strength of mutation at each section (each element of the feature vectors of all queues in the population are mutated at a random strength} * * crossover_strength{the maximum strength of crossover at each section (there is a chance for every queue that the queue will swap a random feature of itself with the corresponding feature of another random queue)} * 'interpolation' - Given a leadsheet file and a reference queue file, encode the leadsheet file with the autoencoder, and generate from the encoded queue for a number of divisions of a full interpolation towards the target queue * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * input_leadsheet={the path to the leadsheet file which will be encoded and interpolated} * * target_queue={the path to the queue to interpolate towards at each interpolation value}; * * output_folder={the path to the output folder which the result leadsheet file will be written in} * * num_interpolation_divisions={the number of divisions of the interpolation strength from 0.0 to 1.0 (the length of the result leadsheet will be equal to the length of the original times 1 + number of divisions, as the first section of the result leadsheet is for interpolation 0.0)} * 'frankenstein' - Given a primary queue, a reference leadsheet for chords, and a corpus of queue files, construct the result leadsheet from a series of randomly weighted interpolations of the primary queue towards the set of selected queues. * * autoencoder_connectome={the path to the connectome which the autoencoder will be loaded with} * * primary_queue_path={the path to the queue which will serve as the base for all of the queue combinations (which are the result of sequential interpolations instead of a weighted sum)} * * reference_leadsheet={the path to the leadsheet we will take the chord sequence from (and loop it to match the desired length of our output} * * queue_folder={the path to the folder containing all queue files we can select from} * * output_file_path={the path to the file we will write our result leadsheet to} * * num_reference_queues={the number of reference queues we will pick at random from the queue folder to sample from) * * num_combinations={the number of queue combinations to sample and create the result leadsheet from} * * interpolation_strength={the total magnitude of all interpolation operations for each combination} */ public static void main(String[] args) throws FileNotFoundException, IOException, ConfigurationException { FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class).configure( new Parameters().properties().setFileName(args[0]).setThrowExceptionOnMissing(true) .setListDelimiterHandler(new DefaultListDelimiterHandler(';')) .setIncludesAllowed(false)); Configuration config = builder.getConfiguration(); LogTimer.initStartTime(); //start our logging timer to keep track of our execution time //switch statement to run the appropriate test switch (config.getString("test_type")) { case "encode+decode": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String nameGeneratorConnectomePath = config.getString("name_generator_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String outputFolderPath = config.getString("output_folder"); //initialize networks NameGenerator nameGenerator = initializeNameGenerator(nameGeneratorConnectomePath); ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize input sequences and output sequence LeadsheetDataSequence inputSequence = leadsheetToSequence(inputLeadsheetPath); LeadsheetDataSequence outputSequence = inputSequence.copy(); outputSequence.clearMelody(); LeadsheetDataSequence decoderInputSequence = outputSequence.copy(); //encode and decode encodeFromSequence(autoencoder, inputSequence); decodeToSequence(autoencoder, outputSequence, decoderInputSequence); //generate song title String songTitle = nameGenerator.generateName(); //write output to specified directory with same file name + _aeOutput suffix writeLeadsheetFile(outputSequence, outputFolderPath, new File(inputLeadsheetPath).getName(), "_aeOutput", songTitle); } break; case "encode+write_queue": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String queueFolderPath = config.getString("queue_folder"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize input sequence LeadsheetDataSequence inputSequence = leadsheetToSequence(inputLeadsheetPath); //encode encodeFromSequence(autoencoder, inputSequence); //write to a queue file in the specified queue folder (the write method will handle removing/adding extensions writeQueueFile(autoencoder, queueFolderPath, new File(inputLeadsheetPath).getName()); } break; case "encode+write_queue+decode": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String nameGeneratorConnectomePath = config.getString("name_generator_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String queueFolderPath = config.getString("queue_folder"); String outputFolderPath = config.getString("output_folder"); //initialize networks NameGenerator nameGenerator = initializeNameGenerator(nameGeneratorConnectomePath); ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize input sequences and output sequence LeadsheetDataSequence inputSequence = leadsheetToSequence(inputLeadsheetPath); LeadsheetDataSequence outputSequence = inputSequence.copy(); outputSequence.clearMelody(); LeadsheetDataSequence decoderInputSequence = outputSequence.copy(); //encode encodeFromSequence(autoencoder, inputSequence); //write to a queue file in the specified queue folder (the write method will handle removing/adding extensions writeQueueFile(autoencoder, queueFolderPath, new File(inputLeadsheetPath).getName()); //decode decodeToSequence(autoencoder, outputSequence, decoderInputSequence); //generate song title String songTitle = nameGenerator.generateName(); //write output to specified directory with same file name + _aeOutput suffix writeLeadsheetFile(outputSequence, outputFolderPath, new File(inputLeadsheetPath).getName(), "_aeOutput", songTitle); } break; case "create_feature_property_vector": { //load parameter values from config file String inputCorpusFolder = config.getString("input_corpus_folder"); int featureSize = config.getInt("feature_size"); String featurePropertiesPath = config.getString("feature_properties_path"); String featureProperty = config.getString("feature_property"); //compile array of valid leadsheet files File[] songFiles = new File(inputCorpusFolder) .listFiles((File dir, String name) -> name.endsWith(".ls")); //construct feature property vector from analyzed feature property values of all songs AVector featurePropertyValues = Vector.createLength(0); int featureIndex = 0; for (File inputFile : songFiles) { LeadsheetDataSequence melodySequence = leadsheetToSequence(inputFile.getPath()); featurePropertyValues.join(melodyFeatureAnalysis(melodySequence, featureProperty, featureSize)); } //write generated feature_properties BufferedWriter writer = new BufferedWriter( new FileWriter(featurePropertiesPath + "_" + featureProperty + ".v")); writer.write(ReadWriteUtilities.getNumpyCSVString(featurePropertyValues)); writer.close(); } break; case "compile_feature_queue_matrix": { //load parameter values from config file String queueFolderPath = config.getString("queue_folder"); String featureMatrixPath = config.getString("feature_matrix_path"); //generate feature matrix from all feature queues in specified queue folder File[] queueFiles = new File(queueFolderPath).listFiles((File dir, String name) -> name.endsWith(".q")); AMatrix totalFeatureMatrix = generateFeatureQueueMatrix(queueFiles); String writeData = ReadWriteUtilities.getNumpyCSVString(totalFeatureMatrix); BufferedWriter writer = new BufferedWriter(new FileWriter(featureMatrixPath)); writer.write(writeData); writer.close(); } break; case "generate_from_feature_queue_matrix": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String referenceLeadsheetPath = config.getString("reference_leadsheet"); String featureQueueMatrixPath = config.getString("feature_queue_matrix_path"); String outputFilePath = config.getString("output_file_path"); String songTitle = config.getString("song_title", "Generation from Feature Matrix " + featureQueueMatrixPath); int featureSize = config.getInt("feature_size"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize chord sequence LeadsheetDataSequence chordSequence = leadsheetToSequence(referenceLeadsheetPath); chordSequence.clearMelody(); //call generation method generateFromFeatureMatrix(autoencoder, autoencoderConnectomePath, chordSequence, featureQueueMatrixPath, featureSize, outputFilePath, songTitle); } break; case "population_trade": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String outputFolderPath = config.getString("output_folder"); int tradingPartSize = config.getInt("trading_part_size"); double interpVariance = config.getDouble("interpolation_variance"); double interpMin = config.getDouble("interpolation_min"); double herdingStrength = config.getDouble("herding_strength"); double mutationStrength = config.getDouble("mutation_strength"); double crossoverStrength = config.getDouble("crossover_strength"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, true); //perform population trading test populationTradingTest(autoencoder, autoencoderConnectomePath, new File(inputLeadsheetPath), new File(outputFolderPath), tradingPartSize, interpVariance, interpMin, herdingStrength, mutationStrength, crossoverStrength); } break; case "interpolation": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String inputLeadsheetPath = config.getString("input_leadsheet"); String targetQueuePath = config.getString("target_queue"); String outputFolderPath = config.getString("output_folder"); int numInterpolationDivisions = config.getInt("num_interpolation_divisions"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //perform the interpolation test interpolateTest(autoencoder, autoencoderConnectomePath, new File(inputLeadsheetPath), new File(targetQueuePath), new File(outputFolderPath), numInterpolationDivisions); } break; case "frankenstein": { //load parameter values from config file String autoencoderConnectomePath = config.getString("autoencoder_connectome"); String primaryQueuePath = config.getString("primary_queue_path"); String referenceLeadsheetPath = config.getString("reference_leadsheet"); String queueFolderPath = config.getString("queue_folder"); String outputFilePath = config.getString("output_file_path"); int numReferenceQueues = config.getInt("num_reference_queues"); int numCombinations = config.getInt("num_combinations"); double interpolationMagnitude = config.getDouble("interpolation_strength"); //initialize network ProductCompressingAutoencoder autoencoder = initializeAutoencoder(autoencoderConnectomePath, false); //initialize chord sequence LeadsheetDataSequence chordSequence = leadsheetToSequence(referenceLeadsheetPath); chordSequence.clearMelody(); //perform frankenstein test frankensteinTest(autoencoder, autoencoderConnectomePath, primaryQueuePath, new File(queueFolderPath), outputFilePath, chordSequence, numReferenceQueues, numCombinations, interpolationMagnitude); } break; default: throw new RuntimeException("Unrecognized test type"); } LogTimer.log("Process finished"); //Done! }
From source file:de.ipbhalle.metfusion.main.SubstructureSearch.java
public static void main(String[] args) { String token = "eeca1d0f-4c03-4d81-aa96-328cdccf171a"; //String token = "a1004d0f-9d37-47e0-acdd-35e58e34f603"; //test();// ww w . jav a 2s . c om //File file = new File("/home/mgerlich/projects/metfusion_tp/BTs/MetFusion_ChemSp_mfs/136m0498_MSMS.mf"); //File file = new File("/home/mgerlich/projects/metfusion_tp/BTs/MetFusion_ChemSp_mfs/148m0859_MSMS.mf"); // File file = new File("/home/mgerlich/projects/metfusion_tp/BTs/MetFusion_ChemSp_mfs/164m0445a_MSMS.mf"); //File file = new File("/home/mgerlich/projects/metfusion_tp/BTs/MetFusion_ChemSp_mfs/192m0757a_MSMS.mf"); //File file = new File("/home/mgerlich/projects/metfusion_tp/BTs/MetFusion_ChemSp_mfs/naringenin.mf"); //File file = new File("/home/mgerlich/projects/metfusion_tp/BTs/Known_BT_MSMS_ChemSp/1MeBT_MSMS.mf"); //File file = new File("/home/mgerlich/projects/metfusion_tp/BTs/Unknown_BT_MSMS_ChemSp/mf_with_substruct_formula/150m0655a_MSMS.mf"); File file = new File( "C:/Users/Michael/Dropbox/Eawag_IPB_Shared_MassBank/BTs/Unknown_BT_MSMS_ChemSp/mf_with_substruct_formula/192m0757b_MSMS.mf"); MetFusionBatchFileHandler mbf = new MetFusionBatchFileHandler(file); try { mbf.readFile(); } catch (IOException e) { //System.out.println(e.getMessage()); System.err.println( "Error reading from MetFusion settings file [" + file.getAbsolutePath() + "]. Aborting!"); System.exit(-1); } MetFusionBatchSettings settings = mbf.getBatchSettings(); List<String> absent = settings.getSubstrucAbsent(); List<String> present = settings.getSubstrucPresent(); for (String s : present) { System.out.println("present -> " + s); } for (String s : absent) { System.out.println("absent -> " + s); } String formula = settings.getMfFormula(); System.out.println("formula -> " + formula); boolean useFormulaAsQuery = true; boolean useSDF = false; String sdfFile = ""; if (useSDF) { sdfFile = "C:/Users/Michael/Dropbox/Eawag_IPB_Shared_MassBank/BTs/Unknown_BT_MSMS_ChemSp/mf_with_substruct_formula/results_afterFormulaQuery/192m0757b_MSMS.sdf"; if (sdfFile.isEmpty()) { // TODO alternatively use SDF file from query file? System.err.println("SDF file needs to be specified! Exiting."); System.exit(-1); } } SubstructureSearch ss = new SubstructureSearch(present, absent, token, formula, mbf, useFormulaAsQuery, useSDF, sdfFile); ss.run(); List<ResultSubstructure> remaining = ss.getResultsRemaining(); List<Result> resultsForSDF = new ArrayList<Result>(); StringBuilder sb = new StringBuilder(); String sep = ","; for (ResultSubstructure rs : remaining) { sb.append(rs.getId()).append(sep); Result r = new Result(rs.getPort(), rs.getId(), rs.getName(), rs.getScore()); r.setMol(rs.getMol()); r.setSmiles(rs.getSmiles()); r.setInchi(rs.getInchi()); r.setInchikey(rs.getInchikey()); resultsForSDF.add(r); } String ids = sb.toString(); String fileSep = System.getProperty("file.separator"); if (!ids.isEmpty()) { ids = ids.substring(0, ids.length() - 1); System.out.println("ids -> " + ids); settings.setMfDatabaseIDs(ids); String filename = file.getName(); String prefix = filename.substring(0, filename.lastIndexOf(".")); filename = filename.replace(prefix, prefix + "_ids"); String dir = file.getParent(); System.out.println("dir -> " + dir); if (!dir.endsWith(fileSep)) dir += fileSep; File output = new File(file.getParent(), filename); mbf.writeFile(output, settings); SDFOutputHandler so = new SDFOutputHandler(dir + prefix + ".sdf"); boolean writeOK = so.writeOriginalResults(resultsForSDF, false); if (!writeOK) System.err.println("Error writing SDF [" + so.getFilename()); } }
From source file:at.tuwien.ifs.somtoolbox.apps.helper.VectorSimilarityWriter.java
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException, SOMToolboxException { JSAPResult config = OptionFactory.parseResults(args, OptionFactory.OPTIONS_INPUT_SIMILARITY_COMPUTER); String inputVectorDistanceMatrix = config.getString("inputVectorDistanceMatrix"); String inputVectorFileName = config.getString("inputVectorFile"); int numNeighbours = config.getInt("numberNeighbours"); String outputFormat = config.getString("outputFormat"); InputVectorDistanceMatrix matrix = null; InputData data = new SOMLibSparseInputData(inputVectorFileName); if (StringUtils.isNotBlank(inputVectorDistanceMatrix)) { matrix = InputVectorDistanceMatrix.initFromFile(inputVectorDistanceMatrix); } else {/*from ww w .j a v a2 s .co m*/ String metricName = config.getString("metric"); DistanceMetric metric = AbstractMetric.instantiate(metricName); matrix = new LeightWeightMemoryInputVectorDistanceMatrix(data, metric); } String outputFileName = config.getString("output"); PrintWriter w = FileUtils.openFileForWriting("Similarity File", outputFileName); if (outputFormat.equals("SAT-DB")) { // find feature type String type = ""; if (inputVectorFileName.endsWith(".rh") || inputVectorFileName.endsWith(".rp") || inputVectorFileName.endsWith(".ssd")) { type = "_" + inputVectorFileName.substring(inputVectorFileName.lastIndexOf(".") + 1); } w.println("INSERT INTO `sat_track_similarity_ifs" + type + "` (`TRACKID`, `SIMILARITYCOUNT`, `SIMILARITYIDS`) VALUES "); } int numVectors = matrix.numVectors(); // numVectors = 10; // for testing StdErrProgressWriter progress = new StdErrProgressWriter(numVectors, "Writing similarities for vector ", 1); for (int i = 0; i < numVectors; i++) { int[] nearest = matrix.getNNearest(i, numNeighbours); if (outputFormat.equals("SAT-DB")) { w.print(" (" + i + " , NULL, '"); for (int j = 0; j < nearest.length; j++) { String label = data.getLabel(nearest[j]); w.print(label.replace(".mp3", "")); // strip ending if (j + 1 < nearest.length) { w.print(","); } else { w.print("')"); } } if (i + 1 < numVectors) { w.print(","); } } else { w.print(data.getLabel(i) + ","); for (int j = 0; j < nearest.length; j++) { w.print(data.getLabel(nearest[j])); if (j + 1 < nearest.length) { w.print(","); } } } w.println(); w.flush(); progress.progress(); } if (outputFormat.equals("SAT-DB")) { w.print(";"); } w.flush(); w.close(); }
From source file:com.samsung.sjs.Compiler.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException, SolverException, InterruptedException { boolean debug = false; boolean use_gc = true; CompilerOptions.Platform p = CompilerOptions.Platform.Native; CompilerOptions opts = null;//from w w w . ja va 2 s . c o m boolean field_opts = false; boolean typecheckonly = false; boolean showconstraints = false; boolean showconstraintsolution = false; String[] decls = null; String[] links = null; String[] objs = null; boolean guest = false; boolean stop_at_c = false; String external_compiler = null; boolean encode_vals = false; boolean x32 = false; boolean validate = true; boolean interop = false; boolean boot_interop = false; boolean oldExpl = false; String explanationStrategy = null; boolean efl = false; Options options = new Options(); options.addOption("debugcompiler", false, "Enable compiler debug spew"); //options.addOption("o", true, "Set compiler output file (must be .c)"); options.addOption(OptionBuilder //.withArgName("o") .withLongOpt("output-file").withDescription("Output file (must be .c)").hasArg().withArgName("file") .create("o")); options.addOption(OptionBuilder.withLongOpt("target") .withDescription("Select target platform: 'native' or 'web'").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("gc") .withDescription("Disable GC: param is 'on' (default) or 'off'").hasArg().create()); options.addOption(OptionBuilder .withDescription("Enable field access optimizations: param is 'true' (default) or 'false'").hasArg() .create("Xfields")); options.addOption(OptionBuilder .withDescription("Compile for encoded values. TEMPORARY. For testing interop codegen").hasArg() .create("XEncodedValues")); options.addOption(OptionBuilder.withLongOpt("typecheck-only") .withDescription("Only typecheck the file, don't compile").create()); options.addOption(OptionBuilder.withLongOpt("show-constraints") .withDescription("Show constraints generated during type inference").create()); options.addOption(OptionBuilder.withLongOpt("show-constraint-solution") .withDescription("Show solution to type inference constraints").create()); options.addOption(OptionBuilder.withLongOpt("extra-decls") .withDescription("Specify extra declaration files, comma-separated").hasArg() .withValueSeparator(',').create()); options.addOption(OptionBuilder.withLongOpt("native-libs") .withDescription("Specify extra linkage files, comma-separated").hasArg().withValueSeparator(',') .create()); Option extraobjs = OptionBuilder.withLongOpt("extra-objs") .withDescription("Specify extra .c/.cpp files, comma-separated").hasArg().withValueSeparator(',') .create(); extraobjs.setArgs(Option.UNLIMITED_VALUES); options.addOption(extraobjs); options.addOption(OptionBuilder.withLongOpt("guest-runtime") .withDescription( "Emit code to be called by another runtime (i.e., main() is written in another language).") .create()); options.addOption(OptionBuilder.withLongOpt("only-c") .withDescription("Generate C code, but do not attempt to compile it").create()); options.addOption(OptionBuilder.withLongOpt("c-compiler") .withDescription("Disable GC: param is 'on' (default) or 'off'").hasArg().create("cc")); options.addOption(OptionBuilder.withLongOpt("runtime-src") .withDescription("Specify path to runtime system source").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("ext-path") .withDescription("Specify path to external dependency dir (GC, etc.)").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("skip-validation") .withDescription("Run the backend without validating the results of type inference").create()); options.addOption(OptionBuilder.withLongOpt("m32").withDescription("Force 32-bit compilation").create()); options.addOption(OptionBuilder.withLongOpt("Xbootinterop") .withDescription("Programs start with global interop dirty flag set (experimental)").create()); options.addOption(OptionBuilder.withLongOpt("Xinterop") .withDescription("Enable (experimental) interoperability backend").create()); options.addOption(OptionBuilder.withDescription("C compiler default optimization level").create("O")); options.addOption(OptionBuilder.withDescription("C compiler optimization level 0").create("O0")); options.addOption(OptionBuilder.withDescription("C compiler optimization level 1").create("O1")); options.addOption(OptionBuilder.withDescription("C compiler optimization level 2").create("O2")); options.addOption(OptionBuilder.withDescription("C compiler optimization level 3").create("O3")); options.addOption( OptionBuilder.withLongOpt("oldExpl").withDescription("Use old error explanations").create()); String explanationStrategyHelp = "default: " + FixingSetFinder.defaultStrategy() + "; other choices: " + FixingSetFinder.strategyNames().stream().filter(s -> !s.equals(FixingSetFinder.defaultStrategy())) .collect(Collectors.joining(", ")); options.addOption(OptionBuilder.withLongOpt("explanation-strategy") .withDescription("Error explanation strategy to use (" + explanationStrategyHelp + ')').hasArg() .create()); options.addOption( OptionBuilder.withLongOpt("efl").withDescription("Set up efl environment in main()").create()); try { CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); String[] newargs = cmd.getArgs(); if (newargs.length != 1) { throw new ParseException("Invalid number of arguments"); } String sourcefile = newargs[0]; if (!sourcefile.endsWith(".js")) { throw new ParseException("Invalid file extension on input file: " + sourcefile); } String gc = cmd.getOptionValue("gc", "on"); if (gc.equals("on")) { use_gc = true; } else if (gc.equals("off")) { use_gc = false; } else { throw new ParseException("Invalid GC option: " + gc); } String fields = cmd.getOptionValue("Xfields", "true"); if (fields.equals("true")) { field_opts = true; } else if (fields.equals("false")) { field_opts = false; } else { throw new ParseException("Invalid field optimization option: " + fields); } String encoding = cmd.getOptionValue("XEncodedValues", "false"); if (encoding.equals("true")) { encode_vals = true; } else if (encoding.equals("false")) { encode_vals = false; } else { throw new ParseException("Invalid value encoding option: " + encode_vals); } String plat = cmd.getOptionValue("target", "native"); if (plat.equals("native")) { p = CompilerOptions.Platform.Native; } else if (plat.equals("web")) { p = CompilerOptions.Platform.Web; } else { throw new ParseException("Invalid target platform: " + plat); } if (cmd.hasOption("cc")) { external_compiler = cmd.getOptionValue("cc"); } if (cmd.hasOption("skip-validation")) { validate = false; } if (cmd.hasOption("typecheck-only")) { typecheckonly = true; } if (cmd.hasOption("show-constraints")) { showconstraints = true; } if (cmd.hasOption("show-constraint-solution")) { showconstraintsolution = true; } if (cmd.hasOption("debugcompiler")) { debug = true; } if (cmd.hasOption("m32")) { x32 = true; } if (cmd.hasOption("Xinterop")) { interop = true; } if (cmd.hasOption("Xbootinterop")) { boot_interop = true; if (!interop) { System.err.println("WARNING: --Xbootinterop enabled without --Xinterop (no effect)"); } } if (cmd.hasOption("oldExpl")) { oldExpl = true; } if (cmd.hasOption("explanation-strategy")) { explanationStrategy = cmd.getOptionValue("explanation-strategy"); } String output = cmd.getOptionValue("o"); if (output == null) { output = sourcefile.replaceFirst(".js$", ".c"); } else { if (!output.endsWith(".c")) { throw new ParseException("Invalid file extension on output file: " + output); } } String runtime_src = cmd.getOptionValue("runtime-src"); String ext_path = cmd.getOptionValue("ext-path"); if (ext_path == null) { ext_path = new File(".").getCanonicalPath() + "/external"; } if (cmd.hasOption("extra-decls")) { decls = cmd.getOptionValues("extra-decls"); } if (cmd.hasOption("native-libs")) { links = cmd.getOptionValues("native-libs"); } if (cmd.hasOption("extra-objs")) { objs = cmd.getOptionValues("extra-objs"); } if (cmd.hasOption("guest-runtime")) { guest = true; } if (cmd.hasOption("only-c")) { stop_at_c = true; } if (cmd.hasOption("efl")) { efl = true; } int coptlevel = -1; // default optimization if (cmd.hasOption("O3")) { coptlevel = 3; } else if (cmd.hasOption("O2")) { coptlevel = 2; } else if (cmd.hasOption("O1")) { coptlevel = 1; } else if (cmd.hasOption("O0")) { coptlevel = 0; } else if (cmd.hasOption("O")) { coptlevel = -1; } else { coptlevel = 3; } if (!Files.exists(Paths.get(sourcefile))) { System.err.println("File " + sourcefile + " was not found."); throw new FileNotFoundException(sourcefile); } String cwd = new java.io.File(".").getCanonicalPath(); opts = new CompilerOptions(p, sourcefile, debug, output, use_gc, external_compiler == null ? "clang" : external_compiler, external_compiler == null ? "emcc" : external_compiler, cwd + "/a.out", // emcc automatically adds .js new File(".").getCanonicalPath(), true, field_opts, showconstraints, showconstraintsolution, runtime_src, encode_vals, x32, oldExpl, explanationStrategy, efl, coptlevel); if (guest) { opts.setGuestRuntime(); } if (interop) { opts.enableInteropMode(); } if (boot_interop) { opts.startInInteropMode(); } opts.setExternalDeps(ext_path); if (decls != null) { for (String s : decls) { Path fname = FileSystems.getDefault().getPath(s); opts.addDeclarationFile(fname); } } if (links != null) { for (String s : links) { Path fname = FileSystems.getDefault().getPath(s); opts.addLinkageFile(fname); } } if (objs == null) { objs = new String[0]; } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sjsc", options); } if (opts != null) { // This typechecks, and depending on flags, also generates C compile(opts, typecheckonly, validate); // don't worry about type validation on command line for now if (!typecheckonly && !stop_at_c) { int ret = 0; // Kept around for debugging 32-bit... if (p == CompilerOptions.Platform.Native) { if (opts.m32()) { String[] x = new String[2]; x[0] = "-m32"; x[1] = opts.getExternalDeps() + "/gc/x86/lib/libgc.a"; ret = clang_compile(opts, objs, x); } else { ret = clang_compile(opts, objs, new String[0]); } } else { ret = emcc_compile(opts, objs, new String[0]); } // If clang failed, propagate the failure outwards if (ret != 0) { System.exit(ret); } } } }
From source file:com.milaboratory.mitcr.cli.Main.java
public static void main(String[] args) { int o = 0;/*w w w . j av a 2 s.c o m*/ BuildInformation buildInformation = BuildInformationProvider.get(); final boolean isProduction = "default".equals(buildInformation.scmBranch); // buildInformation.version != null && buildInformation.version.lastIndexOf("SNAPSHOT") < 0; orderingMap.put(PARAMETERS_SET_OPTION, o++); orderingMap.put(SPECIES_OPTION, o++); orderingMap.put(GENE_OPTION, o++); orderingMap.put(ERROR_CORECTION_LEVEL_OPTION, o++); orderingMap.put(QUALITY_THRESHOLD_OPTION, o++); orderingMap.put(AVERAGE_QUALITY_OPTION, o++); orderingMap.put(LQ_OPTION, o++); orderingMap.put(CLUSTERIZATION_OPTION, o++); orderingMap.put(INCLUDE_CYS_PHE_OPTION, o++); orderingMap.put(LIMIT_OPTION, o++); orderingMap.put(EXPORT_OPTION, o++); orderingMap.put(REPORT_OPTION, o++); orderingMap.put(REPORTING_LEVEL_OPTION, o++); orderingMap.put(PHRED33_OPTION, o++); orderingMap.put(PHRED64_OPTION, o++); orderingMap.put(THREADS_OPTION, o++); orderingMap.put(COMPRESSED_OPTION, o++); orderingMap.put(PRINT_HELP_OPTION, o++); orderingMap.put(PRINT_VERSION_OPTION, o++); orderingMap.put(PRINT_DEBUG_OPTION, o++); options.addOption(OptionBuilder.withArgName("preset name").hasArg() .withDescription("preset of pipeline parameters to use").create(PARAMETERS_SET_OPTION)); options.addOption(OptionBuilder.withArgName("species").hasArg() .withDescription("overrides species ['hs' for Homo sapiens, 'mm' for us Mus musculus] " + "(default for built-in presets is 'hs')") .create(SPECIES_OPTION)); options.addOption(OptionBuilder.withArgName("gene").hasArg() .withDescription("overrides gene: TRB or TRA (default value for built-in parameter sets is TRB)") .create(GENE_OPTION)); options.addOption(OptionBuilder.withArgName("0|1|2").hasArg() .withDescription( "overrides error correction level (0 = don't correct errors, 1 = correct sequenecing " + "errors only (see -" + QUALITY_THRESHOLD_OPTION + " and -" + LQ_OPTION + " options for details), " + "2 = also correct PCR errors (see -" + CLUSTERIZATION_OPTION + " option)") .create(ERROR_CORECTION_LEVEL_OPTION)); options.addOption(OptionBuilder.withArgName("value").hasArg().withDescription( "overrides quality threshold value for segment alignment and bad quality sequences " + "correction algorithms. 0 tells the program not to process quality information. (default is 25)") .create(QUALITY_THRESHOLD_OPTION)); if (!isProduction) options.addOption(OptionBuilder.hasArg(false) .withDescription("use this option to output average instead of " + "maximal, quality for CDR3 nucleotide sequences. (Experimental option, use with caution.)") .create(AVERAGE_QUALITY_OPTION)); options.addOption(OptionBuilder.withArgName("map | drop").hasArg() .withDescription("overrides low quality CDR3s processing strategy (drop = filter off, " + "map = map onto clonotypes created from the high quality CDR3s). This option makes no difference if " + "quality threshold (-" + QUALITY_THRESHOLD_OPTION + " option) is set to 0, or error correction " + "level (-" + ERROR_CORECTION_LEVEL_OPTION + ") is 0.") .create(LQ_OPTION)); options.addOption(OptionBuilder.withArgName("smd | ete").hasArg() .withDescription("overrides the PCR error correction algorithm: smd = \"save my diversity\", " + "ete = \"eliminate these errors\". Default value for built-in parameters is ete.") .create(CLUSTERIZATION_OPTION)); options.addOption(OptionBuilder.withArgName("0|1").hasArg() .withDescription("overrides weather include bounding Cys & Phe into CDR3 sequence") .create(INCLUDE_CYS_PHE_OPTION)); options.addOption( OptionBuilder.withArgName("# of reads").hasArg() .withDescription("limits the number of input sequencing reads, use this parameter to " + "normalize several datasets or to have a glance at the data") .create(LIMIT_OPTION)); options.addOption(OptionBuilder.withArgName("new name").hasArg() .withDescription("use this option to export presets to a local xml files").create(EXPORT_OPTION)); options.addOption(OptionBuilder.withArgName("file name").hasArg() .withDescription("use this option to write analysis report (summary) to file") .create(REPORT_OPTION)); options.addOption(OptionBuilder.withArgName("1|2|3").hasArg(true) .withDescription("output detalization level (1 = simple, 2 = medium, 3 = full, this format " + "could be deserialized using mitcr API). Affects only tab-delimited output. Default value is 3.") .create(REPORTING_LEVEL_OPTION)); options.addOption(OptionBuilder.hasArg(false).withDescription( "add this option if input file is in old illumina format with 64 byte offset for quality " + "string (MiTCR will try to automatically detect file format if one of the \"-phredXX\" options is not provided)") .create(PHRED64_OPTION)); options.addOption(OptionBuilder.hasArg(false) .withDescription("add this option if input file is in Phred+33 format for quality values " + "(MiTCR will try to automatically detect file format if one of the \"-phredXX\" options is not provided)") .create(PHRED33_OPTION)); options.addOption(OptionBuilder.withArgName("threads").hasArg() .withDescription( "specifies the number of CDR3 extraction threads (default = number of available CPU cores)") .create(THREADS_OPTION)); if (!isProduction) options.addOption(OptionBuilder.hasArg(false) .withDescription("use compressed data structures for storing individual " + "clone segments statistics (from which arises the clone segment information). This option reduces required " + "amount of memory, but introduces small stochastic errors into the algorithm which determines clone " + "segments. (Experimental option, use with caution.)") .create(COMPRESSED_OPTION)); options.addOption( OptionBuilder.hasArg(false).withDescription("print this message").create(PRINT_HELP_OPTION)); options.addOption(OptionBuilder.hasArg(false).withDescription("print version information") .create(PRINT_VERSION_OPTION)); options.addOption(OptionBuilder.hasArg(false) .withDescription("print additional information about analysis process").create(PRINT_DEBUG_OPTION)); PosixParser parser = new PosixParser(); try { long input_limit = -1; int threads = Runtime.getRuntime().availableProcessors(); int reporting_level = 3; int ec_level = 2; CommandLine cl = parser.parse(options, args, true); if (cl.hasOption(PRINT_HELP_OPTION)) { printHelp(); return; } boolean averageQuality = cl.hasOption(AVERAGE_QUALITY_OPTION), compressedAggregators = cl.hasOption(COMPRESSED_OPTION); if (cl.hasOption(PRINT_VERSION_OPTION)) { System.out.println("MiTCR by MiLaboratory, version: " + buildInformation.version); System.out.println("Branch: " + buildInformation.scmBranch); System.out.println("Built: " + buildInformation.buildDate + ", " + buildInformation.jdk + " JDK, " + "build machine: " + buildInformation.builtBy); System.out.println("SCM changeset: " + buildInformation.scmChangeset + " (" + buildInformation.scmDate.replace("\"", "") + ")"); return; } //Normal execution String paramName = cl.getOptionValue(PARAMETERS_SET_OPTION); if (paramName == null) { err.println("No parameters set is specified."); return; } Parameters params = ParametersIO.getParameters(paramName); if (params == null) { err.println("No parameters set found with name '" + paramName + "'."); return; } String value; if ((value = cl.getOptionValue(THREADS_OPTION)) != null) threads = Integer.decode(value); if ((value = cl.getOptionValue(REPORTING_LEVEL_OPTION)) != null) reporting_level = Integer.decode(value); if ((value = cl.getOptionValue(LIMIT_OPTION)) != null) input_limit = Long.decode(value); if ((value = cl.getOptionValue(GENE_OPTION)) != null) params.setGene(Gene.fromXML(value)); if ((value = cl.getOptionValue(SPECIES_OPTION)) != null) params.setSpecies(Species.getFromShortName(value)); if ((value = cl.getOptionValue(INCLUDE_CYS_PHE_OPTION)) != null) { if (value.equals("1")) params.getCDR3ExtractorParameters().setIncludeCysPhe(true); else if (value.equals("0")) params.getCDR3ExtractorParameters().setIncludeCysPhe(false); else { err.println("Illegal value for -" + INCLUDE_CYS_PHE_OPTION + " parameter."); return; } } if ((value = cl.getOptionValue(ERROR_CORECTION_LEVEL_OPTION)) != null) { int v = Integer.decode(value); ec_level = v; if (v == 0) { params.setCloneGeneratorParameters(new BasicCloneGeneratorParameters()); params.setClusterizationType(CloneClusterizationType.None); } else if (v == 1) { params.setCloneGeneratorParameters(new LQMappingCloneGeneratorParameters()); params.setClusterizationType(CloneClusterizationType.None); } else if (v == 2) { params.setCloneGeneratorParameters(new LQMappingCloneGeneratorParameters()); params.setClusterizationType(CloneClusterizationType.OneMismatch, .1f); } else throw new RuntimeException("This (" + v + ") error correction level is not supported."); } if ((value = cl.getOptionValue(QUALITY_THRESHOLD_OPTION)) != null) { int v = Integer.decode(value); if (v == 0) params.setQualityInterpretationStrategy(new DummyQualityInterpretationStrategy()); else params.setQualityInterpretationStrategy(new IlluminaQualityInterpretationStrategy((byte) v)); } if ((value = cl.getOptionValue(LQ_OPTION)) != null) if (ec_level > 0) switch (value) { case "map": params.setCloneGeneratorParameters(new LQMappingCloneGeneratorParameters( ((BasicCloneGeneratorParameters) params.getCloneGeneratorParameters()) .getSegmentInformationAggregationFactor(), 3, true)); break; case "drop": params.setCloneGeneratorParameters(new LQFilteringOffCloneGeneratorParameters( ((BasicCloneGeneratorParameters) params.getCloneGeneratorParameters()) .getSegmentInformationAggregationFactor())); break; default: throw new RuntimeException("Wrong value for -" + LQ_OPTION + " option."); } if ((value = cl.getOptionValue(CLUSTERIZATION_OPTION)) != null) if (ec_level > 1) // == 2 switch (value) { case "smd": params.setClusterizationType(CloneClusterizationType.V2D1J2T3Explicit); break; case "ete": params.setClusterizationType(CloneClusterizationType.OneMismatch); break; default: throw new RuntimeException("Wrong value for -" + CLUSTERIZATION_OPTION + " option."); } ((BasicCloneGeneratorParameters) params.getCloneGeneratorParameters()) .setAccumulatorType(AccumulatorType.get(compressedAggregators, averageQuality)); if ((value = cl.getOptionValue(EXPORT_OPTION)) != null) { //Exporting parameters ParametersIO.exportParameters(params, value); return; } String[] offArgs = cl.getArgs(); if (offArgs.length == 0) { err.println("Input file not specified."); return; } else if (offArgs.length == 1) { err.println("Output file not specified."); return; } else if (offArgs.length > 2) { err.println("Unrecognized argument."); return; } String inputFileName = offArgs[0]; String outputFileName = offArgs[1]; File input = new File(inputFileName); if (!input.exists()) { err.println("Input file not found."); return; } //TODO This also done inside SFastqReader constructor CompressionType compressionType = CompressionType.None; if (inputFileName.endsWith(".gz")) compressionType = CompressionType.GZIP; QualityFormat format = null; // If variable remains null file format will be detected automatically if (cl.hasOption(PHRED33_OPTION)) format = QualityFormat.Phred33; if (cl.hasOption(PHRED64_OPTION)) if (format == null) format = QualityFormat.Phred64; else { err.println( "Options: -" + PHRED33_OPTION + " and -" + PHRED64_OPTION + " are mutually exclusive"); return; } SFastqReader reads = format == null ? new SFastqReader(input, compressionType) : new SFastqReader(input, format, compressionType); OutputPort<SSequencingRead> inputToPipeline = reads; if (input_limit >= 0) inputToPipeline = new CountLimitingOutputPort<>(inputToPipeline, input_limit); SegmentLibrary library = DefaultSegmentLibrary.load(); AnalysisStatisticsAggregator statisticsAggregator = new AnalysisStatisticsAggregator(); FullPipeline pipeline = new FullPipeline(inputToPipeline, params, false, library); pipeline.setThreads(threads); pipeline.setAnalysisListener(statisticsAggregator); new Thread(new SmartProgressReporter(pipeline, err)).start(); // Printing status to the standard error stream pipeline.run(); if (cl.hasOption(PRINT_DEBUG_OPTION)) { err.println("Memory = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())); err.println("Clusterization: " + pipeline.getQC().getReadsClusterized() + "% of reads, " + pipeline.getQC().getClonesClusterized() + " % clones"); } CloneSetClustered cloneSet = pipeline.getResult(); if ((value = cl.getOptionValue(REPORT_OPTION)) != null) { File file = new File(value); TablePrintStreamAdapter table; if (file.exists()) table = new TablePrintStreamAdapter(new FileOutputStream(file, true)); else { table = new TablePrintStreamAdapter(file); ReportExporter.printHeader(table); } //CloneSetQualityControl qc = new CloneSetQualityControl(library, params.getSpecies(), params.getGene(), cloneSet); ReportExporter.printRow(table, inputFileName, outputFileName, pipeline.getQC(), statisticsAggregator); table.close(); } if (outputFileName.endsWith(".cls")) ClsExporter.export(pipeline, outputFileName.replace(".cls", "") + " " + new Date().toString(), input.getName(), outputFileName); else { //Dry run if (outputFileName.startsWith("-")) return; ExportDetalizationLevel detalization = ExportDetalizationLevel.fromLevel(reporting_level); CompressionType compressionType1 = CompressionType.None; if (outputFileName.endsWith(".gz")) compressionType1 = CompressionType.GZIP; CloneSetIO.exportCloneSet(outputFileName, cloneSet, detalization, params, input.getAbsolutePath(), compressionType1); } } catch (ParseException | RuntimeException | IOException e) { err.println("Error occurred in the analysis pipeline."); err.println(); e.printStackTrace(); //printHelp(); } }
From source file:se.technipelago.weather.chart.Generator.java
public static void main(String[] args) { Generator generator = new Generator(); if (args.length > 0) { String outputDir = args[0]; if (outputDir.endsWith("/")) { outputDir = outputDir.substring(0, outputDir.length() - 1); }//from w w w.jav a2 s .co m generator.setOutputDirectory(outputDir); } // Generate charts. generator.init(); Map<String, Object> data = generator.getWeatherData(); generator.generateCurrentCharts(data); generator.generateHistoryCharts(-30, 31); int year = Calendar.getInstance().get(Calendar.YEAR); generator.generateMonthlyCharts(year); generator.generateYearlyCharts(year); }
From source file:com.justgiving.raven.kissmetrics.utils.KissmetricsLocalSchemaExtractor.java
public static void main(String[] args) throws FileNotFoundException, IOException { for (String s : args) { System.out.println(s);//from w w w . j a v a2 s . c o m } //String inputFolder ="D:\\datasets\\kissmetrics\\input\\2250.json"; //String outputFile ="D:\\datasets\\kissmetrics\\output\\2250.json"; //String inputFolder ="D:\\datasets\\kissmetrics\\input\\"; //String inputFolder ="D:\\ouptuts\\km\\input\\"; //String inputFolder ="D:\\datasets\\kissmetrics\\input4\\revisions\\"; //String inputFolder ="D:\\datasets\\kissmetrics\\input5\\"; //String outputFile ="D:\\datasets\\kissmetrics\\output\\"; //String inputFolder ="D:\\datasets\\kinesis\\input2\\"; //String outputFile ="D:\\datasets\\kissmetrics\\output\\schema2.txt"; //String inputFolder ="D:\\datasets\\kissmetrics\\stg\\input\\"; //String outputFile ="D:\\datasets\\kissmetrics\\stg\\ouput\\schema1.txt"; String inputFolder = "D:\\datasets\\kinesis\\stg\\input2\\"; String outputFile = "D:\\datasets\\kinesis\\stg\\output2\\schema-kinesis.txt"; //String inputFolder ="D:\\datasets\\kissmetrics\\prd\\input1\\"; //String outputFile ="D:\\datasets\\kissmetrics\\prd\\output1\\schema-kissmetrics.txt"; if (args.length != 2) { System.out.println("No arguments provided, using default values"); System.out.println("InputFolder/File: " + inputFolder); System.out.println("OutputFile: " + outputFile); } else { inputFolder = args[0]; outputFile = args[1]; } if ((new File(outputFile)).isDirectory()) { System.err.println("Error output file cannot be a directory"); return; } String logConfigPath = Paths.get(System.getProperty("user.dir"), "log4j.properties").toString(); System.out.println("log config file used: " + logConfigPath); PropertyConfigurator.configure(logConfigPath); logger.info("log config file used: " + logConfigPath); if (inputFolder.endsWith("\\")) { logger.info("Detected source folder"); countKeysInJsonRecordsFolder(inputFolder, outputFile); } else { logger.info("Detected source file"); countKeysInJsonRecordsFile(inputFolder); } }
From source file:Gen.java
public static void main(String[] args) throws Exception { try {//w w w. j av a 2 s . c o m File[] files = null; if (System.getProperty("dir") != null && !System.getProperty("dir").equals("")) { files = new File(System.getProperty("dir")).listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.toUpperCase().endsWith(".XML"); }; }); } else { String fileName = System.getProperty("file") != null && !System.getProperty("file").equals("") ? System.getProperty("file") : "rjmap.xml"; files = new File[] { new File(fileName) }; } log.info("files : " + Arrays.toString(files)); if (files == null || files.length == 0) { log.info("no files to parse"); System.exit(0); } boolean formatsource = true; if (System.getProperty("formatsource") != null && !System.getProperty("formatsource").equals("") && System.getProperty("formatsource").equalsIgnoreCase("false")) { formatsource = false; } GEN_ROOT = System.getProperty("outputdir"); if (GEN_ROOT == null || GEN_ROOT.equals("")) { GEN_ROOT = new File(files[0].getAbsolutePath()).getParent() + FILE_SEPARATOR + "distrib"; } GEN_ROOT = new File(GEN_ROOT).getAbsolutePath().replace('\\', '/'); if (GEN_ROOT.endsWith("/")) GEN_ROOT = GEN_ROOT.substring(0, GEN_ROOT.length() - 1); System.out.println("GEN ROOT:" + GEN_ROOT); MAPPING_JAR_NAME = System.getProperty("mappingjar") != null && !System.getProperty("mappingjar").equals("") ? System.getProperty("mappingjar") : "mapping.jar"; if (!MAPPING_JAR_NAME.endsWith(".jar")) MAPPING_JAR_NAME += ".jar"; GEN_ROOT_SRC = GEN_ROOT + FILE_SEPARATOR + "src"; GEN_ROOT_LIB = GEN_ROOT + FILE_SEPARATOR + ""; DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); domFactory.setValidating(false); DocumentBuilder documentBuilder = domFactory.newDocumentBuilder(); for (int f = 0; f < files.length; ++f) { log.info("parsing file : " + files[f]); Document document = documentBuilder.parse(files[f]); Vector<Node> initNodes = new Vector<Node>(); Utils.catchNodes(Utils.catchNode(document.getDocumentElement(), "scripts"), "initScript", initNodes); for (int i = 0; i < initNodes.size(); ++i) { NamedNodeMap attrs = initNodes.elementAt(i).getAttributes(); boolean embed = attrs.getNamedItem("embed") != null && attrs.getNamedItem("embed").getNodeValue().equalsIgnoreCase("true"); StringBuffer vbuffer = new StringBuffer(); if (attrs.getNamedItem("inline") != null) { vbuffer.append(attrs.getNamedItem("inline").getNodeValue()); vbuffer.append('\n'); } else { String fname = attrs.getNamedItem("name").getNodeValue(); if (!fname.startsWith("\\") && !fname.startsWith("/") && fname.toCharArray()[1] != ':') { String path = files[f].getAbsolutePath(); path = path.substring(0, path.lastIndexOf(FILE_SEPARATOR)); fname = new File(path + FILE_SEPARATOR + fname).getCanonicalPath(); } vbuffer.append(Utils.getFileAsStringBuffer(fname)); } initScriptBuffer.append(vbuffer); if (embed) embedScriptBuffer.append(vbuffer); } Vector<Node> packageInitNodes = new Vector<Node>(); Utils.catchNodes(Utils.catchNode(document.getDocumentElement(), "scripts"), "packageScript", packageInitNodes); for (int i = 0; i < packageInitNodes.size(); ++i) { NamedNodeMap attrs = packageInitNodes.elementAt(i).getAttributes(); String packageName = attrs.getNamedItem("package").getNodeValue(); if (packageName.equals("")) packageName = "rGlobalEnv"; if (!packageName.endsWith("Function")) packageName += "Function"; if (packageEmbedScriptHashMap.get(packageName) == null) { packageEmbedScriptHashMap.put(packageName, new StringBuffer()); } StringBuffer vbuffer = packageEmbedScriptHashMap.get(packageName); // if (!packageName.equals("rGlobalEnvFunction")) { // vbuffer.append("library("+packageName.substring(0,packageName.lastIndexOf("Function"))+")\n"); // } if (attrs.getNamedItem("inline") != null) { vbuffer.append(attrs.getNamedItem("inline").getNodeValue() + "\n"); initScriptBuffer.append(attrs.getNamedItem("inline").getNodeValue() + "\n"); } else { String fname = attrs.getNamedItem("name").getNodeValue(); if (!fname.startsWith("\\") && !fname.startsWith("/") && fname.toCharArray()[1] != ':') { String path = files[f].getAbsolutePath(); path = path.substring(0, path.lastIndexOf(FILE_SEPARATOR)); fname = new File(path + FILE_SEPARATOR + fname).getCanonicalPath(); } StringBuffer fileBuffer = Utils.getFileAsStringBuffer(fname); vbuffer.append(fileBuffer); initScriptBuffer.append(fileBuffer); } } Vector<Node> functionsNodes = new Vector<Node>(); Utils.catchNodes(Utils.catchNode(document.getDocumentElement(), "functions"), "function", functionsNodes); for (int i = 0; i < functionsNodes.size(); ++i) { NamedNodeMap attrs = functionsNodes.elementAt(i).getAttributes(); String functionName = attrs.getNamedItem("name").getNodeValue(); boolean forWeb = attrs.getNamedItem("forWeb") != null && attrs.getNamedItem("forWeb").getNodeValue().equalsIgnoreCase("true"); String signature = (attrs.getNamedItem("signature") == null ? "" : attrs.getNamedItem("signature").getNodeValue() + ","); String renameTo = (attrs.getNamedItem("renameTo") == null ? null : attrs.getNamedItem("renameTo").getNodeValue()); HashMap<String, FAttributes> sigMap = Globals._functionsToPublish.get(functionName); if (sigMap == null) { sigMap = new HashMap<String, FAttributes>(); Globals._functionsToPublish.put(functionName, sigMap); if (attrs.getNamedItem("returnType") == null) { _functionsVector.add(new String[] { functionName }); } else { _functionsVector.add( new String[] { functionName, attrs.getNamedItem("returnType").getNodeValue() }); } } sigMap.put(signature, new FAttributes(renameTo, forWeb)); if (forWeb) _webPublishingEnabled = true; } if (System.getProperty("targetjdk") != null && !System.getProperty("targetjdk").equals("") && System.getProperty("targetjdk").compareTo("1.5") < 0) { if (_webPublishingEnabled || (System.getProperty("ws.r.api") != null && System.getProperty("ws.r.api").equalsIgnoreCase("true"))) { log.info("be careful, web publishing disabled beacuse target JDK<1.5"); } _webPublishingEnabled = false; } else { if (System.getProperty("ws.r.api") == null || System.getProperty("ws.r.api").equals("") || !System.getProperty("ws.r.api").equalsIgnoreCase("false")) { _webPublishingEnabled = true; } if (_webPublishingEnabled && System.getProperty("java.version").compareTo("1.5") < 0) { log.info("be careful, web publishing disabled beacuse a JDK<1.5 is in use"); _webPublishingEnabled = false; } } Vector<Node> s4Nodes = new Vector<Node>(); Utils.catchNodes(Utils.catchNode(document.getDocumentElement(), "s4classes"), "class", s4Nodes); if (s4Nodes.size() > 0) { String formalArgs = ""; String signature = ""; for (int i = 0; i < s4Nodes.size(); ++i) { NamedNodeMap attrs = s4Nodes.elementAt(i).getAttributes(); String s4Name = attrs.getNamedItem("name").getNodeValue(); formalArgs += "p" + i + (i == s4Nodes.size() - 1 ? "" : ","); signature += "'" + s4Name + "'" + (i == s4Nodes.size() - 1 ? "" : ","); } String genBeansScriptlet = "setGeneric('" + PUBLISH_S4_HEADER + "', function(" + formalArgs + ") standardGeneric('" + PUBLISH_S4_HEADER + "'));" + "setMethod('" + PUBLISH_S4_HEADER + "', signature(" + signature + ") , function(" + formalArgs + ") { })"; initScriptBuffer.append(genBeansScriptlet); _functionsVector.add(new String[] { PUBLISH_S4_HEADER, "numeric" }); } } if (!new File(GEN_ROOT_LIB).exists()) regenerateDir(GEN_ROOT_LIB); else { clean(GEN_ROOT_LIB, true); } for (int i = 0; i < rwebservicesScripts.length; ++i) DirectJNI.getInstance().getRServices().sourceFromResource(rwebservicesScripts[i]); String lastStatus = DirectJNI.getInstance().runR(new ExecutionUnit() { public void run(Rengine e) { DirectJNI.getInstance().toggleMarker(); DirectJNI.getInstance().sourceFromBuffer(initScriptBuffer.toString()); log.info(" init script status : " + DirectJNI.getInstance().cutStatusSinceMarker()); for (int i = 0; i < _functionsVector.size(); ++i) { String[] functionPair = _functionsVector.elementAt(i); log.info("dealing with : " + functionPair[0]); regenerateDir(GEN_ROOT_SRC); String createMapStr = "createMap("; boolean isGeneric = e.rniGetBoolArrayI( e.rniEval(e.rniParse("isGeneric(\"" + functionPair[0] + "\")", 1), 0))[0] == 1; log.info("is Generic : " + isGeneric); if (isGeneric) { createMapStr += functionPair[0]; } else { createMapStr += "\"" + functionPair[0] + "\""; } createMapStr += ", outputDirectory=\"" + GEN_ROOT_SRC .substring(0, GEN_ROOT_SRC.length() - "/src".length()).replace('\\', '/') + "\""; createMapStr += ", typeMode=\"robject\""; createMapStr += (functionPair.length == 1 || functionPair[1] == null || functionPair[1].trim().equals("") ? "" : ", S4DefaultTypedSig=TypedSignature(returnType=\"" + functionPair[1] + "\")"); createMapStr += ")"; log.info("------------------------------------------"); log.info("-- createMapStr=" + createMapStr); DirectJNI.getInstance().toggleMarker(); e.rniEval(e.rniParse(createMapStr, 1), 0); String createMapStatus = DirectJNI.getInstance().cutStatusSinceMarker(); log.info(" createMap status : " + createMapStatus); log.info("------------------------------------------"); deleteDir(GEN_ROOT_SRC + "/org/kchine/r/rserviceJms"); compile(GEN_ROOT_SRC); jar(GEN_ROOT_SRC, GEN_ROOT_LIB + FILE_SEPARATOR + TEMP_JARS_PREFIX + i + ".jar", null); URL url = null; try { url = new URL( "jar:file:" + (GEN_ROOT_LIB + FILE_SEPARATOR + TEMP_JARS_PREFIX + i + ".jar") .replace('\\', '/') + "!/"); } catch (Exception ex) { ex.printStackTrace(); } DirectJNI.generateMaps(url, true); } } }); log.info(lastStatus); log.info(DirectJNI._rPackageInterfacesHash); regenerateDir(GEN_ROOT_SRC); for (int i = 0; i < _functionsVector.size(); ++i) { unjar(GEN_ROOT_LIB + FILE_SEPARATOR + TEMP_JARS_PREFIX + i + ".jar", GEN_ROOT_SRC); } regenerateRPackageClass(true); generateS4BeanRef(); if (formatsource) applyJalopy(GEN_ROOT_SRC); compile(GEN_ROOT_SRC); for (String k : DirectJNI._rPackageInterfacesHash.keySet()) { Rmic rmicTask = new Rmic(); rmicTask.setProject(_project); rmicTask.setTaskName("rmic_packages"); rmicTask.setClasspath(new Path(_project, GEN_ROOT_SRC)); rmicTask.setBase(new File(GEN_ROOT_SRC)); rmicTask.setClassname(k + "ImplRemote"); rmicTask.init(); rmicTask.execute(); } // DirectJNI._rPackageInterfacesHash=new HashMap<String, // Vector<Class<?>>>(); // DirectJNI._rPackageInterfacesHash.put("org.bioconductor.packages.rGlobalEnv.rGlobalEnvFunction",new // Vector<Class<?>>()); if (_webPublishingEnabled) { jar(GEN_ROOT_SRC, GEN_ROOT_LIB + FILE_SEPARATOR + "__temp.jar", null); URL url = new URL( "jar:file:" + (GEN_ROOT_LIB + FILE_SEPARATOR + "__temp.jar").replace('\\', '/') + "!/"); ClassLoader cl = new URLClassLoader(new URL[] { url }, Globals.class.getClassLoader()); for (String className : DirectJNI._rPackageInterfacesHash.keySet()) { if (cl.loadClass(className + "Web").getDeclaredMethods().length == 0) continue; log.info("######## " + className); WsGen wsgenTask = new WsGen(); wsgenTask.setProject(_project); wsgenTask.setTaskName("wsgen"); FileSet rjb_fileSet = new FileSet(); rjb_fileSet.setProject(_project); rjb_fileSet.setDir(new File(".")); rjb_fileSet.setIncludes("RJB.jar"); DirSet src_dirSet = new DirSet(); src_dirSet.setDir(new File(GEN_ROOT_LIB + FILE_SEPARATOR + "src/")); Path classPath = new Path(_project); classPath.addFileset(rjb_fileSet); classPath.addDirset(src_dirSet); wsgenTask.setClasspath(classPath); wsgenTask.setKeep(true); wsgenTask.setDestdir(new File(GEN_ROOT_LIB + FILE_SEPARATOR + "src/")); wsgenTask.setResourcedestdir(new File(GEN_ROOT_LIB + FILE_SEPARATOR + "src/")); wsgenTask.setSei(className + "Web"); wsgenTask.init(); wsgenTask.execute(); } new File(GEN_ROOT_LIB + FILE_SEPARATOR + "__temp.jar").delete(); } embedRScripts(); HashMap<String, String> marker = new HashMap<String, String>(); marker.put("RJBMAPPINGJAR", "TRUE"); Properties props = new Properties(); props.put("PACKAGE_NAMES", PoolUtils.objectToHex(DirectJNI._packageNames)); props.put("S4BEANS_MAP", PoolUtils.objectToHex(DirectJNI._s4BeansMapping)); props.put("S4BEANS_REVERT_MAP", PoolUtils.objectToHex(DirectJNI._s4BeansMappingRevert)); props.put("FACTORIES_MAPPING", PoolUtils.objectToHex(DirectJNI._factoriesMapping)); props.put("S4BEANS_HASH", PoolUtils.objectToHex(DirectJNI._s4BeansHash)); props.put("R_PACKAGE_INTERFACES_HASH", PoolUtils.objectToHex(DirectJNI._rPackageInterfacesHash)); props.put("ABSTRACT_FACTORIES", PoolUtils.objectToHex(DirectJNI._abstractFactories)); new File(GEN_ROOT_SRC + "/" + "maps").mkdirs(); FileOutputStream fos = new FileOutputStream(GEN_ROOT_SRC + "/" + "maps/rjbmaps.xml"); props.storeToXML(fos, null); fos.close(); jar(GEN_ROOT_SRC, GEN_ROOT_LIB + FILE_SEPARATOR + MAPPING_JAR_NAME, marker); if (_webPublishingEnabled) genWeb(); DirectJNI._mappingClassLoader = null; } finally { System.exit(0); } }
From source file:ms1quant.MS1Quant.java
/** * @param args the command line arguments MS1Quant parameterfile *///from ww w. ja v a 2s . c o m public static void main(String[] args) throws Exception { BufferedReader reader = null; try { System.out.println( "================================================================================================="); System.out.println("Umpire MS1 quantification and feature detection analysis (version: " + UmpireInfo.GetInstance().Version + ")"); if (args.length < 3 || !args[1].startsWith("-mode")) { System.out .println("command : java -jar -Xmx10G MS1Quant.jar ms1quant.params -mode[1 or 2] [Option]"); System.out.println("\n-mode"); System.out.println("\t1:Single file mode--> mzXML_file PepXML_file"); System.out.println("\t\tEx: -mode1 file1.mzXML file1.pep.xml"); System.out.println( "\t2:Folder mode--> mzXML_Folder PepXML_Folder, all generated csv tables will be merged into a single csv file"); System.out.println("\t\tEx: -mode2 /data/mzxml/ /data/pepxml/"); System.out.println("\nOptions"); System.out.println( "\t-C\tNo of concurrent files to be processed (only for folder mode), Ex. -C5, default:1"); System.out.println("\t-p\tMinimum probability, Ex. -p0.9, default:0.9"); System.out.println("\t-ID\tDetect identified feature only"); System.out.println("\t-O\toutput folder, Ex. -O/data/"); return; } ConsoleLogger consoleLogger = new ConsoleLogger(); consoleLogger.SetConsoleLogger(Level.DEBUG); consoleLogger.SetFileLogger(Level.DEBUG, FilenameUtils.getFullPath(args[0]) + "ms1quant_debug.log"); Logger logger = Logger.getRootLogger(); logger.debug("Command: " + Arrays.toString(args)); logger.info("MS1Quant version: " + UmpireInfo.GetInstance().Version); String parameterfile = args[0]; logger.info("Parameter file: " + parameterfile); File paramfile = new File(parameterfile); if (!paramfile.exists()) { logger.error("Parameter file " + paramfile.getAbsolutePath() + " cannot be found. The program will exit."); } reader = new BufferedReader(new FileReader(paramfile.getAbsolutePath())); String line = ""; InstrumentParameter param = new InstrumentParameter(InstrumentParameter.InstrumentType.TOF5600); int NoCPUs = 2; int NoFile = 1; param.DetermineBGByID = false; param.EstimateBG = true; //<editor-fold defaultstate="collapsed" desc="Read parameter file"> while ((line = reader.readLine()) != null) { if (!"".equals(line) && !line.startsWith("#")) { logger.info(line); //System.out.println(line); if (line.split("=").length < 2) { continue; } if (line.split("=").length < 2) { continue; } String type = line.split("=")[0].trim(); if (type.startsWith("para.")) { type = type.replace("para.", "SE."); } String value = line.split("=")[1].trim(); switch (type) { case "Thread": { NoCPUs = Integer.parseInt(value); break; } //<editor-fold defaultstate="collapsed" desc="instrument parameters"> case "SE.MS1PPM": { param.MS1PPM = Float.parseFloat(value); break; } case "SE.MS2PPM": { param.MS2PPM = Float.parseFloat(value); break; } case "SE.SN": { param.SNThreshold = Float.parseFloat(value); break; } case "SE.MS2SN": { param.MS2SNThreshold = Float.parseFloat(value); break; } case "SE.MinMSIntensity": { param.MinMSIntensity = Float.parseFloat(value); break; } case "SE.MinMSMSIntensity": { param.MinMSMSIntensity = Float.parseFloat(value); break; } case "SE.MinRTRange": { param.MinRTRange = Float.parseFloat(value); break; } case "SE.MaxNoPeakCluster": { param.MaxNoPeakCluster = Integer.parseInt(value); param.MaxMS2NoPeakCluster = Integer.parseInt(value); break; } case "SE.MinNoPeakCluster": { param.MinNoPeakCluster = Integer.parseInt(value); param.MinMS2NoPeakCluster = Integer.parseInt(value); break; } case "SE.MinMS2NoPeakCluster": { param.MinMS2NoPeakCluster = Integer.parseInt(value); break; } case "SE.MaxCurveRTRange": { param.MaxCurveRTRange = Float.parseFloat(value); break; } case "SE.Resolution": { param.Resolution = Integer.parseInt(value); break; } case "SE.RTtol": { param.RTtol = Float.parseFloat(value); break; } case "SE.NoPeakPerMin": { param.NoPeakPerMin = Integer.parseInt(value); break; } case "SE.StartCharge": { param.StartCharge = Integer.parseInt(value); break; } case "SE.EndCharge": { param.EndCharge = Integer.parseInt(value); break; } case "SE.MS2StartCharge": { param.MS2StartCharge = Integer.parseInt(value); break; } case "SE.MS2EndCharge": { param.MS2EndCharge = Integer.parseInt(value); break; } case "SE.NoMissedScan": { param.NoMissedScan = Integer.parseInt(value); break; } case "SE.Denoise": { param.Denoise = Boolean.valueOf(value); break; } case "SE.EstimateBG": { param.EstimateBG = Boolean.valueOf(value); break; } case "SE.RemoveGroupedPeaks": { param.RemoveGroupedPeaks = Boolean.valueOf(value); break; } case "SE.MinFrag": { param.MinFrag = Integer.parseInt(value); break; } case "SE.IsoPattern": { param.IsoPattern = Float.valueOf(value); break; } case "SE.StartRT": { param.startRT = Float.valueOf(value); } case "SE.EndRT": { param.endRT = Float.valueOf(value); } //</editor-fold> } } } //</editor-fold> int mode = 1; if (args[1].equals("-mode2")) { mode = 2; } else if (args[1].equals("-mode1")) { mode = 1; } else { logger.error("-mode number not recongized. The program will exit."); } String mzXML = ""; String pepXML = ""; String mzXMLPath = ""; String pepXMLPath = ""; File mzXMLfile = null; File pepXMLfile = null; File mzXMLfolder = null; File pepXMLfolder = null; int idx = 0; if (mode == 1) { mzXML = args[2]; logger.info("Mode1 mzXML file: " + mzXML); mzXMLfile = new File(mzXML); if (!mzXMLfile.exists()) { logger.error("Mode1 mzXML file " + mzXMLfile.getAbsolutePath() + " cannot be found. The program will exit."); return; } pepXML = args[3]; logger.info("Mode1 pepXML file: " + pepXML); pepXMLfile = new File(pepXML); if (!pepXMLfile.exists()) { logger.error("Mode1 pepXML file " + pepXMLfile.getAbsolutePath() + " cannot be found. The program will exit."); return; } idx = 4; } else if (mode == 2) { mzXMLPath = args[2]; logger.info("Mode2 mzXML folder: " + mzXMLPath); mzXMLfolder = new File(mzXMLPath); if (!mzXMLfolder.exists()) { logger.error("Mode2 mzXML folder " + mzXMLfolder.getAbsolutePath() + " does not exist. The program will exit."); return; } pepXMLPath = args[3]; logger.info("Mode2 pepXML folder: " + pepXMLPath); pepXMLfolder = new File(pepXMLPath); if (!pepXMLfolder.exists()) { logger.error("Mode2 pepXML folder " + pepXMLfolder.getAbsolutePath() + " does not exist. The program will exit."); return; } idx = 4; } String outputfolder = ""; float MinProb = 0f; for (int i = idx; i < args.length; i++) { if (args[i].startsWith("-")) { if (args[i].equals("-ID")) { param.TargetIDOnly = true; logger.info("Detect ID feature only: true"); } if (args[i].startsWith("-O")) { outputfolder = args[i].substring(2); logger.info("Output folder: " + outputfolder); File outputfile = new File(outputfolder); if (!outputfolder.endsWith("\\") | outputfolder.endsWith("/")) { outputfolder += "/"; } if (!outputfile.exists()) { outputfile.mkdir(); } } if (args[i].startsWith("-C")) { try { NoFile = Integer.parseInt(args[i].substring(2)); logger.info("No of concurrent files: " + NoFile); } catch (Exception ex) { logger.error(args[i] + " is not a correct integer format, will process only one file at a time."); } } if (args[i].startsWith("-p")) { try { MinProb = Float.parseFloat(args[i].substring(2)); logger.info("probability threshold: " + MinProb); } catch (Exception ex) { logger.error(args[i] + " is not a correct format, will use 0 as threshold instead."); } } } } reader.close(); TandemParam tandemparam = new TandemParam(DBSearchParam.SearchInstrumentType.TOF5600); PTMManager.GetInstance(); if (param.TargetIDOnly) { param.EstimateBG = false; param.ApexDelta = 1.5f; param.NoMissedScan = 10; param.MiniOverlapP = 0.2f; param.RemoveGroupedPeaks = false; param.CheckMonoIsotopicApex = false; param.DetectByCWT = false; param.FillGapByBK = false; param.IsoCorrThreshold = -1f; param.SmoothFactor = 3; } if (mode == 1) { logger.info("Processing " + mzXMLfile.getAbsolutePath() + "...."); long time = System.currentTimeMillis(); LCMSPeakMS1 LCMS1 = new LCMSPeakMS1(mzXMLfile.getAbsolutePath(), NoCPUs); LCMS1.SetParameter(param); LCMS1.Resume = false; if (!param.TargetIDOnly) { LCMS1.CreatePeakFolder(); } LCMS1.ExportPeakClusterTable = true; if (pepXMLfile.exists()) { tandemparam.InteractPepXMLPath = pepXMLfile.getAbsolutePath(); LCMS1.ParsePepXML(tandemparam, MinProb); logger.info("No. of PSMs included: " + LCMS1.IDsummary.PSMList.size()); logger.info("No. of Peptide ions included: " + LCMS1.IDsummary.GetPepIonList().size()); } if (param.TargetIDOnly) { LCMS1.SaveSerializationFile = false; } if (param.TargetIDOnly || !LCMS1.ReadPeakCluster()) { LCMS1.PeakClusterDetection(); } if (pepXMLfile.exists()) { LCMS1.AssignQuant(false); LCMS1.IDsummary.ExportPepID(outputfolder); } time = System.currentTimeMillis() - time; logger.info(LCMS1.ParentmzXMLName + " 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)))); LCMS1.BaseClearAllPeaks(); LCMS1.SetSpectrumParser(null); LCMS1.IDsummary = null; LCMS1 = null; System.gc(); } else if (mode == 2) { LCMSID IDsummary = new LCMSID("", "", ""); logger.info("Parsing all pepXML files in " + pepXMLPath + "...."); for (File file : pepXMLfolder.listFiles()) { if (file.getName().toLowerCase().endsWith("pep.xml") || file.getName().toLowerCase().endsWith("pepxml")) { PepXMLParser pepXMLParser = new PepXMLParser(IDsummary, file.getAbsolutePath(), MinProb); } } HashMap<String, LCMSID> LCMSIDMap = IDsummary.GetLCMSIDFileMap(); ExecutorService executorPool = null; executorPool = Executors.newFixedThreadPool(NoFile); logger.info("Processing all mzXML files in " + mzXMLPath + "...."); for (File file : mzXMLfolder.listFiles()) { if (file.getName().toLowerCase().endsWith("mzxml")) { LCMSID id = LCMSIDMap.get(FilenameUtils.getBaseName(file.getName())); if (id == null || id.PSMList == null) { logger.warn("No IDs found in :" + FilenameUtils.getBaseName(file.getName()) + ". Quantification for this file is skipped"); continue; } if (!id.PSMList.isEmpty()) { MS1TargetQuantThread thread = new MS1TargetQuantThread(file, id, NoCPUs, outputfolder, param); executorPool.execute(thread); } } } LCMSIDMap.clear(); LCMSIDMap = null; IDsummary = null; executorPool.shutdown(); try { executorPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { logger.info("interrupted.."); } if (outputfolder == null | outputfolder.equals("")) { outputfolder = mzXMLPath; } logger.info("Merging PSM files.."); File output = new File(outputfolder); FileWriter writer = new FileWriter(output.getAbsolutePath() + "/PSM_merge.csv"); boolean header = false; for (File csvfile : output.listFiles()) { if (csvfile.getName().toLowerCase().endsWith("_psms.csv")) { BufferedReader outreader = new BufferedReader(new FileReader(csvfile)); String outline = outreader.readLine(); if (!header) { writer.write(outline + "\n"); header = true; } while ((outline = outreader.readLine()) != null) { writer.write(outline + "\n"); } outreader.close(); csvfile.delete(); } } writer.close(); } logger.info("MS1 quant module is complete."); } catch (Exception e) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(e)); throw e; } }