]> git.donarmstrong.com Git - mothur.git/blob - getseqscommand.cpp
fixed metastats, added resize to cluster.classic, added code to kill children if...
[mothur.git] / getseqscommand.cpp
1 /*
2  *  getseqscommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 7/8/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "getseqscommand.h"
11 #include "sequence.hpp"
12 #include "listvector.hpp"
13
14 //**********************************************************************************************************************
15 vector<string> GetSeqsCommand::getValidParameters(){    
16         try {
17                 string Array[] =  {"fasta","name", "group", "qfile","alignreport", "accnos", "dups", "list","taxonomy","outputdir","inputdir"};
18                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
19                 return myArray;
20         }
21         catch(exception& e) {
22                 m->errorOut(e, "GetSeqsCommand", "getValidParameters");
23                 exit(1);
24         }
25 }
26 //**********************************************************************************************************************
27 GetSeqsCommand::GetSeqsCommand(){       
28         try {
29                 abort = true;
30                 //initialize outputTypes
31                 vector<string> tempOutNames;
32                 outputTypes["fasta"] = tempOutNames;
33                 outputTypes["taxonomy"] = tempOutNames;
34                 outputTypes["name"] = tempOutNames;
35                 outputTypes["group"] = tempOutNames;
36                 outputTypes["alignreport"] = tempOutNames;
37                 outputTypes["list"] = tempOutNames;
38                 outputTypes["qfile"] = tempOutNames;
39         }
40         catch(exception& e) {
41                 m->errorOut(e, "GetSeqsCommand", "GetSeqsCommand");
42                 exit(1);
43         }
44 }
45 //**********************************************************************************************************************
46 vector<string> GetSeqsCommand::getRequiredParameters(){ 
47         try {
48                 string Array[] =  {"accnos"};
49                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
50                 return myArray;
51         }
52         catch(exception& e) {
53                 m->errorOut(e, "GetSeqsCommand", "getRequiredParameters");
54                 exit(1);
55         }
56 }
57 //**********************************************************************************************************************
58 vector<string> GetSeqsCommand::getRequiredFiles(){      
59         try {
60                 vector<string> myArray;
61                 return myArray;
62         }
63         catch(exception& e) {
64                 m->errorOut(e, "GetSeqsCommand", "getRequiredFiles");
65                 exit(1);
66         }
67 }
68 //**********************************************************************************************************************
69 GetSeqsCommand::GetSeqsCommand(string option)  {
70         try {
71                 abort = false;
72                                 
73                 //allow user to run help
74                 if(option == "help") { help(); abort = true; }
75                 
76                 else {
77                         //valid paramters for this command
78                         string Array[] =  {"fasta","name", "group", "alignreport", "qfile", "accnos", "dups", "list","taxonomy","outputdir","inputdir"};
79                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
80                         
81                         OptionParser parser(option);
82                         map<string,string> parameters = parser.getParameters();
83                         
84                         ValidParameters validParameter;
85                         map<string,string>::iterator it;
86                         
87                         //check to make sure all parameters are valid for command
88                         for (it = parameters.begin(); it != parameters.end(); it++) { 
89                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
90                         }
91                         
92                         //initialize outputTypes
93                         vector<string> tempOutNames;
94                         outputTypes["fasta"] = tempOutNames;
95                         outputTypes["taxonomy"] = tempOutNames;
96                         outputTypes["name"] = tempOutNames;
97                         outputTypes["group"] = tempOutNames;
98                         outputTypes["alignreport"] = tempOutNames;
99                         outputTypes["list"] = tempOutNames;
100                         outputTypes["qfile"] = tempOutNames;
101                         
102                         //if the user changes the output directory command factory will send this info to us in the output parameter 
103                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
104                         
105                         //if the user changes the input directory command factory will send this info to us in the output parameter 
106                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
107                         if (inputDir == "not found"){   inputDir = "";          }
108                         else {
109                                 string path;
110                                 it = parameters.find("alignreport");
111                                 //user has given a template file
112                                 if(it != parameters.end()){ 
113                                         path = m->hasPath(it->second);
114                                         //if the user has not given a path then, add inputdir. else leave path alone.
115                                         if (path == "") {       parameters["alignreport"] = inputDir + it->second;              }
116                                 }
117                                 
118                                 it = parameters.find("fasta");
119                                 //user has given a template file
120                                 if(it != parameters.end()){ 
121                                         path = m->hasPath(it->second);
122                                         //if the user has not given a path then, add inputdir. else leave path alone.
123                                         if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
124                                 }
125                                 
126                                 it = parameters.find("accnos");
127                                 //user has given a template file
128                                 if(it != parameters.end()){ 
129                                         path = m->hasPath(it->second);
130                                         //if the user has not given a path then, add inputdir. else leave path alone.
131                                         if (path == "") {       parameters["accnos"] = inputDir + it->second;           }
132                                 }
133                                 
134                                 it = parameters.find("list");
135                                 //user has given a template file
136                                 if(it != parameters.end()){ 
137                                         path = m->hasPath(it->second);
138                                         //if the user has not given a path then, add inputdir. else leave path alone.
139                                         if (path == "") {       parameters["list"] = inputDir + it->second;             }
140                                 }
141                                 
142                                 it = parameters.find("name");
143                                 //user has given a template file
144                                 if(it != parameters.end()){ 
145                                         path = m->hasPath(it->second);
146                                         //if the user has not given a path then, add inputdir. else leave path alone.
147                                         if (path == "") {       parameters["name"] = inputDir + it->second;             }
148                                 }
149                                 
150                                 it = parameters.find("group");
151                                 //user has given a template file
152                                 if(it != parameters.end()){ 
153                                         path = m->hasPath(it->second);
154                                         //if the user has not given a path then, add inputdir. else leave path alone.
155                                         if (path == "") {       parameters["group"] = inputDir + it->second;            }
156                                 }
157                                 
158                                 it = parameters.find("taxonomy");
159                                 //user has given a template file
160                                 if(it != parameters.end()){ 
161                                         path = m->hasPath(it->second);
162                                         //if the user has not given a path then, add inputdir. else leave path alone.
163                                         if (path == "") {       parameters["taxonomy"] = inputDir + it->second;         }
164                                 }
165                                 
166                                 it = parameters.find("qfile");
167                                 //user has given a template file
168                                 if(it != parameters.end()){ 
169                                         path = m->hasPath(it->second);
170                                         //if the user has not given a path then, add inputdir. else leave path alone.
171                                         if (path == "") {       parameters["qfile"] = inputDir + it->second;            }
172                                 }
173                         }
174
175                         
176                         //check for required parameters
177                         accnosfile = validParameter.validFile(parameters, "accnos", true);
178                         if (accnosfile == "not open") { abort = true; }
179                         else if (accnosfile == "not found") {  accnosfile = "";  m->mothurOut("You must provide an accnos file."); m->mothurOutEndLine(); abort = true; }       
180                         
181                         fastafile = validParameter.validFile(parameters, "fasta", true);
182                         if (fastafile == "not open") { abort = true; }
183                         else if (fastafile == "not found") {  fastafile = "";  }        
184                         
185                         namefile = validParameter.validFile(parameters, "name", true);
186                         if (namefile == "not open") { abort = true; }
187                         else if (namefile == "not found") {  namefile = "";  }  
188                         
189                         groupfile = validParameter.validFile(parameters, "group", true);
190                         if (groupfile == "not open") { abort = true; }
191                         else if (groupfile == "not found") {  groupfile = "";  }        
192                         
193                         alignfile = validParameter.validFile(parameters, "alignreport", true);
194                         if (alignfile == "not open") { abort = true; }
195                         else if (alignfile == "not found") {  alignfile = "";  }
196                         
197                         listfile = validParameter.validFile(parameters, "list", true);
198                         if (listfile == "not open") { abort = true; }
199                         else if (listfile == "not found") {  listfile = "";  }
200                         
201                         taxfile = validParameter.validFile(parameters, "taxonomy", true);
202                         if (taxfile == "not open") { abort = true; }
203                         else if (taxfile == "not found") {  taxfile = "";  }
204                         
205                         qualfile = validParameter.validFile(parameters, "qfile", true);
206                         if (qualfile == "not open") { abort = true; }
207                         else if (qualfile == "not found") {  qualfile = "";  }
208                         
209                         string usedDups = "true";
210                         string temp = validParameter.validFile(parameters, "dups", false);      if (temp == "not found") { temp = "false"; usedDups = ""; }
211                         dups = m->isTrue(temp);
212                         
213                         if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == ""))  { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport, taxonomy, quality or listfile."); m->mothurOutEndLine(); abort = true; }
214                 
215                         if ((usedDups != "") && (namefile == "")) {  m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine();  abort = true; }                       
216
217                 }
218
219         }
220         catch(exception& e) {
221                 m->errorOut(e, "GetSeqsCommand", "GetSeqsCommand");
222                 exit(1);
223         }
224 }
225 //**********************************************************************************************************************
226
227 void GetSeqsCommand::help(){
228         try {
229                 m->mothurOut("The get.seqs command reads an .accnos file and any of the following file types: fasta, name, group, list, taxonomy, quality or alignreport file.\n");
230                 m->mothurOut("It outputs a file containing only the sequences in the .accnos file.\n");
231                 m->mothurOut("The get.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups.  You must provide accnos and at least one of the other parameters.\n");
232                 m->mothurOut("The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n");
233                 m->mothurOut("The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n");
234                 m->mothurOut("Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n");
235                 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
236         }
237         catch(exception& e) {
238                 m->errorOut(e, "GetSeqsCommand", "help");
239                 exit(1);
240         }
241 }
242
243 //**********************************************************************************************************************
244
245 int GetSeqsCommand::execute(){
246         try {
247                 
248                 if (abort == true) { return 0; }
249                 
250                 //get names you want to keep
251                 readAccnos();
252                 
253                 if (m->control_pressed) { return 0; }
254                 
255                 //read through the correct file and output lines you want to keep
256                 if (namefile != "")                     {               readName();             }
257                 if (fastafile != "")            {               readFasta();    }
258                 if (groupfile != "")            {               readGroup();    }
259                 if (alignfile != "")            {               readAlign();    }
260                 if (listfile != "")                     {               readList();             }
261                 if (taxfile != "")                      {               readTax();              }
262                 if (qualfile != "")                     {               readQual();             }
263                 
264                 if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {   remove(outputNames[i].c_str());  } return 0; }
265                 
266                 if (outputNames.size() != 0) {
267                         m->mothurOutEndLine();
268                         m->mothurOut("Output File Names: "); m->mothurOutEndLine();
269                         for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
270                         m->mothurOutEndLine();
271                 }
272                 
273                 return 0;               
274         }
275
276         catch(exception& e) {
277                 m->errorOut(e, "GetSeqsCommand", "execute");
278                 exit(1);
279         }
280 }
281
282 //**********************************************************************************************************************
283 int GetSeqsCommand::readFasta(){
284         try {
285                 string thisOutputDir = outputDir;
286                 if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
287                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" +  m->getExtension(fastafile);
288                 ofstream out;
289                 m->openOutputFile(outputFileName, out);
290                 
291                 
292                 ifstream in;
293                 m->openInputFile(fastafile, in);
294                 string name;
295                 
296                 bool wroteSomething = false;
297                 
298                 while(!in.eof()){
299                 
300                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
301                         
302                         Sequence currSeq(in);
303                         name = currSeq.getName();
304                         
305                         if (name != "") {
306                                 //if this name is in the accnos file
307                                 if (names.count(name) != 0) {
308                                         wroteSomething = true;
309                                         
310                                         currSeq.printSequence(out);
311                                 }
312                         }
313                         m->gobble(in);
314                 }
315                 in.close();     
316                 out.close();
317                 
318                 
319                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
320                 outputNames.push_back(outputFileName);  outputTypes["fasta"].push_back(outputFileName); 
321                 
322                 return 0;
323
324         }
325         catch(exception& e) {
326                 m->errorOut(e, "GetSeqsCommand", "readFasta");
327                 exit(1);
328         }
329 }
330 //**********************************************************************************************************************
331 int GetSeqsCommand::readQual(){
332         try {
333                 string thisOutputDir = outputDir;
334                 if (outputDir == "") {  thisOutputDir += m->hasPath(qualfile);  }
335                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + "pick" +  m->getExtension(qualfile);
336                 ofstream out;
337                 m->openOutputFile(outputFileName, out);
338                 
339                 
340                 ifstream in;
341                 m->openInputFile(qualfile, in);
342                 string name;
343                 
344                 bool wroteSomething = false;
345                 
346                 
347                 while(!in.eof()){       
348                         string saveName = "";
349                         string name = "";
350                         string scores = "";
351                         
352                         in >> name; 
353                                 
354                         if (name.length() != 0) { 
355                                 saveName = name.substr(1);
356                                 while (!in.eof())       {       
357                                         char c = in.get(); 
358                                         if (c == 10 || c == 13){        break;  }
359                                         else { name += c; }     
360                                 } 
361                                 m->gobble(in);
362                         }
363                         
364                         while(in){
365                                 char letter= in.get();
366                                 if(letter == '>'){      in.putback(letter);     break;  }
367                                 else{ scores += letter; }
368                         }
369                         
370                         m->gobble(in);
371                         
372                         if (names.count(saveName) != 0) {
373                                 wroteSomething = true;
374                                                 
375                                 out << name << endl << scores;
376                         }
377                         
378                         m->gobble(in);
379                 }
380                 in.close();
381                 out.close();
382                 
383                 
384                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
385                 outputNames.push_back(outputFileName);  outputTypes["qfile"].push_back(outputFileName); 
386                 
387                 return 0;
388                 
389         }
390         catch(exception& e) {
391                 m->errorOut(e, "GetSeqsCommand", "readQual");
392                 exit(1);
393         }
394 }
395 //**********************************************************************************************************************
396 int GetSeqsCommand::readList(){
397         try {
398                 string thisOutputDir = outputDir;
399                 if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
400                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
401                 ofstream out;
402                 m->openOutputFile(outputFileName, out);
403                 
404                 ifstream in;
405                 m->openInputFile(listfile, in);
406                 
407                 bool wroteSomething = false;
408                 
409                 while(!in.eof()){
410                         
411                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
412
413                         //read in list vector
414                         ListVector list(in);
415                         
416                         //make a new list vector
417                         ListVector newList;
418                         newList.setLabel(list.getLabel());
419                         
420                         //for each bin
421                         for (int i = 0; i < list.getNumBins(); i++) {
422                         
423                                 //parse out names that are in accnos file
424                                 string binnames = list.get(i);
425                                 
426                                 string newNames = "";
427                                 while (binnames.find_first_of(',') != -1) { 
428                                         string name = binnames.substr(0,binnames.find_first_of(','));
429                                         binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
430                                         
431                                         //if that name is in the .accnos file, add it
432                                         if (names.count(name) != 0) {  newNames += name + ",";  }
433                                 }
434                         
435                                 //get last name
436                                 if (names.count(binnames) != 0) {  newNames += binnames + ",";  }
437
438                                 //if there are names in this bin add to new list
439                                 if (newNames != "") { 
440                                         newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
441                                         newList.push_back(newNames);    
442                                 }
443                         }
444                                 
445                         //print new listvector
446                         if (newList.getNumBins() != 0) {
447                                 wroteSomething = true;
448                                 newList.print(out);
449                         }
450                         
451                         m->gobble(in);
452                 }
453                 in.close();     
454                 out.close();
455                 
456                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
457                 outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName);
458                 
459                 return 0;
460
461         }
462         catch(exception& e) {
463                 m->errorOut(e, "GetSeqsCommand", "readList");
464                 exit(1);
465         }
466 }
467 //**********************************************************************************************************************
468 int GetSeqsCommand::readName(){
469         try {
470                 string thisOutputDir = outputDir;
471                 if (outputDir == "") {  thisOutputDir += m->hasPath(namefile);  }
472                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" +  m->getExtension(namefile);
473                 ofstream out;
474                 m->openOutputFile(outputFileName, out);
475                 
476
477                 ifstream in;
478                 m->openInputFile(namefile, in);
479                 string name, firstCol, secondCol;
480                 
481                 bool wroteSomething = false;
482                 
483                 
484                 while(!in.eof()){
485                 
486                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
487
488                         in >> firstCol;                         
489                         in >> secondCol;
490                         
491                         string hold = "";
492                         if (dups) { hold = secondCol; }
493                         
494                         vector<string> parsedNames;
495                         //parse second column saving each name
496                         while (secondCol.find_first_of(',') != -1) { 
497                                 name = secondCol.substr(0,secondCol.find_first_of(','));
498                                 secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
499                                 parsedNames.push_back(name);
500                         }
501                         
502                         //get name after last ,
503                         parsedNames.push_back(secondCol);
504                         
505                         vector<string> validSecond;
506                         for (int i = 0; i < parsedNames.size(); i++) {
507                                 if (names.count(parsedNames[i]) != 0) {
508                                         validSecond.push_back(parsedNames[i]);
509                                 }
510                         }
511
512                         if ((dups) && (validSecond.size() != 0)) { //dups = true and we want to add someone, then add everyone
513                                 for (int i = 0; i < parsedNames.size(); i++) {  names.insert(parsedNames[i]);  }
514                                 out << firstCol << '\t' << hold << endl;
515                                 wroteSomething = true;
516                         }else {
517                                 //if the name in the first column is in the set then print it and any other names in second column also in set
518                                 if (names.count(firstCol) != 0) {
519                                 
520                                         wroteSomething = true;
521                                         
522                                         out << firstCol << '\t';
523                                         
524                                         //you know you have at least one valid second since first column is valid
525                                         for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
526                                         out << validSecond[validSecond.size()-1] << endl;
527                                         
528                                 
529                                 //make first name in set you come to first column and then add the remaining names to second column
530                                 }else {
531                                         //you want part of this row
532                                         if (validSecond.size() != 0) {
533                                         
534                                                 wroteSomething = true;
535                                                 
536                                                 out << validSecond[0] << '\t';
537                                         
538                                                 //you know you have at least one valid second since first column is valid
539                                                 for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
540                                                 out << validSecond[validSecond.size()-1] << endl;
541                                         }
542                                 }
543                         }
544                         m->gobble(in);
545                 }
546                 in.close();
547                 out.close();
548                 
549                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
550                 outputNames.push_back(outputFileName); outputTypes["name"].push_back(outputFileName);
551                 
552                 return 0;
553                 
554         }
555         catch(exception& e) {
556                 m->errorOut(e, "GetSeqsCommand", "readName");
557                 exit(1);
558         }
559 }
560
561 //**********************************************************************************************************************
562 int GetSeqsCommand::readGroup(){
563         try {
564                 string thisOutputDir = outputDir;
565                 if (outputDir == "") {  thisOutputDir += m->hasPath(groupfile);  }
566                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
567                 ofstream out;
568                 m->openOutputFile(outputFileName, out);
569                 
570
571                 ifstream in;
572                 m->openInputFile(groupfile, in);
573                 string name, group;
574                 
575                 bool wroteSomething = false;
576                 
577                 while(!in.eof()){
578
579                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
580
581
582                         in >> name;                             //read from first column
583                         in >> group;                    //read from second column
584                         
585                         //if this name is in the accnos file
586                         if (names.count(name) != 0) {
587                                 wroteSomething = true;
588                                 
589                                 out << name << '\t' << group << endl;
590                         }
591                                         
592                         m->gobble(in);
593                 }
594                 in.close();
595                 out.close();
596                 
597                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
598                 outputNames.push_back(outputFileName);  outputTypes["group"].push_back(outputFileName);
599                 
600                 return 0;
601
602         }
603         catch(exception& e) {
604                 m->errorOut(e, "GetSeqsCommand", "readGroup");
605                 exit(1);
606         }
607 }
608 //**********************************************************************************************************************
609 int GetSeqsCommand::readTax(){
610         try {
611                 string thisOutputDir = outputDir;
612                 if (outputDir == "") {  thisOutputDir += m->hasPath(taxfile);  }
613                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
614                 ofstream out;
615                 m->openOutputFile(outputFileName, out);
616                 
617                 ifstream in;
618                 m->openInputFile(taxfile, in);
619                 string name, tax;
620                 
621                 bool wroteSomething = false;
622                 
623                 while(!in.eof()){
624
625                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
626
627                         in >> name;                             //read from first column
628                         in >> tax;                      //read from second column
629                         
630                         //if this name is in the accnos file
631                         if (names.count(name) != 0) {
632                                 wroteSomething = true;
633                                 
634                                 out << name << '\t' << tax << endl;
635                         }
636                                         
637                         m->gobble(in);
638                 }
639                 in.close();
640                 out.close();
641                 
642                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
643                 outputNames.push_back(outputFileName);  outputTypes["taxonomy"].push_back(outputFileName);
644                         
645                 return 0;
646
647         }
648         catch(exception& e) {
649                 m->errorOut(e, "GetSeqsCommand", "readTax");
650                 exit(1);
651         }
652 }
653 //**********************************************************************************************************************
654 //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
655 int GetSeqsCommand::readAlign(){
656         try {
657                 string thisOutputDir = outputDir;
658                 if (outputDir == "") {  thisOutputDir += m->hasPath(alignfile);  }
659                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report";
660                 ofstream out;
661                 m->openOutputFile(outputFileName, out);
662                 
663
664                 ifstream in;
665                 m->openInputFile(alignfile, in);
666                 string name, junk;
667                 
668                 bool wroteSomething = false;
669                 
670                 //read column headers
671                 for (int i = 0; i < 16; i++) {  
672                         if (!in.eof())  {       in >> junk;      out << junk << '\t';   }
673                         else                    {       break;                  }
674                 }
675                 out << endl;
676                 
677                 while(!in.eof()){
678                 
679                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
680
681
682                         in >> name;                             //read from first column
683                         
684                         //if this name is in the accnos file
685                         if (names.count(name) != 0) {
686                                 wroteSomething = true;
687                                 
688                                 out << name << '\t';
689                                 
690                                 //read rest
691                                 for (int i = 0; i < 15; i++) {  
692                                         if (!in.eof())  {       in >> junk;      out << junk << '\t';   }
693                                         else                    {       break;                  }
694                                 }
695                                 out << endl;
696                                 
697                         }else {//still read just don't do anything with it
698                                 //read rest
699                                 for (int i = 0; i < 15; i++) {  
700                                         if (!in.eof())  {       in >> junk;             }
701                                         else                    {       break;                  }
702                                 }
703                         }
704                         
705                         m->gobble(in);
706                 }
707                 in.close();
708                 out.close();
709                 
710                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
711                 outputNames.push_back(outputFileName);  outputTypes["alignreport"].push_back(outputFileName);
712                 
713                 return 0;
714                 
715         }
716         catch(exception& e) {
717                 m->errorOut(e, "GetSeqsCommand", "readAlign");
718                 exit(1);
719         }
720 }
721 //**********************************************************************************************************************
722
723 int GetSeqsCommand::readAccnos(){
724         try {
725                 
726                 ifstream in;
727                 m->openInputFile(accnosfile, in);
728                 string name;
729                 
730                 while(!in.eof()){
731                         in >> name;
732                                                 
733                         names.insert(name);
734                         
735                         m->gobble(in);
736                 }
737                 in.close();     
738                 
739                 return 0;
740
741         }
742         catch(exception& e) {
743                 m->errorOut(e, "GetSeqsCommand", "readAccnos");
744                 exit(1);
745         }
746 }
747
748 //**********************************************************************************************************************
749