List of usage examples for org.apache.commons.cli Option setArgs
public void setArgs(int num)
From source file:org.jax.bioinfdata.genocall.ConvertGenotypeFlatFileToHDF5Main.java
/** * the main entry point// www .j a v a 2s . co m * @param args command line args * @throws IOException * @throws IllegalFormatException */ public static void main(String[] args) throws IllegalFormatException, IOException { // Deal with the options. CommandLineParser parser = new GnuParser(); Options options = new Options(); CommandLine commandLine = null; final Option helpOption; { helpOption = new Option("help", "Print this help and exit"); helpOption.setRequired(false); options.addOption(helpOption); } final Option genoFileOption; { genoFileOption = new Option("genoinfiles", "the genotype input flat file"); genoFileOption.setRequired(true); genoFileOption.setArgs(Integer.MAX_VALUE); genoFileOption.setArgName("file name"); options.addOption(genoFileOption); } final Option genoInFormatOption; { genoInFormatOption = new Option("genoinformat", "[optional] the format of the genotype file (must be \"csv\"" + " or \"tab\". \"csv\" is the default)"); genoInFormatOption.setRequired(false); genoInFormatOption.setArgs(1); genoInFormatOption.setArgName("csv or tab"); options.addOption(genoInFormatOption); } final Option aAlleleOption; { aAlleleOption = new Option("aallelecol", "[optional] the A allele column # (one-based index). If " + "no A allele column is given then allele codes must be " + "used in place of nucleotide values where 1 = A allele, " + "2 = B allele, 3 = Heterozygous, -1 = No Call"); aAlleleOption.setRequired(false); aAlleleOption.setArgs(1); aAlleleOption.setArgName("column #"); options.addOption(aAlleleOption); } final Option bAlleleOption; { bAlleleOption = new Option("ballelecol", "[optional] the B allele column # (one-based index). If " + "no B allele column is given then allele codes must be " + "used in place of nucleotide values where 1 = A allele, " + "2 = B allele, 3 = Heterozygous, -1 = No Call"); bAlleleOption.setRequired(false); bAlleleOption.setArgs(1); bAlleleOption.setArgName("column #"); options.addOption(bAlleleOption); } final Option snpIdColumnOption; { snpIdColumnOption = new Option("snpcol", "[optional] the SNP ID column # (one-based index)"); snpIdColumnOption.setRequired(false); snpIdColumnOption.setArgs(1); snpIdColumnOption.setArgName("column #"); options.addOption(snpIdColumnOption); } final Option chromosomeColumnOption; { chromosomeColumnOption = new Option("chrcol", "[optional] the chromosome ID column # (one-based index)"); chromosomeColumnOption.setRequired(false); chromosomeColumnOption.setArgs(1); chromosomeColumnOption.setArgName("column #"); options.addOption(chromosomeColumnOption); } final Option bpPositionColumnOption; { bpPositionColumnOption = new Option("poscol", "[optional] base-pair position column # (one-based index)"); bpPositionColumnOption.setRequired(false); bpPositionColumnOption.setArgs(1); bpPositionColumnOption.setArgName("column #"); options.addOption(bpPositionColumnOption); } final Option bpBuildIDOption; { bpBuildIDOption = new Option("bpbuild", "[optional] BP position build identifier (Eg: \"NCBI Build 37\")"); bpBuildIDOption.setRequired(false); bpBuildIDOption.setArgs(1); bpBuildIDOption.setArgName("build identifier"); options.addOption(bpBuildIDOption); } final Option firstGenoColumnOption; { firstGenoColumnOption = new Option("firstgenocol", "the first genotype column # (one-based index)"); firstGenoColumnOption.setRequired(true); firstGenoColumnOption.setArgs(1); firstGenoColumnOption.setArgName("column #"); options.addOption(firstGenoColumnOption); } final Option lastGenoColumnOption; { lastGenoColumnOption = new Option("lastgenocol", "[optional] the last genotype column # (one-based index). " + "The default behavior is to assume that all columns after " + "the first genotype column are genotype columns."); lastGenoColumnOption.setRequired(false); lastGenoColumnOption.setArgs(1); lastGenoColumnOption.setArgName("column #"); options.addOption(lastGenoColumnOption); } final Option outputFileOption; { outputFileOption = new Option("hdf5out", "the file to write HDF5 output to"); outputFileOption.setRequired(true); outputFileOption.setArgs(1); outputFileOption.setArgName("file name"); options.addOption(outputFileOption); } final Option sortOption; { sortOption = new Option("sort", "Sort the matrix by genomic position"); sortOption.setRequired(false); options.addOption(sortOption); } try { commandLine = parser.parse(options, args); // See if we just need to print the help options. if (commandLine.hasOption(helpOption.getOpt())) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("fftohdf5", options); } else { final String[] genoFileNames = commandLine.getOptionValues(genoFileOption.getOpt()); final String genoInFmtStr = commandLine.getOptionValue(genoInFormatOption.getOpt()); final String aColStr = commandLine.getOptionValue(aAlleleOption.getOpt()); final String bColStr = commandLine.getOptionValue(bAlleleOption.getOpt()); final String snpColStr = commandLine.getOptionValue(snpIdColumnOption.getOpt()); final String chrColStr = commandLine.getOptionValue(chromosomeColumnOption.getOpt()); final String bpPosStr = commandLine.getOptionValue(bpPositionColumnOption.getOpt()); final String bpBuildIDStr = commandLine.getOptionValue(bpBuildIDOption.getOpt()); final String fstGenoColStr = commandLine.getOptionValue(firstGenoColumnOption.getOpt()); final String lstGenoColStr = commandLine.getOptionValue(lastGenoColumnOption.getOpt()); final String outFileName = commandLine.getOptionValue(outputFileOption.getOpt()); final FlatFileFormat ffFormat; if (genoInFmtStr == null || genoInFmtStr.trim().toLowerCase().equals("csv")) { ffFormat = CommonFlatFileFormat.CSV_UNIX; } else if (genoInFmtStr.trim().toLowerCase().equals("tab")) { ffFormat = CommonFlatFileFormat.TAB_DELIMITED_UNIX; } else { throw new ParseException("geno file input format must be \"tab\" or \"csv\""); } final FlatFileReader[] genoFFRs = new FlatFileReader[genoFileNames.length]; for (int i = 0; i < genoFFRs.length; i++) { genoFFRs[i] = new FlatFileReader(new FileReader(genoFileNames[i]), ffFormat); } LOG.info("reading genotype flat files"); GenotypeCallMatrix genoMat = GenotypesFlatFile.readGenoCallMatrix(genoFFRs, argToIntMinus1(aColStr), argToIntMinus1(bColStr), argToIntMinus1(snpColStr), argToIntMinus1(chrColStr), argToIntMinus1(bpPosStr), bpBuildIDStr, argToIntMinus1(fstGenoColStr), argToInt(lstGenoColStr)); for (int i = 0; i < genoFFRs.length; i++) { genoFFRs[i].close(); } if (commandLine.hasOption(sortOption.getOpt())) { if (!genoMat.isSortedByPosition()) { LOG.info("sorting genotypes by position"); CallMatrixSorter.sortCallMatrix(genoMat); } } LOG.info("writing call matrix to " + outFileName); IHDF5Factory hdf5Fac = HDF5FactoryProvider.get(); File hdf5File = new File(outFileName); if (hdf5File.exists()) { if (!hdf5File.delete()) { throw new IOException("failed to overwrite \"" + outFileName + "\""); } } IHDF5Writer hdf5Writer = hdf5Fac.open(hdf5File); HDF5GenotypeCallMatrix hdf5GenoMat = new HDF5GenotypeCallMatrix(hdf5Writer); AbstractGenotypeCallMatrix.copyGenoMatrix(genoMat, hdf5GenoMat); hdf5Writer.close(); } } catch (ParseException ex) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("fftohdf5", options); System.exit(-1); } }
From source file:org.jax.bioinfdata.genocall.ConvertGenotypeHDF5ToFlatFileMain.java
/** * the main entry point//from ww w .j a v a 2s . co m * @param args command line args * @throws IOException * @throws IllegalFormatException */ public static void main(String[] args) throws IllegalFormatException, IOException { // Deal with the options. CommandLineParser parser = new GnuParser(); Options options = new Options(); CommandLine commandLine = null; final Option helpOption; { helpOption = new Option("help", "Print this help and exit"); helpOption.setRequired(false); options.addOption(helpOption); } final Option genoFileOption; { genoFileOption = new Option("genooutfile", "the genotype output flat file"); genoFileOption.setRequired(true); genoFileOption.setArgs(1); genoFileOption.setArgName("file name"); options.addOption(genoFileOption); } final Option genoOutFormatOption; { genoOutFormatOption = new Option("genooutformat", "[optional] the format of the genotype file (must be \"csv\" or \"tab\")"); genoOutFormatOption.setRequired(false); genoOutFormatOption.setArgs(1); genoOutFormatOption.setArgName("csv or tab"); options.addOption(genoOutFormatOption); } final Option hdf5InputFileOption; { hdf5InputFileOption = new Option("hdf5in", "the file to read HDF5 input from"); hdf5InputFileOption.setRequired(true); hdf5InputFileOption.setArgs(1); hdf5InputFileOption.setArgName("file name"); options.addOption(hdf5InputFileOption); } try { commandLine = parser.parse(options, args); // See if we just need to print the help options. if (commandLine.hasOption(helpOption.getOpt())) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("hdf5toff", options); } else { final String genoFileName = commandLine.getOptionValue(genoFileOption.getOpt()); final String genoOutFmtStr = commandLine.getOptionValue(genoOutFormatOption.getOpt()); final String hdf5InFileName = commandLine.getOptionValue(hdf5InputFileOption.getOpt()); IHDF5Factory hdf5Fac = HDF5FactoryProvider.get(); IHDF5Reader hdf5Reader = hdf5Fac.openForReading(new File(hdf5InFileName)); HDF5GenotypeCallMatrix hdf5GenoMatrix = new HDF5GenotypeCallMatrix(hdf5Reader); final FlatFileWriter genoFFW; if (genoOutFmtStr == null || genoOutFmtStr.trim().toLowerCase().equals("csv")) { genoFFW = new FlatFileWriter(new FileWriter(genoFileName), CommonFlatFileFormat.CSV_UNIX); } else if (genoOutFmtStr.trim().toLowerCase().equals("tab")) { genoFFW = new FlatFileWriter(new FileWriter(genoFileName), CommonFlatFileFormat.TAB_DELIMITED_UNIX); } else { throw new ParseException("geno file input format must be \"tab\" or \"csv\""); } GenotypesFlatFile.writeGenoCallMatrix(hdf5GenoMatrix, genoFFW); hdf5Reader.close(); genoFFW.close(); } } catch (ParseException ex) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("hdf5toff", options); System.exit(-1); } }
From source file:org.jax.bioinfdata.phylogeny.MaxKPhylogenyMain.java
/** * The main entry point//from ww w. j a v a 2 s . com * @param args function arguments * @throws IOException if we have a problem reading/writing data * @throws NoValidPhylogenyException */ public static void main(String[] args) throws IOException, NoValidPhylogenyException { // Deal with the options. CommandLineParser parser = new GnuParser(); Options options = new Options(); CommandLine commandLine = null; final Option helpOption; { helpOption = new Option("help", "Print this help and exit"); helpOption.setRequired(false); options.addOption(helpOption); } final Option hdf5InputFileOption; { hdf5InputFileOption = new Option("hdf5in", "the HDF5 input file containing the genotype matrix"); hdf5InputFileOption.setRequired(true); hdf5InputFileOption.setArgs(1); hdf5InputFileOption.setArgName("file name"); options.addOption(hdf5InputFileOption); } final Option csvOutputFileOption; { csvOutputFileOption = new Option("csvout", "the CSV output file with max-k intervals and their " + "corresponding perfect phylogenies in newick format"); csvOutputFileOption.setRequired(true); csvOutputFileOption.setArgs(1); csvOutputFileOption.setArgName("file name"); options.addOption(csvOutputFileOption); } try { commandLine = parser.parse(options, args); // See if we just need to print the help options. if (commandLine.hasOption(helpOption.getOpt())) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("maxkphylo", options); } else { final String hdf5InFileName = commandLine.getOptionValue(hdf5InputFileOption.getOpt()); final String csvOutFileName = commandLine.getOptionValue(csvOutputFileOption.getOpt()); IHDF5Factory hdf5Fac = HDF5FactoryProvider.get(); IHDF5Reader hdf5Reader = hdf5Fac.openForReading(new File(hdf5InFileName)); HDF5GenotypeCallMatrix hdf5GenoMatrix = new HDF5GenotypeCallMatrix(hdf5Reader); // write the header row FlatFileWriter ffw = new FlatFileWriter( //new OutputStreamWriter(System.out), new FileWriter(csvOutFileName), CommonFlatFileFormat.CSV_UNIX); ffw.writeRow( new String[] { "chrID", "bpStartPosition", "bpEndPosition", "newickPerfectPhylogeny" }); // scan the chromosomes in order for (AbstractGenotypeCallMatrix currChrView : hdf5GenoMatrix.getChromosomeViews()) { List<IndexedSnpInterval> maxKScanResult = IntervalScanner.maxKScan(currChrView); List<PhylogenyTreeNode> phyloScanResult = PhylogenyScanner.inferPerfectPhylogenies(currChrView, maxKScanResult); assert maxKScanResult.size() == phyloScanResult.size(); String[] chrIDArray = currChrView.getChrIDs(); long[] posArray = currChrView.getBpPositions(); for (int i = 0; i < maxKScanResult.size(); i++) { IndexedSnpInterval isi = maxKScanResult.get(i); PhylogenyTreeNode phylo = phyloScanResult.get(i); ffw.writeRow(new String[] { chrIDArray[isi.getStartIndex()], Long.toString(posArray[isi.getStartIndex()]), Long.toString(posArray[isi.getEndIndex()]), phylo.toNewickFormat() }); } } ffw.flush(); ffw.close(); } } catch (ParseException ex) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("maxkphylo", options); System.exit(-1); } }
From source file:org.jax.bioinfdata.phylogeny.PhylogenySdpMain.java
/** * Main entry point for reading in newick trees at specified intervals and * turning them into SDPs/* w w w.ja v a2 s .com*/ * @param args * @throws IOException * @throws IllegalFormatException */ public static void main(String[] args) throws IOException, IllegalFormatException { // Deal with the options. CommandLineParser parser = new GnuParser(); Options options = new Options(); CommandLine commandLine = null; final Option helpOption; { helpOption = new Option("help", "Print this help and exit"); helpOption.setRequired(false); options.addOption(helpOption); } final Option inputFileOption; { inputFileOption = new Option("phylocsvin", "This is the input " + "CSV file which must have a header row allong with " + "the following four columns in order: chromosome ID, " + "interval start in base pairs, interval end in base pairs, " + "newick formatted phylogeny tree"); inputFileOption.setRequired(true); inputFileOption.setArgs(1); inputFileOption.setArgName("file name"); options.addOption(inputFileOption); } final Option minMinorStrainCountOption; { minMinorStrainCountOption = new Option("minorallelecountthreshold", "this option specifies the minimum minor allele count that " + "an SDP must have. All SDPs that fall below this threshold " + "will be filtered from the output."); minMinorStrainCountOption.setRequired(true); minMinorStrainCountOption.setArgs(1); minMinorStrainCountOption.setArgName("min SDP count"); options.addOption(minMinorStrainCountOption); } final Option outputFileOption; { outputFileOption = new Option("sdpcsvout", "the output CSV file"); outputFileOption.setRequired(true); outputFileOption.setArgs(1); outputFileOption.setArgName("file name"); options.addOption(outputFileOption); } try { commandLine = parser.parse(options, args); // See if we just need to print the help options. if (commandLine.hasOption(helpOption.getOpt())) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("phylosdp", options); } else { final String inFileName = commandLine.getOptionValue(inputFileOption.getOpt()); final String outFileName = commandLine.getOptionValue(outputFileOption.getOpt()); final String minMinorStrainCountStr = commandLine .getOptionValue(minMinorStrainCountOption.getOpt()); final int minMinorStrainCount = Integer.parseInt(minMinorStrainCountStr); FlatFileReader ffr = new FlatFileReader(new FileReader(inFileName), CommonFlatFileFormat.CSV_UNIX); String[] inHeader = ffr.readRow(); if (inHeader == null) { throw new IOException("the input file is empty"); } else if (inHeader.length != 4) { throw new IllegalFormatException( "expected the input to have 4 columns but found " + inHeader.length + " columns"); } else { Map<BitSet, List<GenomeInterval>> sdpMap = new HashMap<BitSet, List<GenomeInterval>>(); ArrayList<String> strainNames = null; String[] outHeader = null; String[] currInRow = null; while ((currInRow = ffr.readRow()) != null) { GenomeInterval genoInt = new GenomeInterval(currInRow[0], Long.parseLong(currInRow[1]), Long.parseLong(currInRow[2])); PhylogenyTreeNode phylo = PhylogenyTreeNode.fromNewickFormat(currInRow[3]); if (strainNames == null) { strainNames = new ArrayList<String>(phylo.getAllStrains()); Collections.sort(strainNames); outHeader = new String[strainNames.size() + 1]; for (int i = 0; i < strainNames.size(); i++) { outHeader[i] = strainNames.get(i); } outHeader[outHeader.length - 1] = "genomicIntervals"; } Set<BitSet> phyloSdps = phylo.sdps(strainNames, minMinorStrainCount); for (BitSet sdp : phyloSdps) { List<GenomeInterval> sdpIntervals = sdpMap.get(sdp); if (sdpIntervals == null) { sdpIntervals = new ArrayList<GenomeInterval>(); sdpMap.put(sdp, sdpIntervals); } sdpIntervals.add(genoInt); } } if (strainNames == null) { System.out.println("The input file " + inFileName + " appears empty"); System.exit(-1); } else { // write the header row FlatFileWriter ffw = new FlatFileWriter( //new OutputStreamWriter(System.out), new FileWriter(outFileName), CommonFlatFileFormat.CSV_UNIX); ffw.writeRow(outHeader); int strainCount = strainNames.size(); String[] currOutRow = new String[strainNames.size() + 1]; for (Map.Entry<BitSet, List<GenomeInterval>> entry : sdpMap.entrySet()) { BitSet currSDP = entry.getKey(); for (int i = 0; i < strainCount; i++) { currOutRow[i] = currSDP.get(i) ? "1" : "0"; } StringBuilder sb = new StringBuilder(); List<GenomeInterval> intervals = entry.getValue(); int intervalCount = intervals.size(); for (int i = 0; i < intervalCount; i++) { GenomeInterval interval = intervals.get(i); sb.append(interval.getChrId()); sb.append(';'); sb.append(interval.getStartPositionBp()); sb.append(';'); sb.append(interval.getEndPositionBp()); if (i < intervalCount - 1) { sb.append('|'); } } currOutRow[strainCount] = sb.toString(); ffw.writeRow(currOutRow); } ffw.flush(); } } } } catch (ParseException ex) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("phylosdp", options); System.exit(-1); } }
From source file:org.jax.haplotype.analysis.EMMAAssociationTest.java
/** * the main entry point//from ww w. ja v a 2 s .c o m * @param args command line args * @throws IOException * @throws IllegalFormatException */ public static void main(String[] args) throws IllegalFormatException, IOException { // Deal with the options. CommandLineParser parser = new GnuParser(); Options options = new Options(); CommandLine commandLine = null; final Option helpOption; { helpOption = new Option("help", "Print this help and exit"); helpOption.setRequired(false); options.addOption(helpOption); } final Option genoFileOption; { genoFileOption = new Option("genofile", "the genotype file"); genoFileOption.setRequired(true); genoFileOption.setArgs(1); genoFileOption.setArgName("file name"); options.addOption(genoFileOption); } final Option aAlleleOption; { aAlleleOption = new Option("aallelecol", "the A allele column # (one-based index)"); aAlleleOption.setRequired(true); aAlleleOption.setArgs(1); aAlleleOption.setArgName("column number"); options.addOption(aAlleleOption); } final Option bAlleleOption; { bAlleleOption = new Option("ballelecol", "the B allele column # (one-based index)"); bAlleleOption.setRequired(true); bAlleleOption.setArgs(1); bAlleleOption.setArgName("column number"); options.addOption(bAlleleOption); } final Option firstGenoColumnOption; { firstGenoColumnOption = new Option("firstgenocol", "the first genotype column # (one-based index)"); firstGenoColumnOption.setRequired(true); firstGenoColumnOption.setArgs(1); firstGenoColumnOption.setArgName("column #"); options.addOption(firstGenoColumnOption); } final Option lastGenoColumnOption; { lastGenoColumnOption = new Option("lastgenocol", "[optional] the last genotype column # (one-based index). " + "The default behavior is to assume that all columns after " + "the first genotype column are genotype columns."); lastGenoColumnOption.setRequired(false); lastGenoColumnOption.setArgs(1); lastGenoColumnOption.setArgName("column #"); options.addOption(lastGenoColumnOption); } final Option phenoFileOption; { phenoFileOption = new Option("phenofile", "the phenotype file"); phenoFileOption.setRequired(true); phenoFileOption.setArgs(1); phenoFileOption.setArgName("file name"); options.addOption(phenoFileOption); } final Option phenoNameOption; { phenoNameOption = new Option("phenoname", "[optional] the name of the phenotype to scan"); phenoNameOption.setRequired(false); phenoNameOption.setArgs(1); phenoNameOption.setArgName("name"); options.addOption(phenoNameOption); } final Option sexOption; { sexOption = new Option("sex", "[optional] filter phenotypes by sex. " + "agnostic is the default value."); sexOption.setRequired(false); sexOption.setArgs(1); sexOption.setArgName("agnostic/female/male"); options.addOption(sexOption); } final Option outputFileOption; { outputFileOption = new Option("out", "the file to write scan output to"); outputFileOption.setRequired(true); outputFileOption.setArgs(1); outputFileOption.setArgName("file name"); options.addOption(outputFileOption); } try { commandLine = parser.parse(options, args); // See if we just need to print the help options. if (commandLine.hasOption(helpOption.getOpt())) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("emmascan", options); } else { final String genoFileName = commandLine.getOptionValue(genoFileOption.getOpt()); final String aColStr = commandLine.getOptionValue(aAlleleOption.getOpt()); final String bColStr = commandLine.getOptionValue(bAlleleOption.getOpt()); final String fstGenoColStr = commandLine.getOptionValue(firstGenoColumnOption.getOpt()); final String lstGenoColStr = commandLine.getOptionValue(lastGenoColumnOption.getOpt()); final String phenoFileName = commandLine.getOptionValue(phenoFileOption.getOpt()); final String phenotype = commandLine.getOptionValue(phenoNameOption.getOpt()); final String sexStr = commandLine.getOptionValue(sexOption.getOpt()); final String outFileName = commandLine.getOptionValue(outputFileOption.getOpt()); final SexFilter sexToScan; if (sexStr == null || sexStr.toLowerCase().equals("agnostic")) { sexToScan = SexFilter.AGNOSTIC; } else if (sexStr.toLowerCase().equals("female")) { sexToScan = SexFilter.ALLOW_FEMALE; } else if (sexStr.toLowerCase().equals("male")) { sexToScan = SexFilter.ALLOW_MALE; } else { throw new ParseException("sex option cannot be: " + sexStr); } EMMAAssociationTest emmaTest = new EMMAAssociationTest(); double[] scanResults = emmaTest.emmaScan(genoFileName, Integer.parseInt(aColStr.trim()) - 1, Integer.parseInt(bColStr.trim()) - 1, Integer.parseInt(fstGenoColStr.trim()) - 1, lstGenoColStr == null ? -1 : Integer.parseInt(lstGenoColStr.trim()), phenoFileName, phenotype, sexToScan); PrintStream out = new PrintStream(outFileName); out.println("pValue"); for (int i = 0; i < scanResults.length; i++) { out.println(scanResults[i]); } out.close(); } } catch (ParseException ex) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("emmascan", options); System.exit(-1); } }
From source file:org.jax.haplotype.analysis.HaplotypeAssociationMappingMain.java
/** * the main application function for haplotype association mapping * @param args// w w w . j av a 2s . c o m * command line arguments */ public static void main(String[] args) { // Deal with the options. CommandLineParser parser = new GnuParser(); Options options = new Options(); CommandLine commandLine = null; final Option helpOption; { helpOption = new Option("help", "Print this help and exit"); helpOption.setRequired(false); options.addOption(helpOption); } final Option designfileOption; { designfileOption = new Option("designfile", "the analysis design file"); designfileOption.setRequired(false); designfileOption.setArgs(1); designfileOption.setArgName("file name"); options.addOption(designfileOption); } try { commandLine = parser.parse(options, args); // See if we just need to print the help options. if (commandLine.hasOption(helpOption.getOpt())) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("ham-analysis", options); } else { if (commandLine.hasOption(designfileOption.getOpt())) { String fileName = commandLine.getOptionValue(designfileOption.getOpt()); HaplotypeAssociationMappingMain mainInstance = new HaplotypeAssociationMappingMain(); mainInstance.setAnalysisDesignFile(fileName); mainInstance.performAnalysis(); } else { System.out.println("initialization failed"); HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("ham-analysis", options); } } } catch (ParseException ex) { LOG.log(Level.SEVERE, "initialization failed", ex); HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("ham-analysis", options); } }
From source file:org.jcryptool.commands.core.api.OptionsBuilder.java
public OptionsBuilder addOption(String longOption, String shortOption, boolean required, String description, String argName, boolean argRequired, char argValueSeparator, int argsCount) { Option option = new Option(shortOption, longOption, true, description); option.setArgName(argName);/*from www . j a v a 2s . com*/ option.setRequired(required); option.setOptionalArg(argRequired); option.setValueSeparator(argValueSeparator); option.setArgs(argsCount); options.add(option); return this; }
From source file:org.jini.commands.utils.DateCalc.java
/** * In this method all the specific Command Line options are defined. * *//*from w w w . jav a2 s . c o m*/ @Override @SuppressWarnings("static-access") public void setJCLIOptions() { Option Help = new Option("h", "help", false, "Show Help."); this.jcOptions.addOption(Help); OptionGroup jcGroup = new OptionGroup(); Option diff = new Option("diff", "difference", false, "Calculate Difference between dates."); diff.setArgs(2); jcGroup.addOption(diff); Option addDays = new Option("a", "add", false, "Add days to date."); addDays.setArgs(2); jcGroup.addOption(addDays); this.jcOptions.addOptionGroup(jcGroup); }
From source file:org.jruyi.launcher.Main.java
private static boolean processCommandLines(String[] args) throws Exception { Options options = new Options(); options.addOption("?", "help", false, null); options.addOption("v", "version", false, null); Option o = new Option("D", true, null); o.setArgs(Option.UNLIMITED_VALUES); options.addOption(o);/* w ww .ja v a 2s. c o m*/ options.addOption("r", "run", true, null); CommandLine line = new PosixParser().parse(options, args); Option[] opts = line.getOptions(); for (Option option : opts) { String opt = option.getOpt(); if (opt.equals("?")) { printHelp(); return false; } else if (opt.equals("v")) { MainHolder.INST.printVersion(); return false; } else if (opt.equals("D")) { handleSystemProps(option.getValues()); } else if (opt.equals("r")) { System.setProperty(JRUYI_INST_NAME, option.getValue().trim()); } else throw new Exception("Unknown option: " + option); } return true; }
From source file:org.objectweb.proactive.examples.fastdeployment.Main.java
public void parseArguments(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption(Params.concurrency.sOpt, Params.concurrency.toString(), true, Params.concurrency.desc); options.addOption(Params.pause.sOpt, Params.pause.toString(), true, Params.pause.desc); Option descOption; descOption = new Option(Params.descriptor.sOpt, Params.descriptor.toString(), true, Params.descriptor.desc); descOption.setArgs(Option.UNLIMITED_VALUES); options.addOption(descOption);/* w ww.j av a2 s.c om*/ Option vnOption; vnOption = new Option(Params.virtualNode.sOpt, Params.virtualNode.toString(), true, Params.virtualNode.desc); vnOption.setArgs(Option.UNLIMITED_VALUES); options.addOption(vnOption); CommandLine line = null; String arg; try { line = parser.parse(options, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fast Deployment", options); System.exit(1); } Option[] pOptions = line.getOptions(); for (Option pOption : pOptions) { if (pOption.getOpt().equals(Params.virtualNode.sOpt)) { for (String s : pOption.getValues()) { virtualNodes.add(s); } } if (pOption.getOpt().equals(Params.descriptor.sOpt)) { for (String s : pOption.getValues()) { descriptors.add(s); } } } arg = line.getOptionValue(Params.concurrency.sOpt); if (arg != null) { try { concurrency = new Integer(arg); } catch (NumberFormatException e) { logger.warn("Invalid option value " + arg); } } arg = line.getOptionValue(Params.pause.sOpt); if (arg != null) { try { pause = new Integer(arg); } catch (NumberFormatException e) { logger.warn("Invalid option value " + arg); } } }