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()) {