Example usage for org.apache.commons.cli Option Option

List of usage examples for org.apache.commons.cli Option Option

Introduction

In this page you can find the example usage for org.apache.commons.cli Option Option.

Prototype

public Option(String opt, boolean hasArg, String description) throws IllegalArgumentException 

Source Link

Document

Creates an Option using the specified parameters.

Usage

From source file:edu.harvard.hul.ois.drs.pdfaconvert.PdfaConvert.java

public static void main(String[] args) throws IOException {
    if (logger == null) {
        System.out.println("About to initialize Log4j");
        logger = LogManager.getLogger();
        System.out.println("Finished initializing Log4j");
    }//ww  w .  j ava2  s.  com

    logger.debug("Entering main()");

    // WIP: the following command line code was pulled from FITS
    Options options = new Options();
    Option inputFileOption = new Option(PARAM_I, true, "input file");
    options.addOption(inputFileOption);
    options.addOption(PARAM_V, false, "print version information");
    options.addOption(PARAM_H, false, "help information");
    options.addOption(PARAM_O, true, "output sub-directory");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args, true);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }

    // print version info
    if (cmd.hasOption(PARAM_V)) {
        if (StringUtils.isEmpty(applicationVersion)) {
            applicationVersion = "<not set>";
            System.exit(1);
        }
        System.out.println("Version: " + applicationVersion);
        System.exit(0);
    }

    // print help info
    if (cmd.hasOption(PARAM_H)) {
        displayHelp();
        System.exit(0);
    }

    // input parameter
    if (cmd.hasOption(PARAM_I)) {
        String input = cmd.getOptionValue(PARAM_I);
        boolean hasValue = cmd.hasOption(PARAM_I);
        logger.debug("Has option {} value: [{}]", PARAM_I, hasValue);
        String paramVal = cmd.getOptionValue(PARAM_I);
        logger.debug("value of option: [{}] ****", paramVal);

        File inputFile = new File(input);
        if (!inputFile.exists()) {
            logger.warn("{} does not exist or is not readable.", input);
            System.exit(1);
        }

        String subDir = cmd.getOptionValue(PARAM_O);
        PdfaConvert convert;
        if (!StringUtils.isEmpty(subDir)) {
            convert = new PdfaConvert(subDir);
        } else {
            convert = new PdfaConvert();
        }
        if (inputFile.isDirectory()) {
            if (inputFile.listFiles() == null || inputFile.listFiles().length < 1) {
                logger.warn("Input directory is empty, nothing to process.");
                System.exit(1);
            } else {
                logger.debug("Have directory: [{}] with file count: {}", inputFile.getAbsolutePath(),
                        inputFile.listFiles().length);
                DirectoryStream<Path> dirStream = null;
                dirStream = Files.newDirectoryStream(inputFile.toPath());
                for (Path filePath : dirStream) {
                    logger.debug("Have file name: {}", filePath.toString());
                    // Note: only handling files, not recursively going into sub-directories
                    if (filePath.toFile().isFile()) {
                        // Catch possible exception for each file so can handle other files in directory.
                        try {
                            convert.examine(filePath.toFile());
                        } catch (Exception e) {
                            logger.error("Problem processing file: {} -- Error message: {}",
                                    filePath.getFileName(), e.getMessage());
                        }
                    } else {
                        logger.warn("Not a file so not processing: {}", filePath.toString()); // could be a directory but not recursing
                    }
                }
                dirStream.close();
            }
        } else {
            logger.debug("About to process file: {}", inputFile.getPath());
            try {
                convert.examine(inputFile);
            } catch (Exception e) {
                logger.error("Problem processing file: {} -- Error message: {}", inputFile.getName(),
                        e.getMessage());
                logger.debug("Problem processing file: {} -- Error message: {}", inputFile.getName(),
                        e.getMessage(), e);
            }
        }
    } else {
        System.err.println("Missing required option: " + PARAM_I);
        displayHelp();
        System.exit(-1);
    }

    System.exit(0);
}

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);//from  w w w  . j  ava2s . c  o m
    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.retrival.SDFExport.SDFSDFExporter.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(false);/*from w  w  w  .  j a  v a  2 s . com*/
    options.addOption(opt);

    opt = new Option("sqlName", true, "name of SQL element in xml file, Default sql.xml in 'sdfExport' config");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("selectStatement", true, "select statement to execute");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("paramTypes", true,
            "'|' separated list of parameter types to pass tostatment int,float,string,date");
    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, oe or .tab each record executes the query once. Use '.tab' to read from stdin");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("queryTags", true, "'|' separetaed list of tags whose values is passt to the sql.");
    opt.setRequired(true);
    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("filterIfNoRecords", false,
            "If no rows are returned by the query that record is filtered out.");
    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 selStr = cmd.getOptionValue("selectStatement");
    String pTypes = cmd.getOptionValue("paramTypes");
    String newLineReplacement = cmd.getOptionValue("newLineReplacement");
    boolean printIfNoRecord = !cmd.hasOption("filterIfNoRecords");
    String[] tagStr = cmd.getOptionValue("queryTags").trim().split("\\|");

    try {
        SDFSDFExporter exporter = null;
        if ((sqlFile != null && sqlFile.length() > 0) || (sqlName != null && sqlName.length() > 0)) {
            if ((selStr != null && selStr.length() > 0) || (pTypes != null && pTypes.length() > 0)) {
                System.err.println("sqlFile and sqlName may not be used with selectStatement and paramTypes");
                exitWithHelp(options);
            }

            exporter = createFromFile(sqlFile, sqlName, inFile, outFile, tagStr, printIfNoRecord,
                    newLineReplacement);

        } else if (selStr == null || selStr.length() == 0 || pTypes == null || pTypes.length() == 0) {
            System.err.println("sqlFile and sqlName or selectStatement and paramTypes must be given");
            exitWithHelp(options);

        } else {
            exporter = createFromStatementStr(selStr, pTypes, inFile, outFile, tagStr, printIfNoRecord,
                    newLineReplacement);
        }

        exporter.export();
        exporter.close();
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println();
        exitWithHelp(options);
    }

}

From source file:com.genentech.chemistry.openEye.apps.SDFCatsIndexer.java

/**
 * @param args/*  www  . ja v  a2  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);
    opt.setArgName("fn");
    options.addOption(opt);

    opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type.");
    opt.setRequired(true);
    opt.setArgName("fn");
    options.addOption(opt);

    opt = new Option(OPT_NORMALIZATION, true,
            "Normalization method: Counts|CountsPerAtom|CountsPerFeature(def) multiple allowed");
    opt.setArgName("meth");
    options.addOption(opt);

    opt = new Option(OPT_PRINTDESC, false,
            "Causes the descriptor for describing each linear path in a molceule to be created");
    options.addOption(opt);

    opt = new Option(OPT_RGROUPTYPES, false, "treat RGroup attachement point ([U]) as atom type.");
    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);
    }

    String inFile = cmd.getOptionValue(OPT_INFILE);
    String outFile = cmd.getOptionValue(OPT_OUTFILE);

    AtomTyperInterface[] myTypes = CATSIndexer.typers;
    String tagPrefix = "";
    if (cmd.hasOption(OPT_RGROUPTYPES)) {
        myTypes = CATSIndexer.rgroupTypers;
        tagPrefix = "RG";
    }

    if (cmd.hasOption(OPT_PRINTDESC)) {
        SDFCatsIndexer sdfIndexer = new SDFCatsIndexer(myTypes, tagPrefix);
        sdfIndexer.printDescriptors(inFile, outFile);
        sdfIndexer.close();
        return;
    }

    EnumSet<Normalization> normMeth = EnumSet.noneOf(Normalization.class);
    if (cmd.hasOption(OPT_NORMALIZATION))
        for (String n : cmd.getOptionValues(OPT_NORMALIZATION))
            normMeth.add(Normalization.valueOf(n));
    else
        normMeth.add(Normalization.CountsPerFeature);

    SDFCatsIndexer sdfIndexer = new SDFCatsIndexer(myTypes, tagPrefix);
    sdfIndexer.run(inFile, outFile, normMeth);
    sdfIndexer.close();
}

From source file:autocorrelator.apps.SDFGroovy.java

public static void main(String[] args) throws Exception {
    long start = System.currentTimeMillis();

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input sd file");
    options.addOption(opt);// w w  w  . java 2s  .co m

    opt = new Option("out", true, "output file for return value true or null");
    options.addOption(opt);

    opt = new Option("falseOut", true, "output file for return value false");
    options.addOption(opt);

    opt = new Option("c", true, "groovy script line");
    options.addOption(opt);

    opt = new Option("f", true, "groovy script file");
    options.addOption(opt);

    opt = new Option("exception", true, "exception handling (Default: stop)");
    options.addOption(opt);

    opt = new Option("h", false, "print help message");
    options.addOption(opt);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        exitWithHelp(e.getMessage(), options);
    }
    if (!cmd.hasOption("c") && !cmd.hasOption("f"))
        exitWithHelp("-c or -f must be given!", options);

    if (cmd.hasOption("c") && cmd.hasOption("f"))
        exitWithHelp("Only one of -c or -f may be given!", options);

    String groovyStrg;
    if (cmd.hasOption("c"))
        groovyStrg = cmd.getOptionValue("c");
    else
        groovyStrg = fileToString(cmd.getOptionValue("f"));

    Set<String> inFileds = new HashSet<String>();
    Set<String> outFields = new HashSet<String>();
    Script script = getGroovyScript(groovyStrg, inFileds, outFields);

    if (cmd.hasOption("h")) {
        callScriptHelp(script);
        exitWithHelp("", options);
    }

    if (!cmd.hasOption("in") || !cmd.hasOption("out")) {
        callScriptHelp(script);
        exitWithHelp("-in and -out must be given", options);
    }

    String[] scriptArgs = cmd.getArgs();
    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String falseOutFile = cmd.getOptionValue("falseOut");
    EXCEPTIONHandling eHandling = EXCEPTIONHandling.stop;
    if (cmd.hasOption("exception"))
        eHandling = EXCEPTIONHandling.getByName(cmd.getOptionValue("exception"));

    callScriptInit(script, scriptArgs);

    oemolistream ifs = new oemolistream(inFile);
    oemolostream ofs = new oemolostream(outFile);
    oemolostream falseOFS = null;
    if (falseOutFile != null)
        falseOFS = new oemolostream(falseOutFile);

    OEMolBase mol = new OEGraphMol();

    int iCounter = 0;
    int oCounter = 0;
    int foCounter = 0;
    while (oechem.OEReadMolecule(ifs, mol)) {
        iCounter++;

        Binding binding = getFieldBindings(mol, inFileds, outFields);

        script.setBinding(binding);
        boolean printToTrue = true;
        boolean printToFalse = true;
        try {
            Object ret = script.run();
            if (ret == null || !(ret instanceof Boolean)) {
                printToFalse = false;
            } else if (((Boolean) ret).booleanValue()) {
                printToFalse = false;
            } else // ret = false
            {
                printToTrue = false;
            }

            setOutputFields(mol, binding, outFields);
        } catch (Exception e) {
            switch (eHandling) {
            case stop:
                throw e;
            case printToTrue:
                printToFalse = false;
                System.err.println(e.getMessage());
                break;
            case printToFalse:
                printToTrue = false;
                System.err.println(e.getMessage());
                break;
            case dropRecord:
                printToTrue = false;
                printToFalse = false;
                System.err.println(e.getMessage());
                break;
            default:
                assert false;
                break;
            }
        }

        if (printToTrue) {
            oechem.OEWriteMolecule(ofs, mol);
            oCounter++;
        }
        if (falseOFS != null && printToFalse) {
            oechem.OEWriteMolecule(falseOFS, mol);
            foCounter++;
        }
    }

    System.err.printf("SDFGroovy: Input %d, output %d,%d structures in %dsec\n", iCounter, oCounter, foCounter,
            (System.currentTimeMillis() - start) / 1000);

    if (falseOFS != null)
        falseOFS.close();
    ofs.close();
    ifs.close();
    mol.delete();
}

From source file:com.genentech.chemistry.openEye.apps.SDFMDLSSSMatcher.java

public static void main(String... args) throws IOException, InterruptedException {
    oechem.OEUseJavaHeap(false);//from  w  ww  .j a  v a2 s.c om

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file [.sdf,...]");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("ref", true, "refrence file with MDL query molecules");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("anyMatch", false, "if set all matches are reported not just the first.");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("printAll", false, "if set even compounds that do not macht are outputted.");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("nCpu", true, "number of CPU's used in parallel, dafault 1");
    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) {
        exitWithHelp("Unknown param: " + args[0], options);
    }

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    int nCpu = 1;
    boolean firstMatch = !cmd.hasOption("anyMatch");
    boolean printAll = cmd.hasOption("printAll");

    String d = cmd.getOptionValue("nCpu");
    if (d != null)
        nCpu = Integer.parseInt(d);

    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String refFile = cmd.getOptionValue("ref");

    SDFMDLSSSMatcher matcher = new SDFMDLSSSMatcher(refFile, outFile, firstMatch, printAll, nCpu);
    matcher.run(inFile);
    matcher.close();
}

From source file:com.genentech.chemistry.tool.mm.SDFMMMinimize.java

/**
 * Main function for running on the command line
 * @param args/* www . j a v a 2s  .  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:com.genentech.chemistry.openEye.apps.enumerate.SDFEnumerator.java

public static void main(String... args) throws IOException {
    Options options = new Options();
    Option opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(true);// www . j a  v  a 2s  . co m
    options.addOption(opt);

    opt = new Option("hydrogenExplicit", false, "Use explicit hydrogens");
    options.addOption(opt);

    opt = new Option("correctValences", false, "Correct valences after the enumeration");
    options.addOption(opt);

    opt = new Option("regenerate2D", false, "Regenerate 2D coordinates for the products");
    options.addOption(opt);

    opt = new Option("reactAllSites", false, "Generate a product for each match in a reagent.");
    options.addOption(opt);

    opt = new Option("randomFraction", true, "Only output a fraction of the products.");
    options.addOption(opt);

    opt = new Option("maxAtoms", true, "Only output products with <= maxAtoms.");
    options.addOption(opt);

    opt = new Option("notReacted", true,
            "Output file for reagents that didn't produce at leaste one output molecule, useful for debugging SMIRKS.");
    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 < 2) {
        exitWithHelp("Transformation and/or reagentFiles missing", options);
    }
    String smirks = args[0];
    if (new File(smirks).canRead())
        smirks = IOUtil.fileToString(smirks).trim();
    if (!smirks.contains(">>"))
        smirks = scaffoldToSmirks(smirks);
    String[] reagentSmiOrFiles = Arrays.copyOfRange(args, 1, args.length);

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    String outFile = cmd.getOptionValue("out");
    OELibraryGen lg = new OELibraryGen();
    lg.Init(smirks);
    if (!lg.IsValid())
        exitWithHelp("Invalid Transform: " + smirks, options);

    lg.SetExplicitHydrogens(cmd.hasOption("hydrogenExplicit"));
    lg.SetValenceCorrection(cmd.hasOption("correctValences"));
    lg.SetRemoveUnmappedFragments(true);

    boolean regenerate2D = cmd.hasOption("regenerate2D");
    boolean reactAllSites = cmd.hasOption("reactAllSites");
    String unreactedFile = null;
    if (cmd.hasOption("notReacted")) {
        unreactedFile = cmd.getOptionValue("notReacted");
    }

    double randomFract = 2;
    if (cmd.hasOption("randomFraction"))
        randomFract = Double.parseDouble(cmd.getOptionValue("randomFraction"));

    int maxAtoms = 0;
    if (cmd.hasOption("maxAtoms"))
        maxAtoms = Integer.parseInt(cmd.getOptionValue("maxAtoms"));

    SDFEnumerator en = new SDFEnumerator(lg, reactAllSites, reagentSmiOrFiles);
    en.generateLibrary(outFile, maxAtoms, randomFract, regenerate2D, unreactedFile);
    en.delete();
}

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);// w ww  .j a v  a 2  s  .  c  o  m
    options.addOption(opt);

    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:edu.harvard.hul.ois.fits.Fits.java

public static void main(String[] args) throws FitsException, IOException, ParseException, XMLStreamException {
    Fits fits = new Fits();

    Options options = new Options();
    options.addOption("i", true, "input file or directory");
    options.addOption("r", false, "process directories recursively when -i is a directory ");
    options.addOption("o", true, "output file");
    options.addOption("h", false, "print this message");
    options.addOption("v", false, "print version information");
    OptionGroup outputOptions = new OptionGroup();
    Option stdxml = new Option("x", false, "convert FITS output to a standard metadata schema");
    Option combinedStd = new Option("xc", false,
            "output using a standard metadata schema and include FITS xml");
    outputOptions.addOption(stdxml);/*from   ww w .ja v  a2s . c o m*/
    outputOptions.addOption(combinedStd);
    options.addOptionGroup(outputOptions);

    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("h")) {
        fits.printHelp(options);
        System.exit(0);
    }
    if (cmd.hasOption("v")) {
        System.out.println(Fits.VERSION);
        System.exit(0);
    }
    if (cmd.hasOption("r")) {
        traverseDirs = true;
    } else {
        traverseDirs = false;
    }

    if (cmd.hasOption("i")) {
        String input = cmd.getOptionValue("i");
        File inputFile = new File(input);

        if (inputFile.isDirectory()) {
            String outputDir = cmd.getOptionValue("o");
            if (outputDir == null || !(new File(outputDir).isDirectory())) {
                throw new FitsException(
                        "When FITS is run in directory processing mode the output location must be a diretory");
            }
            fits.doDirectory(inputFile, new File(outputDir), cmd.hasOption("x"), cmd.hasOption("xc"));
        } else {
            FitsOutput result = fits.doSingleFile(inputFile);
            fits.outputResults(result, cmd.getOptionValue("o"), cmd.hasOption("x"), cmd.hasOption("xc"), false);
        }
    } else {
        System.err.println("Invalid CLI options");
        fits.printHelp(options);
        System.exit(-1);
    }

    System.exit(0);
}