Package com.martiansoftware.jsap

Examples of com.martiansoftware.jsap.JSAPResult


                .setRequired(true)
                .setGreedy(true);
               
    jsap.registerParameter(opt2);
   
    JSAPResult config = jsap.parse(args)

    // check whether the command line was valid, and if it wasn't,
    // display usage information and exit.
    if (!config.success()) {
      System.err.println();
      System.err.println("Usage: java "
                + Manual_HelloWorld_5.class.getName());
      System.err.println("                "
                + jsap.getUsage());
      System.err.println();
      System.exit(1);
    }
   
    String[] names = config.getStringArray("name");
    for (int i = 0; i < config.getInt("count"); ++i) {
      for (int j = 0; j < names.length; ++j) {
        System.out.println((config.getBoolean("verbose") ? "Hello" : "Hi")
                + ", "
                + names[j]
                + "!");
      }
    }
View Full Code Here


            .setShortFlag('v')
            .setLongFlag("verbose");
   
    jsap.registerParameter(sw1);
   
    JSAPResult config = jsap.parse(args)

    for (int i = 0; i < config.getInt("count"); ++i) {
      System.out.println((config.getBoolean("verbose") ? "Hello" : "Hi")
                + ", World!");
    }
   
  }
View Full Code Here

                .setGreedy(true);
   
    opt2.setHelp("One or more names of people you would like to greet.");
    jsap.registerParameter(opt2);
   
    JSAPResult config = jsap.parse(args)

    if (!config.success()) {
     
      System.err.println();

      // print out specific error messages describing the problems
      // with the command line, THEN print usage, THEN print full
      // help.  This is called "beating the user with a clue stick."
      for (java.util.Iterator errs = config.getErrorMessageIterator();
          errs.hasNext();) {
        System.err.println("Error: " + errs.next());
      }
     
      System.err.println();
      System.err.println("Usage: java "
                + Manual_HelloWorld_7.class.getName());
      System.err.println("                "
                + jsap.getUsage());
      System.err.println();
      System.err.println(jsap.getHelp());
      System.exit(1);
    }
   
    String[] names = config.getStringArray("name");
    for (int i = 0; i < config.getInt("count"); ++i) {
      for (int j = 0; j < names.length; ++j) {
        System.out.println((config.getBoolean("verbose") ? "Hello" : "Hi")
                + ", "
                + names[j]
                + "!");
      }
    }
View Full Code Here

  // @@snip:Manual_HelloWorld_9@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP(Manual_HelloWorld_9.class.getResource("Manual_HelloWorld_9.jsap"));
   
    JSAPResult config = jsap.parse(args)

    if (!config.success()) {
     
      System.err.println();

      // print out specific error messages describing the problems
      // with the command line, THEN print usage, THEN print full
      // help.  This is called "beating the user with a clue stick."
      for (java.util.Iterator errs = config.getErrorMessageIterator();
          errs.hasNext();) {
        System.err.println("Error: " + errs.next());
      }
     
      System.err.println();
      System.err.println("Usage: java "
                + Manual_HelloWorld_9.class.getName());
      System.err.println("                "
                + jsap.getUsage());
      System.err.println();
      System.err.println(jsap.getHelp());
      System.exit(1);
    }
   
    String[] names = config.getStringArray("name");
    String[] languages = config.getStringArray("verbose");
    if (languages.length == 0) languages = new String[] {"en"};
   
    for (int lang = 0; lang < languages.length; ++lang) {
      for (int i = 0; i < config.getInt("count"); ++i) {
        for (int j = 0; j < names.length; ++j) {
          System.out.println((config.getBoolean("verbose") ? getVerboseHello(languages[lang]) : "Hi")
                  + ", "
                  + names[j]
                  + "!");
        }
      }
View Full Code Here

            new FlaggedOption("nfile", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 'n', JSAP.NO_LONGFLAG,
                "Location of influenza_na.dat") });
    if (jsap.messagePrinted())
      System.exit(1);

    JSAPResult config = jsap.parse(args);
    InfluenzaDataLoader fluDemo = new InfluenzaDataLoader();
    try {
      fluDemo.createCache(config.getString("InfinispanCfg"));
      fluDemo.populateCache(config);
    } catch (SAXException e1) {
      e1.printStackTrace();
      System.exit(1);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(2);
    }

    while (true) {
      if (config.getBoolean("query")) {
        System.out.print("Enter Virus Genbank Accession Number: ");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String GBAN = null;
        try {
          GBAN = br.readLine();
View Full Code Here

    jsap.registerParameter(new Switch(BSC.VERSION, 'v', BSC.VERSION,
        "Prints out Mockey's version (semantic versioning http://semver.org/)"));

    // parse the command line options
    JSAPResult config = jsap.parse(args);

    // Bail out if they asked for the --help
    if (jsap.messagePrinted()) {
      System.exit(1);
    }

    if (config.getBoolean(BSC.VERSION)) {

      String ver = JettyRunner.class.getPackage().getImplementationVersion();
      System.out.println("Version " + ver);
      System.exit(1);
    }

    // String v = config.

    // Construct the new arguments for jetty-runner
    int port = config.getInt(ARG_PORT);
    boolean transientState = true;

    try {
      transientState = config.getBoolean(BSC.TRANSIENT);
    } catch (Exception e) {
      //
    }

    // Initialize Log4J file roller appender.
    StartUpServlet.getDebugFile();
    InputStream log4jInputStream = Thread.currentThread().getContextClassLoader()
        .getResourceAsStream("WEB-INF/log4j.properties");
    Properties log4JProperties = new Properties();
    log4JProperties.load(log4jInputStream);
    PropertyConfigurator.configure(log4JProperties);

    Server server = new Server(port);

    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setConfigurations(new Configuration[] { new PreCompiledJspConfiguration() });

    ClassPathResourceHandler resourceHandler = new ClassPathResourceHandler();
    resourceHandler.setContextPath("/");

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    contexts.addHandler(resourceHandler);

    contexts.addHandler(webapp);

    server.setHandler(contexts);

    server.start();
    // Construct the arguments for Mockey

    // /////////////////////// Set BASE path for reading files.
    // ////////////////
    String configurationPath = String.valueOf(config.getString(BSC.DEFINITION_LOCATION));
    MockeyXmlFileManager.createInstance(configurationPath);
    MockeyXmlFileManager instance = MockeyXmlFileManager.getInstance();
    System.out.println("Configuration base path: " + instance.getBasePathFile().getAbsolutePath());
    // /////////////////////////////////////////////////////////////////////

    String file = String.valueOf(config.getString(BSC.FILE));
    if (!file.startsWith(File.separator + "")) {
      //No absolute, so we try for a relative path.
      file = instance.getBasePathFile().getAbsolutePath() + File.separator + file;
    }

    String url = String.valueOf(config.getString(BSC.URL));
    String filterTag = config.getString(BSC.FILTERTAG);
    String fTagParam = "";

    boolean headless = config.getBoolean(BSC.HEADLESS);
    if (filterTag != null) {
      fTagParam = "&" + BSC.FILTERTAG + "=" + URLEncoder.encode(filterTag, "UTF-8");
    }

    // Startup displays a big message and URL redirects after x seconds.
View Full Code Here

          new Switch ("multiplex", JSAP.NO_SHORTFLAG, "multiplex", "Analyze each of the multiple datasests given in the input file using all the selection parameters specified."),
          new Switch ("condOnLastSegregating", JSAP.NO_SHORTFLAG, "condOnLastSegregating", "When set, condition on the last sample being segregating."),
              }
          );

    JSAPResult config = jsap.parse(args);
    if (jsap.messagePrinted()) { System.exit(1); }
   
    // what about the binomials
    boolean ignoreBinomials = config.getBoolean ("ignoreBinomials");
    // what about multiplexing
    boolean multiplex = config.getBoolean ("multiplex");
    // what about conditioning
    boolean condOnLastSegregating = config.getBoolean ("condOnLastSegregating");
   
    // precision
    int precision = config.getInt("precision");
    int scale = precision;
    // set precision and some math context
    MathContext mc = new MathContext (precision, RoundingMode.HALF_EVEN);

    // what is the parametrization
    boolean paramByHS = false;
    String param1Name = null, param2Name = null;
    // selection parameterization
    if (config.contains("selection") && config.contains("dominance"))  {
      paramByHS = true;
      param1Name = "selection";
      param2Name = "dominance";
      if (config.contains("hetF") || config.contains("homF"))  {
        System.err.println("Specify exactly either the selection and dominance parameters, or the heterozygote and homozygote advantage parameters");
        System.exit(1);
      }
    }
    else if (config.contains("hetF") && config.contains("homF"))  {
      param1Name = "hetF";
      param2Name = "homF";
      if (config.contains("selection") || config.contains("dominance"))  {
        System.err.println("Specify exactly either the selection and dominance parameters, or the heterozygote and homozygote advantage parameters");
        System.exit(1);
      }
    }
    else {
      System.err.println("Specify exactly either the selection and dominance parameters, or the heterozygote and homozygote advantage parameters");
      System.exit(1);
    }
       
   
    // initial time?
    BigDecimal initTime = null;
    boolean initTimesInFile = !config.contains ("initTime");
    if (initTimesInFile) {
      if (!multiplex) {
        System.err.println ("The flag timesInFile only works together with multiplexing.");
        System.exit(-1);
      }
    }
    else {
      //we do have an initial time
      initTime = config.getBigDecimal("initTime");
    }
   
    // get the initial condition right
    BigDecimal initialFrequency = config.getBigDecimal("initFrequency");
    boolean initFreqSet = (initialFrequency.compareTo(BigDecimal.ZERO) >= 0d) && (initialFrequency.compareTo(BigDecimal.ONE) <= 0d);
    boolean mutSelSet = config.getBoolean ("mutSelBalance");
    boolean mutDriftSet = config.getBoolean ("mutDriftBalance");
    // not check whether exactly one is set, and which one it is
    InitialConditionEnum initialCondition = null;
    if (initFreqSet && !mutSelSet && !mutDriftSet) {
      // initial frequency given
      initialCondition = InitialConditionEnum.InitialFrequency;
    }
    else if (!initFreqSet && mutSelSet && !mutDriftSet) {
      // mutation selection balance requested
      initialCondition = InitialConditionEnum.MutationSelection;
    }
    else if (!initFreqSet && !mutSelSet && mutDriftSet) {
      // mutation drift balance requested
      initialCondition = InitialConditionEnum.MutationDrift;
    }
    else {
      System.err.println ("Must specify consistent initial conditions.");
      System.exit(1);
    }
   
    // get input file
    File inputFile = config.getFile("inputFile");
   
    // get raw mutation parameters
    BigDecimal Ne = (new BigDecimal(config.getString("effPopSize"))).setScale(scale);
    BigDecimal preAlpha = config.getBigDecimal("mutToBenef").setScale(scale);
    if (BigDecimal.ZERO.compareTo(preAlpha) >= 0) throw new IOException ("Zero mutation rate not implemented yet.");
    BigDecimal preBeta = config.getBigDecimal("mutFromBenef").setScale(scale);
    if (BigDecimal.ZERO.compareTo(preBeta) >= 0) throw new IOException ("Zero mutation rate not implemented yet.");
    // and rescale them to be population scaled
    BigDecimal alpha = (new BigDecimal("4")).multiply(Ne, mc).multiply(preAlpha, mc);
    BigDecimal beta = (new BigDecimal("4")).multiply(Ne, mc).multiply(preBeta, mc);
   
    BigDecimal yearsPerGen = (new BigDecimal(config.getString("yearsPerGen"))).setScale(scale);
   
    BigDecimal[] param1Range = null;
    BigDecimal[] param2Range = null;
   
    // some raw selection coefficients
    if (config.contains("selection"))  {
      assert(config.contains("dominance"));
      param1Range = parseRange (config.getString("selection"), scale, mc);
      param2Range = parseRange (config.getString("dominance"), scale, mc);
    }
    if (config.contains("hetF"))  {
      assert(config.contains("homF"));
      param1Range = parseRange (config.getString("hetF"), scale, mc);
      param2Range = parseRange (config.getString("homF"), scale, mc);
    }

    // fill the list of values
    ArrayList<BigDecimal> param1s = buildRange (param1Range[0], param1Range[1], param1Range[2], mc);

    // also we need the other parameters
   
    // make a list of other parameters
    ArrayList<BigDecimal> param2s = buildRange (param2Range[0], param2Range[1], param2Range[2], mc);
   
    // the remaining parameters
    int matrixCutoff = config.getInt("matrixCutoff");
    int maxM = config.getInt("maxM");
    int maxN = config.getInt("maxN");
   
    assert(maxM <= matrixCutoff);
    assert(maxN <= maxM);
   
    //print the command line arguments directly, and also the parameters nicely
View Full Code Here

   }

   protected JSAPResult parseParameters(String[] args) throws Exception {
      SimpleJSAP jsap = buildCommandLineOptions();

      JSAPResult config = jsap.parse(args);
      if (!config.success() || jsap.messagePrinted()) {
         Iterator<?> messageIterator = config.getErrorMessageIterator();
         while (messageIterator.hasNext()) System.err.println(messageIterator.next());
         System.err.println(jsap.getHelp());
         return null;
      }
View Full Code Here

    }

    public static void main(String[] args) throws JSAPException
    {
  JSAP jsap = initArgsParser();
  JSAPResult parsedArgs = jsap.parse(args);
  checkIfArgsParsedSuccessfully(jsap, parsedArgs);
  RougeSeeFormatSerializer s = new RougeSeeFormatSerializer();
  Map<IRougeSummaryModel, Set<IRougeSummaryModel>> results = s.prepareForRouge(parsedArgs.getFile(Config.DOCUMENT_PATH.toString()), parsedArgs.getFile(Config.GOLD_STANDARD_PATH.toString()));

  SummaryStatistics rss = new SummaryStatistics();
  SummaryStatistics pss = new SummaryStatistics();
  SummaryStatistics fss = new SummaryStatistics();

  System.out.println("ROUGE-" + parsedArgs.getInt(Config.GRAM_SIZE.toString()));
  IRouge rouge = null;
  RougeN.DEBUG = parsedArgs.getBoolean(Config.VERBOSE.toString());
  for (IRougeSummaryModel document : results.keySet())
  {
      rouge = new RougeN(
        document,
        results.get(document),
        parsedArgs.getInt(Config.BYTE_LIMIT.toString()),
        parsedArgs.getInt(Config.WORD_LIMIT.toString()),
        parsedArgs.getInt(Config.GRAM_SIZE.toString()),
        parsedArgs.getChar(Config.METHOD.toString()),
        parsedArgs.getDouble(Config.ALPHA.toString())
        );

      Map<ScoreType, Double> scores = rouge.evaluate();

      rss.addValue(scores.get(ScoreType.R));
      pss.addValue(scores.get(ScoreType.P));
      fss.addValue(scores.get(ScoreType.F));
  }

  boolean calculateConfidenceInterval = parsedArgs.getBoolean(Config.CONFIDENCE.toString());
  double confidence = 0;
  if (calculateConfidenceInterval)
  {
      confidence = parsedArgs.getDouble(Config.CONFIDENCE.toString());
  }

  System.out.println("Average_R: " + rss.getMean() + (calculateConfidenceInterval ? " " + getConfidenceInterval(rss, confidence) : ""));
  System.out.println("Average_P: " + pss.getMean() + (calculateConfidenceInterval ? " " + getConfidenceInterval(pss, confidence) : ""));
  System.out.println("Average_F: " + fss.getMean() + (calculateConfidenceInterval ? " " + getConfidenceInterval(fss, confidence) : ""));
View Full Code Here

    jsap.registerParameter(opt3);
    jsap.registerParameter(opt4);

    // check whether the command line was valid, and if it wasn't,
    // display usage information and exit.
    JSAPResult config = jsap.parse(args);
    if (!config.success()) {
      for (java.util.Iterator errs = config.getErrorMessageIterator(); errs
          .hasNext();) {
        System.err.println("Error: " + errs.next());
      }
      displayHelp(config, jsap);
      return;
    }

    if (config.getBoolean("help")) {
      displayHelp(config, jsap);
      return;
    }

    String inDirName      = config.getString("inDir");
    String outDirName     = config.getString("outIndexDir");
    String outLDAIndexName   = config.getString("outLDAIndex");

    // Make sure the specified input directory exists
    if (!(new File((inDirName)).exists())) {
      logger.error("Error: " + inDirName + " does not exist.");
      return;
    }

    // If the output directory already exists, remove it (or else Lucene
    // will complain later)
    File indexDir = new File(outDirName);
    if (indexDir.exists()) {
      logger.info("Deleting index directory " + indexDir.toString());
      FileUtils.deleteDirectory(indexDir);
    }

    // Read the fileCodes, if there is one
    if (config.getString("fileCodes") != null) {
      // TODO: this functionality currently is placed in SimpleIndexer. Is that
      // the best place for it? Maybe we should move it here?
    }

    // Now, for each LDA config on the command line. Since the command line
    // has the form
    // K,dirName, then we need to get the string array (from the JSAP
    // config) and treat them as pairs.
    LDAHelper ldaHelper = new LDAHelper();
    String ldas[] = config.getStringArray("ldaConfig");
    for (int i = 0; i < ldas.length; i += 2) {
      int thisK = Integer.parseInt(ldas[i]);
      String thisInDirName = ldas[i + 1];
      ldaHelper.addScenario(thisK, thisInDirName);
    }
   
    // Serialize the LDAHelper object
    try{
      FileOutputStream fos    = new FileOutputStream(outLDAIndexName);
      ObjectOutputStream out  = new ObjectOutputStream(fos);
      out.writeObject(ldaHelper);
      out.close();
    }
    catch(IOException ex){
      ex.printStackTrace();
      return;
    }

    // Build the index with the options specified.
    SimpleIndexer.indexDirectory(inDirName, outDirName,
        config.getString("fileCodes"), ldaHelper);

    logger.info("Done indexing directory");
  }
View Full Code Here

TOP

Related Classes of com.martiansoftware.jsap.JSAPResult

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.