]> git.donarmstrong.com Git - mothur.git/blobdiff - taxonomyequalizer.cpp
fixed a trimming bug in sffinfo which occurs when the right trim point is smaller...
[mothur.git] / taxonomyequalizer.cpp
index f3ccfe45852ba8065c454d4bf42a0ad83a75d088..1d2832d5fc3a3ba31861d75d93dd202caf82261e 100644 (file)
@@ -10,7 +10,7 @@
 #include "taxonomyequalizer.h"
 
 /**************************************************************************************************/
-TaxEqualizer::TaxEqualizer(string tfile, int c) : cutoff(c) {
+TaxEqualizer::TaxEqualizer(string tfile, int c, string o) : cutoff(c), outputDir(o) {
        try {
                m = MothurOut::getInstance();
                containsConfidence = false;
@@ -19,42 +19,51 @@ TaxEqualizer::TaxEqualizer(string tfile, int c) : cutoff(c) {
                openInputFile(tfile, inTax);
        
                highestLevel = getHighestLevel(inTax);
-       
-               //if the user has specified a cutoff and it's smaller than the highest level
-               if ((cutoff != -1) && (cutoff < highestLevel)) { 
-                       highestLevel = cutoff;
-               }else if (cutoff > highestLevel) {
-                       m->mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel));
-                       m->mothurOutEndLine();
-               }
-               
-               inTax.close(); 
-               ifstream in; 
-               openInputFile(tfile, in);
                
-               ofstream out;
-               equalizedFile = getRootName(tfile) + "equalized.taxonomy";
-               openOutputFile(equalizedFile, out);
-               
-               string name, tax;
-               while (in) {
-                       in >> name >> tax;   gobble(in);
+               if (!m->control_pressed) { 
+                       
+                       //if the user has specified a cutoff and it's smaller than the highest level
+                       if ((cutoff != -1) && (cutoff < highestLevel)) { 
+                               highestLevel = cutoff;
+                       }else if (cutoff > highestLevel) {
+                               m->mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel));
+                               m->mothurOutEndLine();
+                       }
+                       
+                       inTax.close(); 
+                       ifstream in; 
+                       openInputFile(tfile, in);
                        
-                       if (containsConfidence) {  removeConfidences(tax);      }
+                       ofstream out;
+                       equalizedFile = outputDir + getRootName(getSimpleName(tfile)) + "equalized.taxonomy";
+                       openOutputFile(equalizedFile, out);
                        
-                       //is this a taxonomy that needs to be extended?
-                       if (seqLevels[name] < highestLevel) {
-                               extendTaxonomy(name, tax, highestLevel);
-                       }else if (seqLevels[name] > highestLevel) { //this can happen if the user enters a cutoff
-                               truncateTaxonomy(name, tax, highestLevel);
+       
+                       string name, tax;
+                       while (in) {
+                       
+                               if (m->control_pressed) {  break; }
+                               
+                               in >> name >> tax;   gobble(in);
+                               
+                               if (containsConfidence) {  removeConfidences(tax);      }
+                               
+                               //is this a taxonomy that needs to be extended?
+                               if (seqLevels[name] < highestLevel) {
+                                       extendTaxonomy(name, tax, highestLevel);
+                               }else if (seqLevels[name] > highestLevel) { //this can happen if the user enters a cutoff
+                                       truncateTaxonomy(name, tax, highestLevel);
+                               }
+                               
+                               out << name << '\t' << tax << endl;
                        }
                        
-                       out << name << '\t' << tax << endl;
-               }
+                       in.close();
+                       out.close();
+                       
+                       if (m->control_pressed) { remove(equalizedFile.c_str());  }
+               }else { inTax.close(); }
                
-               in.close();
-               out.close();
-                                       
        }
        catch(exception& e) {
                m->errorOut(e, "TaxEqualizer", "TaxEqualizer");
@@ -79,19 +88,19 @@ int TaxEqualizer::getHighestLevel(ifstream& in) {
                
                        //save sequences level
                        seqLevels[name] = thisLevel;
-               
+       
                        //is this the longest taxonomy?
                        if (thisLevel > level) {  
                                level = thisLevel;  
                                testTax = tax; //testTax is used to figure out if this file has confidences we need to strip out
-                       }  
+                       } 
                }
                
                int pos = testTax.find_first_of('(');
 
                //if there are '(' then there are confidences we need to take out
                if (pos != -1) {  containsConfidence = true;  }
-               
+       
                return level;
                                        
        }