List of usage examples for org.apache.commons.cli Option setRequired
public void setRequired(boolean required)
From source file:de.bruse.c2x.cli.Main.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = new Options(); Option input = new Option("i", INPUT, HAS_ARGS, "CityGML file to be converted."); input.setArgs(ONE);/*from w w w .jav a 2 s .co m*/ input.setArgName(INPUT); input.setRequired(Boolean.TRUE); options.addOption(input); Option levelOfDetail = new Option("l", LEVEL_OF_DETAIL, HAS_ARGS, "Level of detail to be converted. Possible values are LOD1 and LOD2."); levelOfDetail.setArgs(ONE); levelOfDetail.setArgName(LEVEL_OF_DETAIL); levelOfDetail.setRequired(Boolean.TRUE); options.addOption(levelOfDetail); Option geometryType = new Option("t", GEOMETRY_TYPE, HAS_ARGS, "Geometry type to be converted. Possible values are SOLID and MULTI_SURFACE."); geometryType.setArgs(ONE); geometryType.setArgName(GEOMETRY_TYPE); geometryType.setRequired(Boolean.TRUE); options.addOption(geometryType); Option output = new Option("o", OUTPUT, HAS_ARGS, "File path of the output file."); output.setArgs(ONE); output.setArgName(OUTPUT); output.setRequired(Boolean.FALSE); options.addOption(output); Option targetFormat = new Option("f", FORMAT, HAS_ARGS, "Format of the output file. Possible values are X3D and COLLADA."); targetFormat.setArgs(ONE); targetFormat.setArgName(FORMAT); targetFormat.setRequired(Boolean.TRUE); options.addOption(targetFormat); Option split = new Option("s", SPLIT, NO_ARGS, "Generate one scene node for each building (X3D only)."); split.setArgName(SPLIT); split.setRequired(Boolean.FALSE); options.addOption(split); Option validate = new Option("v", VALIDATE, NO_ARGS, "Validate the CityGML file."); validate.setArgName(VALIDATE); validate.setRequired(Boolean.FALSE); options.addOption(validate); try { CommandLine line = parser.parse(options, args); if (line.hasOption(INPUT) && line.hasOption(LEVEL_OF_DETAIL) && line.hasOption(GEOMETRY_TYPE) && line.hasOption(FORMAT)) { String inputValue = line.getOptionValue(INPUT); String levelOfDetailValue = line.getOptionValue(LEVEL_OF_DETAIL); String geometryTypeValue = line.getOptionValue(GEOMETRY_TYPE); String targetFormatValue = line.getOptionValue(FORMAT); String outputValue = line.getOptionValue(OUTPUT); LevelOfDetail lod = LevelOfDetail.valueOf(levelOfDetailValue); GeometryType type = GeometryType.valueOf(geometryTypeValue); if (Objects.isNull(lod) || Objects.isNull(type) || (!targetFormatValue.equals(X3D) && !targetFormatValue.equals(COLLADA))) { printHelp(options); } else { if (line.hasOption(VALIDATE)) { triggerValidation(inputValue); } if (targetFormatValue.equals(X3D)) { boolean splitValue = false; if (line.hasOption(SPLIT)) { splitValue = true; } if (Objects.isNull(outputValue) || outputValue.isEmpty()) { outputValue = inputValue + X3D_FILE_EXT; } triggerX3DConversion(inputValue, lod, type, outputValue, splitValue); } else if (targetFormatValue.equals(COLLADA)) { if (Objects.isNull(outputValue) || outputValue.isEmpty()) { outputValue = inputValue + COLLADA_FILE_EXT; } triggerColladaConversion(inputValue, lod, type, outputValue); } System.out.println("Conversion succeeded."); } } else { printHelp(options); } } catch (ParseException | IllegalArgumentException e) { printHelp(options); } catch (ValidationException e) { System.out.println("Input file is invalid. Operation canceled.\n" + e.getMessage()); } catch (ConversionException e) { String message = "Failed to convert CityGML."; if (Objects.nonNull(e.getMessage())) { message += " " + e.getMessage(); } System.out.println(message); } catch (IOException e) { System.out.println("Failed to read from file '" + input + "'."); } }
From source file:fr.inria.atlanmod.atl_mr.utils.NeoEMFHBaseMigrator.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file, both of xmi and zxmi extensions are supported"); inputOpt.setArgs(1);/*w ww . ja v a 2 s. com*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output HBase resource URI"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(E_PACKAGE); inClassOpt.setArgName("METAMODEL"); inClassOpt.setDescription("URI of the ecore Metamodel"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); URI targetUri = URI.createURI(commandLine.getOptionValue(OUT)); URI metamodelUri = URI.createFileURI(commandLine.getOptionValue(E_PACKAGE)); NeoEMFHBaseMigrator.class.getClassLoader().loadClass(commandLine.getOptionValue(E_PACKAGE)) .getMethod("init").invoke(null); //org.eclipse.gmt.modisco.java.kyanos.impl.JavaPackageImpl.init(); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(KyanosURI.KYANOS_HBASE_SCHEME, KyanosResourceFactory.eINSTANCE); //Registering the metamodel // Resource MMResource = resourceSet.createResource(metamodelUri); // MMResource.load(Collections.EMPTY_MAP); // ATLMRUtils.registerPackages(resourceSet, MMResource); //Loading the XMI resource Resource sourceResource = resourceSet.createResource(sourceUri); Map<String, Object> loadOpts = new HashMap<String, Object>(); if ("zxmi".equals(sourceUri.fileExtension())) { loadOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); } Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before loading: {0}", ATLMRUtils.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Loading source resource"); sourceResource.load(loadOpts); LOG.log(Level.INFO, "Source resource loaded"); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after loading: {0}", ATLMRUtils.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", ATLMRUtils.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); Resource targetResource = resourceSet.createResource(targetUri); Map<String, Object> saveOpts = new HashMap<String, Object>(); targetResource.save(saveOpts); LOG.log(Level.INFO, "Start moving elements"); targetResource.getContents().clear(); targetResource.getContents().addAll(sourceResource.getContents()); LOG.log(Level.INFO, "End moving elements"); LOG.log(Level.INFO, "Start saving"); targetResource.save(saveOpts); LOG.log(Level.INFO, "Saved"); if (targetResource instanceof KyanosHbaseResourceImpl) { KyanosHbaseResourceImpl.shutdownWithoutUnload((KyanosHbaseResourceImpl) targetResource); } else { targetResource.unload(); } } catch (ParseException e) { ATLMRUtils.showError(e.toString()); ATLMRUtils.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { ATLMRUtils.showError(e.toString()); e.printStackTrace(); } }
From source file:ca.uhn.hunit.example.MllpHl7v2MessageSwapper.java
public static void main(String[] theArgs) { Options options = new Options(); Option option = new Option("R", true, "Text to substiture in the message"); option.setArgs(2);/* w ww .jav a2s. c om*/ option.setArgName("text=substitution"); option.setValueSeparator('='); option.setRequired(true); options.addOption(option); option = new Option("p", true, "Number of passes"); option.setValueSeparator('='); option.setRequired(false); options.addOption(option); CommandLine commandLine; int passes; try { commandLine = new PosixParser().parse(options, theArgs); passes = Integer.parseInt(commandLine.getOptionValue("p", "1")); } catch (ParseException e) { HelpFormatter hf = new HelpFormatter(); hf.printHelp( "java -cp hunit-[version]-jar-with-dependencies.jar ca.uhn.hunit.example.MllpHl7v2MessageSwapper {-Rtext=substitution}... [options]", options); return; } Properties substitutions = commandLine.getOptionProperties("R"); new MllpHl7v2MessageSwapper(true, substitutions, passes).run(); }
From source file:com.genentech.chemistry.openEye.apps.SdfRMSDNNFinder.java
public static void main(String[] args) throws IOException { Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt);/*from w ww .j a va2 s .co m*/ opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_REFFILE, true, "Reference file containing poses from reference docking run. " + "If " + OPT_REFFILE + " not specified, program uses the input file " + "(internal NN analysis)"); options.addOption(opt); opt = new Option(OPT_MOLIdTag, true, "Name of the field containing the molecule identifier. " + " Assumption: Ref file uses the same field name."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_DONotOpt, false, "If specified the RMSD is computed without trying to optimize the alignment."); options.addOption(opt); opt = new Option(OPT_MIRROR, false, "For non-chiral molecules also try mirror image"); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (args.length != 0) { ; //error message } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); String refFile = cmd.getOptionValue(OPT_REFFILE); boolean noRefFile = false; if (refFile == null) { if (inFile.startsWith(".")) inFile = writeRefMolPosesToTempFile(inFile); refFile = inFile; noRefFile = true; } String molIdTag = cmd.getOptionValue(OPT_MOLIdTag); boolean doOptimize = !cmd.hasOption(OPT_DONotOpt); boolean doMirror = cmd.hasOption(OPT_MIRROR); SdfRMSDNNFinder nnFinder = new SdfRMSDNNFinder(refFile, outFile, molIdTag, doMirror, doOptimize, noRefFile); nnFinder.run(inFile); nnFinder.close(); }
From source file:com.genentech.chemistry.openEye.apps.SDFTorsionScanner.java
/** * @param args//w w w .j ava 2 s. c om */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "Output filename."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_STARTTorsion, true, "The torsion in your inMol will be rotated by this value for the first job"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_TORSIONIncrement, true, "Incremnt each subsequent conformation by this step size"); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_NSTEPS, true, "Number of conformations to create"); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_BONDFILE, true, "The file containing the bond atoms that define the torsion."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_MINIMIZE, false, "Minimize conformer at each step using MMFFs. If maxConfsPerStep is > 1, " + "all confs will be mimimized and the lowest E will be output."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_CONSTRIANT, true, "One of strong (90), medium (45), weak(20), none or a floating point number" + " to specify the tethered constraint strength for -minimize (def=strong)"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_MAXCONFS_PER_STEP, true, "While holding the torsion fixed, maximum number of conformations of free atoms to generat. default=1"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_COREFILE, true, "Outputfile to store guessed core."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_TORSIONS_ATOM_TAG, true, "Name of sdf tag which will contain the indices of atoms that define the torsion."); opt.setRequired(true); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (args.length != 0) { System.err.println("Unknown arguments" + args); exitWithHelp(options); } if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); String bondFile = cmd.getOptionValue(OPT_BONDFILE); String coreFilename = cmd.getOptionValue(OPT_COREFILE); String torsionAtomsTag = cmd.getOptionValue(OPT_TORSIONS_ATOM_TAG); int nSteps = Integer.parseInt(cmd.getOptionValue(OPT_NSTEPS)); int nStartTor = Integer.parseInt(cmd.getOptionValue(OPT_STARTTorsion)); int nTorIncr = Integer.parseInt(cmd.getOptionValue(OPT_TORSIONIncrement)); int nMaxConfsPerStep = 1; if (cmd.hasOption(OPT_MAXCONFS_PER_STEP)) { nMaxConfsPerStep = Integer.parseInt(cmd.getOptionValue(OPT_MAXCONFS_PER_STEP)); } String constraintStrength = cmd.getOptionValue(OPT_CONSTRIANT); boolean doMinimize = cmd.hasOption(OPT_MINIMIZE); SDFTorsionScanner torGenerator = new SDFTorsionScanner(bondFile, coreFilename, torsionAtomsTag, nSteps, nStartTor, nTorIncr, nMaxConfsPerStep, doMinimize, constraintStrength); torGenerator.run(inFile, outFile, coreFilename); }
From source file:com.versusoft.packages.ooo.odt2daisy.gui.CommandLineGUI.java
public static void main(String args[]) throws IOException { Handler fh = new FileHandler(LOG_FILENAME_PATTERN); fh.setFormatter(new SimpleFormatter()); //removeAllLoggersHandlers(Logger.getLogger("")); Logger.getLogger("").addHandler(fh); Logger.getLogger("").setLevel(Level.FINEST); Options options = new Options(); Option option1 = new Option("in", "name of ODT file (required)"); option1.setRequired(true); option1.setArgs(1);/*from w w w .j a v a 2s . c om*/ Option option2 = new Option("out", "name of DAISY DTB file (required)"); option2.setRequired(true); option2.setArgs(1); Option option3 = new Option("h", "show this help"); option3.setArgs(Option.UNLIMITED_VALUES); Option option4 = new Option("alt", "use alternate Level Markup"); Option option5 = new Option("u", "UID of DAISY DTB (optional)"); option5.setArgs(1); Option option6 = new Option("t", "Title of DAISY DTB"); option6.setArgs(1); Option option7 = new Option("c", "Creator of DAISY DTB"); option7.setArgs(1); Option option8 = new Option("p", "Publisher of DAISY DTB"); option8.setArgs(1); Option option9 = new Option("pr", "Producer of DAISY DTB"); option9.setArgs(1); Option option10 = new Option("pic", "set Picture directory"); option10.setArgs(1); Option option11 = new Option("page", "enable pagination"); option11.setArgs(0); Option option12 = new Option("css", "write CSS file"); option12.setArgs(0); options.addOption(option1); options.addOption(option2); options.addOption(option3); options.addOption(option4); options.addOption(option5); options.addOption(option6); options.addOption(option7); options.addOption(option8); options.addOption(option9); options.addOption(option10); options.addOption(option11); options.addOption(option12); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { //System.out.println("***ERROR: " + e.getClass() + ": " + e.getMessage()); printHelp(); return; } if (cmd.hasOption("help")) { printHelp(); return; } try { Odt2Daisy odt2daisy = new Odt2Daisy(cmd.getOptionValue("in")); //@todo add initial output directory URL? odt2daisy.init(); if (odt2daisy.isEmptyDocument()) { logger.info("Cannot convert empty documents. Export Aborted..."); System.exit(1); } //System.out.println("Metadatas"); //System.out.println("- title: " + odt2daisy.getTitleMeta()); //System.out.println("- creator: " + odt2daisy.getCreatorMeta()); if (!odt2daisy.isUsingHeadings()) { logger.info("You SHOULD use Heading styles in your document. Export in a single level."); } //@todo Warning for incompatible image formats should go here. See UnoGui.java. if (cmd.hasOption("u")) { //System.out.println("arg uid:"+cmd.getOptionValue("u")); odt2daisy.setUidParam(cmd.getOptionValue("u")); } if (cmd.hasOption("t")) { //System.out.println("arg title:"+cmd.getOptionValue("t")); odt2daisy.setTitleParam(cmd.getOptionValue("t")); } if (cmd.hasOption("c")) { //System.out.println("arg creator:"+cmd.getOptionValue("c")); odt2daisy.setCreatorParam(cmd.getOptionValue("c")); } if (cmd.hasOption("p")) { //System.out.println("arg publisher:"+cmd.getOptionValue("p")); odt2daisy.setPublisherParam(cmd.getOptionValue("p")); } if (cmd.hasOption("pr")) { //System.out.println("arg producer:"+cmd.getOptionValue("pr")); odt2daisy.setProducerParam(cmd.getOptionValue("pr")); } if (cmd.hasOption("alt")) { //System.out.println("arg alt:"+cmd.getOptionValue("alt")); odt2daisy.setUseAlternateLevelParam(true); } if (cmd.hasOption("css")) { odt2daisy.setWriteCSSParam(true); } if (cmd.hasOption("page")) { odt2daisy.paginationProcessing(); } odt2daisy.correctionProcessing(); if (cmd.hasOption("pic")) { odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), cmd.getOptionValue("pic")); } else { logger.info("Language detected: " + odt2daisy.getLangParam()); odt2daisy.convertAsDTBook(cmd.getOptionValue("out"), Configuration.DEFAULT_IMAGE_DIR); } boolean valid = odt2daisy.validateDTD(cmd.getOptionValue("out")); if (valid) { logger.info("DAISY DTBook produced is valid against DTD - Congratulations !"); } else { logger.info("DAISY Book produced isn't valid against DTD - You SHOULD NOT use this DAISY Book !"); logger.info("Error at line: " + odt2daisy.getErrorHandler().getLineNumber()); logger.info("Error Message: " + odt2daisy.getErrorHandler().getMessage()); } } catch (Exception e) { e.printStackTrace(); } finally { if (fh != null) { fh.flush(); fh.close(); } } }
From source file:com.genentech.chemistry.openEye.apps.SDFEStateCalculator.java
/** * @param args/*from www . ja v a 2s.c o m*/ */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_ESTATE_COUNT, false, "Output the the counts (occurrence) for each E-state atom group." + " E-state counts will be output if no output option is specified"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_ESTATE_SUM, false, "Output the sum of the E-state indices for each E-state atom group" + " in addition to the output of the" + " E-state atom groups."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_ESTATE_SYMBOL, false, "Output the E-state atom group symbol"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_UNASSIGNED_ATOMS, false, "Output atoms in the given molecules that" + " could not be assigned to an E-state atom group"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_UNASSIGNED_COUNT, false, "Output the number of atoms in the given molecules that" + " could not be assigned to an E-state atom group"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_ESTATE_INDICE, false, "Output the E-state indice of all atoms in the given molecule" + " in one field."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_SMARTS, true, "Description of the group of interest. If specified, the" + " E-state indice of atoms matching the SMARTS are output" + " in separated fields."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_PRINT_DETAILS, false, "Output the details of the calculation to stderr"); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); String smarts = cmd.getOptionValue(OPT_SMARTS); boolean outputESIndex = cmd.hasOption(OPT_ESTATE_INDICE); boolean outputESCount = cmd.hasOption(OPT_ESTATE_COUNT); boolean outputESSum = cmd.hasOption(OPT_ESTATE_SUM); boolean outputESSymbol = cmd.hasOption(OPT_ESTATE_SYMBOL); boolean outputUnkCount = cmd.hasOption(OPT_UNASSIGNED_COUNT); boolean outputUnkAtoms = cmd.hasOption(OPT_UNASSIGNED_ATOMS); boolean printDetails = cmd.hasOption(OPT_PRINT_DETAILS); SDFEStateCalculator calculator = new SDFEStateCalculator(outFile); if (!outputESCount && !outputESSum && !outputUnkCount && !outputESSymbol && !outputESIndex && (smarts == null || smarts.length() == 0)) outputESCount = true; try { calculator.prepare(outputESCount, outputESSum, outputESSymbol, outputUnkCount, outputUnkAtoms, outputESIndex, smarts, printDetails); calculator.run(inFile); } finally { calculator.close(); } }
From source file:com.genentech.retrival.SDFExport.SDFExporter.java
public static void main(String[] args) throws ParseException, JDOMException, IOException { // create command line Options object Options options = new Options(); Option opt = new Option("sqlFile", true, "sql-xml file"); opt.setRequired(true); options.addOption(opt);//from ww w. j ava2 s .com opt = new Option("sqlName", true, "name of SQL element in xml file"); opt.setRequired(true); options.addOption(opt); opt = new Option("molSqlName", true, "name of SQL element in xml file returning molfile for first column in sqlName"); opt.setRequired(false); options.addOption(opt); opt = new Option("removeSalt", false, "remove any known salts from structure."); opt.setRequired(false); options.addOption(opt); opt = new Option("o", "out", true, "output file"); opt.setRequired(false); options.addOption(opt); opt = new Option("i", "in", true, "input file, tab separated, each line executes the query once. Use '.tab' to read from stdin"); opt.setRequired(false); options.addOption(opt); opt = new Option("newLineReplacement", true, "If given newlines in fields will be replaced by this string."); options.addOption(opt); opt = new Option("ignoreMismatches", false, "If not given each input must return at least one hit hits."); options.addOption(opt); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } String outFile = cmd.getOptionValue("o"); String inFile = cmd.getOptionValue("i"); String sqlFile = cmd.getOptionValue("sqlFile"); String sqlName = cmd.getOptionValue("sqlName"); String molSqlName = cmd.getOptionValue("molSqlName"); String newLineReplacement = cmd.getOptionValue("newLineReplacement"); boolean removeSalt = cmd.hasOption("removeSalt"); boolean ignoreMismatches = cmd.hasOption("ignoreMismatches"); SDFExporter exporter = null; try { exporter = new SDFExporter(sqlFile, sqlName, molSqlName, outFile, newLineReplacement, removeSalt, ignoreMismatches); } catch (Exception e) { e.printStackTrace(); System.err.println(); exitWithHelp(options); } args = cmd.getArgs(); if (inFile != null && args.length > 0) { System.err.println("inFile and arguments may not be mixed!\n"); exitWithHelp(options); } if (inFile == null) { if (exporter.getParamTypes().length != args.length) { System.err.printf("sql statement (%s) needs %d parameters but got only %d.\n", sqlName, exporter.getParamTypes().length, args.length); exitWithHelp(options); } exporter.export(args); } else { BufferedReader in; if (".tab".equalsIgnoreCase(inFile)) in = new BufferedReader(new InputStreamReader(System.in)); else in = new BufferedReader(new FileReader(inFile)); exporter.export(in); in.close(); } exporter.close(); }
From source file:com.genentech.chemistry.tool.mm.SDFMMMinimize.java
/** * Main function for running on the command line * @param args//w ww.j av a 2 s . com */ public static void main(String... args) throws IOException { // Get the available options from the programs Map<String, List<String>> allowedProgramsAndForceFields = getAllowedProgramsAndForceFields(); Map<String, List<String>> allowedProgramsAndSolvents = getAllowedProgramsAndSolvents(); // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); StringBuilder programOptions = new StringBuilder("Program to use for minimization. Choices are\n"); for (String program : allowedProgramsAndForceFields.keySet()) { programOptions.append("\n*** -program " + program + " ***\n"); String forcefields = ""; for (String option : allowedProgramsAndForceFields.get(program)) { forcefields += option + " "; } programOptions.append("-forcefield " + forcefields + "\n"); String solvents = ""; for (String option : allowedProgramsAndSolvents.get(program)) { solvents += option + " "; } programOptions.append("-solvent " + solvents + "\n"); } opt = new Option(OPT_PROGRAM, true, programOptions.toString()); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_FORCEFIELD, true, "Forcefield options. See -program for choices"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_SOLVENT, true, "Solvent options. See -program for choices"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_FIXED_ATOM_TAG, true, "SD tag name which contains the atom numbers to be held fixed."); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_FIX_TORSION, true, "true/false. if true, the atoms in fixedAtomTag contains 4 indices of atoms defining a torsion angle to be held fixed"); opt.setRequired(false); options.addOption(opt); opt = new Option(OPT_WORKING_DIR, true, "Working directory to put files."); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (args.length != 0) { System.err.println("Unknown arguments" + args); exitWithHelp(options); } if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); String fixedAtomTag = cmd.getOptionValue(OPT_FIXED_ATOM_TAG); boolean fixTorsion = (cmd.getOptionValue(OPT_FIX_TORSION) != null && cmd.getOptionValue(OPT_FIX_TORSION).equalsIgnoreCase("true")); String programName = cmd.getOptionValue(OPT_PROGRAM); String forcefield = cmd.getOptionValue(OPT_FORCEFIELD); String solvent = cmd.getOptionValue(OPT_SOLVENT); String workDir = cmd.getOptionValue(OPT_WORKING_DIR); if (workDir == null || workDir.trim().length() == 0) workDir = "."; // Create a minimizer SDFMMMinimize minimizer = new SDFMMMinimize(); minimizer.setMethod(programName, forcefield, solvent); minimizer.run(inFile, outFile, fixedAtomTag, fixTorsion, workDir); minimizer.close(); System.err.println("Minimization complete."); }
From source file:eu.edisonproject.classification.main.BatchMain.java
public static void main(String[] args) throws Exception { try {/* w w w. j a v a 2s . c o m*/ // args = new String[1]; // args[0] = ".."; // TestDataFlow.execute(args); // System.exit(0); // TestTFIDF.execute(args); Options options = new Options(); Option operation = new Option("op", "operation", true, "type of operation to perform. " + "To convert txt to avro 'a'.\n" + "For running clasification on avro documents 'c'"); operation.setRequired(true); options.addOption(operation); Option input = new Option("i", "input", true, "input path"); input.setRequired(false); options.addOption(input); Option output = new Option("o", "output", true, "output file"); output.setRequired(false); options.addOption(output); Option competencesVector = new Option("c", "competences-vector", true, "competences vectors"); competencesVector.setRequired(false); options.addOption(competencesVector); Option v1 = new Option("v1", "vector1", true, ""); v1.setRequired(false); options.addOption(v1); Option v2 = new Option("v2", "vector2", true, ""); v2.setRequired(false); options.addOption(v2); Option popertiesFile = new Option("p", "properties", true, "path for a properties file"); popertiesFile.setRequired(false); options.addOption(popertiesFile); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); String propPath = cmd.getOptionValue("properties"); MyProperties prop; if (propPath == null) { prop = ConfigHelper .getProperties(".." + File.separator + "etc" + File.separator + "configure.properties"); } else { prop = ConfigHelper.getProperties(propPath); } switch (cmd.getOptionValue("operation")) { case "a": text2Avro(cmd.getOptionValue("input"), cmd.getOptionValue("output"), prop); break; case "c": calculateTFIDF(cmd.getOptionValue("input"), cmd.getOptionValue("output"), cmd.getOptionValue("competences-vector"), prop); break; case "p": // -op p -v2 $HOME/Downloads/msc.csv -v1 $HOME/Downloads/job.csv -p $HOME/workspace/E-CO-2/etc/classification.properties profile(cmd.getOptionValue("v1"), cmd.getOptionValue("v2"), cmd.getOptionValue("output")); break; } } catch (IllegalArgumentException | ParseException | IOException ex) { Logger.getLogger(BatchMain.class.getName()).log(Level.SEVERE, null, ex); } }