X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=heatmap.cpp;h=3dca535b8600e38f29cf87160ab5a487282280d5;hb=f07bf12e0d04340698aff7a36d2fee7c959ffe59;hp=52a29e79e70dde14806e79960de618b7c3b4e4bf;hpb=e729387d0813f82e9cd907dfeeef1afab399ba84;p=mothur.git diff --git a/heatmap.cpp b/heatmap.cpp index 52a29e7..3dca535 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -10,22 +10,24 @@ #include "heatmap.h" //********************************************************************************************************************** -HeatMap::HeatMap(string sort, string scale){ +HeatMap::HeatMap(string sort, string scale, string dir){ try { globaldata = GlobalData::getInstance(); + m = MothurOut::getInstance(); // format = globaldata->getFormat(); sorted = sort; scaler = scale; + outputDir = dir; } catch(exception& e) { - errorOut(e, "HeatMap", "HeatMap"); + m->errorOut(e, "HeatMap", "HeatMap"); exit(1); } } //********************************************************************************************************************** -void HeatMap::getPic(RAbundVector* rabund) { +string HeatMap::getPic(RAbundVector* rabund) { try { @@ -42,6 +44,8 @@ void HeatMap::getPic(RAbundVector* rabund) { for(int i=0;isize();i++){ float relAbund = rabund->get(i) / (float)rabund->getNumSeqs(); + if (m->control_pressed) { return "control"; } + if (rabund->get(i) != 0) { //don't want log value of 0. if (scaler == "log10") { scaleRelAbund[i] = toHex(int(255 * log10(relAbund) / log10(maxRelAbund))) + "0000"; @@ -57,7 +61,7 @@ void HeatMap::getPic(RAbundVector* rabund) { } - string filenamesvg = getRootName(globaldata->inputFileName) + rabund->getLabel() + ".heatmap.bin.svg"; + string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + rabund->getLabel() + ".heatmap.bin.svg"; openOutputFile(filenamesvg, outsvg); //svg image @@ -76,6 +80,7 @@ void HeatMap::getPic(RAbundVector* rabund) { y = 70; for (int i = 0; i < scaleRelAbund.size(); i++) { + if (m->control_pressed) { outsvg.close(); return "control"; } outsvg << "\n"; y += 5; @@ -84,17 +89,17 @@ void HeatMap::getPic(RAbundVector* rabund) { outsvg << "\n\n"; outsvg.close(); - + return filenamesvg; } catch(exception& e) { - errorOut(e, "HeatMap", "getPic"); + m->errorOut(e, "HeatMap", "getPic"); exit(1); } } //********************************************************************************************************************** -void HeatMap::getPic(vector lookup) { +string HeatMap::getPic(vector lookup) { try { //sort lookup so shared bins are on top if (isTrue(sorted) == true) { sortSharedVectors(lookup); } @@ -116,6 +121,7 @@ void HeatMap::getPic(vector lookup) { for(int i=0;isize(), ""); for(int j=0;jsize();j++){ + if (m->control_pressed) { return "control"; } float relAbund = lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs(); if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0. @@ -133,7 +139,7 @@ void HeatMap::getPic(vector lookup) { } } - string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".heatmap.bin.svg"; + string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; openOutputFile(filenamesvg, outsvg); //svg image @@ -158,6 +164,7 @@ void HeatMap::getPic(vector lookup) { y = 70; for (int i = 0; i < scaleRelAbund[0].size(); i++) { for (int j = 0; j < scaleRelAbund.size(); j++) { + if (m->control_pressed) { outsvg.close(); return "control"; } outsvg << "\n"; x += 300; @@ -168,10 +175,12 @@ void HeatMap::getPic(vector lookup) { outsvg << "\n\n"; outsvg.close(); + + return filenamesvg; } catch(exception& e) { - errorOut(e, "HeatMap", "getPic"); + m->errorOut(e, "HeatMap", "getPic"); exit(1); } } @@ -231,7 +240,7 @@ void HeatMap::sortSharedVectors(vector& lookup){ //fill lookup for (int j = 0; j < looktemp.size(); j++) { //if they are not shared then push to back, if they are not insert in front - if (count < 2) { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); } + if (count < 2) { lookup[j]->push_back(looktemp[j]->getAbundance(i), looktemp[j]->getGroup()); } //they are shared by some else { lookup[j]->insert(looktemp[j]->getAbundance(i), place[count], looktemp[j]->getGroup()); updatePlace = true; } } @@ -251,7 +260,7 @@ void HeatMap::sortSharedVectors(vector& lookup){ } catch(exception& e) { - errorOut(e, "HeatMap", "sortSharedVectors"); + m->errorOut(e, "HeatMap", "sortSharedVectors"); exit(1); } } @@ -291,7 +300,7 @@ void HeatMap::printLegend(int y, float maxbin) { } catch(exception& e) { - errorOut(e, "HeatMap", "printLegend"); + m->errorOut(e, "HeatMap", "printLegend"); exit(1); } }