]> git.donarmstrong.com Git - mothur.git/blob - getlineagecommand.cpp
fixes while testing
[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);      if (temp == "not found") { temp = "false"; usedDups = ""; }
186                         dups = m->isTrue(temp);
187                         
188                         taxons = validParameter.validFile(parameters, "taxon", false);  
189                         if (taxons == "not found") { taxons = "";  m->mothurOut("No taxons given, please correct."); m->mothurOutEndLine();  abort = true;  }
190                         else { 
191                                 //rip off quotes
192                                 if (taxons[0] == '\'') {  taxons = taxons.substr(1); }
193                                 if (taxons[(taxons.length()-1)] == '\'') {  taxons = taxons.substr(0, (taxons.length()-1)); }
194                         }
195                         
196                         
197                         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; }
198                 
199                         if ((usedDups != "") && (namefile == "")) {  m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine();  abort = true; }                       
200
201                 }
202
203         }
204         catch(exception& e) {
205                 m->errorOut(e, "GetLineageCommand", "GetLineageCommand");
206                 exit(1);
207         }
208 }
209 //**********************************************************************************************************************
210
211 void GetLineageCommand::help(){
212         try {
213                 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");
214                 m->mothurOut("It outputs a file containing only the sequences from the taxonomy file that are from the taxon requested.\n");
215                 m->mothurOut("The get.lineage command parameters are taxon, fasta, name, group, list, taxonomy, alignreport and dups.  You must provide taxonomy and taxon.\n");
216                 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");
217                 m->mothurOut("The taxon parameter allows you to select the taxons you would like to get.\n");
218                 m->mothurOut("The get.lineage command should be in the following format: get.lineage(taxonomy=yourTaxonomyFile, taxon=yourTaxons).\n");
219                 m->mothurOut("Example get.lineage(taxonomy=amazon.silva.taxonomy, taxon=Bacteria;Firmicutes;Bacilli;Lactobacillales;).\n");
220                 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");
221                 m->mothurOut("Example get.lineage(taxonomy=amazon.silva.taxonomy, taxon='Bacteria;Firmicutes;Bacilli;Lactobacillales;').\n");
222                 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
223         }
224         catch(exception& e) {
225                 m->errorOut(e, "GetLineageCommand", "help");
226                 exit(1);
227         }
228 }
229
230 //**********************************************************************************************************************
231
232 int GetLineageCommand::execute(){
233         try {
234                 
235                 if (abort == true) { return 0; }
236                 
237                 if (m->control_pressed) { return 0; }
238                 
239                 //read through the correct file and output lines you want to keep
240                 if (taxfile != "")                      {               readTax();              }  //fills the set of names to get
241                 if (namefile != "")                     {               readName();             }
242                 if (fastafile != "")            {               readFasta();    }
243                 if (groupfile != "")            {               readGroup();    }
244                 if (alignfile != "")            {               readAlign();    }
245                 if (listfile != "")                     {               readList();             }
246                 
247                 
248                 if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {   remove(outputNames[i].c_str());  } return 0; }
249                 
250                 if (outputNames.size() != 0) {
251                         m->mothurOutEndLine();
252                         m->mothurOut("Output File Names: "); m->mothurOutEndLine();
253                         for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
254                         m->mothurOutEndLine();
255                 }
256                 
257                 return 0;               
258         }
259
260         catch(exception& e) {
261                 m->errorOut(e, "GetLineageCommand", "execute");
262                 exit(1);
263         }
264 }
265
266 //**********************************************************************************************************************
267 int GetLineageCommand::readFasta(){
268         try {
269                 string thisOutputDir = outputDir;
270                 if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
271                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" +  m->getExtension(fastafile);
272                 ofstream out;
273                 m->openOutputFile(outputFileName, out);
274                 
275                 
276                 ifstream in;
277                 m->openInputFile(fastafile, in);
278                 string name;
279                 
280                 bool wroteSomething = false;
281                 
282                 while(!in.eof()){
283                 
284                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
285                         
286                         Sequence currSeq(in);
287                         name = currSeq.getName();
288                         
289                         if (name != "") {
290                                 //if this name is in the accnos file
291                                 if (names.count(name) != 0) {
292                                         wroteSomething = true;
293                                         
294                                         currSeq.printSequence(out);
295                                 }
296                         }
297                         m->gobble(in);
298                 }
299                 in.close();     
300                 out.close();
301                 
302                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
303                 outputNames.push_back(outputFileName);  outputTypes["fasta"].push_back(outputFileName);
304                 
305                 return 0;
306
307         }
308         catch(exception& e) {
309                 m->errorOut(e, "GetLineageCommand", "readFasta");
310                 exit(1);
311         }
312 }
313 //**********************************************************************************************************************
314 int GetLineageCommand::readList(){
315         try {
316                 string thisOutputDir = outputDir;
317                 if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
318                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
319                 ofstream out;
320                 m->openOutputFile(outputFileName, out);
321                 
322                 ifstream in;
323                 m->openInputFile(listfile, in);
324                 
325                 bool wroteSomething = false;
326                 
327                 while(!in.eof()){
328                         
329                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
330
331                         //read in list vector
332                         ListVector list(in);
333                         
334                         //make a new list vector
335                         ListVector newList;
336                         newList.setLabel(list.getLabel());
337                         
338                         //for each bin
339                         for (int i = 0; i < list.getNumBins(); i++) {
340                         
341                                 //parse out names that are in accnos file
342                                 string binnames = list.get(i);
343                                 
344                                 string newNames = "";
345                                 while (binnames.find_first_of(',') != -1) { 
346                                         string name = binnames.substr(0,binnames.find_first_of(','));
347                                         binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
348                                         
349                                         //if that name is in the .accnos file, add it
350                                         if (names.count(name) != 0) {  newNames += name + ",";  }
351                                 }
352                         
353                                 //get last name
354                                 if (names.count(binnames) != 0) {  newNames += binnames + ",";  }
355
356                                 //if there are names in this bin add to new list
357                                 if (newNames != "") { 
358                                         newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
359                                         newList.push_back(newNames);    
360                                 }
361                         }
362                                 
363                         //print new listvector
364                         if (newList.getNumBins() != 0) {
365                                 wroteSomething = true;
366                                 newList.print(out);
367                         }
368                         
369                         m->gobble(in);
370                 }
371                 in.close();     
372                 out.close();
373                 
374                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
375                 outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName);
376                 
377                 return 0;
378
379         }
380         catch(exception& e) {
381                 m->errorOut(e, "GetLineageCommand", "readList");
382                 exit(1);
383         }
384 }
385 //**********************************************************************************************************************
386 int GetLineageCommand::readName(){
387         try {
388                 string thisOutputDir = outputDir;
389                 if (outputDir == "") {  thisOutputDir += m->hasPath(namefile);  }
390                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" +  m->getExtension(namefile);
391                 ofstream out;
392                 m->openOutputFile(outputFileName, out);
393                 
394
395                 ifstream in;
396                 m->openInputFile(namefile, in);
397                 string name, firstCol, secondCol;
398                 
399                 bool wroteSomething = false;
400                 
401                 
402                 while(!in.eof()){
403                 
404                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
405
406                         in >> firstCol;                         
407                         in >> secondCol;
408                         
409                         string hold = "";
410                         if (dups) { hold = secondCol; }
411                         
412                         vector<string> parsedNames;
413                         //parse second column saving each name
414                         while (secondCol.find_first_of(',') != -1) { 
415                                 name = secondCol.substr(0,secondCol.find_first_of(','));
416                                 secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
417                                 parsedNames.push_back(name);
418                         }
419                         
420                         //get name after last ,
421                         parsedNames.push_back(secondCol);
422                         
423                         vector<string> validSecond;
424                         for (int i = 0; i < parsedNames.size(); i++) {
425                                 if (names.count(parsedNames[i]) != 0) {
426                                         validSecond.push_back(parsedNames[i]);
427                                 }
428                         }
429
430                         if ((dups) && (validSecond.size() != 0)) { //dups = true and we want to add someone, then add everyone
431                                 for (int i = 0; i < parsedNames.size(); i++) {  names.insert(parsedNames[i]);  }
432                                 out << firstCol << '\t' << hold << endl;
433                                 wroteSomething = true;
434                         }else {
435                                 //if the name in the first column is in the set then print it and any other names in second column also in set
436                                 if (names.count(firstCol) != 0) {
437                                 
438                                         wroteSomething = true;
439                                         
440                                         out << firstCol << '\t';
441                                         
442                                         //you know you have at least one valid second since first column is valid
443                                         for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
444                                         out << validSecond[validSecond.size()-1] << endl;
445                                         
446                                 
447                                 //make first name in set you come to first column and then add the remaining names to second column
448                                 }else {
449                                         //you want part of this row
450                                         if (validSecond.size() != 0) {
451                                         
452                                                 wroteSomething = true;
453                                                 
454                                                 out << validSecond[0] << '\t';
455                                         
456                                                 //you know you have at least one valid second since first column is valid
457                                                 for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
458                                                 out << validSecond[validSecond.size()-1] << endl;
459                                         }
460                                 }
461                         }
462                         m->gobble(in);
463                 }
464                 in.close();
465                 out.close();
466                 
467                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
468                 outputNames.push_back(outputFileName);  outputTypes["name"].push_back(outputFileName);
469                 
470                 return 0;
471                 
472         }
473         catch(exception& e) {
474                 m->errorOut(e, "GetLineageCommand", "readName");
475                 exit(1);
476         }
477 }
478
479 //**********************************************************************************************************************
480 int GetLineageCommand::readGroup(){
481         try {
482                 string thisOutputDir = outputDir;
483                 if (outputDir == "") {  thisOutputDir += m->hasPath(groupfile);  }
484                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
485                 ofstream out;
486                 m->openOutputFile(outputFileName, out);
487                 
488
489                 ifstream in;
490                 m->openInputFile(groupfile, in);
491                 string name, group;
492                 
493                 bool wroteSomething = false;
494                 
495                 while(!in.eof()){
496
497                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
498
499
500                         in >> name;                             //read from first column
501                         in >> group;                    //read from second column
502                         
503                         //if this name is in the accnos file
504                         if (names.count(name) != 0) {
505                                 wroteSomething = true;
506                                 
507                                 out << name << '\t' << group << endl;
508                         }
509                                         
510                         m->gobble(in);
511                 }
512                 in.close();
513                 out.close();
514                 
515                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
516                 outputNames.push_back(outputFileName);  outputTypes["group"].push_back(outputFileName);
517                 
518                 return 0;
519
520         }
521         catch(exception& e) {
522                 m->errorOut(e, "GetLineageCommand", "readGroup");
523                 exit(1);
524         }
525 }
526 //**********************************************************************************************************************
527 int GetLineageCommand::readTax(){
528         try {
529                 string thisOutputDir = outputDir;
530                 if (outputDir == "") {  thisOutputDir += m->hasPath(taxfile);  }
531                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
532                 ofstream out;
533                 m->openOutputFile(outputFileName, out);
534                 
535                 ifstream in;
536                 m->openInputFile(taxfile, in);
537                 string name, tax;
538                 
539                 bool wroteSomething = false;
540                 
541                 while(!in.eof()){
542
543                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
544
545                         in >> name;                             //read from first column
546                         in >> tax;                      //read from second column
547                         
548                         string newtax = tax;
549                         
550                         //if the users file contains confidence scores we want to ignore them when searching for the taxons
551                         int hasConfidences = tax.find_first_of('(');
552                         if (hasConfidences != string::npos) { 
553                                 newtax = removeConfidences(tax);
554                         }
555                         
556                         int pos = newtax.find(taxons);
557                         
558                         if (pos != string::npos) { //this sequence contains the taxon the user wants
559                                 names.insert(name);
560                                 out << name << '\t' << tax << endl;
561                         }
562                         
563                         m->gobble(in);
564                 }
565                 in.close();
566                 out.close();
567                 
568                 if (names.size() == 0) { m->mothurOut("Your taxonomy file does not contain any sequences from " + taxons + "."); m->mothurOutEndLine();  }
569                 outputNames.push_back(outputFileName); outputTypes["taxonomy"].push_back(outputFileName);
570                         
571                 return 0;
572
573         }
574         catch(exception& e) {
575                 m->errorOut(e, "GetLineageCommand", "readTax");
576                 exit(1);
577         }
578 }
579 /**************************************************************************************************/
580 string GetLineageCommand::removeConfidences(string tax) {
581         try {
582                 
583                 string taxon = "";
584                 int taxLength = tax.length();
585                 for(int i=0;i<taxLength;i++){
586                         if(tax[i] == ';'){
587                                 taxon = taxon.substr(0, taxon.find_first_of('(')); //rip off confidence
588                                 taxon += ";";
589                         }
590                         else{
591                                 taxon += tax[i];
592                         }
593                 }
594                                 
595                 return taxon;
596         }
597         catch(exception& e) {
598                 m->errorOut(e, "GetLineageCommand", "removeConfidences");
599                 exit(1);
600         }
601 }
602 //**********************************************************************************************************************
603 //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
604 int GetLineageCommand::readAlign(){
605         try {
606                 string thisOutputDir = outputDir;
607                 if (outputDir == "") {  thisOutputDir += m->hasPath(alignfile);  }
608                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report";
609                 ofstream out;
610                 m->openOutputFile(outputFileName, out);
611                 
612
613                 ifstream in;
614                 m->openInputFile(alignfile, in);
615                 string name, junk;
616                 
617                 bool wroteSomething = false;
618                 
619                 //read column headers
620                 for (int i = 0; i < 16; i++) {  
621                         if (!in.eof())  {       in >> junk;      out << junk << '\t';   }
622                         else                    {       break;                  }
623                 }
624                 out << endl;
625                 
626                 while(!in.eof()){
627                 
628                         if (m->control_pressed) { in.close(); out.close(); remove(outputFileName.c_str());  return 0; }
629
630
631                         in >> name;                             //read from first column
632                         
633                         //if this name is in the accnos file
634                         if (names.count(name) != 0) {
635                                 wroteSomething = true;
636                                 
637                                 out << name << '\t';
638                                 
639                                 //read rest
640                                 for (int i = 0; i < 15; i++) {  
641                                         if (!in.eof())  {       in >> junk;      out << junk << '\t';   }
642                                         else                    {       break;                  }
643                                 }
644                                 out << endl;
645                                 
646                         }else {//still read just don't do anything with it
647                                 //read rest
648                                 for (int i = 0; i < 15; i++) {  
649                                         if (!in.eof())  {       in >> junk;             }
650                                         else                    {       break;                  }
651                                 }
652                         }
653                         
654                         m->gobble(in);
655                 }
656                 in.close();
657                 out.close();
658                 
659                 if (wroteSomething == false) { m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine();  }
660                 outputNames.push_back(outputFileName); outputTypes["alignreport"].push_back(outputFileName);
661                 
662                 return 0;
663                 
664         }
665         catch(exception& e) {
666                 m->errorOut(e, "GetLineageCommand", "readAlign");
667                 exit(1);
668         }
669 }
670 //**********************************************************************************************************************
671
672
673
674