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