]> git.donarmstrong.com Git - mothur.git/blobdiff - heatmapsim.cpp
sffinfo bug with flow grams right index when clipQualRight=0
[mothur.git] / heatmapsim.cpp
index 9a1255037c4312291238b613d39929c7b50549b5..62965f9a3291d0052b6c216b6a800d6c97072f46 100644 (file)
@@ -20,8 +20,7 @@
 #include "sharedbraycurtis.h"
 
 //**********************************************************************************************************************
-HeatMapSim::HeatMapSim(string dir) : outputDir(dir) {
-               globaldata = GlobalData::getInstance();
+HeatMapSim::HeatMapSim(string dir, string i, int f) : outputDir(dir), inputfile(i), fontSize(f) {
                m = MothurOut::getInstance();
 }
 //**********************************************************************************************************************
@@ -32,10 +31,12 @@ vector<string> HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Cal
                vector<string> outputNames;
                                
                //make file for each calculator selected
-               for (int m = 0; m < calcs.size(); m++) {
-                       
-                       string filenamesvg = outputDir + getRootName(getSimpleName(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
@@ -44,12 +45,12 @@ vector<string> HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Cal
                
                        //white backround
                        outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString((lookup.size() * 150) + 160) + "\" height=\"" + toString((lookup.size() * 150) + 160)  + "\"/>"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((lookup.size() * 75) - 40) + "\" y=\"25\">Heatmap at distance " + lookup[0]->getLabel() + "</text>\n";
+                       outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\"  x=\"" + toString((lookup.size() * 75) - 40) + "\" y=\"25\">Heatmap at distance " + lookup[0]->getLabel() + "</text>\n";
                
                        //column labels
                        for (int h = 0; h < lookup.size(); h++) {
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(((150 * (h+1)) ) - ((int)lookup[h]->getGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "</text>\n"; 
-                               outsvg << "<text fill=\"black\" class=\"seri\" y=\"" + toString(((150 * (h+1)) ) - ((int)lookup[h]->getGroup().length() / 2)) + "\" x=\"50\">" + lookup[h]->getGroup() + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(((150 * (h+1)) ) - ((int)lookup[h]->getGroup().length() / 2)) + "\" y=\"50\">" + lookup[h]->getGroup() + "</text>\n"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" y=\"" + toString(((150 * (h+1)) ) - ((int)lookup[h]->getGroup().length() / 2)) + "\" x=\"50\">" + lookup[h]->getGroup() + "</text>\n";
                        }
                        
                        sims.clear();
@@ -60,13 +61,15 @@ vector<string> HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Cal
                        //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<SharedRAbundVector*> 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]; }
@@ -110,8 +113,8 @@ string HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups)
                
                vector<double> sims;
                
-               string filenamesvg = outputDir + getRootName(getSimpleName(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 << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString((dists.size() * 150) + 160) + " " + toString((dists.size() * 150) + 160)  + "\">\n";
@@ -119,12 +122,12 @@ string HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups)
                
                //white backround
                outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString((dists.size() * 150) + 160) + "\" height=\"" + toString((dists.size() * 150) + 160)  + "\"/>"; 
-               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((dists.size() * 75) - 40) + "\" y=\"25\">Heatmap for " + globaldata->inputFileName + "</text>\n";
+               outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString((dists.size() * 75) - 40) + "\" y=\"25\">Heatmap for " + inputfile + "</text>\n";
                
                //column labels
                for (int h = 0; h < groups.size(); h++) {
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(((150 * (h+1)) ) - ((int)groups[h].length() / 2)) + "\" y=\"50\">" + groups[h] + "</text>\n"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" y=\"" + toString(((150 * (h+1)) ) - ((int)groups[h].length() / 2)) + "\" x=\"50\">" + groups[h] + "</text>\n";
+                       outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(((150 * (h+1)) ) - ((int)groups[h].length() / 2)) + "\" y=\"50\">" + groups[h] + "</text>\n"; 
+                       outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" y=\"" + toString(((150 * (h+1)) ) - ((int)groups[h].length() / 2)) + "\" x=\"50\">" + groups[h] + "</text>\n";
                }
                        
                double biggest = -1;
@@ -133,6 +136,8 @@ string HeatMapSim::getPic(vector< vector<double> > dists, vector<string> 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);
@@ -201,7 +206,7 @@ void HeatMapSim::printLegend(int y, float maxSim) {
                        label /= 1000.0;
                        string text = toString(label, 1);
                        
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(x) + "\" y=\"" + toString(y-3) + "\">" + text + "</text>\n";
+                       outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(x) + "\" y=\"" + toString(y-3) + "\">" + text + "</text>\n";
                        x += 153;
                }
        }