5 // Created by Sarah Westcott on 2/3/12.
6 // Copyright (c) 2012 Schloss Lab. All rights reserved.
9 #include "sortseqscommand.h"
10 #include "sequence.hpp"
11 #include "qualityscores.h"
13 //**********************************************************************************************************************
14 vector<string> SortSeqsCommand::setParameters(){
16 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta);
17 CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname);
18 CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pgroup);
19 CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy);
20 CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile);
21 CommandParameter plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge);
22 CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos);
23 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
24 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
26 vector<string> myArray;
27 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
31 m->errorOut(e, "SortSeqsCommand", "setParameters");
35 //**********************************************************************************************************************
36 string SortSeqsCommand::getHelpString(){
38 string helpString = "";
39 helpString += "The sort.seqs command puts the sequences in the same order for the following file types: accnos fasta, name, group, taxonomy or quality file.\n";
40 helpString += "The sort.seqs command parameters are accnos, fasta, name, group, taxonomy, qfile and large.\n";
41 helpString += "The accnos file allows you to specify the order you want the files in. If none is provided, mothur will use the order of the first file it reads.\n";
42 helpString += "The large parameters is used to indicate your files are too large to fit in RAM.\n";
43 helpString += "The sort.seqs command should be in the following format: sort.seqs(fasta=yourFasta).\n";
44 helpString += "Example sort.seqs(fasta=amazon.fasta).\n";
45 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
49 m->errorOut(e, "SortSeqsCommand", "getHelpString");
55 //**********************************************************************************************************************
56 SortSeqsCommand::SortSeqsCommand(){
58 abort = true; calledHelp = true;
60 vector<string> tempOutNames;
61 outputTypes["fasta"] = tempOutNames;
62 outputTypes["taxonomy"] = tempOutNames;
63 outputTypes["name"] = tempOutNames;
64 outputTypes["group"] = tempOutNames;
65 outputTypes["qfile"] = tempOutNames;
68 m->errorOut(e, "SortSeqsCommand", "SortSeqsCommand");
72 //**********************************************************************************************************************
73 SortSeqsCommand::SortSeqsCommand(string option) {
75 abort = false; calledHelp = false;
77 //allow user to run help
78 if(option == "help") { help(); abort = true; calledHelp = true; }
79 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
82 vector<string> myArray = setParameters();
84 OptionParser parser(option);
85 map<string,string> parameters = parser.getParameters();
87 ValidParameters validParameter;
88 map<string,string>::iterator it;
90 //check to make sure all parameters are valid for command
91 for (it = parameters.begin(); it != parameters.end(); it++) {
92 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
95 //initialize outputTypes
96 vector<string> tempOutNames;
97 outputTypes["fasta"] = tempOutNames;
98 outputTypes["taxonomy"] = tempOutNames;
99 outputTypes["name"] = tempOutNames;
100 outputTypes["group"] = tempOutNames;
101 outputTypes["qfile"] = tempOutNames;
103 //if the user changes the output directory command factory will send this info to us in the output parameter
104 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
106 //if the user changes the input directory command factory will send this info to us in the output parameter
107 string inputDir = validParameter.validFile(parameters, "inputdir", false);
108 if (inputDir == "not found"){ inputDir = ""; }
111 it = parameters.find("fasta");
112 //user has given a template file
113 if(it != parameters.end()){
114 path = m->hasPath(it->second);
115 //if the user has not given a path then, add inputdir. else leave path alone.
116 if (path == "") { parameters["fasta"] = inputDir + it->second; }
119 it = parameters.find("name");
120 //user has given a template file
121 if(it != parameters.end()){
122 path = m->hasPath(it->second);
123 //if the user has not given a path then, add inputdir. else leave path alone.
124 if (path == "") { parameters["name"] = inputDir + it->second; }
127 it = parameters.find("group");
128 //user has given a template file
129 if(it != parameters.end()){
130 path = m->hasPath(it->second);
131 //if the user has not given a path then, add inputdir. else leave path alone.
132 if (path == "") { parameters["group"] = inputDir + it->second; }
135 it = parameters.find("taxonomy");
136 //user has given a template file
137 if(it != parameters.end()){
138 path = m->hasPath(it->second);
139 //if the user has not given a path then, add inputdir. else leave path alone.
140 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
143 it = parameters.find("qfile");
144 //user has given a template file
145 if(it != parameters.end()){
146 path = m->hasPath(it->second);
147 //if the user has not given a path then, add inputdir. else leave path alone.
148 if (path == "") { parameters["qfile"] = inputDir + it->second; }
151 it = parameters.find("accnos");
152 //user has given a template file
153 if(it != parameters.end()){
154 path = m->hasPath(it->second);
155 //if the user has not given a path then, add inputdir. else leave path alone.
156 if (path == "") { parameters["accnos"] = inputDir + it->second; }
161 //check for parameters
162 accnosfile = validParameter.validFile(parameters, "accnos", true);
163 if (accnosfile == "not open") { accnosfile = ""; abort = true; }
164 else if (accnosfile == "not found") { accnosfile = ""; }
165 else { m->setAccnosFile(accnosfile); }
167 fastafile = validParameter.validFile(parameters, "fasta", true);
168 if (fastafile == "not open") { fastafile = ""; abort = true; }
169 else if (fastafile == "not found") { fastafile = ""; }
170 else { m->setFastaFile(fastafile); }
172 namefile = validParameter.validFile(parameters, "name", true);
173 if (namefile == "not open") { namefile = ""; abort = true; }
174 else if (namefile == "not found") { namefile = ""; }
175 else { m->setNameFile(namefile); }
177 groupfile = validParameter.validFile(parameters, "group", true);
178 if (groupfile == "not open") { abort = true; }
179 else if (groupfile == "not found") { groupfile = ""; }
180 else { m->setGroupFile(groupfile); }
182 taxfile = validParameter.validFile(parameters, "taxonomy", true);
183 if (taxfile == "not open") { abort = true; }
184 else if (taxfile == "not found") { taxfile = ""; }
185 else { m->setTaxonomyFile(taxfile); }
187 qualfile = validParameter.validFile(parameters, "qfile", true);
188 if (qualfile == "not open") { abort = true; }
189 else if (qualfile == "not found") { qualfile = ""; }
190 else { m->setQualFile(qualfile); }
192 string temp = validParameter.validFile(parameters, "large", false); if (temp == "not found") { temp = "f"; }
193 large = m->isTrue(temp);
195 if ((fastafile == "") && (namefile == "") && (groupfile == "") && (taxfile == "") && (qualfile == "")) { m->mothurOut("You must provide at least one of the following: fasta, name, group, taxonomy or quality."); m->mothurOutEndLine(); abort = true; }
197 if ((fastafile != "") && (namefile == "")) {
198 vector<string> files; files.push_back(fastafile);
199 parser.getNameFile(files);
204 catch(exception& e) {
205 m->errorOut(e, "SortSeqsCommand", "SortSeqsCommand");
209 //**********************************************************************************************************************
211 int SortSeqsCommand::execute(){
214 if (abort == true) { if (calledHelp) { return 0; } return 2; }
216 //read through the correct file and output lines you want to keep
217 if (accnosfile != "") { readAccnos(); }
218 if (fastafile != "") { readFasta(); }
219 if (qualfile != "") { readQual(); }
220 if (namefile != "") { readName(); }
221 if (groupfile != "") { readGroup(); }
222 if (taxfile != "") { readTax(); }
224 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
226 if (outputNames.size() != 0) {
227 m->mothurOutEndLine();
228 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
229 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
230 m->mothurOutEndLine();
232 //set fasta file as new current fastafile
234 itTypes = outputTypes.find("fasta");
235 if (itTypes != outputTypes.end()) {
236 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
239 itTypes = outputTypes.find("name");
240 if (itTypes != outputTypes.end()) {
241 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
244 itTypes = outputTypes.find("group");
245 if (itTypes != outputTypes.end()) {
246 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
250 itTypes = outputTypes.find("taxonomy");
251 if (itTypes != outputTypes.end()) {
252 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); }
255 itTypes = outputTypes.find("qfile");
256 if (itTypes != outputTypes.end()) {
257 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
264 catch(exception& e) {
265 m->errorOut(e, "SortSeqsCommand", "execute");
270 //**********************************************************************************************************************
271 int SortSeqsCommand::readFasta(){
273 string thisOutputDir = outputDir;
274 if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
275 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "sorted" + m->getExtension(fastafile);
276 outputTypes["fasta"].push_back(outputFileName); outputNames.push_back(outputFileName);
279 m->openOutputFile(outputFileName, out);
282 m->openInputFile(fastafile, in);
285 if (names.size() != 0) {//this is not the first file we are reading so we need to use the order we already have
287 if (large) { //if the file is too large to fit in memory we can still process it, but the io will be very time consuming.
288 //read through the file looking for 1000 seqs at a time. Once we find them output them and start looking for the next 1000.
289 //this way we only store 1000 seqs in memory at a time.
291 int numNames = names.size();
292 int numNamesInFile = 0;
294 //to make sure we dont miss any seqs, add any seqs that are not in names but in the file to the end of names
296 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
298 Sequence currSeq(in);
299 name = currSeq.getName();
303 map<string, int>::iterator it = names.find(name);
304 if (it == names.end()) {
305 names[name] = numNames; numNames++;
306 m->mothurOut(name + " was not in the contained the file which determined the order, adding it to the end.\n");
314 int numLeft = names.size();
315 if (numNamesInFile < numLeft) { numLeft = numNamesInFile; }
317 int size = 1000; //assume that user can hold 1000 seqs in memory
318 if (numLeft < size) { size = numLeft; }
321 vector<Sequence> seqs; seqs.resize(size);
323 while (numLeft > 0) {
326 m->openInputFile(fastafile, in2);
328 if (m->control_pressed) { in2.close(); m->mothurRemove(outputFileName); return 0; }
331 int needToFind = size;
332 if (numLeft < size) { needToFind = numLeft; }
335 if (m->control_pressed) { in2.close(); m->mothurRemove(outputFileName); return 0; }
337 //stop reading if we already found the seqs we are looking for
338 if (found >= needToFind) { break; }
340 Sequence currSeq(in2);
341 name = currSeq.getName();
344 map<string, int>::iterator it = names.find(name);
345 if (it != names.end()) { //we found it, so put it in the vector in the right place.
346 //is it in the set of seqs we are looking for this time around
347 int thisSeqsPlace = it->second;
348 thisSeqsPlace -= (times * size);
349 if ((thisSeqsPlace < size) && (thisSeqsPlace >= 0)) {
350 seqs[thisSeqsPlace] = currSeq;
353 }else { m->mothurOut("[ERROR]: in logic of readFasta function.\n"); m->control_pressed = true; }
360 m->openOutputFileAppend(outputFileName, out2);
362 int output = seqs.size();
363 if (numLeft < seqs.size()) { output = numLeft; }
365 for (int i = 0; i < output; i++) {
366 seqs[i].printSequence(out2);
374 m->mothurOut("Ordered " + toString(numNamesInFile) + " sequences from " + fastafile + ".\n");
377 vector<Sequence> seqs; seqs.resize(names.size());
380 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
382 Sequence currSeq(in);
383 name = currSeq.getName();
386 map<string, int>::iterator it = names.find(name);
387 if (it != names.end()) { //we found it, so put it in the vector in the right place.
388 seqs[it->second] = currSeq;
389 }else { //if we cant find it then add it to the end
390 names[name] = seqs.size();
391 seqs.push_back(currSeq);
392 m->mothurOut(name + " was not in the contained the file which determined the order, adding it to the end.\n");
399 for (int i = 0; i < seqs.size(); i++) {
400 seqs[i].printSequence(out);
404 m->mothurOut("Ordered " + toString(seqs.size()) + " sequences from " + fastafile + ".\n");
407 }else { //read in file to fill names
411 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
413 Sequence currSeq(in);
414 name = currSeq.getName();
417 //if this name is in the accnos file
420 currSeq.printSequence(out);
427 m->mothurOut("\nUsing " + fastafile + " to determine the order. It contains " + toString(count) + " sequences.\n");
433 catch(exception& e) {
434 m->errorOut(e, "SortSeqsCommand", "readFasta");
438 //**********************************************************************************************************************
439 int SortSeqsCommand::readQual(){
441 string thisOutputDir = outputDir;
442 if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); }
443 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + "sorted" + m->getExtension(qualfile);
444 outputTypes["qfile"].push_back(outputFileName); outputNames.push_back(outputFileName);
447 m->openOutputFile(outputFileName, out);
450 m->openInputFile(qualfile, in);
453 if (names.size() != 0) {//this is not the first file we are reading so we need to use the order we already have
455 if (large) { //if the file is too large to fit in memory we can still process it, but the io will be very time consuming.
456 //read through the file looking for 1000 seqs at a time. Once we find them output them and start looking for the next 1000.
457 //this way we only store 1000 seqs in memory at a time.
459 int numNames = names.size();
460 int numNamesInFile = 0;
462 //to make sure we dont miss any seqs, add any seqs that are not in names but in the file to the end of names
464 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
466 QualityScores currQual;
467 currQual = QualityScores(in);
468 name = currQual.getName();
472 map<string, int>::iterator it = names.find(name);
473 if (it == names.end()) {
474 names[name] = numNames; numNames++;
475 m->mothurOut(name + " was not in the contained the file which determined the order, adding it to the end.\n");
483 int numLeft = names.size();
484 if (numNamesInFile < numLeft) { numLeft = numNamesInFile; }
486 int size = 1000; //assume that user can hold 1000 seqs in memory
487 if (numLeft < size) { size = numLeft; }
491 vector<QualityScores> seqs; seqs.resize(size);
493 while (numLeft > 0) {
496 m->openInputFile(qualfile, in2);
498 if (m->control_pressed) { in2.close(); m->mothurRemove(outputFileName); return 0; }
501 int needToFind = size;
502 if (numLeft < size) { needToFind = numLeft; }
505 if (m->control_pressed) { in2.close(); m->mothurRemove(outputFileName); return 0; }
507 //stop reading if we already found the seqs we are looking for
508 if (found >= needToFind) { break; }
510 QualityScores currQual;
511 currQual = QualityScores(in2);
512 name = currQual.getName();
515 map<string, int>::iterator it = names.find(name);
516 if (it != names.end()) { //we found it, so put it in the vector in the right place.
517 //is it in the set of seqs we are looking for this time around
518 int thisSeqsPlace = it->second;
519 thisSeqsPlace -= (times * size);
520 if ((thisSeqsPlace < size) && (thisSeqsPlace >= 0)) {
521 seqs[thisSeqsPlace] = currQual;
524 }else { m->mothurOut("[ERROR]: in logic of readQual function.\n"); m->control_pressed = true; }
531 m->openOutputFileAppend(outputFileName, out2);
533 int output = seqs.size();
534 if (numLeft < seqs.size()) { output = numLeft; }
536 for (int i = 0; i < output; i++) {
537 seqs[i].printQScores(out2);
545 m->mothurOut("Ordered " + toString(numNamesInFile) + " sequences from " + qualfile + ".\n");
549 vector<QualityScores> seqs; seqs.resize(names.size());
552 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
554 QualityScores currQual;
555 currQual = QualityScores(in);
556 name = currQual.getName();
559 map<string, int>::iterator it = names.find(name);
560 if (it != names.end()) { //we found it, so put it in the vector in the right place.
561 seqs[it->second] = currQual;
562 }else { //if we cant find it then add it to the end
563 names[name] = seqs.size();
564 seqs.push_back(currQual);
565 m->mothurOut(name + " was not in the contained the file which determined the order, adding it to the end.\n");
572 for (int i = 0; i < seqs.size(); i++) {
573 seqs[i].printQScores(out);
577 m->mothurOut("Ordered " + toString(seqs.size()) + " sequences from " + qualfile + ".\n");
580 }else { //read in file to fill names
584 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
586 QualityScores currQual;
587 currQual = QualityScores(in);
591 if (currQual.getName() != "") {
592 //if this name is in the accnos file
593 names[currQual.getName()] = count;
595 currQual.printQScores(out);
602 m->mothurOut("\nUsing " + qualfile + " to determine the order. It contains " + toString(count) + " sequences.\n");
608 catch(exception& e) {
609 m->errorOut(e, "SortSeqsCommand", "readQual");
613 //**********************************************************************************************************************
614 int SortSeqsCommand::readName(){
616 string thisOutputDir = outputDir;
617 if (outputDir == "") { thisOutputDir += m->hasPath(namefile); }
618 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "sorted" + m->getExtension(namefile);
619 outputTypes["name"].push_back(outputFileName); outputNames.push_back(outputFileName);
622 m->openOutputFile(outputFileName, out);
625 m->openInputFile(namefile, in);
626 string name, firstCol, secondCol;
628 if (names.size() != 0) {//this is not the first file we are reading so we need to use the order we already have
630 vector<string> seqs; seqs.resize(names.size());
633 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
635 in >> firstCol; m->gobble(in);
636 in >> secondCol; m->gobble(in);
638 if (firstCol != "") {
639 map<string, int>::iterator it = names.find(firstCol);
640 if (it != names.end()) { //we found it, so put it in the vector in the right place.
641 seqs[it->second] = firstCol + '\t' + secondCol;
642 }else { //if we cant find it then add it to the end
643 names[firstCol] = seqs.size();
644 seqs.push_back((firstCol + '\t' + secondCol));
645 m->mothurOut(firstCol + " was not in the contained the file which determined the order, adding it to the end.\n");
651 for (int i = 0; i < seqs.size(); i++) {
652 out << seqs[i] << endl;
656 m->mothurOut("Ordered " + toString(seqs.size()) + " sequences from " + namefile + ".\n");
658 }else { //read in file to fill names
662 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
664 in >> firstCol; m->gobble(in);
665 in >> secondCol; m->gobble(in);
667 if (firstCol != "") {
668 //if this name is in the accnos file
669 names[firstCol] = count;
671 out << firstCol << '\t' << secondCol << endl;
678 m->mothurOut("\nUsing " + namefile + " to determine the order. It contains " + toString(count) + " representative sequences.\n");
683 catch(exception& e) {
684 m->errorOut(e, "SortSeqsCommand", "readName");
689 //**********************************************************************************************************************
690 int SortSeqsCommand::readGroup(){
692 string thisOutputDir = outputDir;
693 if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); }
694 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
695 outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName);
698 m->openOutputFile(outputFileName, out);
701 m->openInputFile(groupfile, in);
704 if (names.size() != 0) {//this is not the first file we are reading so we need to use the order we already have
706 vector<string> seqs; seqs.resize(names.size());
709 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
711 in >> name; m->gobble(in);
712 in >> group; m->gobble(in);
715 map<string, int>::iterator it = names.find(name);
716 if (it != names.end()) { //we found it, so put it in the vector in the right place.
717 seqs[it->second] = name + '\t' + group;
718 }else { //if we cant find it then add it to the end
719 names[name] = seqs.size();
720 seqs.push_back((name + '\t' + group));
721 m->mothurOut(name + " was not in the contained the file which determined the order, adding it to the end.\n");
727 for (int i = 0; i < seqs.size(); i++) {
728 out << seqs[i] << endl;
732 m->mothurOut("Ordered " + toString(seqs.size()) + " sequences from " + groupfile + ".\n");
734 }else { //read in file to fill names
738 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
740 in >> name; m->gobble(in);
741 in >> group; m->gobble(in);
744 //if this name is in the accnos file
747 out << name << '\t' << group << endl;
754 m->mothurOut("\nUsing " + groupfile + " to determine the order. It contains " + toString(count) + " sequences.\n");
759 catch(exception& e) {
760 m->errorOut(e, "SortSeqsCommand", "readGroup");
764 //**********************************************************************************************************************
765 int SortSeqsCommand::readTax(){
767 string thisOutputDir = outputDir;
768 if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); }
769 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
770 outputTypes["taxonomy"].push_back(outputFileName); outputNames.push_back(outputFileName);
773 m->openOutputFile(outputFileName, out);
776 m->openInputFile(taxfile, in);
779 if (names.size() != 0) {//this is not the first file we are reading so we need to use the order we already have
781 vector<string> seqs; seqs.resize(names.size());
784 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
786 in >> name; m->gobble(in);
787 in >> tax; m->gobble(in);
790 map<string, int>::iterator it = names.find(name);
791 if (it != names.end()) { //we found it, so put it in the vector in the right place.
792 seqs[it->second] = name + '\t' + tax;
793 }else { //if we cant find it then add it to the end
794 names[name] = seqs.size();
795 seqs.push_back((name + '\t' + tax));
796 m->mothurOut(name + " was not in the contained the file which determined the order, adding it to the end.\n");
802 for (int i = 0; i < seqs.size(); i++) {
803 out << seqs[i] << endl;
807 m->mothurOut("Ordered " + toString(seqs.size()) + " sequences from " + taxfile + ".\n");
809 }else { //read in file to fill names
813 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
815 in >> name; m->gobble(in);
816 in >> tax; m->gobble(in);
819 //if this name is in the accnos file
822 out << name << '\t' << tax << endl;
829 m->mothurOut("\nUsing " + taxfile + " to determine the order. It contains " + toString(count) + " sequences.\n");
835 catch(exception& e) {
836 m->errorOut(e, "SortSeqsCommand", "readTax");
840 //**********************************************************************************************************************
841 int SortSeqsCommand::readAccnos(){
845 m->openInputFile(accnosfile, in);
851 if (m->control_pressed) { break; }
853 in >> name; m->gobble(in);
862 m->mothurOut("\nUsing " + accnosfile + " to determine the order. It contains " + toString(count) + " representative sequences.\n");
866 catch(exception& e) {
867 m->errorOut(e, "SortSeqsCommand", "readAccnos");
872 //**********************************************************************************************************************