X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=listseqscommand.cpp;h=3200137343e8691e2e8df3f70fcd1940f933b88c;hb=c27e902ede71ea4d20af65752ef04459c101611b;hp=d0b00bd3061d2a14365ee43ef96db1bc04ac1cb0;hpb=315e38cf393c82be238da5b32574f225a020d25c;p=mothur.git diff --git a/listseqscommand.cpp b/listseqscommand.cpp index d0b00bd..3200137 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -13,7 +13,7 @@ //********************************************************************************************************************** -ListSeqsCommand::ListSeqsCommand(string option){ +ListSeqsCommand::ListSeqsCommand(string option) { try { abort = false; @@ -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,18 +114,22 @@ 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 == "")) { mothurOut("You must provide a file."); 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++; } + if (inputDir != "") { okay++; } - if (parameters.size() > okay) { mothurOut("You may only enter one file."); mothurOutEndLine(); abort = true; } + if (parameters.size() > okay) { m->mothurOut("You may only enter one file."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); + m->errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); exit(1); } } @@ -125,14 +137,14 @@ ListSeqsCommand::ListSeqsCommand(string option){ void ListSeqsCommand::help(){ try { - mothurOut("The list.seqs command reads a fasta, name, group, list or alignreport file and outputs a .accnos file containing sequence names.\n"); - mothurOut("The list.seqs command parameters are fasta, name, group and alignreport. You must provide one of these parameters.\n"); - mothurOut("The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n"); - mothurOut("Example list.seqs(fasta=amazon.fasta).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\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"); } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "help"); + m->errorOut(e, "ListSeqsCommand", "help"); exit(1); } } @@ -150,6 +162,9 @@ 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; } //sort in alphabetical order sort(names.begin(), names.end()); @@ -163,21 +178,31 @@ int ListSeqsCommand::execute(){ //output to .accnos file for (int i = 0; i < names.size(); i++) { + + if (m->control_pressed) { out.close(); remove(outputFileName.c_str()); return 0; } + out << names[i] << endl; } out.close(); + if (m->control_pressed) { remove(outputFileName.c_str()); return 0; } + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "execute"); + m->errorOut(e, "ListSeqsCommand", "execute"); exit(1); } } //********************************************************************************************************************** -void ListSeqsCommand::readFasta(){ +int ListSeqsCommand::readFasta(){ try { ifstream in; @@ -185,6 +210,9 @@ void ListSeqsCommand::readFasta(){ string name; while(!in.eof()){ + + if (m->control_pressed) { in.close(); return 0; } + Sequence currSeq(in); name = currSeq.getName(); @@ -192,16 +220,18 @@ void ListSeqsCommand::readFasta(){ gobble(in); } - in.close(); + in.close(); + + return 0; } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readFasta"); + m->errorOut(e, "ListSeqsCommand", "readFasta"); exit(1); } } //********************************************************************************************************************** -void ListSeqsCommand::readList(){ +int ListSeqsCommand::readList(){ try { ifstream in; openInputFile(listfile, in); @@ -214,6 +244,8 @@ void ListSeqsCommand::readList(){ for (int i = 0; i < list.getNumBins(); i++) { string binnames = list.get(i); + if (m->control_pressed) { in.close(); return 0; } + while (binnames.find_first_of(',') != -1) { string name = binnames.substr(0,binnames.find_first_of(',')); binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length()); @@ -225,15 +257,17 @@ void ListSeqsCommand::readList(){ } in.close(); + return 0; + } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readList"); + m->errorOut(e, "ListSeqsCommand", "readList"); exit(1); } } //********************************************************************************************************************** -void ListSeqsCommand::readName(){ +int ListSeqsCommand::readName(){ try { ifstream in; @@ -241,6 +275,8 @@ void ListSeqsCommand::readName(){ string name, firstCol, secondCol; while(!in.eof()){ + + if (m->control_pressed) { in.close(); return 0; } in >> firstCol; in >> secondCol; @@ -258,16 +294,17 @@ void ListSeqsCommand::readName(){ gobble(in); } in.close(); + return 0; } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readName"); + m->errorOut(e, "ListSeqsCommand", "readName"); exit(1); } } //********************************************************************************************************************** -void ListSeqsCommand::readGroup(){ +int ListSeqsCommand::readGroup(){ try { ifstream in; @@ -275,7 +312,9 @@ void ListSeqsCommand::readGroup(){ string name, group; while(!in.eof()){ - + + if (m->control_pressed) { in.close(); return 0; } + in >> name; //read from first column in >> group; //read from second column @@ -284,17 +323,18 @@ void ListSeqsCommand::readGroup(){ gobble(in); } in.close(); + return 0; } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readGroup"); + m->errorOut(e, "ListSeqsCommand", "readGroup"); exit(1); } } //********************************************************************************************************************** //alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name -void ListSeqsCommand::readAlign(){ +int ListSeqsCommand::readAlign(){ try { ifstream in; @@ -309,6 +349,8 @@ void ListSeqsCommand::readAlign(){ while(!in.eof()){ + + if (m->control_pressed) { in.close(); return 0; } in >> name; //read from first column @@ -323,11 +365,42 @@ void ListSeqsCommand::readAlign(){ gobble(in); } in.close(); + + return 0; } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readAlign"); + m->errorOut(e, "ListSeqsCommand", "readAlign"); + exit(1); + } +} +//********************************************************************************************************************** +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); } }