X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=venn.cpp;h=ad74376456f96e09176fa4c97c53e949e7d748b4;hb=31c6076fe649829d9b8f773f6f12b627d3ef5d9b;hp=98c63a1cbe4127714be2939e0605741497e415e6;hpb=38fd0bcfcb1a77ce58a0d1c8ec7c8c8541cf3892;p=mothur.git diff --git a/venn.cpp b/venn.cpp index 98c63a1..ad74376 100644 --- a/venn.cpp +++ b/venn.cpp @@ -8,13 +8,18 @@ */ #include "venn.h" +#include "ace.h" +#include "sobs.h" +#include "chao1.h" +#include "sharedchao1.h" +#include "sharedsobscollectsummary.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 +31,32 @@ Venn::Venn(){ } } //********************************************************************************************************************** -void Venn::getPic(OrderVector* order) { +void Venn::getPic(SAbundVector* sabund, vector vCalcs) { try { - - rabund = order->getRAbundVector(); - - string filenamesvg = globaldata->inputFileName + ".venn." + order->getLabel() + ".svg"; - - openOutputFile(filenamesvg, outsvg); - + + for(int i=0;iinputFileName + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg"; + openOutputFile(filenamesvg, outsvg); + + vector data = vCalcs[i]->getValues(sabund); - //svg image - outsvg << "\n"; - outsvg << "\n"; - - outsvg << ""; - outsvg << "Venn Diagram at distance " + order->getLabel() + "\n"; - outsvg << ""; - outsvg << "" + toString(rabund.getNumBins()) + "\n"; - outsvg << "\n\n"; - - outsvg.close(); + //svg image + outsvg << "\n"; + outsvg << "\n"; + + outsvg << ""; + outsvg << "Venn Diagram at distance " + sabund->getLabel() + "\n"; + outsvg << ""; + outsvg << "" + toString(data[0]) + "\n"; + + if (data.size() == 3) { + outsvg << "The lower bound of the confidence interval is " + toString(data[1]) + "\n"; + outsvg << "The upper bound of the confidence interval is " + toString(data[2]) + "\n"; + } + + outsvg << "\n\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,242 +68,462 @@ void Venn::getPic(OrderVector* order) { } } //********************************************************************************************************************** -void Venn::getPic(SharedOrderVector* sharedorder) { +void Venn::getPic(vector lookup, vector vCalcs) { try { - //fills vector of sharedsabunds - lookup - getSharedVectors(sharedorder); - - string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + "." + groupComb + ".svg"; - openOutputFile(filenamesvg, outsvg); + vector subset; - //image window - outsvg << "\n"; - outsvg << "\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++; } - } - - outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; - outsvg << ""; - outsvg << "" + toString(numA) + "\n"; + + SAbundVector s; + s = lookup[0]->getSAbundVector(); SAbundVector* sabund = &s; - }else if (lookup.size() == 2) { - //calc the shared otu - int shared = 0; - int numA = 0; - int numB = 0; + //make a file for each calculator + for(int i=0;iinputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg"; + openOutputFile(filenamesvg, outsvg); - //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++; } - } + //in essence you want to run it like a single + if (vCalcs[i]->getName() == "sharedsobs") { + singleCalc = new Sobs(); + }else if (vCalcs[i]->getName() == "sharedchao") { + singleCalc = new Chao1(); + }else if (vCalcs[i]->getName() == "sharedace") { + singleCalc = new Ace(10); + } + + vector data = singleCalc->getValues(sabund); - //draw circles - outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; - outsvg << ""; - outsvg << ""; - outsvg << "" + toString(numA) + "\n"; - outsvg << "" + toString(numB) + "\n"; - outsvg << "" + toString(shared) + "\n"; - outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString((shared / (float)(numA + numB + shared))) + "\n"; - - }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; + //svg image + outsvg << "\n"; + outsvg << "\n"; + + outsvg << ""; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; + outsvg << ""; + outsvg << "getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "\n"; + outsvg << "" + toString(data[0]) + "\n"; - //float scalerB; + if (data.size() == 3) { + outsvg << "The lower bound of the confidence interval is " + toString(data[1]) + "\n"; + outsvg << "The upper bound of the confidence interval is " + toString(data[2]) + "\n"; + } - //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++; } - - //are they shared by all - if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0)) { sharedABC++; } + outsvg << "\n\n"; + outsvg.close(); + delete singleCalc; + } - - //draw circles - outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; - outsvg << ""; - outsvg << ""; - outsvg << ""; - - //place labels within overlaps - outsvg << "" + toString(numA) + "\n"; - outsvg << "" + toString(sharedAB) + "\n"; - outsvg << "" + toString(numB) + "\n"; - outsvg << "" + toString(sharedAC) + "\n"; - outsvg << "" + toString(numC) + "\n"; - outsvg << "" + toString(sharedBC) + "\n"; - outsvg << "" + toString(sharedABC) + "\n"; - - outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(((sharedAB + sharedABC) / (float)(numA + numB + sharedAB + sharedABC))) + "\n"; - outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(((sharedAC + sharedABC) / (float)(numA + numC + sharedAC + sharedABC))) + "\n"; - outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedBC + sharedABC) / (float)(numB + numC + sharedBC + sharedABC))) + "\n"; - outsvg << "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))) + "\n"; + /******************* 2 Groups **************************/ - }else if (lookup.size() == 4) { - //calc the shared otu - int sharedABCD = 0; - int numA = 0; int numB = 0; int numC = 0; int numD = 0; - int sharedAB = 0; int sharedAC = 0; int sharedBC = 0; int sharedAD = 0; int sharedBD = 0; int sharedCD = 0; - int sharedABC = 0; int sharedACD = 0; int sharedBCD = 0; int sharedABD = 0; - - //A = red, B = green, C = blue, D = yellow + }else if (lookup.size() == 2) { + //get sabund vector pointers so you can use the single calculators + //one for each group + SAbundVector sA, sB; + SAbundVector* sabundA; SAbundVector* sabundB; + sabundA = new SAbundVector(lookup[0]->getSAbundVector());// sabundA = &sA; + sabundB = new SAbundVector(lookup[1]->getSAbundVector());// sabundB = &sB; - //float scalerB; + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); - //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) && (lookup[3]->getAbundance(i) == 0)) { numA++; } - if ((lookup[1]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { numB++; } - if ((lookup[2]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { numC++; } - if ((lookup[3]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[2]->getAbundance(i) == 0)) { numD++; } - //are they shared by 2 - if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { sharedAB++; } - if ((lookup[0]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { sharedAC++; } - if ((lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { sharedBC++; } - if ((lookup[0]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[1]->getAbundance(i) == 0)) { sharedAD++; } - if ((lookup[3]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[0]->getAbundance(i) == 0)) { sharedBD++; } - if ((lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[0]->getAbundance(i) == 0)) { sharedCD++; } - //are they shared by 3 - if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) == 0)) { sharedABC++; } - if ((lookup[0]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0)) { sharedACD++; } - if ((lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0)) { sharedBCD++; } - if ((lookup[0]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0)) { sharedABD++; } - //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++; } + //make a file for each calculator + for(int i=0;iinputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg"; + openOutputFile(filenamesvg, outsvg); + + //get estimates for sharedAB + vector shared = vCalcs[i]->getValues(subset); + + //in essence you want to run it like a single + if (vCalcs[i]->getName() == "sharedsobs") { + singleCalc = new Sobs(); + }else if (vCalcs[i]->getName() == "sharedchao") { + singleCalc = new Chao1(); + }else if (vCalcs[i]->getName() == "sharedace") { + singleCalc = new Ace(10); + } + + //get estimates for numA + vector numA = singleCalc->getValues(sabundA); + + //get estimates for numB + vector numB = singleCalc->getValues(sabundB); + + //image window + outsvg << "\n"; + outsvg << "\n"; + + //draw circles + outsvg << ""; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; + outsvg << ""; + outsvg << ""; + outsvg << "" + toString(numA[0] - shared[0]) + "\n"; + outsvg << "" + toString(numB[0] - shared[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "\n"; + outsvg << "" + toString(shared[0]) + "\n"; + outsvg << "The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]); + if (numA.size() == 3) { + outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "\n"; + }else { outsvg << "\n"; } + + outsvg << "The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]); + if (numB.size() == 3) { + outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "\n"; + }else { outsvg << "\n"; } + + outsvg << "The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(shared[0]) + "\n"; + outsvg << "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]))) + "\n"; + outsvg << "The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0])) + "\n"; + + //close file + outsvg << "\n\n"; + outsvg.close(); + delete singleCalc; } + /******************* 3 Groups **************************/ - //draw circles - outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; - outsvg << "\n "; - outsvg << "\n "; - outsvg << "\n "; - outsvg << "\n "; + }else if (lookup.size() == 3) { + //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; + + //make a file for each calculator + for(int i=0;igetName() == "sharedsobs") { + singleCalc = new Sobs(); + }else if (vCalcs[i]->getName() == "sharedchao") { + singleCalc = new Chao1(); + }else if (vCalcs[i]->getName() == "sharedace") { + singleCalc = new Ace(10); + } + + //get estimates for numA + vector numA = singleCalc->getValues(sabundA); + + //get estimates for numB + vector numB = singleCalc->getValues(sabundB); + + //get estimates for numC + vector numC = singleCalc->getValues(sabundC); + + + string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg"; + openOutputFile(filenamesvg, outsvg); + + //get estimates for sharedAB, sharedAC and sharedBC + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); + vector sharedAB = vCalcs[i]->getValues(subset); + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[2]); + vector sharedAC = vCalcs[i]->getValues(subset); + + subset.clear(); + subset.push_back(lookup[1]); subset.push_back(lookup[2]); + vector sharedBC = vCalcs[i]->getValues(subset); + + vector sharedAwithBC; + vector sharedBwithAC; + vector sharedCwithAB; + + //find possible sharedABC values + float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0; + + if (vCalcs[i]->getMultiple() == false) { + //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, ""); + } + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(merge); + sharedAwithBC = vCalcs[i]->getValues(subset); - //place labels within overlaps - outsvg << "" + toString(numA) + "\n"; - outsvg << "" + toString(sharedAB) + "\n"; - outsvg << "" + toString(numB) + "\n"; - outsvg << "" + toString(sharedAC) + "\n"; - outsvg << "" + toString(numC) + "\n"; - outsvg << "" + toString(sharedBC) + "\n"; - outsvg << "" + toString(numD) + "\n"; - outsvg << "" + toString(sharedAD) + "\n"; - outsvg << "" + toString(sharedBD) + "\n"; - outsvg << "" + toString(sharedCD) + "\n"; - outsvg << "" + toString(sharedABD) + "\n"; - outsvg << "" + toString(sharedBCD) + "\n"; - outsvg << "" + toString(sharedACD) + "\n"; - outsvg << "" + toString(sharedABC) + "\n"; - outsvg << "" + toString(sharedABCD) + "\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, ""); + } + + subset.clear(); + subset.push_back(merge); subset.push_back(lookup[1]); + sharedBwithAC = vCalcs[i]->getValues(subset); - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\n"; - outsvg << "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))) + "\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, ""); + } + + subset.clear(); + subset.push_back(lookup[2]); subset.push_back(merge); + sharedCwithAB = vCalcs[i]->getValues(subset); + delete merge; + + 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.00001) { sharedABC1 = 0; } + if (sharedABC2 < 0.00001) { sharedABC2 = 0; } + if (sharedABC3 < 0.00001) { sharedABC3 = 0; } - outsvg << "\n\n"; - outsvg.close(); - + //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; } + }else{ + vector data = vCalcs[i]->getValues(lookup); + sharedABC = data[0]; + sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC); + sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC); + sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC); + } + //image window + outsvg << "\n"; + outsvg << "\n"; + + //draw circles + outsvg << ""; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; + outsvg << ""; + outsvg << ""; + outsvg << ""; +//cout << "numA = " << numA[0] << " numB = " << numB[0] << " numC = " << numC[0] << endl; +//cout << "sharedAB = " << sharedAB[0] << " sharedAC = " << sharedAC[0] << " sharedBC = " << sharedBC[0] << endl; +//cout << "sharedAwithBC = " << sharedAwithBC[0] << " sharedBwithAC = " << sharedBwithAC[0] << " sharedCwithAB = " << sharedCwithAB[0] << endl; + //place labels within overlaps + outsvg << "" + toString(numA[0]-sharedAwithBC[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "\n"; + outsvg << "" + toString(sharedAB[0] - sharedABC) + "\n"; + outsvg << "" + toString(numB[0]-sharedBwithAC[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "\n"; + outsvg << "" + toString(sharedAC[0] - sharedABC) + "\n"; + outsvg << "" + toString(numC[0]-sharedCwithAB[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "\n"; + outsvg << "" + toString(sharedBC[0] - sharedABC) + "\n"; + outsvg << "" + toString(sharedABC) + "\n"; + + outsvg << "The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(sharedAB[0]) + "\n"; + outsvg << "The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(sharedAC[0]) + "\n"; + outsvg << "The number of sepecies shared between groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(sharedBC[0]) + "\n"; + outsvg << "The number of sepecies shared between groups " + globaldata->Groups[0] + " and combined groups " + globaldata->Groups[1] + globaldata->Groups[2] + " is " + toString(sharedAwithBC[0]) + "\n"; + outsvg << "The number of sepecies shared between groups " + globaldata->Groups[1] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[2] + " is " + toString(sharedBwithAC[0]) + "\n"; + outsvg << "The number of sepecies shared between groups " + globaldata->Groups[2] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[1] + " is " + toString(sharedCwithAB[0]) + "\n"; + outsvg << "The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]); + if (numA.size() == 3) { + outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "\n"; + }else { outsvg << "\n"; } - } - 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"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the Venn class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -//********************************************************************************************************************** -void Venn::getSharedVectors(SharedOrderVector* order){ - try { - - //delete lookup - for (int j = 0; j < lookup.size(); j++) { - delete lookup[j]; - } + outsvg << "The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]); + if (numB.size() == 3) { + outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "\n"; + }else { outsvg << "\n"; } + + outsvg << "The number of species in group " + globaldata->Groups[2] + " is " + toString(numC[0]); + if (numC.size() == 3) { + outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "\n"; + }else { outsvg << "\n"; } + + outsvg << "The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "\n"; + + //close file + outsvg << "\n\n"; + outsvg.close(); + delete singleCalc; - lookup.clear(); + } + + /******************* 4 Groups **************************/ - groupComb = ""; + }else if (lookup.size() == 4) { + //calc the shared otu + float sharedABCD = 0; + float numA = 0; float numB = 0; float numC = 0; float numD = 0; + float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0; + float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0; + vector data; + //get sabund vector pointers so you can use the single calculators + //one for each group + SAbundVector sA, sB, sC, sD; + SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD; + sA = lookup[0]->getSAbundVector(); sabundA = &sA; + sB = lookup[1]->getSAbundVector(); sabundB = &sB; + sC = lookup[2]->getSAbundVector(); sabundC = &sC; + sD = lookup[3]->getSAbundVector(); sabundD = &sD; + + //A = red, B = green, C = blue, D = yellow + + //make a file for each calculator + for(int i=0;igetName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { cout << vCalcs[i]->getName() << " is not a valid calculator with four groups. It will be disregarded. " << endl; } + else{ + string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg"; + openOutputFile(filenamesvg, outsvg); + + + //in essence you want to run it like a single + if (vCalcs[i]->getName() == "sharedsobs") { + singleCalc = new Sobs(); + }else if (vCalcs[i]->getName() == "sharedchao") { + singleCalc = new Chao1(); + } + + //get estimates for numA + data = singleCalc->getValues(sabundA); + numA = data[0]; + + //get estimates for numB + data = singleCalc->getValues(sabundB); + numB = data[0]; + + //get estimates for numC + data = singleCalc->getValues(sabundC); + numC = data[0]; + + //get estimates for numD + data = singleCalc->getValues(sabundD); + numD = data[0]; + + + //get estimates for pairs + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); + data = vCalcs[i]->getValues(subset); + sharedAB = data[0]; + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[2]); + data = vCalcs[i]->getValues(subset); + sharedAC = data[0]; + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset); + sharedAD = data[0]; + + subset.clear(); + subset.push_back(lookup[1]); subset.push_back(lookup[2]); + data = vCalcs[i]->getValues(subset); + sharedBC = data[0]; + + subset.clear(); + subset.push_back(lookup[1]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset); + sharedBD = data[0]; + + subset.clear(); + subset.push_back(lookup[2]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset); + sharedCD = data[0]; + + + //get estimates for combos of 3 + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]); + data = vCalcs[i]->getValues(subset); + sharedABC = data[0]; + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset); + sharedACD = data[0]; + + subset.clear(); + subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset); + sharedBCD = data[0]; + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset); + sharedABD = data[0]; + + //get estimate for all four + data = vCalcs[i]->getValues(lookup); + sharedABCD = data[0]; + - //create and initialize vector of sharedvectors, one for each group - for (int i = 0; i < globaldata->Groups.size(); i++) { - SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins()); - temp->setLabel(order->getLabel()); - temp->setGroup(globaldata->Groups[i]); - groupComb += globaldata->Groups[i]; - lookup.push_back(temp); - } + //image window + outsvg << "\n"; + outsvg << "\n"; + + //draw circles + outsvg << ""; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; + outsvg << "\n "; + outsvg << "\n "; + outsvg << "\n "; + outsvg << "\n "; + + //A = red, B = green, C = blue, D = yellow + + //place labels within overlaps + outsvg << "" + toString(numA) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "\n"; + outsvg << "" + toString(sharedAB) + "\n"; + outsvg << "" + toString(numB) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"90\">" + lookup[1]->getGroup() + "\n"; + outsvg << "" + toString(sharedAC) + "\n"; + outsvg << "" + toString(numC) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"210\">" + lookup[2]->getGroup() + "\n"; + outsvg << "" + toString(sharedBC) + "\n"; + outsvg << "" + toString(numD) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"210\">" + lookup[3]->getGroup() + "\n"; + outsvg << "" + toString(sharedAD) + "\n"; + outsvg << "" + toString(sharedBD) + "\n"; + outsvg << "" + toString(sharedCD) + "\n"; + outsvg << "" + toString(sharedABD) + "\n"; + outsvg << "" + toString(sharedBCD) + "\n"; + outsvg << "" + toString(sharedACD) + "\n"; + outsvg << "" + toString(sharedABC) + "\n"; + outsvg << "" + toString(sharedABCD) + "\n"; + outsvg << "The total richness of all the groups is " + toString((float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD)) + "\n"; + + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; + //outsvg << "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))) + "\n"; - int numSeqs = order->size(); - //sample all the members - for(int i=0;iget(i); - int abundance; - - //set info for sharedvector in chosens group - for (int j = 0; j < lookup.size(); j++) { - if (chosen.group == lookup[j]->getGroup()) { - abundance = lookup[j]->getAbundance(chosen.bin); - lookup[j]->set(chosen.bin, (abundance + 1), chosen.group); - break; + outsvg << "\n\n"; + outsvg.close(); + delete singleCalc; } } } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } catch(...) { - cout << "An unknown error has occurred in the Venn class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "An unknown error has occurred in the Venn class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } - } -//********************************************************************************************************************** -