List of usage examples for org.apache.commons.cli CommandLine equals
public boolean equals(Object obj)
From source file:edu.msu.cme.rdp.probematch.cli.PrimerMatch.java
public static void main(String[] args) throws Exception { PrintStream out = new PrintStream(System.out); int maxDist = Integer.MAX_VALUE; try {/*from w w w . java 2 s . c o m*/ CommandLine line = new PosixParser().parse(options, args); if (line.hasOption("outFile")) { out = new PrintStream(new File(line.getOptionValue("outFile"))); } if (line.hasOption("maxDist")) { maxDist = Integer.valueOf(line.getOptionValue("maxDist")); } args = line.getArgs(); if (args.length != 2) { throw new Exception("Unexpected number of command line arguments"); } } catch (Exception e) { System.err.println("Error: " + e.getMessage()); new HelpFormatter().printHelp("PrimerMatch <primer_list | primer_file> <seq_file>", options); return; } List<PatternBitMask64> primers = new ArrayList(); if (new File(args[0]).exists()) { File primerFile = new File(args[0]); SequenceFormat seqformat = SeqUtils.guessFileFormat(primerFile); if (seqformat.equals(SequenceFormat.FASTA)) { SequenceReader reader = new SequenceReader(primerFile); Sequence seq; while ((seq = reader.readNextSequence()) != null) { primers.add(new PatternBitMask64(seq.getSeqString(), true, seq.getSeqName())); } reader.close(); } else { BufferedReader reader = new BufferedReader(new FileReader(args[0])); String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (!line.equals("")) { primers.add(new PatternBitMask64(line, true)); } } reader.close(); } } else { for (String primer : args[0].split(",")) { primers.add(new PatternBitMask64(primer, true)); } } SeqReader seqReader = new SequenceReader(new File(args[1])); Sequence seq; String primerRegion; out.println("#seqname\tdesc\tprimer_index\tprimer_name\tposition\tmismatches\tseq_primer_region"); while ((seq = seqReader.readNextSequence()) != null) { for (int index = 0; index < primers.size(); index++) { PatternBitMask64 primer = primers.get(index); BitVector64Result results = BitVector64.process(seq.getSeqString().toCharArray(), primer, maxDist); for (BitVector64Match result : results.getResults()) { primerRegion = seq.getSeqString().substring( Math.max(0, result.getPosition() - primer.getPatternLength()), result.getPosition()); if (result.getPosition() < primer.getPatternLength()) { for (int pad = result.getPosition(); pad < primer.getPatternLength(); pad++) { primerRegion = "x" + primerRegion; } } out.println(seq.getSeqName() + "\t" + seq.getDesc() + "\t" + (index + 1) + "\t" + primer.getPrimerName() + "\t" + result.getPosition() + "\t" + result.getScore() + "\t" + primerRegion); } } } out.close(); seqReader.close(); }
From source file:org.apache.hadoop.hbase.client.HBaseFsck.java
/** * Main program//from w ww .ja va 2 s .c o m * * @param args * @throws ParseException */ public static void main(String[] args) throws IOException, MasterNotRunningException, InterruptedException, ParseException { Options opt = new Options(); opt.addOption(OptionBuilder.withArgName("property=value").hasArg() .withDescription("Override HBase Configuration Settings").create("D")); opt.addOption(OptionBuilder.withArgName("timeInSeconds").hasArg() .withDescription("Ignore regions with metadata updates in the last {timeInSeconds}.") .withType(PatternOptionBuilder.NUMBER_VALUE).create("timelag")); opt.addOption(OptionBuilder.withArgName("timeInSeconds").hasArg() .withDescription("Stop scan jobs after a fixed time & analyze existing data.") .withType(PatternOptionBuilder.NUMBER_VALUE).create("timeout")); opt.addOption("fix", false, "Try to fix some of the errors."); opt.addOption("y", false, "Do not prompt for reconfirmation from users on fix."); opt.addOption("w", false, "Try to fix warnings as well as errors."); opt.addOption("summary", false, "Print only summary of the tables and status."); opt.addOption("detail", false, "Display full report of all regions."); opt.addOption("checkRegionInfo", false, "Check if .regioninfo is consistent with .META."); opt.addOption("h", false, "Display this help"); CommandLine cmd = new GnuParser().parse(opt, args); // any unknown args or -h if (!cmd.getArgList().isEmpty() || cmd.hasOption("h")) { new HelpFormatter().printHelp("hbck", opt); return; } Configuration conf = HBaseConfiguration.create(); conf.set("fs.defaultFS", conf.get("hbase.rootdir")); if (cmd.hasOption("D")) { for (String confOpt : cmd.getOptionValues("D")) { String[] kv = confOpt.split("=", 2); if (kv.length == 2) { conf.set(kv[0], kv[1]); LOG.debug("-D configuration override: " + kv[0] + "=" + kv[1]); } else { throw new ParseException("-D option format invalid: " + confOpt); } } } if (cmd.hasOption("timeout")) { Object timeout = cmd.getParsedOptionValue("timeout"); if (timeout instanceof Long) { conf.setLong(HConstants.HBASE_RPC_TIMEOUT_KEY, ((Long) timeout).longValue() * 1000); } else { throw new ParseException("-timeout needs a long value."); } } // create a fsck object HBaseFsck fsck = new HBaseFsck(conf); fsck.setTimeLag(HBaseFsckRepair.getEstimatedFixTime(conf)); if (cmd.hasOption("details")) { fsck.displayFullReport(); } if (cmd.hasOption("timelag")) { Object timelag = cmd.getParsedOptionValue("timelag"); if (timelag instanceof Long) { fsck.setTimeLag(((Long) timelag).longValue() * 1000); } else { throw new ParseException("-timelag needs a long value."); } } if (cmd.hasOption("fix")) { fsck.setFixState(FixState.ERROR); } if (cmd.hasOption("w")) { fsck.setFixState(FixState.ALL); } if (cmd.hasOption("y")) { fsck.setPromptResponse(true); } if (cmd.equals("summary")) { fsck.setSummary(); } if (cmd.hasOption("checkRegionInfo")) { checkRegionInfo = true; } int code = -1; try { // do the real work of fsck code = fsck.doWork(); // If we have tried to fix the HBase state, run fsck again // to see if we have fixed our problems if (fsck.shouldRerun()) { fsck.setFixState(FixState.NONE); long fixTime = HBaseFsckRepair.getEstimatedFixTime(conf); if (fixTime > 0) { LOG.info("Waiting " + StringUtils.formatTime(fixTime) + " before checking to see if fixes worked..."); Thread.sleep(fixTime); } code = fsck.doWork(); } } catch (InterruptedException ie) { LOG.info("HBCK was interrupted by user. Exiting..."); code = -1; } Runtime.getRuntime().exit(code); }