]> git.donarmstrong.com Git - mothur.git/commitdiff
venn command with up to 4 groups using sharedsobs, sharedchao and sharedace estimator...
authorwestcott <westcott>
Fri, 3 Apr 2009 13:36:40 +0000 (13:36 +0000)
committerwestcott <westcott>
Fri, 3 Apr 2009 13:36:40 +0000 (13:36 +0000)
globaldata.cpp
helpcommand.cpp
summarycommand.cpp
validcalculator.cpp
validcalculator.h
validparameter.cpp
venn.cpp
venn.h
venncommand.cpp
venncommand.h

index 64a7c93ac0a7c5067cf102250d3efd9cf8ab7380..da81879f48fff6fbe87ac67ba950afd84c03a69e 100644 (file)
@@ -190,6 +190,14 @@ void GlobalData::parseGlobalData(string commandString, string optionText){
                        Estimators.clear();
                        splitAtDash(calc, Estimators); 
                }
+               if (commandName == "venn") {
+                       if ((calc == "default") || (calc == "")) { 
+                               if (format == "list") { calc = "sobs"; }
+                               else { calc = "sharedsobs"; }
+                       }
+                       Estimators.clear();
+                       splitAtDash(calc, Estimators); 
+               }
 
                //if you have done a read.otu with a groupfile but don't want to use it anymore because you want to do single commands
                if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
index c50f2517ce3e149dbf69d91b432eb796145f96a1..d69577311ec2a091e5ff46673e92ba13119db252 100644 (file)
@@ -198,6 +198,17 @@ int HelpCommand::execute(){
                cout << "The default value for sorted is 1 meaning you want the shared otus on top, you may change it to 0 meaning the exact representation of your input file." << "\n";
                cout << "The heatmap command outputs a .svg file for each line or label you specify." << "\n";
                cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n";
+       }else if (globaldata->helpRequest == "venn") { 
+               cout << "The venn command can only be executed after a successful read.otu command." << "\n";
+               cout << "The venn command parameters are groups, calc, line and label.  No parameters are required, but you may not use line and label at the same time." << "\n";
+               cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your venn diagram, you may only use a maximum of 4 groups." << "\n";
+               cout << "The group names are separated by dashes. The line and label allow you to select what distance levels you would like a venn diagram created for, and are also separated by dashes." << "\n";
+               cout << "The venn command should be in the following format: venn(groups=yourGroups, calc=yourSorted, line=yourLines, label=yourLabels)." << "\n";
+               cout << "Example venn(groups=A-B-C, line=1-3-5, calc=sharedsobs-sharedchao)." << "\n";
+               cout << "The default value for groups is all the groups in your groupfile up to 4, and all lines in your inputfile will be used." << "\n";
+               cout << "The default value for calc is sobs if you have only read a list file or if you have selected only one group, and sharedsobs if you have multiple groups." << "\n";
+               cout << "The venn command outputs a .svg file for each calculator you specify at each distance you choose." << "\n";
+               cout << "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups)." << "\n" << "\n";
        }else if (globaldata->helpRequest == "quit") {
                cout << "The quit command will terminate Dotur and should be in the following format: " << "\n";
                cout << "quit()" << "\n" << "\n";
index 8c8a2aadf93440ab0e6271381e641bdae2167686..05fc6e8c77057c00bd64e9c057f8784ea71a7188 100644 (file)
@@ -33,7 +33,6 @@ SummaryCommand::SummaryCommand(){
                
                for (i=0; i<globaldata->Estimators.size(); i++) {
                        if (validCalculator->isValidCalculator("summary", globaldata->Estimators[i]) == true) { 
-                       
                                if(globaldata->Estimators[i] == "sobs"){
                                        sumCalculators.push_back(new Sobs());
                                }else if(globaldata->Estimators[i] == "chao"){
@@ -128,7 +127,7 @@ int SummaryCommand::execute(){
                                for(int i=0;i<sumCalculators.size();i++){
                                        vector<double> data = sumCalculators[i]->getValues(sabund);
                                        outputFileHandle << '\t';
-                                       //sumCalculators[i]->print(outputFileHandle);
+                                       sumCalculators[i]->print(outputFileHandle);
                                }
                                
                                outputFileHandle << endl;
index 4c014452069ea1a6f5d98c50e04f79a0f5d54996..a875900411bd5b5b3678927e07acbd4e9cd9b9e6 100644 (file)
@@ -18,6 +18,8 @@ ValidCalculators::ValidCalculators() {
                 initialSharedRarefact();
                 initialSummary();
                 initialSharedSummary();
+                initialVennSingle();
+                initialVennShared();
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function ValidCalculator. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -108,7 +110,29 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) {
                                }
                                cout << endl;
                                return false; }
-               //not a valid paramter
+               }else if (parameter == "vennsingle") {
+                       //is it valid
+                       if ((vennsingle.find(calculator)) != (vennsingle.end())) {
+                               return true;
+                       }else { 
+                               cout << calculator << " is not a valid estimator for the venn command in single mode and will be disregarded. Valid estimators are ";
+                               for (it = vennsingle.begin(); it != vennsingle.end(); it++) {
+                                       cout << it->first << ", ";
+                               }
+                               cout << endl;
+                               return false; }
+               }else if (parameter == "vennshared") {
+                       //is it valid
+                       if ((vennshared.find(calculator)) != (vennshared.end())) {
+                               return true;
+                       }else { 
+                               cout << calculator << " is not a valid estimator for the venn command in shared mode and will be disregarded. Valid estimators are ";
+                               for (it = vennshared.begin(); it != vennshared.end(); it++) {
+                                       cout << it->first << ", ";
+                               }
+                               cout << endl;
+                               return false; }
+               //not a valid parameter
                }else { return false; }
                
        }
@@ -125,7 +149,6 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) {
 /********************************************************************/
 void ValidCalculators::initialSingle() {
        try {   
-       
                single["sobs"]          = "sobs";
                single["chao"]              = "chao";
                single["ace"]               = "ace";
@@ -141,7 +164,6 @@ void ValidCalculators::initialSingle() {
                single["bstick"]        = "bstick";
                single["nseqs"]         = "nseqs";
                single["default"]           = "default";
-               
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -298,6 +320,44 @@ void ValidCalculators::initialSharedRarefact() {
        }       
 }
 
+
+/********************************************************************/
+void ValidCalculators::initialVennSingle() {
+       try {
+               vennsingle["sobs"]              = "sobs";
+               vennsingle["chao"]                  = "chao";
+               vennsingle["ace"]                               = "ace";
+               vennsingle["jack"]                  = "jack";
+               vennsingle["default"]                   = "default";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+/********************************************************************/
+void ValidCalculators::initialVennShared() {
+       try {
+               vennshared["sharedsobs"]        = "sharedsobs";
+               vennshared["sharedchao"]        = "sharedchao";
+               vennshared["sharedace"]         = "sharedace";
+               vennshared["default"]           = "default";
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ValidCalculator class Function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ValidCalculator class function initialSingle. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
 /********************************************************************/
 
 
index 1534432799d2dfe8a9ef1e52fefe80d9096488dc..1c39d49253f6f138cbd27523a2fbb86b675e02a5 100644 (file)
@@ -31,6 +31,8 @@ class ValidCalculators {
                map<string, string> summary;
                map<string, string> sharedrarefaction;
                map<string, string> sharedsummary;
+               map<string, string> vennsingle;
+               map<string, string> vennshared;
                map<string, string>::iterator it;
                
                void initialSingle();
@@ -39,6 +41,9 @@ class ValidCalculators {
                void initialSharedRarefact();
                void initialSummary();
                void initialSharedSummary();
+               void initialVennSingle();
+               void initialVennShared();
+
 };
 
 #endif
index 084068df81f6f2e9c4263e9a58f9549443bf69aa..3806f5054b9c2a0faad7787c9ff9549b13c1fda6 100644 (file)
@@ -286,7 +286,7 @@ void ValidParameters::initCommandParameters() {
                string heatmapArray[] =  {"group","line","label","sorted"};
                commandParameters["heatmap"] = addParameters(heatmapArray, sizeof(heatmapArray)/sizeof(string));
 
-               string vennArray[] =  {"groups","line","label"};
+               string vennArray[] =  {"groups","line","label","calc"};
                commandParameters["venn"] = addParameters(vennArray, sizeof(vennArray)/sizeof(string));
                
                string quitArray[] = {};
index 98c63a1cbe4127714be2939e0605741497e415e6..6da78bb20c895f70b5e17157ac8281bdd16a8d10 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
@@ -8,13 +8,16 @@
  */
 
 #include "venn.h"
+#include "ace.h"
+#include "sobs.h"
+#include "chao1.h"
+
 
 //**********************************************************************************************************************
 Venn::Venn(){
        try {
                globaldata = GlobalData::getInstance();
                format = globaldata->getFormat();
-               
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -26,27 +29,34 @@ Venn::Venn(){
        }
 }
 //**********************************************************************************************************************
-void Venn::getPic(OrderVector* order) {
+void Venn::getPic(OrderVector* order, vector<Calculator*> vCalcs) {
        try {
+               SAbundVector s;
+               s = order->getSAbundVector();  sabund = &s;
                
-               rabund = order->getRAbundVector();
-               
-               string filenamesvg = globaldata->inputFileName + ".venn." + order->getLabel() + ".svg";
-               
-               openOutputFile(filenamesvg, outsvg);
-               
+               for(int i=0;i<vCalcs.size();i++){
+                       string filenamesvg = globaldata->inputFileName + ".venn." + order->getLabel() + vCalcs[i]->getName() + ".svg";
+                       openOutputFile(filenamesvg, outsvg);
+
+                       vector<double> data = vCalcs[i]->getValues(sabund);
                        
-               //svg image
-               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
-               outsvg << "<g>\n";
+                       //svg image
+                       outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
+                       outsvg << "<g>\n";
                                
-               outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
-               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + order->getLabel() + "</text>\n";
-               outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"100\"/>"; 
-               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(rabund.getNumBins()).length() / 2)) + "\" y=\"195\">" + toString(rabund.getNumBins()) + "</text>\n";  
-               outsvg << "</g>\n</svg>\n";
-               
-               outsvg.close();
+                       outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + order->getLabel() + "</text>\n";
+                       outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
+                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
+                       
+                       if (data.size() == 3) { 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
+                       }
+                       
+                       outsvg << "</g>\n</svg>\n";
+                       outsvg.close();
+               }
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -58,100 +68,238 @@ void Venn::getPic(OrderVector* order) {
        }
 }
 //**********************************************************************************************************************
-void Venn::getPic(SharedOrderVector* sharedorder) {
+void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
        try {
                
                //fills vector of sharedsabunds - lookup
                getSharedVectors(sharedorder);
-                               
-               string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + "." + groupComb + ".svg";
-               openOutputFile(filenamesvg, outsvg);
                
-               //image window
-               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
-               outsvg << "<g>\n";
-                               
+               /******************* 1 Group **************************/
                if (lookup.size() == 1) {
-                       int numA = 0;
-                       //for each bin
-                       for (int i = 0; i < lookup[0]->size(); i++) {
-                               //are they only in one
-                               if (lookup[0]->getAbundance(i) != 0)  { numA++; }
+                                       
+                       SAbundVector s;
+                       s = lookup[0]->getSAbundVector();  sabund = &s;
+                       
+                       //make a file for each calculator
+                       for(int i=0;i<vCalcs.size();i++){
+                               string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+                               openOutputFile(filenamesvg, outsvg);
+                       
+                               //in essence you want to run it like a single 
+                               if (vCalcs[i]->getName() == "SharedSobs") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Sobs();
+                               }else if (vCalcs[i]->getName() == "SharedChao") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Chao1();
+                               }else if (vCalcs[i]->getName() == "SharedAce") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Ace(10);
+                               }
+                               
+                               vector<double> data = vCalcs[i]->getValues(sabund);
+                       
+                               //svg image
+                               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
+                               outsvg << "<g>\n";
+                               
+                               outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
+                               outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
+                       
+                               if (data.size() == 3) { 
+                                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
+                                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
+                               }
+                       
+                               outsvg << "</g>\n</svg>\n";
+                               outsvg.close();
                        }
-
-                       outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
-                       outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(numA).length() / 2)) + "\" y=\"195\">" + toString(numA) + "</text>\n";  
                        
+               /******************* 2 Groups **************************/       
+               
                }else if (lookup.size() == 2) {
-                       //calc the shared otu
-                       int shared = 0;
-                       int numA = 0;
-                       int numB = 0;
+                       //get sabund vector pointers so you can use the single calculators
+                       //one for each group
+                       SAbundVector sA, sB;
+                       SAbundVector* sabundA; SAbundVector* sabundB;
+                       sA = lookup[0]->getSAbundVector();  sabundA = &sA;
+                       sB = lookup[1]->getSAbundVector();  sabundB = &sB;
                        
-                       //for each bin
-                       for (int i = 0; i < lookup[0]->size(); i++) {
-                               //are they only in one
-                               if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0)) { numA++; }
-                               if ((lookup[1]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0)) { numB++; }
-                               //are they shared
-                               if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { shared++; }
+                       //make a file for each calculator
+                       for(int i=0;i<vCalcs.size();i++){
+                               string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+                               openOutputFile(filenamesvg, outsvg);
+                               
+                               //get estimates for sharedAB
+                               vector<double> shared = vCalcs[i]->getValues(lookup[0], lookup[1]);
+                               
+                               //in essence you want to run it like a single 
+                               if (vCalcs[i]->getName() == "SharedSobs") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Sobs();
+                               }else if (vCalcs[i]->getName() == "SharedChao") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Chao1();
+                               }else if (vCalcs[i]->getName() == "SharedAce") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Ace(10);
+                               }
+                               
+                               //get estimates for numA
+                               vector<double> numA = vCalcs[i]->getValues(sabundA);
+                               
+                               //get estimates for numB
+                               vector<double> numB = vCalcs[i]->getValues(sabundB);
+                               
+                                               
+                               //image window
+                               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
+                               outsvg << "<g>\n";
+
+                               //draw circles
+                               outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
+                               outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>"; 
+                               outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"500\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(shared[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))) + "</text>\n";
+                               
+                               //close file
+                               outsvg << "</g>\n</svg>\n";
+                               outsvg.close();
+
                        }
                        
-                       //draw circles
-                       outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
-                       outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>"; 
-                       outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA).length() / 2)) + "\" y=\"195\">" + toString(numA) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB).length() / 2)) + "\" y=\"195\">" + toString(numB) + "</text>\n"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared).length() / 2)) + "\" y=\"195\">" + toString(shared) + "</text>\n";  
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"580\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString((shared / (float)(numA + numB + shared))) + "</text>\n";
-               
+               /******************* 3 Groups **************************/
+                                               
                }else if (lookup.size() == 3) {
-                       //calc the shared otu
-                       int sharedABC = 0;
-                       int numA = 0; int numB = 0; int numC = 0;
-                       int sharedAB = 0; int sharedAC = 0; int sharedBC = 0;
+                       //get sabund vector pointers so you can use the single calculators
+                       //one for each group
+                       SAbundVector sA, sB, sC;
+                       SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
+                       sA = lookup[0]->getSAbundVector();  sabundA = &sA;
+                       sB = lookup[1]->getSAbundVector();  sabundB = &sB;
+                       sC = lookup[2]->getSAbundVector();  sabundC = &sC;
                        
-                       //float scalerB;
+                       //make a file for each calculator
+                       for(int i=0;i<vCalcs.size();i++){
+                               string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + vCalcs[i]->getName() + "." + groupComb + ".svg";
+                               openOutputFile(filenamesvg, outsvg);
+                               
+                               //get estimates for sharedAB, sharedAC and sharedBC
+                               vector<double> sharedAB = vCalcs[i]->getValues(lookup[0], lookup[1]);
+                               vector<double> sharedAC = vCalcs[i]->getValues(lookup[0], lookup[2]);
+                               vector<double> sharedBC = vCalcs[i]->getValues(lookup[1], lookup[2]);
                        
-                       //for each bin
-                       for (int i = 0; i < lookup[0]->size(); i++) {
-                               //are they only in one
-                               if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[2]->getAbundance(i) == 0)) { numA++; }
-                               if ((lookup[1]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[2]->getAbundance(i) == 0)) { numB++; }
-                               if ((lookup[2]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[0]->getAbundance(i) == 0)) { numC++; }
-                               //are they shared by 2
-                               if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0)) { sharedAB++; }
-                               if ((lookup[0]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0)) { sharedAC++; }
-                               if ((lookup[2]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0)) { sharedBC++; }
+                               //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, "");
+                               }
                                
-                               //are they shared by all
-                               if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0)) { sharedABC++; }
-                       }
-                                               
-                       //draw circles
-                       outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
-                       outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
-                       outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
-                       outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
+                               vector<double> sharedAwithBC = vCalcs[i]->getValues(lookup[0], merge);
                        
-                       //place labels within overlaps
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA).length() / 2)) + "\" y=\"170\">" + toString(numA) + "</text>\n";  
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB).length() / 2)) + "\"  y=\"170\">" + toString(sharedAB) + "</text>\n";  
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB).length() / 2)) + "\"  y=\"170\">" + toString(numB) + "</text>\n";  
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC).length() / 2)) + "\"  y=\"305\">" + toString(sharedAC) + "</text>\n";  
-                       outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)toString(numC).length() / 2)) + "\"   y=\"430\">" + toString(numC) + "</text>\n";  
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC) + "</text>\n";  
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"280\">" + toString(sharedABC) + "</text>\n"; 
+                               delete merge;
+                               //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, "");
+                               }
+               
+                               vector<double> sharedBwithAC = vCalcs[i]->getValues(lookup[1], merge);
                        
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"580\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(((sharedAB + sharedABC) / (float)(numA + numB + sharedAB + sharedABC))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"610\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(((sharedAC + sharedABC) / (float)(numA + numC + sharedAC + sharedABC))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"640\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedBC + sharedABC) / (float)(numB + numC + sharedBC + sharedABC))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"670\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString((sharedABC / (float)(numA + numB + numC + sharedAB + sharedAC + sharedBC + sharedABC))) + "</text>\n";
+                               delete merge;
+                               //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, "");
+                               }
+                               
+                               vector<double> sharedCwithAB = vCalcs[i]->getValues(lookup[2], merge);
+                               
+                               
+                               //in essence you want to run it like a single 
+                               if (vCalcs[i]->getName() == "SharedSobs") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Sobs();
+                               }else if (vCalcs[i]->getName() == "SharedChao") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Chao1();
+                               }else if (vCalcs[i]->getName() == "SharedAce") {
+                                       delete vCalcs[i];
+                                       vCalcs[i] = new Ace(10);
+                               }
+                               
+                               //get estimates for numA
+                               vector<double> numA = vCalcs[i]->getValues(sabundA);
+                       
+                               //get estimates for numB
+                               vector<double> numB = vCalcs[i]->getValues(sabundB);
+                               
+                               //get estimates for numC
+                               vector<double> numC = vCalcs[i]->getValues(sabundC);
+                               
+                               //find possible sharedABC values
+                               float sharedABC1, sharedABC2, sharedABC3, sharedABC;
+                               
+                               sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
+                               sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
+                               sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
+                               //if any of the possible m's are - throw them out
+                               if (sharedABC1 < 0.0) { sharedABC1 = 0; }
+                               if (sharedABC2 < 0.0) { sharedABC2 = 0; }
+                               if (sharedABC3 < 0.0) { sharedABC3 = 0; }
+               
+                               //sharedABC is the minimum of the 3 possibilities
+                               if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
+                               else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
+                               else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }    
+                       
+                               //image window
+                               outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 800 800\" >\n";
+                               outsvg << "<g>\n";
+
+                               //draw circles
+                               outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>"; 
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
+                               outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
+                               outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
+                               outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
+                       
+                               //place labels within overlaps
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\"  y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\"  y=\"170\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\"  y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\"   y=\"430\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";  
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"280\">" + toString(sharedABC) + "</text>\n"; 
+                       
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"660\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(sharedAB[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"680\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(sharedAC[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"700\">The number of sepecies shared between groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(sharedBC[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and combined groups " + globaldata->Groups[1] + globaldata->Groups[2] + " is " + toString(sharedAwithBC[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"740\">The number of sepecies shared between groups " + globaldata->Groups[1] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[2] + " is " + toString(sharedBwithAC[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"760\">The number of sepecies shared between groups " + globaldata->Groups[2] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[1] + " is " + toString(sharedCwithAB[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + globaldata->Groups[2] + " is " + toString(numC[0]) + "</text>\n";
+                               outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total number of species in all groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
+                               
+                               //close file
+                               outsvg << "</g>\n</svg>\n";
+                               outsvg.close();
+                       }
+                       
+               /******************* 4 Groups **************************/
                
                }else if (lookup.size() == 4) {
                        //calc the shared otu
@@ -162,7 +310,7 @@ void Venn::getPic(SharedOrderVector* sharedorder) {
                        
                        //A = red, B = green, C = blue, D = yellow
                        
-                       //float scalerB;
+                       if ((vCalcs.size() > 1) || (vCalcs[0]->getName() != "SharedSobs")) { cout << "The only calculator able to be used with 4 groups is sharedsobs. I will run that for you. " << endl; }
                        
                        //for each bin
                        for (int i = 0; i < lookup[0]->size(); i++) {
@@ -186,7 +334,14 @@ void Venn::getPic(SharedOrderVector* sharedorder) {
                                //are they shared by all
                                if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0)) { sharedABCD++; }
                        }
-                                               
+                               
+                       string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + "." + groupComb + ".svg";
+                       openOutputFile(filenamesvg, outsvg);
+               
+                       //image window
+                       outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
+                       outsvg << "<g>\n";
+
                        //draw circles
                        outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
@@ -214,23 +369,25 @@ void Venn::getPic(SharedOrderVector* sharedorder) {
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"240\">" + toString(sharedABC) + "</text>\n"; 
                        outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\"  y=\"320\">" + toString(sharedABCD) + "</text>\n"; 
                        
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"490\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(((sharedAB + sharedABD + sharedABC + sharedABCD) / (float)(numA + numB + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"510\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(((sharedAC + sharedACD + sharedABC + sharedABCD) / (float)(numA + numC + sharedAB + sharedAC + sharedAD + sharedBC + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"530\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[3] + " is " + toString(((sharedAD + sharedACD + sharedABD + sharedABCD) / (float)(numA + numD + sharedAB + sharedAC + sharedAD + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"550\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedBC + sharedABC + sharedBCD + sharedABCD) / (float)(numB + numC + sharedAB + sharedAC + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"570\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[3] + " is " + toString(((sharedBD + sharedABD + sharedBCD + sharedABCD) / (float)(numB + numD + sharedAB + sharedAD + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"590\">Percentage of species that are shared in groups " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedCD + sharedBCD + sharedACD + sharedABCD) / (float)(numC + numD + sharedAC + sharedAD + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"610\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedABC + sharedABCD) / (float)(numA + numB + numC + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"630\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[3] + " is " + toString(((sharedABD + sharedABCD) / (float)(numA + numB + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"650\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedACD + sharedABCD) / (float)(numA + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"670\">Percentage of species that are shared in groups " + globaldata->Groups[1] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedBCD + sharedABCD) / (float)(numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
-                       outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"690\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString((sharedABCD / (float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"490\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(((sharedAB + sharedABD + sharedABC + sharedABCD) / (float)(numA + numB + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"510\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(((sharedAC + sharedACD + sharedABC + sharedABCD) / (float)(numA + numC + sharedAB + sharedAC + sharedAD + sharedBC + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"530\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[3] + " is " + toString(((sharedAD + sharedACD + sharedABD + sharedABCD) / (float)(numA + numD + sharedAB + sharedAC + sharedAD + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"550\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedBC + sharedABC + sharedBCD + sharedABCD) / (float)(numB + numC + sharedAB + sharedAC + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"570\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[3] + " is " + toString(((sharedBD + sharedABD + sharedBCD + sharedABCD) / (float)(numB + numD + sharedAB + sharedAD + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"590\">Percentage of species that are shared in groups " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedCD + sharedBCD + sharedACD + sharedABCD) / (float)(numC + numD + sharedAC + sharedAD + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"610\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedABC + sharedABCD) / (float)(numA + numB + numC + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"630\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[3] + " is " + toString(((sharedABD + sharedABCD) / (float)(numA + numB + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"650\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedACD + sharedABCD) / (float)(numA + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"670\">Percentage of species that are shared in groups " + globaldata->Groups[1] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedBCD + sharedABCD) / (float)(numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+                       //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"690\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString((sharedABCD / (float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
+               
+                       outsvg << "</g>\n</svg>\n";
+                       outsvg.close();
+
                }
 
                
-               outsvg << "</g>\n</svg>\n";
-               outsvg.close();
-
+               
                
                
        }
@@ -293,7 +450,4 @@ void Venn::getSharedVectors(SharedOrderVector* order){
        }
 
 }
-//**********************************************************************************************************************
-
-
 
diff --git a/venn.h b/venn.h
index fbb6cf183ba7ac1409ad83c4cee42ef3d59e5cb9..ceb52fda7a5447f812133aea9c343d7ccf8e71b5 100644 (file)
--- a/venn.h
+++ b/venn.h
 using namespace std;
 
 #include "ordervector.hpp"
-#include "rabundvector.hpp"
+#include "Sabundvector.hpp"
 #include "sharedrabundvector.h"
 #include "sharedordervector.h"
 #include "datavector.hpp"
 #include "globaldata.hpp"
+#include "calculator.h"
 
 /***********************************************************************/
 
@@ -26,13 +27,13 @@ class Venn {
                Venn();
                ~Venn(){};
        
-               void getPic(OrderVector*);
-               void getPic(SharedOrderVector*);
+               void getPic(OrderVector*, vector<Calculator*>);
+               void getPic(SharedOrderVector*, vector<Calculator*>);
 
        private:
                void getSharedVectors(SharedOrderVector*);
                
-               RAbundVector rabund;
+               SAbundVector* sabund;
                GlobalData* globaldata;
                vector<SharedRAbundVector*> lookup;
                string format, groupComb;
index 85dcd93c33d9b1df4baf8dcbef8bf16e2677154b..56284811af853a6504cac1adf026d6b6e67f3214 100644 (file)
@@ -8,14 +8,61 @@
  */
 
 #include "venncommand.h"
+#include "ace.h"
+#include "sobs.h"
+#include "chao1.h"
+#include "jackknife.h"
+#include "sharedsobscollectsummary.h"
+#include "sharedchao1.h"
+#include "sharedace.h"
+
 
 //**********************************************************************************************************************
 
 VennCommand::VennCommand(){
        try {
                globaldata = GlobalData::getInstance();
-               venn = new Venn();
                format = globaldata->getFormat();
+               validCalculator = new ValidCalculators();
+               
+               int i;
+               
+               if (format == "list") {
+                       for (i=0; i<globaldata->Estimators.size(); i++) {
+                               if (validCalculator->isValidCalculator("vennsingle", globaldata->Estimators[i]) == true) { 
+                                       if (globaldata->Estimators[i] == "sobs") { 
+                                               vennCalculators.push_back(new Sobs());
+                                       }else if (globaldata->Estimators[i] == "chao") { 
+                                               vennCalculators.push_back(new Chao1());
+                                       }else if (globaldata->Estimators[i] == "ace") {
+                                               convert(globaldata->getAbund(), abund);
+                                               if(abund < 5)
+                                                       abund = 10;
+                                               vennCalculators.push_back(new Ace(abund));
+                                       }else if (globaldata->Estimators[i] == "jack") {        
+                                               vennCalculators.push_back(new Jackknife());
+                                       }
+                               }
+                       }
+               }else {
+                       for (i=0; i<globaldata->Estimators.size(); i++) {
+                               if (validCalculator->isValidCalculator("vennshared", globaldata->Estimators[i]) == true) { 
+                                       if (globaldata->Estimators[i] == "sharedsobs") { 
+                                               vennCalculators.push_back(new SharedSobsCS());
+                                       }else if (globaldata->Estimators[i] == "sharedchao") { 
+                                               vennCalculators.push_back(new SharedChao1());
+                                       }else if (globaldata->Estimators[i] == "sharedace") { 
+                                               vennCalculators.push_back(new SharedAce());
+                                       }
+                               }
+                       }
+               }
+               
+               venn = new Venn();
+               
+               //reset calc for next command
+               globaldata->setCalc("");
+
                
        }
        catch(exception& e) {
@@ -41,6 +88,9 @@ int VennCommand::execute(){
        try {
                int count = 1;  
                
+               //if the users entered no valid calculators don't execute command
+               if (vennCalculators.size() == 0) { return 0; }
+               
                if (format == "sharedfile") {
                        //you have groups
                        read = new ReadPhilFile(globaldata->inputFileName);     
@@ -75,7 +125,7 @@ int VennCommand::execute(){
                                if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
        
                                        cout << order->getLabel() << '\t' << count << endl;
-                                       venn->getPic(order);
+                                       venn->getPic(order, vennCalculators);
 
                                }
                                                
@@ -103,7 +153,7 @@ int VennCommand::execute(){
                                if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(ordersingle->getLabel()) == 1){                 
        
                                        cout << ordersingle->getLabel() << '\t' << count << endl;
-                                       venn->getPic(ordersingle);
+                                       venn->getPic(ordersingle, vennCalculators);
                                        
                                }
                                
index f8151c1bdf0e3a547638639dfbf2aa5ac9f437ed..d91aaef1c7e47185862cf1a681976a31c47ebb75 100644 (file)
@@ -14,6 +14,7 @@
 #include "readmatrix.hpp"
 #include "sharedlistvector.h"
 #include "venn.h"
+#include "validcalculator.h"
 
 
 class GlobalData;
@@ -35,6 +36,9 @@ private:
        OrderVector* ordersingle;
        Venn* venn;
        string format;
+       vector<Calculator*> vennCalculators;    
+       ValidCalculators* validCalculator;
+       int abund;
        
        void setGroups();