X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=taxonomyequalizer.cpp;h=c7e8cb9e4add8388602dc2bfc12cff28673f7db3;hb=d01397212a287495d3d0ec00beea93759bf25402;hp=e7fa07af76ea792137475c6dff67b2ec0c9bcf7c;hpb=bee7952bbdc4ed46c7a12bef11769345fa3224d7;p=mothur.git diff --git a/taxonomyequalizer.cpp b/taxonomyequalizer.cpp index e7fa07a..c7e8cb9 100644 --- a/taxonomyequalizer.cpp +++ b/taxonomyequalizer.cpp @@ -10,52 +10,63 @@ #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; ifstream inTax; 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) { - mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel)); - mothurOutEndLine(); - } - - inTax.close(); - openInputFile(tfile, inTax); - ofstream out; - equalizedFile = getRootName(tfile) + "equalized.taxonomy"; - openOutputFile(equalizedFile, out); - - string name, tax; - while (inTax) { - inTax >> name >> tax; gobble(inTax); + 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); + + + string name, tax; + while (in) { - //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); + 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(); } - inTax.close(); - out.close(); - } catch(exception& e) { - errorOut(e, "TaxEqualizer", "TaxEqualizer"); + m->errorOut(e, "TaxEqualizer", "TaxEqualizer"); exit(1); } } @@ -94,7 +105,7 @@ int TaxEqualizer::getHighestLevel(ifstream& in) { } catch(exception& e) { - errorOut(e, "TaxEqualizer", "getHighestLevel"); + m->errorOut(e, "TaxEqualizer", "getHighestLevel"); exit(1); } } @@ -117,7 +128,7 @@ void TaxEqualizer::extendTaxonomy(string name, string& tax, int desiredLevel) { } } catch(exception& e) { - errorOut(e, "TaxEqualizer", "extendTaxonomy"); + m->errorOut(e, "TaxEqualizer", "extendTaxonomy"); exit(1); } } @@ -136,7 +147,7 @@ void TaxEqualizer::truncateTaxonomy(string name, string& tax, int desiredLevel) tax += ";"; } catch(exception& e) { - errorOut(e, "TaxEqualizer", "truncateTaxonomy"); + m->errorOut(e, "TaxEqualizer", "truncateTaxonomy"); exit(1); } } @@ -160,7 +171,7 @@ void TaxEqualizer::removeConfidences(string& tax) { tax = newTax; } catch(exception& e) { - errorOut(e, "TaxEqualizer", "removeConfidences"); + m->errorOut(e, "TaxEqualizer", "removeConfidences"); exit(1); } }