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