]> git.donarmstrong.com Git - mothur.git/blobdiff - heatmapsim.cpp
added command descriptions
[mothur.git] / heatmapsim.cpp
index c68d0cc413855650efc86f2370ad7ab82508e6b7..9c5e780703a7d4f8d9117e38dddb693a40337bb0 100644 (file)
 #include "sharedbraycurtis.h"
 
 //**********************************************************************************************************************
-HeatMapSim::HeatMapSim(){
-               globaldata = GlobalData::getInstance();
+HeatMapSim::HeatMapSim(string dir, string i) : outputDir(dir), inputfile(i) {
+               m = MothurOut::getInstance();
 }
 //**********************************************************************************************************************
-void HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> calcs) {
+vector<string> HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> calcs) {
        try {
                EstOutput data;
                vector<double> sims;
+               vector<string> 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 << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString((lookup.size() * 150) + 160) + " " + toString((lookup.size() * 150) + 160)  + "\">\n";
@@ -57,12 +61,14 @@ void HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*>
                        //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);
+                                               data = calcs[k]->getValues(subset);
                                                sims.push_back(data[0]);
                                        
                                                //save biggest similairity to set relative sim
@@ -94,21 +100,21 @@ void HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*>
 
                }
                
-               
+               return outputNames;
        }
        catch(exception& e) {
-               errorOut(e, "HeatMapSim", "getPic");
+               m->errorOut(e, "HeatMapSim", "getPic");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-void HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups) {
+string HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups) {
        try {
                
                vector<double> 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 << "<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";
@@ -116,7 +122,7 @@ void 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\" x=\"" + toString((dists.size() * 75) - 40) + "\" y=\"25\">Heatmap for " + inputfile + "</text>\n";
                
                //column labels
                for (int h = 0; h < groups.size(); h++) {
@@ -130,6 +136,8 @@ void 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);
@@ -161,9 +169,11 @@ void HeatMapSim::getPic(vector< vector<double> > dists, vector<string> groups) {
                outsvg << "</g>\n</svg>\n";
                outsvg.close();
                
+               return filenamesvg;
+               
        }
        catch(exception& e) {
-               errorOut(e, "HeatMapSim", "getPic");
+               m->errorOut(e, "HeatMapSim", "getPic");
                exit(1);
        }
 }
@@ -202,7 +212,7 @@ void HeatMapSim::printLegend(int y, float maxSim) {
        }
        
        catch(exception& e) {
-               errorOut(e, "HeatMapSim", "printLegend");
+               m->errorOut(e, "HeatMapSim", "printLegend");
                exit(1);
        }
 }