List of usage examples for org.apache.commons.cli OptionBuilder withArgName
public static OptionBuilder withArgName(String name)
From source file:io.anserini.index.UserPostFrequencyDistribution.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(new Option(STORE_TERM_VECTORS_OPTION, "store term vectors")); options.addOption(OptionBuilder.withArgName("collection").hasArg() .withDescription("source collection directory").create(COLLECTION_OPTION)); options.addOption(OptionBuilder.withArgName("property").hasArg() .withDescription("source collection directory").create("property")); options.addOption(OptionBuilder.withArgName("collection_pattern").hasArg() .withDescription("source collection directory").create("collection_pattern")); CommandLine cmdline = null;//from w w w .j av a 2 s.c o m CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (cmdline.hasOption(HELP_OPTION) || !cmdline.hasOption(COLLECTION_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(UserPostFrequencyDistribution.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); final FieldType textOptions = new FieldType(); textOptions.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); textOptions.setStored(true); textOptions.setTokenized(true); textOptions.setStoreTermVectors(true); LOG.info("collection: " + collectionPath); LOG.info("collection_pattern " + cmdline.getOptionValue("collection_pattern")); LOG.info("property " + cmdline.getOptionValue("property")); LongOpenHashSet deletes = null; long startTime = System.currentTimeMillis(); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } final JsonStatusCorpusReader stream = new JsonStatusCorpusReader(file, cmdline.getOptionValue("collection_pattern")); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { stream.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ; System.out.println("# of users indexed this round: " + userIndexedCount); System.out.println("Shutting down"); } }); Status status; boolean readerNotInitialized = true; try { Properties prop = new Properties(); while ((status = stream.next()) != null) { // try{ // status = DataObjectFactory.createStatus(s); // if (status==null||status.getText() == null) { // continue; // }}catch(Exception e){ // // } // boolean pittsburghRelated = false; try { if (Math.abs(status.getLongitude() - pittsburghLongitude) < 0.05d && Math.abs(status.getlatitude() - pittsburghLatitude) < 0.05d) pittsburghRelated = true; } catch (Exception e) { } try { if (status.getPlace().contains("Pittsburgh, PA")) pittsburghRelated = true; } catch (Exception e) { } try { if (status.getUserLocation().contains("Pittsburgh, PA")) pittsburghRelated = true; } catch (Exception e) { } try { if (status.getText().contains("Pittsburgh")) pittsburghRelated = true; } catch (Exception e) { } if (pittsburghRelated) { int previousPostCount = 0; if (prop.containsKey(String.valueOf(status.getUserid()))) { previousPostCount = Integer .valueOf(prop.getProperty(String.valueOf(status.getUserid())).split(" ")[1]); } prop.setProperty(String.valueOf(status.getUserid()), String.valueOf(status.getStatusesCount()) + " " + (1 + previousPostCount)); if (prop.size() > 0 && prop.size() % 1000 == 0) { Runtime runtime = Runtime.getRuntime(); runtime.gc(); System.out.println("Property size " + prop.size() + "Memory used: " + ((runtime.totalMemory() - runtime.freeMemory()) / (1024L * 1024L)) + " MB\n"); } OutputStream output = new FileOutputStream(cmdline.getOptionValue("property"), false); prop.store(output, null); output.close(); } } // prop.store(output, null); LOG.info(String.format("Total of %s statuses added", userIndexedCount)); LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms"); } catch (Exception e) { e.printStackTrace(); } finally { stream.close(); } }
From source file:com.milaboratory.mitcr.cli.Main.java
public static void main(String[] args) { int o = 0;/*ww w .jav 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:net.sf.mpaxs.spi.computeHost.StartUp.java
/** * * @param args//from ww w. j a v a 2 s . co m */ public static void main(String args[]) { FileHandler handler; try { handler = new FileHandler("computeHost.log"); Logger logger = Logger.getLogger(StartUp.class.getName()); logger.addHandler(handler); } catch (IOException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } Options options = new Options(); Option[] optionArray = new Option[] { OptionBuilder.withArgName("configuration").hasArg().isRequired() .withDescription("URL to configuration file for compute host").create("c") }; for (Option opt : optionArray) { options.addOption(opt); } if (args.length == 0) { HelpFormatter hf = new HelpFormatter(); hf.printHelp(StartUp.class.getCanonicalName(), options, true); System.exit(1); } GnuParser gp = new GnuParser(); try { CommandLine cl = gp.parse(options, args); try { URL configURL = new URL(cl.getOptionValue("c")); PropertiesConfiguration cfg = new PropertiesConfiguration(configURL); StartUp su = new StartUp(cfg); } catch (ConfigurationException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParseException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.harvard.med.screensaver.io.Spammer.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { CommandLineApplication app = new CommandLineApplication(args); String[] option = MAIL_RECIPIENT_LIST_OPTION; app.addCommandLineOption(OptionBuilder.withType(Integer.class).hasArg().isRequired() .withArgName(option[SHORT_OPTION_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); option = MAIL_CC_LIST_OPTION;//www . j ava 2s. c om app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_REPLYTO_LIST_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_MESSAGE_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_FILE_ATTACHMENT; app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_SUBJECT_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_SERVER_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_USERNAME_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_USER_PASSWORD_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_FROM_OPTION; app.addCommandLineOption(OptionBuilder.hasArg().withArgName(option[SHORT_OPTION_INDEX]) .withDescription(option[DESCRIPTION_INDEX]).withLongOpt(option[LONG_OPTION_INDEX]) .create(option[SHORT_OPTION_INDEX])); option = MAIL_USE_SMTPS; app.addCommandLineOption( OptionBuilder.withArgName(option[SHORT_OPTION_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); app.processOptions(true, true); String message = app.getCommandLineOptionValue(MAIL_MESSAGE_OPTION[SHORT_OPTION_INDEX]); File attachedFile = null; if (app.isCommandLineFlagSet(MAIL_FILE_ATTACHMENT[SHORT_OPTION_INDEX])) { attachedFile = new File(app.getCommandLineOptionValue(MAIL_FILE_ATTACHMENT[SHORT_OPTION_INDEX])); if (!attachedFile.exists()) { log.error("Specified file does not exist: " + attachedFile.getCanonicalPath()); System.exit(1); } } String subject = app.getCommandLineOptionValue(MAIL_SUBJECT_OPTION[SHORT_OPTION_INDEX]); String recipientlist = app.getCommandLineOptionValue(MAIL_RECIPIENT_LIST_OPTION[SHORT_OPTION_INDEX]); String[] recipients = recipientlist.split(DELIMITER); String[] ccrecipients = null; if (app.isCommandLineFlagSet(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX])) { String cclist = app.getCommandLineOptionValue(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX]); ccrecipients = cclist.split(DELIMITER); } String replytos = null; if (app.isCommandLineFlagSet(MAIL_REPLYTO_LIST_OPTION[SHORT_OPTION_INDEX])) { replytos = app.getCommandLineOptionValue(MAIL_CC_LIST_OPTION[SHORT_OPTION_INDEX]); } String mailHost = app.getCommandLineOptionValue(MAIL_SERVER_OPTION[SHORT_OPTION_INDEX]); String username = app.getCommandLineOptionValue(MAIL_USERNAME_OPTION[SHORT_OPTION_INDEX]); String password = app.getCommandLineOptionValue(MAIL_USER_PASSWORD_OPTION[SHORT_OPTION_INDEX]); boolean useSmtps = app.isCommandLineFlagSet(MAIL_USE_SMTPS[SHORT_OPTION_INDEX]); String mailFrom = username; if (app.isCommandLineFlagSet(MAIL_FROM_OPTION[SHORT_OPTION_INDEX])) { mailFrom = app.getCommandLineOptionValue(MAIL_FROM_OPTION[SHORT_OPTION_INDEX]); } SmtpEmailService service = new SmtpEmailService(mailHost, username, replytos, password, useSmtps); service.send(subject, message, mailFrom, recipients, ccrecipients, attachedFile); }
From source file:edu.harvard.med.screensaver.io.screens.StudyCreator.java
@SuppressWarnings("static-access") public static void main(String[] args) { final CommandLineApplication app = new CommandLineApplication(args); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("first name") .withLongOpt("lead-screener-first-name").create("lf")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("last name") .withLongOpt("lead-screener-last-name").create("ll")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("email") .withLongOpt("lead-screener-email").create("le")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("first name") .withLongOpt("lab-head-first-name").create("hf")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("last name") .withLongOpt("lab-head-last-name").create("hl")); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("email") .withLongOpt("lab-head-email").create("he")); List<String> desc = new ArrayList<String>(); for (ScreenType t : EnumSet.allOf(ScreenType.class)) desc.add(t.name());/*from www. j a v a2 s . c o m*/ app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("screen type") .withLongOpt("screen-type").withDescription(StringUtils.makeListString(desc, ", ")).create("y")); desc.clear(); for (StudyType t : EnumSet.allOf(StudyType.class)) desc.add(t.name()); app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("study type") .withLongOpt("study-type").withDescription(StringUtils.makeListString(desc, ", ")).create("yy")); app.addCommandLineOption( OptionBuilder.hasArg().isRequired().withArgName("summary").withLongOpt("summary").create("s")); app.addCommandLineOption( OptionBuilder.hasArg().isRequired().withArgName("title").withLongOpt("title").create("t")); app.addCommandLineOption( OptionBuilder.hasArg().withArgName("protocol").withLongOpt("protocol").create("p")); app.addCommandLineOption( OptionBuilder.hasArg().isRequired().withArgName("#").withLongOpt("facilityId").create("i")); app.addCommandLineOption(OptionBuilder.hasArg(false).withLongOpt("replace") .withDescription("replace an existing Screen with the same facilityId").create("r")); app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-wellkey") .withDescription("default value is to key by reagent vendor id").create("keyByWellId")); app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-facility-id") .withDescription("default value is to key by reagent vendor id").create("keyByFacilityId")); app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-compound-name") .withDescription("default value is to key by reagent vendor id").create("keyByCompoundName")); app.addCommandLineOption(OptionBuilder.withDescription( "optional: pivot the input col/rows so that the AT names are in Col1, and the AT well_id/rvi's are in Row1") .withLongOpt("annotation-names-in-col1").create("annotationNamesInCol1")); app.addCommandLineOption(OptionBuilder.hasArg().withArgName("file").withLongOpt("data-file").create("f")); app.addCommandLineOption(OptionBuilder.withArgName("parseLincsSpecificFacilityID") .withLongOpt("parseLincsSpecificFacilityID").create("parseLincsSpecificFacilityID")); app.processOptions(/* acceptDatabaseOptions= */true, /* acceptAdminUserOptions= */true); execute(app); }
From source file:com.jones_systems.Tieout.java
public static void main(String[] args) { String testFilename = null;//from w w w. j a v a 2 s. c o m Options options = new Options(); //options.addOption("f", "filename", true, "the file to use for the Tieout check"); Option filename = OptionBuilder.withArgName("filename").hasArg() .withDescription("the file name of the XML test file").create("filename"); options.addOption(filename); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("filename")) { testFilename = line.getOptionValue("filename"); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("tieout", options); System.exit(2); } } catch (ParseException exp) { } File testfile = new File(testFilename); if (!testfile.exists()) { System.err.println("Cannot find file!"); System.exit(1); } System.out.println("Starting test with file: " + testFilename); Tieout ts = new Tieout(testfile); boolean connected = ts.connectDatasources(); if (!connected) { System.err.print("Could not connect to all datasources"); System.exit(1); } ts.runTests(); }
From source file:com.evolveum.midpoint.testing.model.client.sample.RunScript.java
/** * @param args/*from www. ja va2s . c o m*/ */ public static void main(String[] args) { try { Options options = new Options(); options.addOption(OPT_HELP, "help", false, "Print this help information"); options.addOption(OPT_SCRIPT, "script", true, "Script file (XML for the moment)"); options.addOption(OPT_URL, true, "Endpoint URL (default: " + DEFAULT_ENDPOINT_URL + ")"); options.addOption(OPT_USER, "user", true, "User name (default: " + ADM_USERNAME + ")"); options.addOption(OPT_PASSWORD, "password", true, "Password"); options.addOption(OPT_FILE_FOR_DATA, "file-for-data", true, "Name of the file to write resulting XML data into"); options.addOption(OPT_FILE_FOR_CONSOLE, "file-for-console", true, "Name of the file to write resulting console output into"); options.addOption(OPT_FILE_FOR_RESULT, "file-for-result", true, "Name of the file to write operation result into"); options.addOption(OPT_HIDE_DATA, "hide-data", false, "Don't display data output"); options.addOption(OPT_HIDE_SCRIPT, "hide-script", false, "Don't display input script"); options.addOption(OPT_HIDE_CONSOLE, "hide-console", false, "Don't display console output"); options.addOption(OPT_HIDE_RESULT, "hide-result", false, "Don't display detailed operation result (default: showing if not SUCCESS)"); options.addOption(OPT_SHOW_RESULT, "show-result", false, "Always show detailed operation result (default: showing if not SUCCESS)"); options.addOption(OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator() .withDescription("use value for given property").create("D")); CommandLineParser parser = new GnuParser(); CommandLine cmdline = parser.parse(options, args); if (!cmdline.hasOption(OPT_SCRIPT) || cmdline.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("runscript", options); System.exit(0); } ExecuteScriptsType request = new ExecuteScriptsType(); String script = readXmlFile(cmdline.getOptionValue(OPT_SCRIPT)); script = replaceParameters(script, cmdline.getOptionProperties("D")); request.setMslScripts(script); // todo fix this hack ExecuteScriptsOptionsType optionsType = new ExecuteScriptsOptionsType(); optionsType.setOutputFormat(OutputFormatType.MSL); // todo fix this hack request.setOptions(optionsType); if (!cmdline.hasOption(OPT_HIDE_SCRIPT)) { System.out.println("\nScript to execute:\n" + script); } System.out.println("================================================================="); ModelPortType modelPort = createModelPort(cmdline); ExecuteScriptsResponseType response = modelPort.executeScripts(request); System.out.println("================================================================="); for (SingleScriptOutputType output : response.getOutputs().getOutput()) { if (!cmdline.hasOption(OPT_HIDE_DATA)) { System.out.println("Data:\n" + output.getMslData()); System.out.println("-----------------------------------------------------------------"); } if (cmdline.hasOption(OPT_FILE_FOR_DATA)) { IOUtils.write(output.getMslData(), new FileOutputStream(cmdline.getOptionValue(OPT_FILE_FOR_DATA)), "UTF-8"); } if (!cmdline.hasOption(OPT_HIDE_CONSOLE)) { System.out.println("Console output:\n" + output.getTextOutput()); } if (cmdline.hasOption(OPT_HIDE_CONSOLE)) { IOUtils.write(output.getMslData(), new FileWriter(cmdline.getOptionValue(OPT_FILE_FOR_CONSOLE))); } } System.out.println("================================================================="); System.out.println("Operation result: " + getResultStatus(response.getResult())); if (!cmdline.hasOption(OPT_HIDE_RESULT) && (cmdline.hasOption(OPT_SHOW_RESULT) || response.getResult() == null || response.getResult().getStatus() != OperationResultStatusType.SUCCESS)) { System.out.println("\n\n" + marshalResult(response.getResult())); } if (cmdline.hasOption(OPT_FILE_FOR_RESULT)) { IOUtils.write(marshalResult(response.getResult()), new FileWriter(cmdline.getOptionValue(OPT_FILE_FOR_RESULT))); } } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }
From source file:com.github.r351574nc3.amex.assignment2.App.java
public static void main(final String... args) { if (args.length < 1) { printUsage();/*from w ww.j a v a 2 s . com*/ System.exit(0); } final Options options = new Options(); options.addOption(OptionBuilder.withArgName("test").hasArg(true).isRequired(true) .withDescription("Path for ARFF test data").create("t")); options.addOption(OptionBuilder.withArgName("output").hasArg(true).isRequired(true) .withDescription("Path for ARFF output").create("o")); options.addOption(OptionBuilder.withArgName("input").hasArg(true).isRequired(true) .withDescription("Path for ARFF input").create("i")); final CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.out.println(e.getMessage()); printUsage(); System.exit(0); } final String outputName = cmd.getOptionValue("o"); final String inputName = cmd.getOptionValue("i"); final String testName = cmd.getOptionValue("t"); final App app = new App(); try { if (args.length > 0) { app.setTrained(app.load(testName)); app.setTest(app.load(testName)); } } catch (Exception e) { error("There was an exception loading training and test datasets: %s", e.getMessage()); } try { app.train(); app.test(); } catch (Exception e) { error("There was an exception testing the model: %s", e.getMessage()); } try { app.predict(inputName, outputName); } catch (Exception e) { error("There was an exception predicting MPG: %s", e.getMessage()); e.printStackTrace(); } System.exit(0); }
From source file:ar.edu.taco.TacoMain.java
/** * @param args/*from w w w .j a va 2 s . co m*/ */ @SuppressWarnings({ "static-access" }) public static void main(String[] args) { @SuppressWarnings("unused") int loopUnrolling = 3; String tacoVersion = getManifestAttribute(Attributes.Name.IMPLEMENTATION_VERSION); String tacoCreatedBy = getManifestAttribute(new Name("Created-By")); System.out.println("TACO: Taco static analysis tool."); System.out.println("Created By: " + tacoCreatedBy); System.out.println("Version: " + tacoVersion); System.out.println(""); System.out.println(""); Option helpOption = new Option("h", "help", false, "print this message"); Option versionOption = new Option("v", "version", false, "shows version"); Option configFileOption = OptionBuilder.withArgName("path").withLongOpt("configFile").hasArg() .withDescription("set the configuration file").create("cf"); Option classToCheckOption = OptionBuilder.withArgName("classname").withLongOpt("classToCheck").hasArg() .withDescription("set the class to be checked").create('c'); Option methodToCheckOption = OptionBuilder.withArgName("methodname").withLongOpt("methodToCheck").hasArg() .withDescription("set the method to be checked").create('m'); Option dependenciesOption = OptionBuilder.withArgName("classname").withLongOpt("dependencies").hasArgs() .withDescription("additional sources to be parsed").create('d'); Option relevantClassesOption = OptionBuilder.withArgName("classname").withLongOpt("relevantClasses") .hasArgs().withDescription("Set the relevant classes to be used").create("rd"); Option loopsOptions = OptionBuilder.withArgName("integer").withLongOpt("unroll").hasArg() .withDescription("set number of loop unrollings").create('u'); Option bitOptions = OptionBuilder.withArgName("integer").withLongOpt("width").hasArg() .withDescription("set bit width").create('w'); Option instOptions = OptionBuilder.withArgName("integer").withLongOpt("bound").hasArg() .withDescription("set class bound").create('b'); Option skolemizeOption = OptionBuilder.withLongOpt("skolemize") .withDescription("set whether or not skolemize").create("sk"); Option simulateOption = OptionBuilder.withLongOpt("simulate") .withDescription("run method instead of checking").create("r"); Option modularReasoningOption = OptionBuilder.withLongOpt("modularReasoning") .withDescription("check method using modular reasoning").create("mr"); Option relevancyAnalysisOption = OptionBuilder.withLongOpt("relevancyAnalysis") .withDescription("calculate the needed relevantClasses").create("ra"); Option scopeRestrictionOption = OptionBuilder.withLongOpt("scopeRestriction") .withDescription("restrict signature scope to value set in -b option").create("sr"); /* * Option noVerifyOption = OptionBuilder.withLongOpt( * "noVerify").withDescription( * "builds output but does not invoke verification engine").create( * "nv"); */ Options options = new Options(); options.addOption(helpOption); options.addOption(versionOption); options.addOption(configFileOption); options.addOption(classToCheckOption); options.addOption(methodToCheckOption); options.addOption(dependenciesOption); options.addOption(relevantClassesOption); options.addOption(loopsOptions); options.addOption(bitOptions); options.addOption(instOptions); options.addOption(skolemizeOption); options.addOption(simulateOption); options.addOption(modularReasoningOption); options.addOption(relevancyAnalysisOption); options.addOption(scopeRestrictionOption); // options.addOption(noVerifyOption) String configFileArgument = null; Properties overridingProperties = new Properties(); TacoCustomScope tacoScope = new TacoCustomScope(); // create the parser CommandLineParser parser = new PosixParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); // help if (line.hasOption(helpOption.getOpt())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(120, CMD, HEADER, options, FOOTER, true); return; } // version if (line.hasOption(versionOption.getOpt())) { System.out.println(FOOTER); System.out.println(""); return; } // Configuration file if (line.hasOption(configFileOption.getOpt())) { configFileArgument = line.getOptionValue(configFileOption.getOpt()); } // class to check if (line.hasOption(classToCheckOption.getOpt())) { overridingProperties.put(TacoConfigurator.CLASS_TO_CHECK_FIELD, line.getOptionValue(classToCheckOption.getOpt())); } // method to check if (line.hasOption(methodToCheckOption.getOpt())) { String methodtoCheck = line.getOptionValue(methodToCheckOption.getOpt()); if (!methodtoCheck.matches("^[A-Za-z0-9_-]+_[0-9]")) { methodtoCheck = methodtoCheck + "_0"; } overridingProperties.put(TacoConfigurator.METHOD_TO_CHECK_FIELD, methodtoCheck); } // Dependencies classes if (line.hasOption(dependenciesOption.getOpt())) { String dependenciesClasses = ""; for (String aDependencyClass : line.getOptionValues(dependenciesOption.getOpt())) { dependenciesClasses += aDependencyClass; } overridingProperties.put(TacoConfigurator.CLASSES_FIELD, dependenciesClasses); } // Relevant classes if (line.hasOption(relevantClassesOption.getOpt())) { String relevantClasses = ""; for (String aRelevantClass : line.getOptionValues(relevantClassesOption.getOpt())) { relevantClasses += aRelevantClass; } overridingProperties.put(TacoConfigurator.RELEVANT_CLASSES, relevantClasses); } // Loop unrolling if (line.hasOption(loopsOptions.getOpt())) { loopUnrolling = Integer.parseInt(line.getOptionValue(loopsOptions.getOpt())); } // Int bitwidth if (line.hasOption(bitOptions.getOpt())) { String alloy_bitwidth_str = line.getOptionValue(bitOptions.getOpt()); overridingProperties.put(TacoConfigurator.BITWIDTH, alloy_bitwidth_str); int alloy_bitwidth = new Integer(alloy_bitwidth_str); tacoScope.setAlloyBitwidth(alloy_bitwidth); } // instances scope if (line.hasOption(instOptions.getOpt())) { String assertionsArguments = "for " + line.getOptionValue(instOptions.getOpt()); overridingProperties.put(TacoConfigurator.ASSERTION_ARGUMENTS, assertionsArguments); } // Skolemize if (line.hasOption(skolemizeOption.getOpt())) { overridingProperties.put(TacoConfigurator.SKOLEMIZE_INSTANCE_INVARIANT, false); overridingProperties.put(TacoConfigurator.SKOLEMIZE_INSTANCE_ABSTRACTION, false); } // Simulation if (line.hasOption(simulateOption.getOpt())) { overridingProperties.put(TacoConfigurator.INCLUDE_SIMULATION_PROGRAM_DECLARATION, true); overridingProperties.put(TacoConfigurator.GENERATE_CHECK, false); overridingProperties.put(TacoConfigurator.GENERATE_RUN, false); } // Modular Reasoning if (line.hasOption(modularReasoningOption.getOpt())) { overridingProperties.put(TacoConfigurator.MODULAR_REASONING, true); } // Relevancy Analysis if (line.hasOption(relevancyAnalysisOption.getOpt())) { overridingProperties.put(TacoConfigurator.RELEVANCY_ANALYSIS, true); } } catch (ParseException e) { System.err.println("Command line parsing failed: " + e.getMessage()); } try { System.out.println("****** Starting Taco (version. " + tacoVersion + ") ****** "); System.out.println(""); File file = new File("config/log4j.xml"); if (file.exists()) { DOMConfigurator.configure("config/log4j.xml"); } else { System.err.println("log4j:WARN File config/log4j.xml not found"); } TacoMain main = new TacoMain(); // BUILD TacoScope // main.run(configFileArgument, overridingProperties); } catch (IllegalArgumentException e) { System.err.println("Error found:"); System.err.println(e.getMessage()); } catch (MethodToCheckNotFoundException e) { System.err.println("Error found:"); System.err.println("Method to check was not found. Please verify config file, or add -m option"); } catch (TacoException e) { System.err.println("Error found:"); System.err.println(e.getMessage()); } }
From source file:edu.harvard.med.iccbl.screensaver.soaputils.PubchemChembankQueryUtility.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException, InterruptedException { final PubchemChembankQueryUtility app = new PubchemChembankQueryUtility(args); String[] option = LIBRARY_NAME; app.addCommandLineOption(/* www . ja v a 2 s.c o m*/ OptionBuilder.hasArg().withArgName(option[ARG_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); option = QUERY_ALL_LIBRARIES; app.addCommandLineOption( OptionBuilder.withArgName(option[ARG_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); option = OUTPUT_FILE; app.addCommandLineOption( OptionBuilder.hasArg().withArgName(option[ARG_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); option = TRY_LIMIT; app.addCommandLineOption( OptionBuilder.hasArg().withArgName(option[ARG_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); option = INTERVAL_BETWEEN_TRIES; app.addCommandLineOption( OptionBuilder.hasArg().withArgName(option[ARG_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); option = QUERY_PUBCHEM; app.addCommandLineOption( OptionBuilder.withArgName(option[ARG_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); option = QUERY_CHEMBANK; app.addCommandLineOption( OptionBuilder.withArgName(option[ARG_INDEX]).withDescription(option[DESCRIPTION_INDEX]) .withLongOpt(option[LONG_OPTION_INDEX]).create(option[SHORT_OPTION_INDEX])); try { if (!app.processOptions(/* acceptDatabaseOptions= */true, /* showHelpOnError= */true)) { return; } final boolean queryPubchem = app.isCommandLineFlagSet(QUERY_PUBCHEM[SHORT_OPTION_INDEX]); final boolean queryChembank = app.isCommandLineFlagSet(QUERY_CHEMBANK[SHORT_OPTION_INDEX]); if (!(queryPubchem || queryChembank)) { log.error("Must specify either " + QUERY_PUBCHEM[LONG_OPTION_INDEX] + " or " + QUERY_CHEMBANK[LONG_OPTION_INDEX]); app.showHelp(); return; } if (!app.isCommandLineFlagSet(LIBRARY_NAME[SHORT_OPTION_INDEX]) && !app.isCommandLineFlagSet(QUERY_ALL_LIBRARIES[SHORT_OPTION_INDEX])) { log.error("Must specify either " + LIBRARY_NAME[LONG_OPTION_INDEX] + " or " + QUERY_ALL_LIBRARIES[LONG_OPTION_INDEX]); app.showHelp(); return; } if (app.isCommandLineFlagSet(LIBRARY_NAME[SHORT_OPTION_INDEX]) && app.isCommandLineFlagSet(QUERY_ALL_LIBRARIES[SHORT_OPTION_INDEX])) { log.error("Must specify either " + LIBRARY_NAME[LONG_OPTION_INDEX] + " or " + QUERY_ALL_LIBRARIES[LONG_OPTION_INDEX]); app.showHelp(); return; } if (app.isCommandLineFlagSet(QUERY_ALL_LIBRARIES[SHORT_OPTION_INDEX]) && app.isCommandLineFlagSet(OUTPUT_FILE[SHORT_OPTION_INDEX])) { log.error("option \"" + OUTPUT_FILE[LONG_OPTION_INDEX] + "\" not allowed with \"" + QUERY_ALL_LIBRARIES[LONG_OPTION_INDEX] + "\" option."); app.showHelp(); return; } // if(app.isCommandLineFlagSet(LIBRARY_NAME[SHORT_OPTION_INDEX]) // && !app.isCommandLineFlagSet(OUTPUT_FILE[SHORT_OPTION_INDEX])) { // log.error("option \"" + OUTPUT_FILE[LONG_OPTION_INDEX] + "\" must be specified with \"" + LIBRARY_NAME[LONG_OPTION_INDEX] + "\" option."); // app.showHelp(); // return; // } final GenericEntityDAO dao = (GenericEntityDAO) app.getSpringBean("genericEntityDao"); dao.doInTransaction(new DAOTransaction() { public void runTransaction() { PrintWriter writer = null; PrintWriter errorWriter = null; try { int intervalMs = PugSoapUtil.INTERVAL_BETWEEN_TRIES_MS; if (app.isCommandLineFlagSet(INTERVAL_BETWEEN_TRIES[SHORT_OPTION_INDEX])) { intervalMs = app.getCommandLineOptionValue(INTERVAL_BETWEEN_TRIES[SHORT_OPTION_INDEX], Integer.class); } int numberOfTries = PugSoapUtil.TRY_LIMIT; if (app.isCommandLineFlagSet(TRY_LIMIT[SHORT_OPTION_INDEX])) { numberOfTries = app.getCommandLineOptionValue(TRY_LIMIT[SHORT_OPTION_INDEX], Integer.class); } List<Library> libraries = Lists.newArrayList(); if (app.isCommandLineFlagSet(LIBRARY_NAME[SHORT_OPTION_INDEX])) { String temp = app.getCommandLineOptionValue(LIBRARY_NAME[SHORT_OPTION_INDEX]); for (String libraryName : temp.split(",")) { Library library = dao.findEntityByProperty(Library.class, "shortName", libraryName.trim()); if (library == null) { throw new IllegalArgumentException( "no library with short name: " + libraryName); } libraries.add(library); } // if there is only one library to query, then set these values from the command line option if (libraries.size() == 1) { String outputFilename = app .getCommandLineOptionValue(OUTPUT_FILE[SHORT_OPTION_INDEX]); writer = app.getOutputFile(outputFilename); errorWriter = app.getOutputFile(outputFilename + ".errors"); } } else if (app.isCommandLineFlagSet(QUERY_ALL_LIBRARIES[SHORT_OPTION_INDEX])) { libraries = dao.findEntitiesByProperty(Library.class, "screenType", ScreenType.SMALL_MOLECULE); for (Iterator<Library> iter = libraries.iterator(); iter.hasNext();) { Library library = iter.next(); if (library.getLibraryType() == LibraryType.ANNOTATION || library.getLibraryType() == LibraryType.NATURAL_PRODUCTS) { iter.remove(); } } } Collections.sort(libraries, new NullSafeComparator<Library>() { @Override protected int doCompare(Library o1, Library o2) { return o1.getShortName().compareTo(o2.getShortName()); } }); List<String> libraryNames = Lists.transform(libraries, new Function<Library, String>() { @Override public String apply(Library from) { return from.getShortName(); } }); log.info("libraries to process:\n" + libraryNames); int i = 0; for (Library library : libraries) { if (writer == null || i > 0) { writer = app.getOutputFile(library.getShortName()); } if (errorWriter == null || i > 0) { errorWriter = app.getOutputFile(library.getShortName() + ".errors"); } log.info("\nProcessing the library: " + library.getShortName() + "\nlong name: " + library.getLibraryName() + "\noutput file: " + library.getShortName() + ".csv"); app.query(library, queryPubchem, queryChembank, dao, intervalMs, numberOfTries, writer, errorWriter); i++; } } catch (Exception e) { throw new DAOTransactionRollbackException(e); } finally { if (writer != null) writer.close(); if (errorWriter != null) errorWriter.close(); } } }); System.exit(0); } catch (ParseException e) { log.error("error parsing command line options: " + e.getMessage()); } }