]> git.donarmstrong.com Git - mothur.git/blob - classifyseqscommand.cpp
added checks for ^C to quit command instead of program
[mothur.git] / classifyseqscommand.cpp
1 /*
2  *  classifyseqscommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 11/2/09.
6  *  Copyright 2009 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "classifyseqscommand.h"
11 #include "sequence.hpp"
12 #include "bayesian.h"
13 #include "phylotree.h"
14 #include "knn.h"
15
16 //**********************************************************************************************************************
17
18 ClassifySeqsCommand::ClassifySeqsCommand(string option)  {
19         try {
20                 abort = false;
21                 
22                 //allow user to run help
23                 if(option == "help") { help(); abort = true; }
24                 
25                 else {
26                         
27                         //valid paramters for this command
28                         string AlignArray[] =  {"template","fasta","name","search","ksize","method","processors","taxonomy","match","mismatch","gapopen","gapextend","numwanted","cutoff","probs","iters", "outputdir","inputdir"};
29                         vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
30                         
31                         OptionParser parser(option);
32                         map<string, string> parameters = parser.getParameters(); 
33                         
34                         ValidParameters validParameter;
35                         map<string, string>::iterator it;
36                         
37                         //check to make sure all parameters are valid for command
38                         for (it = parameters.begin(); it != parameters.end(); it++) { 
39                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
40                         }
41                         
42                         //if the user changes the output directory command factory will send this info to us in the output parameter 
43                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
44                         
45                         //if the user changes the input directory command factory will send this info to us in the output parameter 
46                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
47                         if (inputDir == "not found"){   inputDir = "";          }
48                         else {
49                                 string path;
50                                 it = parameters.find("template");
51                                 //user has given a template file
52                                 if(it != parameters.end()){ 
53                                         path = hasPath(it->second);
54                                         //if the user has not given a path then, add inputdir. else leave path alone.
55                                         if (path == "") {       parameters["template"] = inputDir + it->second;         }
56                                 }
57                                 
58                                 it = parameters.find("taxonomy");
59                                 //user has given a template file
60                                 if(it != parameters.end()){ 
61                                         path = hasPath(it->second);
62                                         //if the user has not given a path then, add inputdir. else leave path alone.
63                                         if (path == "") {       parameters["taxonomy"] = inputDir + it->second;         }
64                                 }
65                         }
66
67                         //check for required parameters
68                         templateFileName = validParameter.validFile(parameters, "template", true);
69                         if (templateFileName == "not found") { 
70                                 m->mothurOut("template is a required parameter for the classify.seqs command."); 
71                                 m->mothurOutEndLine();
72                                 abort = true; 
73                         }
74                         else if (templateFileName == "not open") { abort = true; }      
75                         
76                         fastaFileName = validParameter.validFile(parameters, "fasta", false);
77                         if (fastaFileName == "not found") { m->mothurOut("fasta is a required parameter for the classify.seqs command."); m->mothurOutEndLine(); abort = true;  }
78                         else { 
79                                 splitAtDash(fastaFileName, fastaFileNames);
80                                 
81                                 //go through files and make sure they are good, if not, then disregard them
82                                 for (int i = 0; i < fastaFileNames.size(); i++) {
83                                         if (inputDir != "") {
84                                                 string path = hasPath(fastaFileNames[i]);
85                                                 //if the user has not given a path then, add inputdir. else leave path alone.
86                                                 if (path == "") {       fastaFileNames[i] = inputDir + fastaFileNames[i];               }
87                                         }
88                                         
89                                         int ableToOpen;
90                                         ifstream in;
91                                         ableToOpen = openInputFile(fastaFileNames[i], in);
92                                         if (ableToOpen == 1) { 
93                                                 m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); 
94                                                 //erase from file list
95                                                 fastaFileNames.erase(fastaFileNames.begin()+i);
96                                                 i--;
97                                         }
98                                         in.close();
99                                 }
100                                 
101                                 //make sure there is at least one valid file left
102                                 if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; }
103                         }
104
105                         
106                         taxonomyFileName = validParameter.validFile(parameters, "taxonomy", true);
107                         if (taxonomyFileName == "not found") { 
108                                 m->mothurOut("taxonomy is a required parameter for the classify.seqs command."); 
109                                 m->mothurOutEndLine();
110                                 abort = true; 
111                         }
112                         else if (taxonomyFileName == "not open") { abort = true; }      
113                         
114                         
115                         namefile = validParameter.validFile(parameters, "name", false);
116                         if (namefile == "not found") { namefile = "";  }
117
118                         else { 
119                                 splitAtDash(namefile, namefileNames);
120                                 
121                                 //go through files and make sure they are good, if not, then disregard them
122                                 for (int i = 0; i < namefileNames.size(); i++) {
123                                         if (inputDir != "") {
124                                                 string path = hasPath(namefileNames[i]);
125                                                 //if the user has not given a path then, add inputdir. else leave path alone.
126                                                 if (path == "") {       namefileNames[i] = inputDir + namefileNames[i];         }
127                                         }
128
129                                         int ableToOpen;
130                                         ifstream in;
131                                         ableToOpen = openInputFile(namefileNames[i], in);
132                                         if (ableToOpen == 1) {  m->mothurOut("Unable to match name file with fasta file."); m->mothurOutEndLine(); abort = true;        }
133                                         in.close();
134                                 }
135                         }
136
137                         if (namefile != "") {
138                                 if (namefileNames.size() != fastaFileNames.size()) { abort = true; m->mothurOut("If you provide a name file, you must have one for each fasta file."); m->mothurOutEndLine(); }
139                         }
140                         
141                         //check for optional parameter and set defaults
142                         // ...at some point should added some additional type checking...
143                         string temp;
144                         temp = validParameter.validFile(parameters, "ksize", false);            if (temp == "not found"){       temp = "8";                             }
145                         convert(temp, kmerSize); 
146                         
147                         temp = validParameter.validFile(parameters, "processors", false);       if (temp == "not found"){       temp = "1";                             }
148                         convert(temp, processors); 
149                         
150                         search = validParameter.validFile(parameters, "search", false);         if (search == "not found"){     search = "kmer";                }
151                         
152                         method = validParameter.validFile(parameters, "method", false);         if (method == "not found"){     method = "bayesian";    }
153                         
154                         temp = validParameter.validFile(parameters, "match", false);            if (temp == "not found"){       temp = "1.0";                   }
155                         convert(temp, match);  
156                         
157                         temp = validParameter.validFile(parameters, "mismatch", false);         if (temp == "not found"){       temp = "-1.0";                  }
158                         convert(temp, misMatch);  
159                         
160                         temp = validParameter.validFile(parameters, "gapopen", false);          if (temp == "not found"){       temp = "-2.0";                  }
161                         convert(temp, gapOpen);  
162                         
163                         temp = validParameter.validFile(parameters, "gapextend", false);        if (temp == "not found"){       temp = "-1.0";                  }
164                         convert(temp, gapExtend); 
165                         
166                         temp = validParameter.validFile(parameters, "numwanted", false);        if (temp == "not found"){       temp = "10";                    }
167                         convert(temp, numWanted);
168                         
169                         temp = validParameter.validFile(parameters, "cutoff", false);           if (temp == "not found"){       temp = "0";                             }
170                         convert(temp, cutoff);
171                         
172                         temp = validParameter.validFile(parameters, "probs", false);            if (temp == "not found"){       temp = "true";                  }
173                         probs = isTrue(temp);
174                         
175                         temp = validParameter.validFile(parameters, "iters", false);            if (temp == "not found") { temp = "100";                        }
176                         convert(temp, iters); 
177
178
179                         
180                         if ((method == "bayesian") && (search != "kmer"))  { 
181                                 m->mothurOut("The bayesian method requires the kmer search." + search + "will be disregarded." ); m->mothurOutEndLine();
182                                 search = "kmer";
183                         }
184                 }
185                 
186         }
187         catch(exception& e) {
188                 m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand");
189                 exit(1);
190         }
191 }
192
193 //**********************************************************************************************************************
194
195 ClassifySeqsCommand::~ClassifySeqsCommand(){    
196
197         if (abort == false) {
198                 for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
199         }
200 }
201
202 //**********************************************************************************************************************
203
204 void ClassifySeqsCommand::help(){
205         try {
206                 m->mothurOut("The classify.seqs command reads a fasta file containing sequences and creates a .taxonomy file and a .tax.summary file.\n");
207                 m->mothurOut("The classify.seqs command parameters are template, fasta, name, search, ksize, method, taxonomy, processors, match, mismatch, gapopen, gapextend, numwanted and probs.\n");
208                 m->mothurOut("The template, fasta and taxonomy parameters are required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n");
209                 m->mothurOut("The search parameter allows you to specify the method to find most similar template.  Your options are: suffix, kmer, blast and distance. The default is kmer.\n");
210                 m->mothurOut("The name parameter allows you add a names file with your fasta file, if you enter multiple fasta files, you must enter matching names files for them.\n");
211                 m->mothurOut("The method parameter allows you to specify classification method to use.  Your options are: bayesian and knn. The default is bayesian.\n");
212                 m->mothurOut("The ksize parameter allows you to specify the kmer size for finding most similar template to candidate.  The default is 8.\n");
213                 m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n");
214                 m->mothurOut("The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n");
215                 m->mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases.  The default is -1.0.\n");
216                 m->mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n");
217                 m->mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment.  The default is -1.0.\n");
218                 m->mothurOut("The numwanted parameter allows you to specify the number of sequence matches you want with the knn method.  The default is 10.\n");
219                 m->mothurOut("The cutoff parameter allows you to specify a bootstrap confidence threshold for your taxonomy.  The default is 0.\n");
220                 m->mothurOut("The probs parameter shut off the bootstrapping results for the bayesian method. The default is true, meaning you want the bootstrapping to be run.\n");
221                 m->mothurOut("The iters parameter allows you to specify how many iterations to do when calculating the bootstrap confidence score for your taxonomy with the bayesian method.  The default is 100.\n");
222                 m->mothurOut("The classify.seqs command should be in the following format: \n");
223                 m->mothurOut("classify.seqs(template=yourTemplateFile, fasta=yourFastaFile, method=yourClassificationMethod, search=yourSearchmethod, ksize=yourKmerSize, taxonomy=yourTaxonomyFile, processors=yourProcessors) \n");
224                 m->mothurOut("Example classify.seqs(fasta=amazon.fasta, template=core.filtered, method=knn, search=gotoh, ksize=8, processors=2)\n");
225                 m->mothurOut("The .taxonomy file consists of 2 columns: 1 = your sequence name, 2 = the taxonomy for your sequence. \n");
226                 m->mothurOut("The .tax.summary is a summary of the different taxonomies represented in your fasta file. \n");
227                 m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n");
228         }
229         catch(exception& e) {
230                 m->errorOut(e, "ClassifySeqsCommand", "help");
231                 exit(1);
232         }
233 }
234
235
236 //**********************************************************************************************************************
237
238 int ClassifySeqsCommand::execute(){
239         try {
240                 if (abort == true) {    return 0;       }
241                 
242                 if(method == "bayesian"){       classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters);           }
243                 else if(method == "knn"){       classify = new Knn(taxonomyFileName, templateFileName, search, kmerSize, gapOpen, gapExtend, match, misMatch, numWanted);                               }
244                 else {
245                         m->mothurOut(search + " is not a valid method option. I will run the command using bayesian.");
246                         m->mothurOutEndLine();
247                         classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters);   
248                 }
249                 
250                 if (m->control_pressed) { delete classify; return 0; }
251                 
252                 vector<string> outputNames;
253                                 
254                 for (int s = 0; s < fastaFileNames.size(); s++) {
255                 
256                         //read namefile
257                         if(namefile != "") {
258                                 nameMap.clear(); //remove old names
259                                 
260                                 ifstream inNames;
261                                 openInputFile(namefileNames[s], inNames);
262                                 
263                                 string firstCol, secondCol;
264                                 while(!inNames.eof()) {
265                                         inNames >> firstCol >> secondCol; gobble(inNames);
266                                         nameMap[firstCol] = getNumNames(secondCol);  //ex. seq1 seq1,seq3,seq5 -> seq1 = 3.
267                                 }
268                                 inNames.close();
269                         }
270                 
271                         m->mothurOut("Classifying sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine();
272                         
273                         if (outputDir == "") { outputDir += hasPath(fastaFileNames[s]); }
274                         string newTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + getRootName(getSimpleName(taxonomyFileName)) + "taxonomy";
275                         string tempTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "taxonomy.temp";
276                         string taxSummary = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + getRootName(getSimpleName(taxonomyFileName)) + "tax.summary";
277                         
278                         outputNames.push_back(newTaxonomyFile);
279                         outputNames.push_back(taxSummary);
280                         
281                         int start = time(NULL);
282                         int numFastaSeqs = 0;
283                         for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
284                         
285 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
286                         if(processors == 1){
287                                 ifstream inFASTA;
288                                 openInputFile(fastaFileNames[s], inFASTA);
289                                 numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
290                                 inFASTA.close();
291                                 
292                                 lines.push_back(new linePair(0, numFastaSeqs));
293                                 
294                                 driver(lines[0], newTaxonomyFile, tempTaxonomyFile, fastaFileNames[s]);
295                         }
296                         else{
297                                 vector<int> positions;
298                                 processIDS.resize(0);
299                                 
300                                 ifstream inFASTA;
301                                 openInputFile(fastaFileNames[s], inFASTA);
302                                 
303                                 string input;
304                                 while(!inFASTA.eof()){
305                                         input = getline(inFASTA);
306                                         if (input.length() != 0) {
307                                                 if(input[0] == '>'){    int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1);       }
308                                         }
309                                 }
310                                 inFASTA.close();
311                                 
312                                 numFastaSeqs = positions.size();
313                                 
314                                 int numSeqsPerProcessor = numFastaSeqs / processors;
315                                 
316                                 for (int i = 0; i < processors; i++) {
317                                         int startPos = positions[ i * numSeqsPerProcessor ];
318                                         if(i == processors - 1){
319                                                 numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
320                                         }
321                                         lines.push_back(new linePair(startPos, numSeqsPerProcessor));
322                                 }
323                                 createProcesses(newTaxonomyFile, tempTaxonomyFile, fastaFileNames[s]); 
324                                 
325                                 rename((newTaxonomyFile + toString(processIDS[0]) + ".temp").c_str(), newTaxonomyFile.c_str());
326                                 rename((tempTaxonomyFile + toString(processIDS[0]) + ".temp").c_str(), tempTaxonomyFile.c_str());
327                                 
328                                 for(int i=1;i<processors;i++){
329                                         appendTaxFiles((newTaxonomyFile + toString(processIDS[i]) + ".temp"), newTaxonomyFile);
330                                         appendTaxFiles((tempTaxonomyFile + toString(processIDS[i]) + ".temp"), tempTaxonomyFile);
331                                         remove((newTaxonomyFile + toString(processIDS[i]) + ".temp").c_str());
332                                         remove((tempTaxonomyFile + toString(processIDS[i]) + ".temp").c_str());
333                                 }
334                                 
335                         }
336 #else
337                         ifstream inFASTA;
338                         openInputFile(fastaFileNames[s], inFASTA);
339                         numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
340                         inFASTA.close();
341                         
342                         lines.push_back(new linePair(0, numFastaSeqs));
343                         
344                         driver(lines[0], newTaxonomyFile, tempTaxonomyFile, fastaFileNames[s]);
345 #endif  
346                         //make taxonomy tree from new taxonomy file 
347                         PhyloTree taxaBrowser;
348                         
349                         if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } delete classify; return 0; }
350                         
351                         ifstream in;
352                         openInputFile(tempTaxonomyFile, in);
353                 
354                         //read in users taxonomy file and add sequences to tree
355                         string name, taxon;
356                         while(!in.eof()){
357                                 in >> name >> taxon; gobble(in);
358                                 
359                                 if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } remove(tempTaxonomyFile.c_str()); delete classify; return 0; }
360                                 
361                                 if (namefile != "") {
362                                         itNames = nameMap.find(name);
363                 
364                                         if (itNames == nameMap.end()) { 
365                                                 m->mothurOut(name + " is not in your name file please correct."); m->mothurOutEndLine(); exit(1);
366                                         }else{
367                                                 for (int i = 0; i < itNames->second; i++) { 
368                                                         taxaBrowser.addSeqToTree(name+toString(i), taxon);  //add it as many times as there are identical seqs
369                                                 }
370                                         }
371                                 }else {  taxaBrowser.addSeqToTree(name, taxon);  } //add it once
372                         }
373                         in.close();
374         
375                         taxaBrowser.assignHeirarchyIDs(0);
376                         
377                         if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } remove(tempTaxonomyFile.c_str()); delete classify; return 0; }
378
379                         taxaBrowser.binUnclassified();
380                         
381                         remove(tempTaxonomyFile.c_str());
382                         
383                         if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } delete classify; return 0; }
384
385                         
386                         //print summary file
387                         ofstream outTaxTree;
388                         openOutputFile(taxSummary, outTaxTree);
389                         taxaBrowser.print(outTaxTree);
390                         outTaxTree.close();
391                         
392                         //output taxonomy with the unclassified bins added
393                         ifstream inTax;
394                         openInputFile(newTaxonomyFile, inTax);
395                         
396                         ofstream outTax;
397                         string unclass = newTaxonomyFile + ".unclass.temp";
398                         openOutputFile(unclass, outTax);
399                         
400                         //get maxLevel from phylotree so you know how many 'unclassified's to add
401                         int maxLevel = taxaBrowser.getMaxLevel();
402                         
403                         //read taxfile - this reading and rewriting is done to preserve the confidence scores.
404                         while (!inTax.eof()) {
405                                 if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } remove(unclass.c_str()); delete classify; return 0; }
406
407                                 inTax >> name >> taxon; gobble(inTax);
408                                 
409                                 string newTax = addUnclassifieds(taxon, maxLevel);
410                                 
411                                 outTax << name << '\t' << newTax << endl;
412                         }
413                         inTax.close();  
414                         outTax.close();
415                         
416                         remove(newTaxonomyFile.c_str());
417                         rename(unclass.c_str(), newTaxonomyFile.c_str());
418                         
419                         m->mothurOutEndLine();
420                         m->mothurOut("Output File Names: "); m->mothurOutEndLine();
421                         for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
422                         m->mothurOutEndLine();
423
424                         
425                         m->mothurOutEndLine();
426                         m->mothurOut("It took " + toString(time(NULL) - start) + " secs to classify " + toString(numFastaSeqs) + " sequences."); m->mothurOutEndLine(); m->mothurOutEndLine();
427                 }
428                 
429                 delete classify;
430                 return 0;
431         }
432         catch(exception& e) {
433                 m->errorOut(e, "ClassifySeqsCommand", "execute");
434                 exit(1);
435         }
436 }
437
438 /**************************************************************************************************/
439 string ClassifySeqsCommand::addUnclassifieds(string tax, int maxlevel) {
440         try{
441                 string newTax, taxon;
442                 int level = 0;
443                 
444                 //keep what you have counting the levels
445                 while (tax.find_first_of(';') != -1) {
446                         //get taxon
447                         taxon = tax.substr(0,tax.find_first_of(';'))+';';
448                         tax = tax.substr(tax.find_first_of(';')+1, tax.length());
449                         newTax += taxon;
450                         level++;
451                 }
452                 
453                 //add "unclassified" until you reach maxLevel
454                 while (level < maxlevel) {
455                         newTax += "unclassified;";
456                         level++;
457                 }
458                 
459                 return newTax;
460         }
461         catch(exception& e) {
462                 m->errorOut(e, "ClassifySeqsCommand", "addUnclassifieds");
463                 exit(1);
464         }
465 }
466
467 /**************************************************************************************************/
468
469 void ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile, string filename) {
470         try {
471 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
472                 int process = 0;
473                 //              processIDS.resize(0);
474                 
475                 //loop through and create all the processes you want
476                 while (process != processors) {
477                         int pid = fork();
478                         
479                         if (pid > 0) {
480                                 processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
481                                 process++;
482                         }else if (pid == 0){
483                                 driver(lines[process], taxFileName + toString(getpid()) + ".temp", tempTaxFile + toString(getpid()) + ".temp", filename);
484                                 exit(0);
485                         }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
486                 }
487                 
488                 //force parent to wait until all the processes are done
489                 for (int i=0;i<processors;i++) { 
490                         int temp = processIDS[i];
491                         wait(&temp);
492                 }
493 #endif          
494         }
495         catch(exception& e) {
496                 m->errorOut(e, "ClassifySeqsCommand", "createProcesses");
497                 exit(1);
498         }
499 }
500 /**************************************************************************************************/
501
502 void ClassifySeqsCommand::appendTaxFiles(string temp, string filename) {
503         try{
504                 
505                 ofstream output;
506                 ifstream input;
507                 openOutputFileAppend(filename, output);
508                 openInputFile(temp, input);
509                 
510                 while(char c = input.get()){
511                         if(input.eof())         {       break;                  }
512                         else                            {       output << c;    }
513                 }
514                 
515                 input.close();
516                 output.close();
517         }
518         catch(exception& e) {
519                 m->errorOut(e, "ClassifySeqsCommand", "appendTaxFiles");
520                 exit(1);
521         }
522 }
523
524 //**********************************************************************************************************************
525
526 int ClassifySeqsCommand::driver(linePair* line, string taxFName, string tempTFName, string filename){
527         try {
528                 ofstream outTax;
529                 openOutputFile(taxFName, outTax);
530                 
531                 ofstream outTaxSimple;
532                 openOutputFile(tempTFName, outTaxSimple);
533         
534                 ifstream inFASTA;
535                 openInputFile(filename, inFASTA);
536
537                 inFASTA.seekg(line->start);
538                 
539                 string taxonomy;
540
541                 for(int i=0;i<line->numSeqs;i++){
542                         if (m->control_pressed) { return 0; }
543                         
544                         Sequence* candidateSeq = new Sequence(inFASTA);
545                         
546                         if (candidateSeq->getName() != "") {
547                                 taxonomy = classify->getTaxonomy(candidateSeq);
548                                 
549                                 if (m->control_pressed) { delete candidateSeq; return 0; }
550
551                                 if (taxonomy != "bad seq") {
552                                         //output confidence scores or not
553                                         if (probs) {
554                                                 outTax << candidateSeq->getName() << '\t' << taxonomy << endl;
555                                         }else{
556                                                 outTax << candidateSeq->getName() << '\t' << classify->getSimpleTax() << endl;
557                                         }
558                                         
559                                         outTaxSimple << candidateSeq->getName() << '\t' << classify->getSimpleTax() << endl;
560                                 }
561                         }                               
562                         delete candidateSeq;
563                         
564                         if((i+1) % 100 == 0){
565                                 m->mothurOut("Classifying sequence " + toString(i+1)); m->mothurOutEndLine();
566                         }
567                 }
568                 
569                 inFASTA.close();
570                 outTax.close();
571                 outTaxSimple.close();
572                 
573                 return 1;
574         }
575         catch(exception& e) {
576                 m->errorOut(e, "ClassifySeqsCommand", "driver");
577                 exit(1);
578         }
579 }
580
581 /**************************************************************************************************/