]> git.donarmstrong.com Git - mothur.git/blobdiff - venn.cpp
a few modifications for 1.9
[mothur.git] / venn.cpp
index 82020d46a18de0cb4ad4959498f3cbee1ddfe4a2..638a12fa817e6737d453c25e85b5b50cc66562d8 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
 
 
 //**********************************************************************************************************************
-Venn::Venn(){
+Venn::Venn(string o) : outputDir(o) {
        try {
                globaldata = GlobalData::getInstance();
+               m = MothurOut::getInstance();
 
        }
        catch(exception& e) {
-               errorOut(e, "Venn", "Venn");
+               m->errorOut(e, "Venn", "Venn");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-void Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
+vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
        try {
-                               
+               
+               vector<string> outputNames;
+               
                for(int i=0;i<vCalcs.size();i++){
-                       string filenamesvg = globaldata->inputFileName + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
+                       string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
+                       outputNames.push_back(filenamesvg);
                        openOutputFile(filenamesvg, outsvg);
+                       
+                       if (m->control_pressed) { outsvg.close(); return outputNames; }
 
                        vector<double> data = vCalcs[i]->getValues(sabund);
                        
@@ -53,17 +59,20 @@ void Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
                        outsvg << "</g>\n</svg>\n";
                        outsvg.close();
                }
+               
+               return outputNames;
        }
        catch(exception& e) {
-               errorOut(e, "Venn", "getPic");
+               m->errorOut(e, "Venn", "getPic");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
+vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
        try {
                
                vector<SharedRAbundVector*> subset;
+               vector<string> outputNames;
                
                /******************* 1 Group **************************/
                if (lookup.size() == 1) {
@@ -73,9 +82,12 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               outputNames.push_back(filenamesvg);
                                openOutputFile(filenamesvg, outsvg);
-                       
+                               
+                               if (m->control_pressed) { outsvg.close(); return outputNames; }
+                               
                                //in essence you want to run it like a single 
                                if (vCalcs[i]->getName() == "sharedsobs") {
                                        singleCalc = new Sobs();
@@ -122,9 +134,12 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               outputNames.push_back(filenamesvg);
                                openOutputFile(filenamesvg, outsvg);
                                
+                               if (m->control_pressed) { outsvg.close(); return outputNames; }
+                               
                                //get estimates for sharedAB
                                vector<double> shared = vCalcs[i]->getValues(subset);
                                
@@ -168,7 +183,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                                }else { outsvg << "</text>\n"; }
 
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"500\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(shared[0]) + "</text>\n";
-                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))*100) + "</text>\n";
                                outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"540\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0])) + "</text>\n";
                                
                                //close file
@@ -190,10 +205,12 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
                        
-                                                                                               
-                               string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                               outputNames.push_back(filenamesvg);
                                openOutputFile(filenamesvg, outsvg);
                                
+                               if (m->control_pressed) { outsvg.close(); return outputNames; }
+                               
                                if (vCalcs[i]->getName() == "sharedace") {
                                
                                        singleCalc = new Ace(10);
@@ -232,7 +249,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                                                //merge BC and estimate with shared with A
                                                SharedRAbundVector* merge = new SharedRAbundVector();
                                                for (int j = 0; j < lookup[1]->size(); j++) {
-                                                       merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), j, "");
+                                                       merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
                                                }
                                        
                                                subset.clear();
@@ -243,7 +260,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                                                //merge AC and estimate with shared with B
                                                merge = new SharedRAbundVector();
                                                for (int j = 0; j < lookup[0]->size(); j++) {
-                                                       merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), j, "");
+                                                       merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
                                                }
                                        
                                                subset.clear();
@@ -254,7 +271,7 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                                                //merge AB and estimate with shared with C
                                                merge = new SharedRAbundVector();
                                                for (int j = 0; j < lookup[0]->size(); j++) {
-                                                       merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), j, "");
+                                                       merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), "");
                                                }
                                        
                                                subset.clear();
@@ -444,12 +461,14 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
                                
-                               if ((vCalcs[i]->getName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups.  It will be disregarded. "); mothurOutEndLine(); }
+                               if ((vCalcs[i]->getName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { m->mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups.  It will be disregarded. "); m->mothurOutEndLine(); }
                                else{
-                                       string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                                       string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
+                                       outputNames.push_back(filenamesvg);
                                        openOutputFile(filenamesvg, outsvg);
 
-                               
+                                       if (m->control_pressed) { outsvg.close(); return outputNames; }
+                                       
                                        //in essence you want to run it like a single 
                                        if (vCalcs[i]->getName() == "sharedsobs") {
                                                singleCalc = new Sobs();
@@ -625,9 +644,11 @@ void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs
                        }
                }
                
+               return outputNames;
+               
        }
        catch(exception& e) {
-               errorOut(e, "Venn", "getPic");
+               m->errorOut(e, "Venn", "getPic");
                exit(1);
        }
 }