]> git.donarmstrong.com Git - mothur.git/blob - removeseqscommand.cpp
fixed metastats, added resize to cluster.classic, added code to kill children if...
[mothur.git] / removeseqscommand.cpp
1 /*
2  *  removeseqscommand.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 "removeseqscommand.h"
11 #include "sequence.hpp"
12 #include "listvector.hpp"
13
14 //**********************************************************************************************************************
15 vector<string> RemoveSeqsCommand::getValidParameters(){ 
16         try {
17                 string Array[] =  {"fasta","name", "group", "alignreport", "accnos", "qfile","list","taxonomy","outputdir","inputdir", "dups" };
18                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
19                 return myArray;
20         }
21         catch(exception& e) {
22                 m->errorOut(e, "RemoveSeqsCommand", "getValidParameters");
23                 exit(1);
24         }
25 }
26 //**********************************************************************************************************************
27 RemoveSeqsCommand::RemoveSeqsCommand(){ 
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, "RemoveSeqsCommand", "RemoveSeqsCommand");
42                 exit(1);
43         }
44 }
45 //**********************************************************************************************************************
46 vector<string> RemoveSeqsCommand::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, "RemoveSeqsCommand", "getRequiredParameters");
54                 exit(1);
55         }
56 }
57 //**********************************************************************************************************************
58 vector<string> RemoveSeqsCommand::getRequiredFiles(){   
59         try {
60                 vector<string> myArray;
61                 return myArray;
62         }
63         catch(exception& e) {
64                 m->errorOut(e, "RemoveSeqsCommand", "getRequiredFiles");
65                 exit(1);
66         }
67 }
68 //**********************************************************************************************************************
69 RemoveSeqsCommand::RemoveSeqsCommand(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", "accnos", "qfile", "list","taxonomy","outputdir","inputdir", "dups" };
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                         
210                         string usedDups = "true";
211                         string temp = validParameter.validFile(parameters, "dups", false);      
212                         if (temp == "not found") { 
213                                 if (namefile != "") {  temp = "true";                                   }
214                                 else                            {  temp = "false"; usedDups = "";       }
215                         }
216                         dups = m->isTrue(temp);
217                         
218                         if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == ""))  { m->mothurOut("You must provide at least one of the following: fasta, name, group, taxonomy, quality, alignreport or list."); m->mothurOutEndLine(); abort = true; }
219                         
220                         if ((usedDups != "") && (namefile == "")) {  m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine();  abort = true; }                       
221                 }
222
223         }
224         catch(exception& e) {
225                 m->errorOut(e, "RemoveSeqsCommand", "RemoveSeqsCommand");
226                 exit(1);
227         }
228 }
229 //**********************************************************************************************************************
230
231 void RemoveSeqsCommand::help(){
232         try {
233                 m->mothurOut("The remove.seqs command reads an .accnos file and at least one of the following file types: fasta, name, group, list, taxonomy, quality or alignreport file.\n");
234                 m->mothurOut("It outputs a file containing the sequences NOT in the .accnos file.\n");
235                 m->mothurOut("The remove.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups.  You must provide accnos and at least one of the file parameters.\n");
236                 m->mothurOut("The dups parameter allows you to remove the entire line from a name file if you remove any name from the line. default=true. \n");
237                 m->mothurOut("The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n");
238                 m->mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n");
239                 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n");
240         }
241         catch(exception& e) {
242                 m->errorOut(e, "RemoveSeqsCommand", "help");
243                 exit(1);
244         }
245 }
246
247 //**********************************************************************************************************************
248
249 int RemoveSeqsCommand::execute(){
250         try {
251                 
252                 if (abort == true) { return 0; }
253                 
254                 //get names you want to keep
255                 readAccnos();
256                 
257                 if (m->control_pressed) { return 0; }
258                 
259                 //read through the correct file and output lines you want to keep
260                 if (namefile != "")                     {               readName();             }
261                 if (fastafile != "")            {               readFasta();    }
262                 if (groupfile != "")            {               readGroup();    }
263                 if (alignfile != "")            {               readAlign();    }
264                 if (listfile != "")                     {               readList();             }
265                 if (taxfile != "")                      {               readTax();              }
266                 if (qualfile != "")                     {               readQual();             }
267                 
268                 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str()); } return 0; }
269                 
270                 if (outputNames.size() != 0) {
271                         m->mothurOutEndLine();
272                         m->mothurOut("Output File Names: "); m->mothurOutEndLine();
273                         for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
274                         m->mothurOutEndLine();
275                 }
276                 
277                 return 0;               
278         }
279
280         catch(exception& e) {
281                 m->errorOut(e, "RemoveSeqsCommand", "execute");
282                 exit(1);
283         }
284 }
285
286 //**********************************************************************************************************************
287 int RemoveSeqsCommand::readFasta(){
288         try {
289                 string thisOutputDir = outputDir;
290                 if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
291                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile);
292                 
293                 ofstream out;
294                 m->openOutputFile(outputFileName, out);
295                 
296                 ifstream in;
297                 m->openInputFile(fastafile, in);
298                 string name;
299                 
300                 bool wroteSomething = false;
301                 
302                 while(!in.eof()){
303                         if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
304                         
305                         Sequence currSeq(in);
306                         name = currSeq.getName();
307                         
308                         if (name != "") {
309                                 //if this name is in the accnos file
310                                 if (names.count(name) == 0) {
311                                         wroteSomething = true;
312                                         
313                                         currSeq.printSequence(out);
314                                 }
315                         }
316                         m->gobble(in);
317                 }
318                 in.close();     
319                 out.close();
320                 
321                 if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
322                 outputTypes["fasta"].push_back(outputFileName);  outputNames.push_back(outputFileName);
323                 
324                 return 0;
325                 
326         }
327         catch(exception& e) {
328                 m->errorOut(e, "RemoveSeqsCommand", "readFasta");
329                 exit(1);
330         }
331 }
332 //**********************************************************************************************************************
333 int RemoveSeqsCommand::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 contains only sequences 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, "RemoveSeqsCommand", "readQual");
394                 exit(1);
395         }
396 }
397 //**********************************************************************************************************************
398 int RemoveSeqsCommand::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                 
404                 ofstream out;
405                 m->openOutputFile(outputFileName, out);
406                 
407                 ifstream in;
408                 m->openInputFile(listfile, in);
409                 
410                 bool wroteSomething = false;
411                 
412                 while(!in.eof()){
413                         //read in list vector
414                         ListVector list(in);
415                         
416                         //make a new list vector
417                         ListVector newList;
418                         newList.setLabel(list.getLabel());
419                         
420                         //for each bin
421                         for (int i = 0; i < list.getNumBins(); i++) {
422                                 if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
423                         
424                                 //parse out names that are in accnos file
425                                 string binnames = list.get(i);
426                                 
427                                 string newNames = "";
428                                 while (binnames.find_first_of(',') != -1) { 
429                                         string name = binnames.substr(0,binnames.find_first_of(','));
430                                         binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
431                                         
432                                         //if that name is in the .accnos file, add it
433                                         if (names.count(name) == 0) {  newNames += name + ",";  }
434                                 }
435                         
436                                 //get last name
437                                 if (names.count(binnames) == 0) {  newNames += binnames + ",";  }
438
439                                 //if there are names in this bin add to new list
440                                 if (newNames != "") {  
441                                         newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
442                                         newList.push_back(newNames);    
443                                 }
444                         }
445                                 
446                         //print new listvector
447                         if (newList.getNumBins() != 0) {
448                                 wroteSomething = true;
449                                 newList.print(out);
450                         }
451                         
452                         m->gobble(in);
453                 }
454                 in.close();     
455                 out.close();
456                 
457                 if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
458                 outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
459                                 
460                 return 0;
461
462         }
463         catch(exception& e) {
464                 m->errorOut(e, "RemoveSeqsCommand", "readList");
465                 exit(1);
466         }
467 }
468 //**********************************************************************************************************************
469 int RemoveSeqsCommand::readName(){
470         try {
471                 string thisOutputDir = outputDir;
472                 if (outputDir == "") {  thisOutputDir += m->hasPath(namefile);  }
473                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile);
474
475                 ofstream out;
476                 m->openOutputFile(outputFileName, out);
477
478                 ifstream in;
479                 m->openInputFile(namefile, in);
480                 string name, firstCol, secondCol;
481                 
482                 bool wroteSomething = false;
483                 
484                 while(!in.eof()){
485                         if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
486
487                         in >> firstCol;         m->gobble(in);          
488                         in >> secondCol;                        
489
490                         vector<string> parsedNames;
491                         //parse second column saving each name
492                         while (secondCol.find_first_of(',') != -1) { 
493                                 name = secondCol.substr(0,secondCol.find_first_of(','));
494                                 secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
495                                 parsedNames.push_back(name);
496                         }
497                         
498                         //get name after last ,
499                         parsedNames.push_back(secondCol);
500
501                         vector<string> validSecond;  validSecond.clear();
502                         for (int i = 0; i < parsedNames.size(); i++) {
503                                 if (names.count(parsedNames[i]) == 0) {
504                                         validSecond.push_back(parsedNames[i]);
505                                 }
506                         }
507                         
508                         if ((dups) && (validSecond.size() != parsedNames.size())) {  //if dups is true and we want to get rid of anyone, get rid of everyone
509                                 for (int i = 0; i < parsedNames.size(); i++) {  names.insert(parsedNames[i]);  }
510                         }else {
511                                         //if the name in the first column is in the set then print it and any other names in second column also in set
512                                 if (names.count(firstCol) == 0) {
513                                         
514                                         wroteSomething = true;
515                                         
516                                         out << firstCol << '\t';
517                                         
518                                         //you know you have at least one valid second since first column is valid
519                                         for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
520                                         out << validSecond[validSecond.size()-1] << endl;
521                                         
522                                         //make first name in set you come to first column and then add the remaining names to second column
523                                 }else {
524                                         
525                                         //you want part of this row
526                                         if (validSecond.size() != 0) {
527                                                 
528                                                 wroteSomething = true;
529                                                 
530                                                 out << validSecond[0] << '\t';
531                                                 
532                                                 //you know you have at least one valid second since first column is valid
533                                                 for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
534                                                 out << validSecond[validSecond.size()-1] << endl;
535                                         }
536                                 }
537                         }
538                         m->gobble(in);
539                 }
540                 in.close();
541                 out.close();
542
543                 if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
544                 outputTypes["name"].push_back(outputFileName); outputNames.push_back(outputFileName);
545                                 
546                 return 0;
547         }
548         catch(exception& e) {
549                 m->errorOut(e, "RemoveSeqsCommand", "readName");
550                 exit(1);
551         }
552 }
553
554 //**********************************************************************************************************************
555 int RemoveSeqsCommand::readGroup(){
556         try {
557                 string thisOutputDir = outputDir;
558                 if (outputDir == "") {  thisOutputDir += m->hasPath(groupfile);  }
559                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
560                 
561                 ofstream out;
562                 m->openOutputFile(outputFileName, out);
563
564                 ifstream in;
565                 m->openInputFile(groupfile, in);
566                 string name, group;
567                 
568                 bool wroteSomething = false;
569                 
570                 while(!in.eof()){
571                         if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
572                         
573                         in >> name;                             //read from first column
574                         in >> group;                    //read from second column
575                         
576                         //if this name is in the accnos file
577                         if (names.count(name) == 0) {
578                                 wroteSomething = true;
579                                 out << name << '\t' << group << endl;
580                         }
581                                         
582                         m->gobble(in);
583                 }
584                 in.close();
585                 out.close();
586                 
587                 if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
588                 outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName);
589                 
590                 return 0;
591         }
592         catch(exception& e) {
593                 m->errorOut(e, "RemoveSeqsCommand", "readGroup");
594                 exit(1);
595         }
596 }
597 //**********************************************************************************************************************
598 int RemoveSeqsCommand::readTax(){
599         try {
600                 string thisOutputDir = outputDir;
601                 if (outputDir == "") {  thisOutputDir += m->hasPath(taxfile);  }
602                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
603                 ofstream out;
604                 m->openOutputFile(outputFileName, out);
605
606                 ifstream in;
607                 m->openInputFile(taxfile, in);
608                 string name, tax;
609                 
610                 bool wroteSomething = false;
611                 
612                 while(!in.eof()){
613                         if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
614                         
615                         in >> name;                             //read from first column
616                         in >> tax;                      //read from second column
617                         
618                         //if this name is in the accnos file
619                         if (names.count(name) == 0) {
620                                 wroteSomething = true;
621                                 out << name << '\t' << tax << endl;
622                         }
623                                         
624                         m->gobble(in);
625                 }
626                 in.close();
627                 out.close();
628                 
629                 if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
630                 outputTypes["taxonomy"].push_back(outputFileName); outputNames.push_back(outputFileName);
631                 
632                 return 0;
633         }
634         catch(exception& e) {
635                 m->errorOut(e, "RemoveSeqsCommand", "readTax");
636                 exit(1);
637         }
638 }
639 //**********************************************************************************************************************
640 //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
641 int RemoveSeqsCommand::readAlign(){
642         try {
643                 string thisOutputDir = outputDir;
644                 if (outputDir == "") {  thisOutputDir += m->hasPath(alignfile);  }
645                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report";
646                 
647                 ofstream out;
648                 m->openOutputFile(outputFileName, out);
649
650                 ifstream in;
651                 m->openInputFile(alignfile, in);
652                 string name, junk;
653                 
654                 bool wroteSomething = false;
655                 
656                 //read column headers
657                 for (int i = 0; i < 16; i++) {  
658                         if (!in.eof())  {       in >> junk;      out << junk << '\t';   }
659                         else                    {       break;                  }
660                 }
661                 out << endl;
662                 
663                 while(!in.eof()){
664                         if (m->control_pressed) { in.close();  out.close();  remove(outputFileName.c_str());  return 0; }
665                         
666                         in >> name;                             //read from first column
667                         
668                         //if this name is in the accnos file
669                         if (names.count(name) == 0) {
670                                 wroteSomething = true;
671                                 
672                                 out << name << '\t';
673                                 
674                                 //read rest
675                                 for (int i = 0; i < 15; i++) {  
676                                         if (!in.eof())  {       in >> junk;      out << junk << '\t';   }
677                                         else                    {       break;                  }
678                                 }
679                                 out << endl;
680                                 
681                         }else {//still read just don't do anything with it
682                                 
683                                 //read rest
684                                 for (int i = 0; i < 15; i++) {  
685                                         if (!in.eof())  {       in >> junk;             }
686                                         else                    {       break;                  }
687                                 }
688                         }
689                         
690                         m->gobble(in);
691                 }
692                 in.close();
693                 out.close();
694                 
695                 if (wroteSomething == false) {  m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine();  }
696                 outputTypes["alignreport"].push_back(outputFileName); outputNames.push_back(outputFileName);
697                 
698                 return 0;
699                 
700         }
701         catch(exception& e) {
702                 m->errorOut(e, "RemoveSeqsCommand", "readAlign");
703                 exit(1);
704         }
705 }
706 //**********************************************************************************************************************
707 void RemoveSeqsCommand::readAccnos(){
708         try {
709                 
710                 ifstream in;
711                 m->openInputFile(accnosfile, in);
712                 string name;
713                 
714                 while(!in.eof()){
715                         in >> name;
716                                                 
717                         names.insert(name);
718                         
719                         m->gobble(in);
720                 }
721                 in.close();             
722
723         }
724         catch(exception& e) {
725                 m->errorOut(e, "RemoveSeqsCommand", "readAccnos");
726                 exit(1);
727         }
728 }
729
730 //**********************************************************************************************************************
731
732