]> git.donarmstrong.com Git - mothur.git/blob - getseqscommand.cpp
added get.groups and remove.groups commands
[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                 m->mothurOut("Selected " + toString(names.size()) + " sequences."); m->mothurOutEndLine();
267                 
268                 if (outputNames.size() != 0) {
269                         m->mothurOutEndLine();
270                         m->mothurOut("Output File Names: "); m->mothurOutEndLine();
271                         for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
272                         m->mothurOutEndLine();
273                 }
274                 
275                 return 0;               
276         }
277
278         catch(exception& e) {
279                 m->errorOut(e, "GetSeqsCommand", "execute");
280                 exit(1);
281         }
282 }
283
284 //**********************************************************************************************************************
285 int GetSeqsCommand::readFasta(){
286         try {
287                 string thisOutputDir = outputDir;
288                 if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
289                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" +  m->getExtension(fastafile);
290                 ofstream out;
291                 m->openOutputFile(outputFileName, out);
292                 
293                 
294                 ifstream in;
295                 m->openInputFile(fastafile, in);
296                 string name;
297                 
298                 bool wroteSomething = false;
299                 
300                 while(!in.eof()){
301                 
302                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
303                         
304                         Sequence currSeq(in);
305                         name = currSeq.getName();
306                         
307                         if (name != "") {
308                                 //if this name is in the accnos file
309                                 if (names.count(name) != 0) {
310                                         wroteSomething = true;
311                                         
312                                         currSeq.printSequence(out);
313                                 }
314                         }
315                         m->gobble(in);
316                 }
317                 in.close();     
318                 out.close();
319                 
320                 
321                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
322                 outputNames.push_back(outputFileName);  outputTypes["fasta"].push_back(outputFileName); 
323                 
324                 return 0;
325
326         }
327         catch(exception& e) {
328                 m->errorOut(e, "GetSeqsCommand", "readFasta");
329                 exit(1);
330         }
331 }
332 //**********************************************************************************************************************
333 int GetSeqsCommand::readQual(){
334         try {
335                 string thisOutputDir = outputDir;
336                 if (outputDir == "") {  thisOutputDir += m->hasPath(qualfile);  }
337                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + "pick" +  m->getExtension(qualfile);
338                 ofstream out;
339                 m->openOutputFile(outputFileName, out);
340                 
341                 
342                 ifstream in;
343                 m->openInputFile(qualfile, in);
344                 string name;
345                 
346                 bool wroteSomething = false;
347                 
348                 
349                 while(!in.eof()){       
350                         string saveName = "";
351                         string name = "";
352                         string scores = "";
353                         
354                         in >> name; 
355                                 
356                         if (name.length() != 0) { 
357                                 saveName = name.substr(1);
358                                 while (!in.eof())       {       
359                                         char c = in.get(); 
360                                         if (c == 10 || c == 13){        break;  }
361                                         else { name += c; }     
362                                 } 
363                                 m->gobble(in);
364                         }
365                         
366                         while(in){
367                                 char letter= in.get();
368                                 if(letter == '>'){      in.putback(letter);     break;  }
369                                 else{ scores += letter; }
370                         }
371                         
372                         m->gobble(in);
373                         
374                         if (names.count(saveName) != 0) {
375                                 wroteSomething = true;
376                                                 
377                                 out << name << endl << scores;
378                         }
379                         
380                         m->gobble(in);
381                 }
382                 in.close();
383                 out.close();
384                 
385                 
386                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
387                 outputNames.push_back(outputFileName);  outputTypes["qfile"].push_back(outputFileName); 
388                 
389                 return 0;
390                 
391         }
392         catch(exception& e) {
393                 m->errorOut(e, "GetSeqsCommand", "readQual");
394                 exit(1);
395         }
396 }
397 //**********************************************************************************************************************
398 int GetSeqsCommand::readList(){
399         try {
400                 string thisOutputDir = outputDir;
401                 if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
402                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
403                 ofstream out;
404                 m->openOutputFile(outputFileName, out);
405                 
406                 ifstream in;
407                 m->openInputFile(listfile, in);
408                 
409                 bool wroteSomething = false;
410                 
411                 while(!in.eof()){
412                         
413                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
414
415                         //read in list vector
416                         ListVector list(in);
417                         
418                         //make a new list vector
419                         ListVector newList;
420                         newList.setLabel(list.getLabel());
421                         
422                         //for each bin
423                         for (int i = 0; i < list.getNumBins(); i++) {
424                         
425                                 //parse out names that are in accnos file
426                                 string binnames = list.get(i);
427                                 
428                                 string newNames = "";
429                                 while (binnames.find_first_of(',') != -1) { 
430                                         string name = binnames.substr(0,binnames.find_first_of(','));
431                                         binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
432                                         
433                                         //if that name is in the .accnos file, add it
434                                         if (names.count(name) != 0) {  newNames += name + ",";  }
435                                 }
436                         
437                                 //get last name
438                                 if (names.count(binnames) != 0) {  newNames += binnames + ",";  }
439
440                                 //if there are names in this bin add to new list
441                                 if (newNames != "") { 
442                                         newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
443                                         newList.push_back(newNames);    
444                                 }
445                         }
446                                 
447                         //print new listvector
448                         if (newList.getNumBins() != 0) {
449                                 wroteSomething = true;
450                                 newList.print(out);
451                         }
452                         
453                         m->gobble(in);
454                 }
455                 in.close();     
456                 out.close();
457                 
458                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
459                 outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName);
460                 
461                 return 0;
462
463         }
464         catch(exception& e) {
465                 m->errorOut(e, "GetSeqsCommand", "readList");
466                 exit(1);
467         }
468 }
469 //**********************************************************************************************************************
470 int GetSeqsCommand::readName(){
471         try {
472                 string thisOutputDir = outputDir;
473                 if (outputDir == "") {  thisOutputDir += m->hasPath(namefile);  }
474                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" +  m->getExtension(namefile);
475                 ofstream out;
476                 m->openOutputFile(outputFileName, out);
477                 
478
479                 ifstream in;
480                 m->openInputFile(namefile, in);
481                 string name, firstCol, secondCol;
482                 
483                 bool wroteSomething = false;
484                 
485                 
486                 while(!in.eof()){
487                 
488                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
489
490                         in >> firstCol;                         
491                         in >> secondCol;
492                         
493                         string hold = "";
494                         if (dups) { hold = secondCol; }
495                         
496                         vector<string> parsedNames;
497                         //parse second column saving each name
498                         while (secondCol.find_first_of(',') != -1) { 
499                                 name = secondCol.substr(0,secondCol.find_first_of(','));
500                                 secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
501                                 parsedNames.push_back(name);
502                         }
503                         
504                         //get name after last ,
505                         parsedNames.push_back(secondCol);
506                         
507                         vector<string> validSecond;
508                         for (int i = 0; i < parsedNames.size(); i++) {
509                                 if (names.count(parsedNames[i]) != 0) {
510                                         validSecond.push_back(parsedNames[i]);
511                                 }
512                         }
513
514                         if ((dups) && (validSecond.size() != 0)) { //dups = true and we want to add someone, then add everyone
515                                 for (int i = 0; i < parsedNames.size(); i++) {  names.insert(parsedNames[i]);  }
516                                 out << firstCol << '\t' << hold << endl;
517                                 wroteSomething = true;
518                         }else {
519                                 //if the name in the first column is in the set then print it and any other names in second column also in set
520                                 if (names.count(firstCol) != 0) {
521                                 
522                                         wroteSomething = true;
523                                         
524                                         out << firstCol << '\t';
525                                         
526                                         //you know you have at least one valid second since first column is valid
527                                         for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
528                                         out << validSecond[validSecond.size()-1] << endl;
529                                         
530                                 
531                                 //make first name in set you come to first column and then add the remaining names to second column
532                                 }else {
533                                         //you want part of this row
534                                         if (validSecond.size() != 0) {
535                                         
536                                                 wroteSomething = true;
537                                                 
538                                                 out << validSecond[0] << '\t';
539                                         
540                                                 //you know you have at least one valid second since first column is valid
541                                                 for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
542                                                 out << validSecond[validSecond.size()-1] << endl;
543                                         }
544                                 }
545                         }
546                         m->gobble(in);
547                 }
548                 in.close();
549                 out.close();
550                 
551                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
552                 outputNames.push_back(outputFileName); outputTypes["name"].push_back(outputFileName);
553                 
554                 return 0;
555                 
556         }
557         catch(exception& e) {
558                 m->errorOut(e, "GetSeqsCommand", "readName");
559                 exit(1);
560         }
561 }
562
563 //**********************************************************************************************************************
564 int GetSeqsCommand::readGroup(){
565         try {
566                 string thisOutputDir = outputDir;
567                 if (outputDir == "") {  thisOutputDir += m->hasPath(groupfile);  }
568                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
569                 ofstream out;
570                 m->openOutputFile(outputFileName, out);
571                 
572
573                 ifstream in;
574                 m->openInputFile(groupfile, in);
575                 string name, group;
576                 
577                 bool wroteSomething = false;
578                 
579                 while(!in.eof()){
580
581                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
582
583
584                         in >> name;                             //read from first column
585                         in >> group;                    //read from second column
586                         
587                         //if this name is in the accnos file
588                         if (names.count(name) != 0) {
589                                 wroteSomething = true;
590                                 
591                                 out << name << '\t' << group << endl;
592                         }
593                                         
594                         m->gobble(in);
595                 }
596                 in.close();
597                 out.close();
598                 
599                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
600                 outputNames.push_back(outputFileName);  outputTypes["group"].push_back(outputFileName);
601                 
602                 return 0;
603
604         }
605         catch(exception& e) {
606                 m->errorOut(e, "GetSeqsCommand", "readGroup");
607                 exit(1);
608         }
609 }
610 //**********************************************************************************************************************
611 int GetSeqsCommand::readTax(){
612         try {
613                 string thisOutputDir = outputDir;
614                 if (outputDir == "") {  thisOutputDir += m->hasPath(taxfile);  }
615                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
616                 ofstream out;
617                 m->openOutputFile(outputFileName, out);
618                 
619                 ifstream in;
620                 m->openInputFile(taxfile, in);
621                 string name, tax;
622                 
623                 bool wroteSomething = false;
624                 
625                 while(!in.eof()){
626
627                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
628
629                         in >> name;                             //read from first column
630                         in >> tax;                      //read from second column
631                         
632                         //if this name is in the accnos file
633                         if (names.count(name) != 0) {
634                                 wroteSomething = true;
635                                 
636                                 out << name << '\t' << tax << endl;
637                         }
638                                         
639                         m->gobble(in);
640                 }
641                 in.close();
642                 out.close();
643                 
644                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
645                 outputNames.push_back(outputFileName);  outputTypes["taxonomy"].push_back(outputFileName);
646                         
647                 return 0;
648
649         }
650         catch(exception& e) {
651                 m->errorOut(e, "GetSeqsCommand", "readTax");
652                 exit(1);
653         }
654 }
655 //**********************************************************************************************************************
656 //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
657 int GetSeqsCommand::readAlign(){
658         try {
659                 string thisOutputDir = outputDir;
660                 if (outputDir == "") {  thisOutputDir += m->hasPath(alignfile);  }
661                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report";
662                 ofstream out;
663                 m->openOutputFile(outputFileName, out);
664                 
665
666                 ifstream in;
667                 m->openInputFile(alignfile, in);
668                 string name, junk;
669                 
670                 bool wroteSomething = false;
671                 
672                 //read column headers
673                 for (int i = 0; i < 16; i++) {  
674                         if (!in.eof())  {       in >> junk;      out << junk << '\t';   }
675                         else                    {       break;                  }
676                 }
677                 out << endl;
678                 
679                 while(!in.eof()){
680                 
681                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
682
683
684                         in >> name;                             //read from first column
685                         
686                         //if this name is in the accnos file
687                         if (names.count(name) != 0) {
688                                 wroteSomething = true;
689                                 
690                                 out << name << '\t';
691                                 
692                                 //read rest
693                                 for (int i = 0; i < 15; i++) {  
694                                         if (!in.eof())  {       in >> junk;      out << junk << '\t';   }
695                                         else                    {       break;                  }
696                                 }
697                                 out << endl;
698                                 
699                         }else {//still read just don't do anything with it
700                                 //read rest
701                                 for (int i = 0; i < 15; i++) {  
702                                         if (!in.eof())  {       in >> junk;             }
703                                         else                    {       break;                  }
704                                 }
705                         }
706                         
707                         m->gobble(in);
708                 }
709                 in.close();
710                 out.close();
711                 
712                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
713                 outputNames.push_back(outputFileName);  outputTypes["alignreport"].push_back(outputFileName);
714                 
715                 return 0;
716                 
717         }
718         catch(exception& e) {
719                 m->errorOut(e, "GetSeqsCommand", "readAlign");
720                 exit(1);
721         }
722 }
723 //**********************************************************************************************************************
724
725 int GetSeqsCommand::readAccnos(){
726         try {
727                 
728                 ifstream in;
729                 m->openInputFile(accnosfile, in);
730                 string name;
731                 
732                 while(!in.eof()){
733                         in >> name;
734                                                 
735                         names.insert(name);
736                         
737                         m->gobble(in);
738                 }
739                 in.close();     
740                 
741                 return 0;
742
743         }
744         catch(exception& e) {
745                 m->errorOut(e, "GetSeqsCommand", "readAccnos");
746                 exit(1);
747         }
748 }
749
750 //**********************************************************************************************************************
751