Package org.apache.commons.cli

Examples of org.apache.commons.cli.CommandLine


        ClassificationResultFormatter.FORMAT format = CmdOptions.DEFAULT_FORMAT;
        float conf_cutoff = CmdOptions.DEFAULT_CONF;
        String gene = null;

        try {
            CommandLine line = new PosixParser().parse(options, args);

            if (line.hasOption(QUERYFILE1_SHORT_OPT)) {
                queryFile1 = line.getOptionValue(QUERYFILE1_SHORT_OPT);
            } else {
                throw new Exception("queryFile1 must be specified");
            }
            if (line.hasOption(QUERYFILE2_SHORT_OPT)) {
                queryFile2 = line.getOptionValue(QUERYFILE2_SHORT_OPT);
            } else {
                throw new Exception("queryFile2 must be specified");
            }

            if (line.hasOption(CmdOptions.OUTFILE_SHORT_OPT)) {
                class_outputFile = line.getOptionValue(CmdOptions.OUTFILE_SHORT_OPT);
            } else {
                throw new Exception("outputFile for classification results must be specified");
            }

            if (line.hasOption(COMPARE_OUTFILE_SHORT_OPT)) {
                compare_outputFile = line.getOptionValue(COMPARE_OUTFILE_SHORT_OPT);
            } else {
                throw new Exception("outputFile for comparsion results must be specified");
            }

            if (line.hasOption(CmdOptions.TRAINPROPFILE_SHORT_OPT)) {
                if (gene != null) {
                    throw new IllegalArgumentException("Already specified the gene from the default location. Can not specify train_propfile");
                } else {
                    propFile = line.getOptionValue(CmdOptions.TRAINPROPFILE_SHORT_OPT);
                }
            }
            if (line.hasOption(CmdOptions.BOOTSTRAP_SHORT_OPT)) {
                conf_cutoff = Float.parseFloat(line.getOptionValue(CmdOptions.BOOTSTRAP_SHORT_OPT));
            }
            if (line.hasOption(CmdOptions.FORMAT_SHORT_OPT)) {
                String f = line.getOptionValue(CmdOptions.FORMAT_SHORT_OPT);
                if (f.equalsIgnoreCase("allrank")) {
                    format = ClassificationResultFormatter.FORMAT.allRank;
                } else if (f.equalsIgnoreCase("fixrank")) {
                    format = ClassificationResultFormatter.FORMAT.fixRank;
                } else if (f.equalsIgnoreCase("filterbyconf")) {
                    format = ClassificationResultFormatter.FORMAT.filterbyconf;
                } else if (f.equalsIgnoreCase("db")) {
                    format = ClassificationResultFormatter.FORMAT.dbformat;
                }else {
                    throw new IllegalArgumentException("Not valid output format, only allrank, fixrank, filterbyconf and db allowed");
                }
               
            }
            if (line.hasOption(CmdOptions.GENE_SHORT_OPT)) {
                if (propFile != null) {
                    throw new IllegalArgumentException("Already specified train_propfile. Can not specify gene any more");
                }
                gene = line.getOptionValue(CmdOptions.GENE_SHORT_OPT).toLowerCase();

                if (!gene.equals(ClassifierFactory.RRNA_16S_GENE) && !gene.equals(ClassifierFactory.FUNGALLSU_GENE)) {
                    throw new IllegalArgumentException(gene + " is NOT valid, only allows " + ClassifierFactory.RRNA_16S_GENE + " and " + ClassifierFactory.FUNGALLSU_GENE);
                }
            }
View Full Code Here


        return ret;
    }

    public static void main(String[] args) throws Exception {
        CommandLineParser parser = new PosixParser();
        CommandLine line = null;
        try {
             line = parser.parse(options, args);
        } catch(UnrecognizedOptionException e) {
            System.err.println(e.getMessage());
            printUsage();
            return;
        }
        UnifracTree unifracTree = null;
        PrintStream out = System.out;

        if (line.hasOption("tree") && line.hasOption("sequence-files")) {
            printUsage();
        } else if (!(line.hasOption("weighted") || line.hasOption("unweighted") || line.hasOption("significance"))) {
            System.err.println("Must specify at least one calculation option");
            printUsage();
        } else if (line.hasOption("sample-mapping")) {
            Map<String, UnifracSample> sampleMap = readSampleMap(line.getOptionValue("sample-mapping"));

            if (line.hasOption("tree")) {
                unifracTree = parseNewickTree(line.getOptionValue("tree"), sampleMap);
            }
        } else {
            if (!line.hasOption("sample-mapping")) {
                System.err.println("A sample mapping file must be provided");
            }
            printUsage();
        }

        if (line.hasOption("outfile")) {
            out = new PrintStream(line.getOptionValue("outfile"));
        }

        if (unifracTree != null) {
            if (line.hasOption("unweighted")) {
                printResults(out, unifracTree.computeUnifrac(), "Unweighted Unifrac");
                if (line.hasOption("significance")) {
                    printResults(out, unifracTree.computeUnifracSig(1000, false), "Unweighted Unifrac Significance");
                }
            }

            if (line.hasOption("weighted")) {
                printResults(out, unifracTree.computeWeightedUnifrac(), "Weighted Unifrac");
                if (line.hasOption("significance")) {
                    printResults(out, unifracTree.computeUnifracSig(1000, true), "Weighted Unifrac Significance");
                }
            }
        }
    }
View Full Code Here

        String gene = null;
        ClassificationResultFormatter.FORMAT format = CmdOptions.DEFAULT_FORMAT;
        int min_bootstrap_words = Classifier.MIN_BOOTSTRSP_WORDS;

        try {
            CommandLine line = new PosixParser().parse(options, args);
           
            if (line.hasOption(CmdOptions.OUTFILE_SHORT_OPT)) {
                outputFile = line.getOptionValue(CmdOptions.OUTFILE_SHORT_OPT);
            } else {
                throw new Exception("outputFile must be specified");
            }

            if (line.hasOption(CmdOptions.TRAINPROPFILE_SHORT_OPT)) {
                if (gene != null) {
                    throw new IllegalArgumentException("Already specified the gene from the default location. Can not specify train_propfile");
                } else {
                    propFile = line.getOptionValue(CmdOptions.TRAINPROPFILE_SHORT_OPT);
                }
            }
            if (line.hasOption(CmdOptions.FORMAT_SHORT_OPT)) {
                String f = line.getOptionValue(CmdOptions.FORMAT_SHORT_OPT);
                if (f.equalsIgnoreCase("allrank")) {
                    format = ClassificationResultFormatter.FORMAT.allRank;
                } else if (f.equalsIgnoreCase("fixrank")) {
                    format = ClassificationResultFormatter.FORMAT.fixRank;
                } else if (f.equalsIgnoreCase("filterbyconf")) {
                    format = ClassificationResultFormatter.FORMAT.filterbyconf;
                } else if (f.equalsIgnoreCase("db")) {
                    format = ClassificationResultFormatter.FORMAT.dbformat;
                }else {
                    throw new IllegalArgumentException("Not valid output format, only allrank, fixrank, filterbyconf and db allowed");
                }
            }
            if (line.hasOption(CmdOptions.GENE_SHORT_OPT)) {
                if (propFile != null) {
                    throw new IllegalArgumentException("Already specified train_propfile. Can not specify gene any more");
                }
                gene = line.getOptionValue(CmdOptions.GENE_SHORT_OPT).toLowerCase();

                if (!gene.equals(ClassifierFactory.RRNA_16S_GENE) && !gene.equals(ClassifierFactory.FUNGALLSU_GENE)) {
                    throw new IllegalArgumentException(gene + " is NOT valid, only allows " + ClassifierFactory.RRNA_16S_GENE + " and " + ClassifierFactory.FUNGALLSU_GENE);
                }
            }
            if (line.hasOption(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)) {
                min_bootstrap_words = Integer.parseInt(line.getOptionValue(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT));
                if (min_bootstrap_words < Classifier.MIN_BOOTSTRSP_WORDS) {
                    throw new IllegalArgumentException(CmdOptions.MIN_BOOTSTRAP_WORDS_LONG_OPT + " must be at least " + Classifier.MIN_BOOTSTRSP_WORDS);
                }               
            }
           
            args = line.getArgs();
            if ( args.length != 1){
                throw new Exception("Expect one query file");
            }
            queryFile = args[0];
           
View Full Code Here

        float conf = CmdOptions.DEFAULT_CONF;
        String gene = null;
        int min_bootstrap_words = Classifier.MIN_BOOTSTRSP_WORDS;
       
        try {
            CommandLine line = new PosixParser().parse(options, args);

            if (line.hasOption(CmdOptions.OUTFILE_SHORT_OPT)) {
                assign_out = new PrintWriter(line.getOptionValue(CmdOptions.OUTFILE_SHORT_OPT));
            } else {
                throw new IllegalArgumentException("Require the output file for classification assignment" );
            }
            if (line.hasOption(CmdOptions.HIER_OUTFILE_SHORT_OPT)) {
                hier_out_filename = new File(line.getOptionValue(CmdOptions.HIER_OUTFILE_SHORT_OPT));
                hier_out = new PrintStream(hier_out_filename);
            }
            if (line.hasOption(CmdOptions.BIOMFILE_SHORT_OPT)) {
                biomFile = new File(line.getOptionValue(CmdOptions.BIOMFILE_SHORT_OPT));
            }
            if (line.hasOption(CmdOptions.METADATA_SHORT_OPT)) {
                metadataFile = new File(line.getOptionValue(CmdOptions.METADATA_SHORT_OPT));
            }

            if (line.hasOption(CmdOptions.TRAINPROPFILE_SHORT_OPT)) {
                if (gene != null) {
                    throw new IllegalArgumentException("Already specified the gene from the default location. Can not specify train_propfile");
                } else {
                    propFile = line.getOptionValue(CmdOptions.TRAINPROPFILE_SHORT_OPT);
                }
            }
            if (line.hasOption(CmdOptions.FORMAT_SHORT_OPT)) {
                String f = line.getOptionValue(CmdOptions.FORMAT_SHORT_OPT);
                if (f.equalsIgnoreCase("allrank")) {
                    format = ClassificationResultFormatter.FORMAT.allRank;
                } else if (f.equalsIgnoreCase("fixrank")) {
                    format = ClassificationResultFormatter.FORMAT.fixRank;
                } else if (f.equalsIgnoreCase("filterbyconf")) {
                    format = ClassificationResultFormatter.FORMAT.filterbyconf;
                } else if (f.equalsIgnoreCase("db")) {
                    format = ClassificationResultFormatter.FORMAT.dbformat;
                } else if (f.equalsIgnoreCase("biom")) {
                    format = ClassificationResultFormatter.FORMAT.biom;
                }else {
                    throw new IllegalArgumentException("Not an valid output format, only allrank, fixrank, biom, filterbyconf and db allowed");
                }
            }
            if (line.hasOption(CmdOptions.GENE_SHORT_OPT)) {
                if (propFile != null) {
                    throw new IllegalArgumentException("Already specified train_propfile. Can not specify gene any more");
                }
                gene = line.getOptionValue(CmdOptions.GENE_SHORT_OPT).toLowerCase();

                if (!gene.equals(ClassifierFactory.RRNA_16S_GENE) && !gene.equals(ClassifierFactory.FUNGALLSU_GENE)
                    && !gene.equals(ClassifierFactory.FUNGALITS_warcup_GENE) && !gene.equals(ClassifierFactory.FUNGALITS_unite_GENE) ) {
                    throw new IllegalArgumentException(gene + " not found, choose from" + ClassifierFactory.RRNA_16S_GENE + ", "
                     + ClassifierFactory.FUNGALLSU_GENE + ", " + ClassifierFactory.FUNGALITS_warcup_GENE  + ", " + ClassifierFactory.FUNGALITS_unite_GENE);
                }
            }
            if (line.hasOption(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)) {
                min_bootstrap_words = Integer.parseInt(line.getOptionValue(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT));
                if (min_bootstrap_words < Classifier.MIN_BOOTSTRSP_WORDS) {
                    throw new IllegalArgumentException(CmdOptions.MIN_BOOTSTRAP_WORDS_LONG_OPT + " must be at least " + Classifier.MIN_BOOTSTRSP_WORDS);
                }               
            }
            if (line.hasOption(CmdOptions.BOOTSTRAP_SHORT_OPT)) {
                String confString = line.getOptionValue(CmdOptions.BOOTSTRAP_SHORT_OPT);
                try {
                    conf = Float.valueOf(confString);
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("Confidence must be a decimal number");
                }

                if (conf < 0 || conf > 1) {
                    throw new IllegalArgumentException("Confidence must be in the range [0,1]");
                }
            }
            if (line.hasOption(CmdOptions.SHORTSEQ_OUTFILE_SHORT_OPT)) {
                shortseq_out = new PrintWriter(line.getOptionValue(CmdOptions.SHORTSEQ_OUTFILE_SHORT_OPT));
            }
            if (line.hasOption(CmdOptions.BOOTSTRAP_OUTFILE_SHORT_OPT)) {
                bootstrap_out = new PrintStream(line.getOptionValue(CmdOptions.BOOTSTRAP_OUTFILE_SHORT_OPT));
            }
           
            if ( format.equals( ClassificationResultFormatter.FORMAT.biom) && biomFile == null){
                throw new IllegalArgumentException("biom format requires an input biom file");
            }
            if ( biomFile != null ) {  // if input biom file provided, use biom format
                format = ClassificationResultFormatter.FORMAT.biom;              
            }
            
            args = line.getArgs();
            for ( String arg: args){
                String[] inFileNames = arg.split(",");
                File inputFile = new File(inFileNames[0]);
                File idmappingFile = null;
                if (!inputFile.exists()) {
View Full Code Here

        String version = null;
        String modification = null;
        String outdir = null;
       
        try {
            CommandLine line = new PosixParser().parse(options, args);

            if (line.hasOption("t")) {
                taxFile = line.getOptionValue("t");
            } else {
                throw new Exception("taxon file must be specified");
            }
            if (line.hasOption("c")) {
                cnFile = line.getOptionValue("c");
            }
            if (line.hasOption("s")) {
                seqFile = line.getOptionValue("s");
            } else {
                throw new Exception("seq file must be specified");
            }

            if (line.hasOption("n")) {
                try {
                    trainset_no = Integer.parseInt(line.getOptionValue("n"));
                } catch (NumberFormatException ex) {
                    throw new IllegalArgumentException("trainset_no needs to be an integer.");
                }
            }
            if (line.hasOption("o")) {
                outdir = line.getOptionValue("o");
            } else {
                throw new Exception("output directory must be specified");
            }
            if (line.hasOption("v")) {
                version = line.getOptionValue("v");
            }
            if (line.hasOption("m")) {
                modification = line.getOptionValue("m");
            }
           
        } catch (Exception e) {
            System.out.println("Command Error: " + e.getMessage());
            new HelpFormatter().printHelp(120, "train", "", options, "", true);
View Full Code Here

      option = new Option("h", "help", false, "display help text");
      options.addOption(option);

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

      if (commandLine.hasOption('h')) {
        new HelpFormatter().printHelp("flume-ng agent", options, true);
        return;
      }

      String agentName = commandLine.getOptionValue('n');
      boolean reload = !commandLine.hasOption("no-reload-conf");

      if (commandLine.hasOption('z') || commandLine.hasOption("zkConnString")) {
        isZkConfigured = true;
      }
      Application application = null;
      if (isZkConfigured) {
        // get options
        String zkConnectionStr = commandLine.getOptionValue('z');
        String baseZkPath = commandLine.getOptionValue('p');

        if (reload) {
          EventBus eventBus = new EventBus(agentName + "-event-bus");
          List<LifecycleAware> components = Lists.newArrayList();
          PollingZooKeeperConfigurationProvider zookeeperConfigurationProvider =
            new PollingZooKeeperConfigurationProvider(
              agentName, zkConnectionStr, baseZkPath, eventBus);
          components.add(zookeeperConfigurationProvider);
          application = new Application(components);
          eventBus.register(application);
        } else {
          StaticZooKeeperConfigurationProvider zookeeperConfigurationProvider =
            new StaticZooKeeperConfigurationProvider(
              agentName, zkConnectionStr, baseZkPath);
          application = new Application();
          application.handleConfigurationEvent(zookeeperConfigurationProvider
            .getConfiguration());
        }
      } else {
        File configurationFile = new File(commandLine.getOptionValue('f'));

        /*
         * The following is to ensure that by default the agent will fail on
         * startup if the file does not exist.
         */
 
View Full Code Here

      .addOption("l", "dataDirs", true, "Comma-separated list of data " +
        "directories which the tool must verify. This option is mandatory")
      .addOption("h", "help", false, "Display help");

    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = parser.parse(options, args);
    if(commandLine.hasOption("help")) {
      new HelpFormatter().printHelp("java -jar fcintegritytool ",
        options, true);
      return false;
    }
    if(!commandLine.hasOption("dataDirs")) {
      new HelpFormatter().printHelp("java -jar fcintegritytool ", "",
        options, "dataDirs is required.", true);
      return false;
    } else {
      String dataDirStr[] = commandLine.getOptionValue("dataDirs").split(",");
      for(String dataDir : dataDirStr) {
        File f = new File(dataDir);
        if(!f.exists()) {
          throw new FlumeException("Data directory, " + dataDir + " does not " +
            "exist.");
View Full Code Here

            registar, false);
  }

  public void testPreprocessCommandValidInput() throws Exception {
    String content = String.format("%s arg1 arg2\n", commandName);
    CommandLine commandLine = agent.preprocessCommand(content);
    assertEquals(3, commandLine.getArgs().length);
  }
View Full Code Here

    assertEquals(3, commandLine.getArgs().length);
  }

  public void testPreprocessCommandNoCommandInput() throws Exception {
    String content = String.format("%s arg1 arg2\n", "not_a_command");
    CommandLine commandLine = agent.preprocessCommand(content);
    assertNull(commandLine);
  }
View Full Code Here

    return UriBuilder.fromUri("http://0.0.0.0/").port(port).build();
  }

  public static void main(final String[] args) throws Exception {
    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options(), args);
   
    int port = Integer.parseInt(cmd.getOptionValue("port", "8080"));
    String dbHost = cmd.getOptionValue("dbhost", "localhost");
    int dbPort = Integer.parseInt(cmd.getOptionValue("dbport", "3306"));
   
    new JerseyWebServer(port,dbHost, dbPort).run();
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.cli.CommandLine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.