X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=listseqscommand.cpp;h=3200137343e8691e2e8df3f70fcd1940f933b88c;hb=83b5acbe3d6087a6cd73e80dde4b923387a01d01;hp=23c71ecdcf2ac06f522f034cbea813d4a1f2cd22;hpb=21805b1c466a341d64a5a451f156a56d12c75dca;p=mothur.git diff --git a/listseqscommand.cpp b/listseqscommand.cpp index 23c71ec..3200137 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -22,7 +22,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { else { //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport","list","outputdir","inputdir"}; + string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -83,6 +83,14 @@ ListSeqsCommand::ListSeqsCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["group"] = inputDir + it->second; } } + + it = parameters.find("taxonomy"); + //user has given a template file + if(it != parameters.end()){ + path = hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["taxonomy"] = inputDir + it->second; } + } } //check for required parameters @@ -106,8 +114,11 @@ ListSeqsCommand::ListSeqsCommand(string option) { if (listfile == "not open") { abort = true; } else if (listfile == "not found") { listfile = ""; } + taxfile = validParameter.validFile(parameters, "taxonomy", true); + if (taxfile == "not open") { abort = true; } + else if (taxfile == "not found") { taxfile = ""; } - if ((fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == "")) { m->mothurOut("You must provide a file."); m->mothurOutEndLine(); abort = true; } + if ((fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == "") && (taxfile == "")) { m->mothurOut("You must provide a file."); m->mothurOutEndLine(); abort = true; } int okay = 1; if (outputDir != "") { okay++; } @@ -126,8 +137,8 @@ ListSeqsCommand::ListSeqsCommand(string option) { void ListSeqsCommand::help(){ try { - m->mothurOut("The list.seqs command reads a fasta, name, group, list or alignreport file and outputs a .accnos file containing sequence names.\n"); - m->mothurOut("The list.seqs command parameters are fasta, name, group and alignreport. You must provide one of these parameters.\n"); + m->mothurOut("The list.seqs command reads a fasta, name, group, list, taxonomy or alignreport file and outputs a .accnos file containing sequence names.\n"); + m->mothurOut("The list.seqs command parameters are fasta, name, group, list, taxonomy and alignreport. You must provide one of these parameters.\n"); m->mothurOut("The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n"); m->mothurOut("Example list.seqs(fasta=amazon.fasta).\n"); m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); @@ -151,6 +162,7 @@ int ListSeqsCommand::execute(){ else if (groupfile != "") { inputFileName = groupfile; readGroup(); } else if (alignfile != "") { inputFileName = alignfile; readAlign(); } else if (listfile != "") { inputFileName = listfile; readList(); } + else if (taxfile != "") { inputFileName = taxfile; readTax(); } if (m->control_pressed) { return 0; } @@ -364,3 +376,32 @@ int ListSeqsCommand::readAlign(){ } } //********************************************************************************************************************** +int ListSeqsCommand::readTax(){ + try { + + ifstream in; + openInputFile(taxfile, in); + string name, firstCol, secondCol; + + while(!in.eof()){ + + if (m->control_pressed) { in.close(); return 0; } + + in >> firstCol; + in >> secondCol; + + names.push_back(firstCol); + + gobble(in); + } + in.close(); + + return 0; + + } + catch(exception& e) { + m->errorOut(e, "ListSeqsCommand", "readTax"); + exit(1); + } +} +//**********************************************************************************************************************