X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=heatmapsim.cpp;h=62965f9a3291d0052b6c216b6a800d6c97072f46;hp=88a49ed93512369a5c3d0e9d7c17fde7304d5f7f;hb=a8e2df1b96a57f5f29576b08361b86a96a8eff4f;hpb=d5bf2c1354d0811a33394d918b15620606560d58 diff --git a/heatmapsim.cpp b/heatmapsim.cpp index 88a49ed..62965f9 100644 --- a/heatmapsim.cpp +++ b/heatmapsim.cpp @@ -20,20 +20,24 @@ #include "sharedbraycurtis.h" //********************************************************************************************************************** -HeatMapSim::HeatMapSim(){ - globaldata = GlobalData::getInstance(); +HeatMapSim::HeatMapSim(string dir, string i, int f) : outputDir(dir), inputfile(i), fontSize(f) { + m = MothurOut::getInstance(); } //********************************************************************************************************************** -void HeatMapSim::getPic(vector lookup, vector calcs) { +vector HeatMapSim::getPic(vector lookup, vector calcs) { try { EstOutput data; vector sims; + vector outputNames; //make file for each calculator selected - for (int m = 0; m < calcs.size(); m++) { - - string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + calcs[m]->getName() + ".heatmap.sim.svg"; - openOutputFile(filenamesvg, outsvg); + for (int k = 0; k < calcs.size(); k++) { + + if (m->control_pressed) { return outputNames; } + + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + calcs[k]->getName() + ".heatmap.sim.svg"; + m->openOutputFile(filenamesvg, outsvg); + outputNames.push_back(filenamesvg); //svg image outsvg << "\n"; @@ -41,31 +45,34 @@ void HeatMapSim::getPic(vector lookup, vector //white backround outsvg << ""; - outsvg << "Heatmap at distance " + lookup[0]->getLabel() + "\n"; + 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"; - outsvg << "getGroup().length() / 2)) + "\" x=\"50\">" + lookup[h]->getGroup() + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "\n"; + outsvg << "getGroup().length() / 2)) + "\" x=\"50\">" + lookup[h]->getGroup() + "\n"; } sims.clear(); - double biggest = -1; +// double biggest = -1; + double biggest = 1; float scaler; //get sim for each comparison and save them so you can find the relative similairity for(int i = 0; i < (lookup.size()-1); i++){ for(int j = (i+1); j < lookup.size(); j++){ - + + if (m->control_pressed) { outsvg.close(); return outputNames; } + vector subset; subset.push_back(lookup[i]); subset.push_back(lookup[j]); //get similairity between groups - data = calcs[m]->getValues(subset); - sims.push_back(data[0]); + data = calcs[k]->getValues(subset); + sims.push_back(1.0 - data[0]); //save biggest similairity to set relative sim - if (data[0] > biggest) { biggest = data[0]; } +// if (data[0] > biggest) { biggest = data[0]; } } } @@ -93,21 +100,21 @@ void HeatMapSim::getPic(vector lookup, vector } - + return outputNames; } catch(exception& e) { - errorOut(e, "HeatMapSim", "getPic"); + m->errorOut(e, "HeatMapSim", "getPic"); exit(1); } } //********************************************************************************************************************** -void HeatMapSim::getPic(vector< vector > dists, vector groups) { +string HeatMapSim::getPic(vector< vector > dists, vector groups) { try { vector sims; - string filenamesvg = getRootName(globaldata->inputFileName) + "heatmap.sim.svg"; - openOutputFile(filenamesvg, outsvg); + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "heatmap.sim.svg"; + m->openOutputFile(filenamesvg, outsvg); //svg image outsvg << "\n"; @@ -115,12 +122,12 @@ void HeatMapSim::getPic(vector< vector > dists, vector groups) { //white backround outsvg << ""; - outsvg << "Heatmap for " + globaldata->inputFileName + "\n"; + outsvg << "Heatmap for " + inputfile + "\n"; //column labels for (int h = 0; h < groups.size(); h++) { - outsvg << "" + groups[h] + "\n"; - outsvg << "" + groups[h] + "\n"; + outsvg << "" + groups[h] + "\n"; + outsvg << "" + groups[h] + "\n"; } double biggest = -1; @@ -129,6 +136,8 @@ void HeatMapSim::getPic(vector< vector > dists, vector groups) { //get sim for each comparison and save them so you can find the relative similairity for(int i = 0; i < (dists.size()-1); i++){ for(int j = (i+1); j < dists.size(); j++){ + + if (m->control_pressed) { outsvg.close(); return filenamesvg; } float sim = 1.0 - dists[i][j]; sims.push_back(sim); @@ -160,9 +169,11 @@ void HeatMapSim::getPic(vector< vector > dists, vector groups) { outsvg << "\n\n"; outsvg.close(); + return filenamesvg; + } catch(exception& e) { - errorOut(e, "HeatMapSim", "getPic"); + m->errorOut(e, "HeatMapSim", "getPic"); exit(1); } } @@ -171,6 +182,7 @@ void HeatMapSim::getPic(vector< vector > dists, vector groups) { void HeatMapSim::printLegend(int y, float maxSim) { try { + maxSim = 1; //output legend and color labels //go through map and give each score a color value @@ -180,27 +192,27 @@ void HeatMapSim::printLegend(int y, float maxSim) { //prints legend for (int i = 1; i < 255; i++) { color = toHex(int((float)(i))); - outsvg << "\n"; - x += 1; + outsvg << "\n"; + x += 3; } float scaler = maxSim / 5.0; //prints legend labels - x = 10; - for (int i = 1; i<=5; i++) { + x = 0; + for (int i = 0; i<=5; i++) { float label = scaler*i; label = int(label * 1000 + 0.5); label /= 1000.0; - string text = toString(label, 3); + string text = toString(label, 1); - outsvg << "" + text + "\n"; - x += 60; + outsvg << "" + text + "\n"; + x += 153; } } catch(exception& e) { - errorOut(e, "HeatMapSim", "printLegend"); + m->errorOut(e, "HeatMapSim", "printLegend"); exit(1); } }