]> git.donarmstrong.com Git - mothur.git/blobdiff - venn.cpp
added getCommandInfoCommand for gui
[mothur.git] / venn.cpp
index 378e004ac4524d78088b054a91947d604ca32768..cd14785b776723d10672f6c5de11505bfc5bdafe 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
 
 
 //**********************************************************************************************************************
-Venn::Venn(string o, bool n) : outputDir(o), nseqs(n) {
+Venn::Venn(string o, bool n, string f) : outputDir(o), nseqs(n), inputfile(f) {
        try {
-               globaldata = GlobalData::getInstance();
                m = MothurOut::getInstance();
-
        }
        catch(exception& e) {
                m->errorOut(e, "Venn", "Venn");
@@ -33,9 +31,9 @@ vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
        try {
                
                vector<string> outputNames;
-               
+
                for(int i=0;i<vCalcs.size();i++){
-                       string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg";
+                       string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg";
                        outputNames.push_back(filenamesvg);
                        m->openOutputFile(filenamesvg, outsvg);
                        
@@ -78,7 +76,7 @@ vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
 //**********************************************************************************************************************
 vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
        try {
-               
+
                vector<SharedRAbundVector*> subset;
                vector<string> outputNames;
                
@@ -93,7 +91,7 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg";
+                               string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg";
                                outputNames.push_back(filenamesvg);
                                m->openOutputFile(filenamesvg, outsvg);
                                
@@ -149,7 +147,7 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg";
+                               string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg";
 
                                outputNames.push_back(filenamesvg);
                                m->openOutputFile(filenamesvg, outsvg);
@@ -168,14 +166,16 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                        //singleCalc = new Ace(10);
                                //}
                                
-                               int sharedVal, numSeqsA, numSeqsB;
+                               int sharedVal, numSeqsA, numSeqsB, uniqSeqsToA, uniqSeqsToB;
                                if (nseqs) {
                                        NSeqs* nseqsCalc = new NSeqs();
                                        vector<double> data = nseqsCalc->getValues(lookup);
-                                       
+                                       cout << data[0] << '\t' << data[1] << endl;
                                        sharedVal = data[0] + data[1];
                                        numSeqsA = sabundA->getNumSeqs();
                                        numSeqsB = sabundB->getNumSeqs();
+                                       uniqSeqsToA = numSeqsA-data[0];
+                                       uniqSeqsToB = numSeqsB-data[1];
                                        
                                        delete nseqsCalc;
                                }
@@ -205,21 +205,22 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                if (numA.size() == 3) { 
                                        outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
                                }
-                               if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsA);  }  
+                               if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared";  }  
                                outsvg << "</text>\n";
                
                                outsvg << "<text fill=\"black\" class=\"seri\"   font-size=\"24\" x=\"" +  toString(int(0.25 * width)) +  "\" y=\"" +  toString(int(0.69 * height)) +  "\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
                                if (numB.size() == 3) { 
                                        outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
                                }
-                               if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsB);  }  
+                               if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared";  }  
                                outsvg << "</text>\n";
 
                                outsvg << "<text fill=\"black\" class=\"seri\"  font-size=\"24\" x=\"" +  toString(int(0.25 * width)) +  "\" y=\"" +  toString(int(0.72 * height)) +  "\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(shared[0]);
-                               if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedVal);  }  
+                               if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedVal) + "; " + toString((sharedVal / (float)(numSeqsA + numSeqsB))*100) + "% of these sequences are shared";  }  
                                outsvg << "</text>\n";
                                
                                outsvg << "<text fill=\"black\" class=\"seri\"  font-size=\"24\" x=\"" +  toString(int(0.25 * width)) +  "\" y=\"" +  toString(int(0.75 * height)) +  "\">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\"  font-size=\"24\" x=\"" +  toString(int(0.25 * width)) +  "\" y=\"" +  toString(int(0.78 * height)) +  "\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0]))+ "</text>\n";;
                                
                                
@@ -247,14 +248,14 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
                        
-                               string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg";
+                               string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg";
 
                                outputNames.push_back(filenamesvg);
                                m->openOutputFile(filenamesvg, outsvg);
                                
                                if (m->control_pressed) { outsvg.close(); return outputNames; }
                                
-                               int sharedVal, sharedABVal, sharedACVal, sharedBCVal, numSeqsA, numSeqsB, numSeqsC;
+                               int sharedVal, sharedABVal, sharedACVal, sharedBCVal, numSeqsA, numSeqsB, numSeqsC, uniqSeqsToA, uniqSeqsToB, uniqSeqsToC;
                                
                                if (nseqs) {
                                        NSeqs* nseqsCalc = new NSeqs();
@@ -276,6 +277,9 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                        numSeqsA = sabundA->getNumSeqs();
                                        numSeqsB = sabundB->getNumSeqs();
                                        numSeqsC = sabundC->getNumSeqs();
+                                       uniqSeqsToA = numSeqsA-sharedData[0];
+                                       uniqSeqsToB = numSeqsC-sharedData[1];
+                                       uniqSeqsToC = numSeqsB-sharedData[1];
 
                                        delete nseqsCalc;
                                }
@@ -409,21 +413,21 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                        if (numA.size() == 3) { 
                                                outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
                                        } 
-                                       if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsA);  }  
+                                       if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared";  }  
                                        outsvg << "</text>\n";
                        
                                        outsvg << "<text fill=\"black\" class=\"seri\"  font-size=\"24\" x=\"" +  toString(int(0.25 * width)) +  "\" y=\"" +  toString(int(0.75 * height)) +  "\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
                                        if (numB.size() == 3) { 
                                                outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
                                        }
-                                       if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsB);  }  
+                                       if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared";  }  
                                        outsvg << "</text>\n";
                                        
                                        outsvg << "<text fill=\"black\" class=\"seri\"  font-size=\"24\" x=\"" +  toString(int(0.25 * width)) +  "\" y=\"" +  toString(int(0.775 * height)) +  "\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
                                        if (numC.size() == 3) { 
                                                outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
                                        }
-                                       if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsC);  }  
+                                       if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsC) + "; " + toString(uniqSeqsToC) + " sequences are not shared";  }  
                                        outsvg << "</text>\n";
 
                                        outsvg << "<text fill=\"black\" class=\"seri\"  font-size=\"24\" x=\"" +  toString(int(0.25 * width)) +  "\" y=\"" +  toString(int(0.80 * height)) +  "\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
@@ -565,7 +569,7 @@ vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                
                                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 = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg";
+                                       string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg";
                                        outputNames.push_back(filenamesvg);
                                        m->openOutputFile(filenamesvg, outsvg);