X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=heatmap.cpp;h=514c7af15312b60d4787bb0aa659dbd9f1ccaf08;hp=7d6eeaa146b84db4233974a70c16dc482bc12ef9;hb=cf9987b67aa49777a4c91c2d21f96e58bf17aa82;hpb=7ae40733a270f73ec8a331540cc7f28fd60b24fc diff --git a/heatmap.cpp b/heatmap.cpp index 7d6eeaa..514c7af 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -10,9 +10,8 @@ #include "heatmap.h" //********************************************************************************************************************** -HeatMap::HeatMap(string sort, string scale, int num, int fsize, string dir){ +HeatMap::HeatMap(string sort, string scale, int num, int fsize, string dir, string i){ try { - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); // format = globaldata->getFormat(); sorted = sort; @@ -20,6 +19,7 @@ HeatMap::HeatMap(string sort, string scale, int num, int fsize, string dir){ outputDir = dir; numOTU = num; fontSize = fsize; + inputfile = i; } catch(exception& e) { m->errorOut(e, "HeatMap", "HeatMap"); @@ -70,7 +70,7 @@ string HeatMap::getPic(RAbundVector* rabund) { } - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + rabund->getLabel() + ".heatmap.bin.svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + rabund->getLabel() + ".heatmap.bin.svg"; m->openOutputFile(filenamesvg, outsvg); //svg image @@ -119,7 +119,8 @@ string HeatMap::getPic(vector lookup) { } //sort lookup so shared bins are on top - if (sorted != "none") { sortSharedVectors(lookup); } + vector sortedLabels = m->currentSharedBinLabels; + if (sorted != "none") { sortedLabels = sortSharedVectors(lookup); } vector > scaleRelAbund; vector maxRelAbund(lookup[0]->size(), 0.0); @@ -156,38 +157,48 @@ string HeatMap::getPic(vector lookup) { } } - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; m->openOutputFile(filenamesvg, outsvg); + int binHeight = 20; + int labelBump = 100; + int binWidth = 300; //svg image - outsvg << "\n"; + outsvg << "\n"; outsvg << "\n"; //white backround - outsvg << ""; + outsvg << ""; outsvg << "Heatmap at distance " + lookup[0]->getLabel() + "\n"; //column labels - for (int h = 0; h < lookup.size(); h++) { - outsvg << "getGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "\n"; + for (int h = 0; h < lookup.size()+1; h++) { + if (h == 0) { + string tempLabel = "OTU"; + outsvg << "" + tempLabel + "\n"; + }else { + outsvg << "getGroup().length() / 2)+labelBump/2) + "\" y=\"50\">" + lookup[h-1]->getGroup() + "\n"; + } } //output legend and color labels string color; int x = 0; - int y = 103 + (numBinsToDisplay*5); + int y = 103 + (numBinsToDisplay*binHeight); printLegend(y, superMaxRelAbund); y = 70; for (int i = 0; i < numBinsToDisplay; i++) { + outsvg << "" + sortedLabels[i] + "\n"; + x += labelBump; for (int j = 0; j < scaleRelAbund.size(); j++) { if (m->control_pressed) { outsvg.close(); return "control"; } - outsvg << "\n"; - x += 300; + outsvg << "\n"; + x += binWidth; } x = 0; - y += 5; + y += binHeight; } outsvg << "\n\n"; @@ -203,12 +214,14 @@ string HeatMap::getPic(vector lookup) { } //********************************************************************************************************************** -int HeatMap::sortSharedVectors(vector& lookup){ +vector HeatMap::sortSharedVectors(vector& lookup){ try { vector looktemp; map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. map::iterator it; + + vector sortedLabels = m->currentSharedBinLabels; /****************** find order of otus **********************/ if (sorted == "shared") { @@ -217,7 +230,7 @@ int HeatMap::sortSharedVectors(vector& lookup){ place = orderTopOtu(lookup); }else if (sorted == "topgroup") { place = orderTopGroup(lookup); - }else { m->mothurOut("Error: invalid sort option."); m->mothurOutEndLine(); return 1; } + }else { m->mothurOut("Error: invalid sort option."); m->mothurOutEndLine(); return sortedLabels; } /******************* create copy of lookup *********************/ @@ -241,6 +254,7 @@ int HeatMap::sortSharedVectors(vector& lookup){ int newAbund = looktemp[j]->getAbundance(i); // 1 -> 3 lookup[j]->set(place[i], newAbund, looktemp[j]->getGroup()); //binNumber, abundance, group } + sortedLabels[place[i]] = m->currentSharedBinLabels[i]; } //delete looktemp -- Sarah look at - this is causing segmentation faults @@ -248,7 +262,7 @@ int HeatMap::sortSharedVectors(vector& lookup){ // delete looktemp[j]; } - return 0; + return sortedLabels; } catch(exception& e) { @@ -416,7 +430,8 @@ string HeatMap::getPic(vector lookup) { } //sort lookup so shared bins are on top - if (sorted != "none") { sortSharedVectors(lookup); } + vector sortedLabels = m->currentSharedBinLabels; + if (sorted != "none") { sortedLabels = sortSharedVectors(lookup); } vector > scaleRelAbund; vector maxRelAbund(lookup.size(), 0.0); @@ -453,38 +468,49 @@ string HeatMap::getPic(vector lookup) { } } - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; m->openOutputFile(filenamesvg, outsvg); + + int binHeight = 20; + int labelBump = 100; + int binWidth = 300; //svg image - outsvg << "\n"; + outsvg << "\n"; outsvg << "\n"; //white backround - outsvg << ""; + outsvg << ""; outsvg << "Heatmap at distance " + lookup[0]->getLabel() + "\n"; //column labels - for (int h = 0; h < lookup.size(); h++) { - outsvg << "getGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "\n"; - } - + for (int h = 0; h < lookup.size()+1; h++) { + if (h == 0) { + string tempLabel = "OTU"; + outsvg << "" + tempLabel + "\n"; + }else { + outsvg << "getGroup().length() / 2)+labelBump/2) + "\" y=\"50\">" + lookup[h-1]->getGroup() + "\n"; + } + } + //output legend and color labels string color; int x = 0; - int y = 103 + (numBinsToDisplay*5); + int y = 103 + (numBinsToDisplay*binHeight); printLegend(y, superMaxRelAbund); y = 70; for (int i = 0; i < numBinsToDisplay; i++) { + outsvg << "" + sortedLabels[i] + "\n"; + x += labelBump; for (int j = 0; j < scaleRelAbund.size(); j++) { if (m->control_pressed) { outsvg.close(); return "control"; } - outsvg << "\n"; - x += 300; + outsvg << "\n"; + x += binWidth; } x = 0; - y += 5; + y += binHeight; } outsvg << "\n\n"; @@ -499,12 +525,14 @@ string HeatMap::getPic(vector lookup) { } } //********************************************************************************************************************** -int HeatMap::sortSharedVectors(vector& lookup){ +vector HeatMap::sortSharedVectors(vector& lookup){ try { vector looktemp; map place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2. map::iterator it; + + vector sortedLabels = m->currentSharedBinLabels; /****************** find order of otus **********************/ if (sorted == "shared") { @@ -513,7 +541,7 @@ int HeatMap::sortSharedVectors(vector& lookup){ place = orderTopOtu(lookup); }else if (sorted == "topgroup") { place = orderTopGroup(lookup); - }else { m->mothurOut("Error: invalid sort option."); m->mothurOutEndLine(); return 1; } + }else { m->mothurOut("Error: invalid sort option."); m->mothurOutEndLine(); return sortedLabels; } /******************* create copy of lookup *********************/ @@ -536,6 +564,7 @@ int HeatMap::sortSharedVectors(vector& lookup){ for (int j = 0; j < looktemp.size(); j++) { // 3 -> 2 float newAbund = looktemp[j]->getAbundance(i); // 1 -> 3 lookup[j]->set(place[i], newAbund, looktemp[j]->getGroup()); //binNumber, abundance, group + sortedLabels[place[i]] = m->currentSharedBinLabels[i]; } } @@ -544,7 +573,7 @@ int HeatMap::sortSharedVectors(vector& lookup){ // delete looktemp[j]; } - return 0; + return sortedLabels; } catch(exception& e) {