X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=venn.cpp;h=66dbb8eac3ee13c069b85374503dd87cc0ae538f;hp=282ca984782a8fd05f979179c589806897649862;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=62f1ae1378c4c36175ec11fec8f70a3d2d26112e diff --git a/venn.cpp b/venn.cpp index 282ca98..66dbb8e 100644 --- a/venn.cpp +++ b/venn.cpp @@ -8,224 +8,993 @@ */ #include "venn.h" +#include "ace.h" +#include "sobs.h" +#include "chao1.h" +#include "nseqs.h" +#include "sharedchao1.h" +#include "sharedsobscollectsummary.h" + //********************************************************************************************************************** -Venn::Venn(){ +Venn::Venn(string o, bool n, string f, int fs, bool so) : outputDir(o), nseqs(n), inputfile(f), fontSize(fs), sharedOtus(so) { try { - globaldata = GlobalData::getInstance(); - format = globaldata->getFormat(); - + m = MothurOut::getInstance(); } 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"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the Venn class function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "Venn", "Venn"); exit(1); } } //********************************************************************************************************************** -void Venn::getPic(OrderVector* order) { +vector Venn::getPic(SAbundVector* sabund, vector vCalcs) { try { - rabund = order->getRAbundVector(); - - string filenamesvg = globaldata->inputFileName + ".venn." + order->getLabel() + ".svg"; - - openOutputFile(filenamesvg, outsvg); - + vector outputNames; + + for(int i=0;igetRootName(m->getSimpleName(inputfile)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg"; + outputNames.push_back(filenamesvg); + m->openOutputFile(filenamesvg, outsvg); + + if (m->control_pressed) { outsvg.close(); return outputNames; } + + vector data = vCalcs[i]->getValues(sabund); + + int width = 1500; + int height = 1500; - //svg image - outsvg << "\n"; - outsvg << "\n"; + //svg image + outsvg << "\n"; + outsvg << "\n"; - outsvg << ""; - outsvg << "" + toString(rabund.getNumBins()) + "\n"; - outsvg << "\n\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"; + } + + if (nseqs) { + outsvg << "The number of sequences represented is " + toString(sabund->getNumSeqs()) + "\n"; + } + + outsvg << "\n\n"; + outsvg.close(); + } - outsvg.close(); + return outputNames; } 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"; + m->errorOut(e, "Venn", "getPic"); exit(1); } } //********************************************************************************************************************** -void Venn::getPic(SharedOrderVector* sharedorder) { +vector Venn::getPic(vector lookup, vector vCalcs) { try { + + vector subset; + vector outputNames; - //fills vector of sharedsabunds - lookup - getSharedVectors(sharedorder); - - string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + "." + groupComb + ".svg"; - openOutputFile(filenamesvg, outsvg); + int width = 1500; + int height = 1500; - //image window - outsvg << "\n"; - outsvg << "\n"; - + /******************* 1 Group **************************/ if (lookup.size() == 1) { - outsvg << ""; - outsvg << "" + toString(lookup[0]->getNumBins()) + "\n"; - outsvg << "\n\n"; + + SAbundVector s; + s = lookup[0]->getSAbundVector(); SAbundVector* sabund = &s; + + //make a file for each calculator + for(int i=0;igetRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg"; + outputNames.push_back(filenamesvg); + m->openOutputFile(filenamesvg, outsvg); + + if (m->control_pressed) { outsvg.close(); return outputNames; } + + //in essence you want to run it like a single + if (vCalcs[i]->getName() == "sharedsobs") { + singleCalc = new Sobs(); + }else if (vCalcs[i]->getName() == "sharedchao") { + singleCalc = new Chao1(); + }else if (vCalcs[i]->getName() == "sharedace") { + singleCalc = new Ace(10); + } + + vector data = singleCalc->getValues(sabund); + + //svg image + outsvg << "\n"; + outsvg << "\n"; + + outsvg << ""; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; + outsvg << ""; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.24 * height)) + "\">" + lookup[0]->getGroup() + "\n"; + 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"; + } + + if (nseqs) { + outsvg << "The number of sequences represented is " + toString(sabund->getNumSeqs()) + "\n"; + } + + outsvg << "\n\n"; + outsvg.close(); + delete singleCalc; + + } + /******************* 2 Groups **************************/ + }else if (lookup.size() == 2) { - //calc the shared otu - int shared = 0; - int numA = 0; - int numB = 0; - - float rScaler; - - //for each bin - for (int i = 0; i < lookup[0]->size(); i++) { - if (lookup[0]->getAbundance(i) != 0) { numA++; } - if (lookup[1]->getAbundance(i) != 0) { numB++; } - //are they shared - if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { shared++; } + //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; + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); + + //make a file for each calculator + for(int i=0;igetRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg"; + + outputNames.push_back(filenamesvg); + m->openOutputFile(filenamesvg, outsvg); + + if (m->control_pressed) { outsvg.close(); return outputNames; } + + //get estimates for sharedAB + vector labels; + vector shared = vCalcs[i]->getValues(subset, labels); + + //in essence you want to run it like a single + if (vCalcs[i]->getName() == "sharedsobs") { + singleCalc = new Sobs(); + if (sharedOtus && (labels.size() != 0)) { + string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus"; + + outputNames.push_back(filenameShared); + ofstream outShared; + m->openOutputFile(filenameShared, outShared); + outShared << "Groups\tNumShared\tOTULabels\n"; + outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t' << labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + outShared.close(); + } + }else if (vCalcs[i]->getName() == "sharedchao") { + singleCalc = new Chao1(); + } + + int sharedVal, numSeqsA, numSeqsB, uniqSeqsToA, uniqSeqsToB; + if (nseqs) { + NSeqs* nseqsCalc = new NSeqs(); + vector data = nseqsCalc->getValues(lookup); + cout << data[0] << '\t' << data[1] << endl; + sharedVal = data[0] + data[1]; + numSeqsA = sabundA->getNumSeqs(); + numSeqsB = sabundB->getNumSeqs(); + uniqSeqsToA = numSeqsA-data[0]; + uniqSeqsToB = numSeqsB-data[1]; + + delete nseqsCalc; + } + + + //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=\"" + toString(int(0.25 * height)) + "\">" + lookup[0]->getGroup() + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.25 * height)) + "\">" + lookup[1]->getGroup() + "\n"; + outsvg << "" + toString(shared[0]) + "\n"; + outsvg << "The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]); + if (numA.size() == 3) { + outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]); + } + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared"; } + outsvg << "\n"; + + outsvg << "The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]); + if (numB.size() == 3) { + outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]); + } + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared"; } + outsvg << "\n"; + + outsvg << "The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(shared[0]); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal) + "; " + toString((sharedVal / (float)(numSeqsA + numSeqsB))*100) + "% of these sequences are shared"; } + outsvg << "\n"; + + outsvg << "Percentage of species that are shared in groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))*100) + "\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 **************************/ + + }else if (lookup.size() == 3) { - if (numA > numB) { rScaler = 150 / float(numA); } - else { rScaler = 150 / float(numB); } + height = 1600; + int windowSize = height; + - //to determine how far over to overlap b onto a. - float percentOverlap = shared / (float) numA; + //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;igetRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg"; - int mida = leftedgeA + ((leftedgeB - leftedgeA) / 2); - int midb = rightedgeA + ((rightedgeB - rightedgeA) / 2); - int midab = leftedgeB + ((rightedgeA - leftedgeB) / 2); + outputNames.push_back(filenamesvg); + m->openOutputFile(filenamesvg, outsvg); + + if (m->control_pressed) { outsvg.close(); return outputNames; } + + int sharedVal, sharedABVal, sharedACVal, sharedBCVal, numSeqsA, numSeqsB, numSeqsC, uniqSeqsToA, uniqSeqsToB, uniqSeqsToC; + + if (nseqs) { + NSeqs* nseqsCalc = new NSeqs(); + vector sharedData = nseqsCalc->getValues(lookup); + + vector mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); + vector sharedAB = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]); + vector sharedAC = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]); + vector sharedBC = nseqsCalc->getValues(mysubset); + + sharedVal = sharedData[0] + sharedData[1] + sharedData[2]; + sharedABVal = sharedAB[0] + sharedAB[1]; + sharedACVal = sharedAC[0] + sharedAC[1]; + sharedBCVal = sharedBC[0] + sharedBC[1]; + numSeqsA = sabundA->getNumSeqs(); + numSeqsB = sabundB->getNumSeqs(); + numSeqsC = sabundC->getNumSeqs(); + uniqSeqsToA = numSeqsA-sharedData[0]; + uniqSeqsToB = numSeqsC-sharedData[1]; + uniqSeqsToC = numSeqsB-sharedData[1]; + + delete nseqsCalc; + } + + + 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); + + + //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)), ""); + } + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(merge); + sharedAwithBC = vCalcs[i]->getValues(subset); + + 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)), ""); + } + + subset.clear(); + subset.push_back(merge); subset.push_back(lookup[1]); + sharedBwithAC = vCalcs[i]->getValues(subset); + + 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)), ""); + } + + 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; } - //draw circles - outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; - outsvg << ""; - outsvg << ""; - outsvg << "" + toString(numA-shared) + "\n"; - outsvg << "" + toString(shared) + "\n"; - outsvg << "" + toString(numB-shared) + "\n"; - outsvg << "Percentage of species that are shared is " + toString((shared / (float)(numA + numB - shared))) + "\n"; + //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 << ""; + + //place labels within overlaps + outsvg << "" + toString(numA[0]-sharedAwithBC[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[0]->getGroup() + "\n"; + outsvg << "" + toString(sharedAB[0] - sharedABC) + "\n"; + outsvg << "" + toString(numB[0]-sharedBwithAC[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[1]->getGroup() + "\n"; + outsvg << "" + toString(sharedAC[0] - sharedABC) + "\n"; + outsvg << "" + toString(numC[0]-sharedCwithAB[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.52 * height)) + "\">" + lookup[2]->getGroup() + "\n"; + outsvg << "" + toString(sharedBC[0] - sharedABC) + "\n"; + outsvg << "" + toString(sharedABC) + "\n"; + + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB[0]); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC[0]); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC[0]); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + " and combined groups " + lookup[1]->getGroup() + lookup[2]->getGroup() + " is " + toString(sharedAwithBC[0]) + "\n"; + outsvg << "The number of species shared between groups " + lookup[1]->getGroup() + " and combined groups " + lookup[0]->getGroup() + lookup[2]->getGroup() + " is " + toString(sharedBwithAC[0]) + "\n"; + outsvg << "The number of species shared between groups " + lookup[2]->getGroup() + " and combined groups " + lookup[0]->getGroup() + lookup[1]->getGroup() + " is " + toString(sharedCwithAB[0]) + "\n"; + outsvg << "The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]); + if (numA.size() == 3) { + outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]); + } + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared"; } + outsvg << "\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; - - //float scalerB; - - //for each bin - for (int i = 0; i < lookup[0]->size(); i++) { - if (lookup[0]->getAbundance(i) != 0) { numA++; } - if (lookup[1]->getAbundance(i) != 0) { numB++; } - if (lookup[2]->getAbundance(i) != 0) { numC++; } - //are they shared by 2 - if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { sharedAB++; } - if ((lookup[0]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0)) { sharedAC++; } - if ((lookup[2]->getAbundance(i) != 0) && (lookup[1]->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++; } - } - - //draw circles - outsvg << ""; - outsvg << "Venn Diagram at distance " + sharedorder->getLabel() + "\n"; - outsvg << ""; - outsvg << ""; - outsvg << ""; - - //place labels within overlaps - outsvg << "" + toString(numA-sharedAB-sharedAC+sharedABC) + "\n"; - outsvg << "" + toString(sharedAB) + "\n"; - outsvg << "" + toString(numB-sharedAB-sharedBC+sharedABC) + "\n"; - outsvg << "" + toString(sharedAC) + "\n"; - outsvg << "" + toString(numC-sharedAC-sharedBC+sharedABC) + "\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 / (float)(numA + numB - sharedAB))) + "\n"; - outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString((sharedAC / (float)(numA + numC - sharedAC))) + "\n"; - outsvg << "Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString((sharedBC / (float)(numB + numC - sharedBC))) + "\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 - (2 * sharedABC)))) + "\n"; - } - - outsvg << "\n\n"; - outsvg.close(); + outsvg << "The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]); + if (numB.size() == 3) { + outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]); + } + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared"; } + outsvg << "\n"; + + outsvg << "The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]); + if (numC.size() == 3) { + outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]); + } + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC) + "; " + toString(uniqSeqsToC) + " sequences are not shared"; } + 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 total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "\n"; + outsvg << "The total shared richness is " + toString(sharedABC); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal); } + outsvg << "\n"; + + delete singleCalc; + + }else { //sharedchao and sharedsobs are multigroup + + ofstream outShared; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) { + string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus"; + + outputNames.push_back(filenameShared); + + m->openOutputFile(filenameShared, outShared); + outShared << "Groups\tNumShared\tOTULabels\n"; + } + vector subset; - lookup.clear(); - - groupComb = ""; + //get estimates for numA + subset.push_back(lookup[0]); + vector numA = vCalcs[i]->getValues(subset); + + //get estimates for numB + subset.clear(); + subset.push_back(lookup[1]); + vector numB = vCalcs[i]->getValues(subset); + + //get estimates for numC + subset.clear(); + subset.push_back(lookup[2]); + vector numC = vCalcs[i]->getValues(subset); + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); + vector labels; + vector sharedab = vCalcs[i]->getValues(subset, labels); + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t' << labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[2]); + vector sharedac = vCalcs[i]->getValues(subset, labels); + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + + subset.clear(); + subset.push_back(lookup[1]); subset.push_back(lookup[2]); + vector sharedbc = vCalcs[i]->getValues(subset, labels); + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + + + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]); + vector sharedabc = vCalcs[i]->getValues(subset, labels); + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + outShared.close(); + } + + //image window + outsvg << "\n"; + outsvg << "\n"; + + //draw circles + outsvg << ""; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; + outsvg << ""; + outsvg << ""; + outsvg << ""; + + //place labels within overlaps + outsvg << "" + toString(numA[0]-sharedab[0]-sharedac[0]+sharedabc[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[0]->getGroup() + "\n"; + outsvg << "" + toString(sharedab[0] - sharedabc[0]) + "\n"; + outsvg << "" + toString(numB[0]-sharedab[0]-sharedbc[0]+sharedabc[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[1]->getGroup() + "\n"; + outsvg << "" + toString(sharedac[0] - sharedabc[0]) + "\n"; + outsvg << "" + toString(numC[0]-sharedac[0]-sharedbc[0]+sharedabc[0]) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.51 * height)) + "\">" + lookup[2]->getGroup() + "\n"; + outsvg << "" + toString(sharedbc[0] - sharedabc[0]) + "\n"; + outsvg << "" + toString(sharedabc[0]) + "\n"; + + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedab[0]); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedac[0]); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedbc[0]); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); } + outsvg << "\n"; + + outsvg << "The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]); + if (numA.size() == 3) { + outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]); + } + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA); } + outsvg << "\n"; + + outsvg << "The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]); + if (numB.size() == 3) { + outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]); + } + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB); } + outsvg << "\n"; + + outsvg << "The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]); + if (numC.size() == 3) { + outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]); + } + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC); } + 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[0]) + "\n"; + outsvg << "The total shared richness is " + toString(sharedabc[0]); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal); } + outsvg << "\n"; + + } + + //close file + outsvg << "\n\n"; + outsvg.close(); + + + } + + /******************* 4 Groups **************************/ - //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); - } + }else if (lookup.size() == 4) { + + height = 1600; + + int windowSize = height; - 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; + //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")) { m->mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups. It will be disregarded. "); m->mothurOutEndLine(); } + else{ + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg"; + outputNames.push_back(filenamesvg); + m->openOutputFile(filenamesvg, outsvg); + + if (m->control_pressed) { outsvg.close(); return outputNames; } + + //in essence you want to run it like a single + if (vCalcs[i]->getName() == "sharedsobs") { + singleCalc = new Sobs(); + }else if (vCalcs[i]->getName() == "sharedchao") { + singleCalc = new Chao1(); + } + + //get estimates for numA + data = singleCalc->getValues(sabundA); + numA = data[0]; + //cout << "num a = " << numA << endl; + + //get estimates for numB + data = singleCalc->getValues(sabundB); + numB = data[0]; + //cout << "num b = " << numB << endl; + //get estimates for numC + data = singleCalc->getValues(sabundC); + numC = data[0]; + //cout << "num c = " << numC << endl; + //get estimates for numD + data = singleCalc->getValues(sabundD); + numD = data[0]; +//cout << "num d = " << numD << endl; + + ofstream outShared; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) { + string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus"; + + outputNames.push_back(filenameShared); + + m->openOutputFile(filenameShared, outShared); + outShared << "Groups\tNumShared\tOTULabels\n"; + } + + //get estimates for pairs + subset.clear(); + vector labels; + subset.push_back(lookup[0]); subset.push_back(lookup[1]); + data = vCalcs[i]->getValues(subset, labels); + sharedAB = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + //cout << "num ab = " << sharedAB << endl; + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[2]); + data = vCalcs[i]->getValues(subset, labels); + sharedAC = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + //cout << "num ac = " << sharedAC << endl; + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset, labels); + sharedAD = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + //cout << "num ad = " << sharedAD << endl; + subset.clear(); + subset.push_back(lookup[1]); subset.push_back(lookup[2]); + data = vCalcs[i]->getValues(subset, labels); + sharedBC = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + //cout << "num bc = " << sharedBC << endl; + subset.clear(); + subset.push_back(lookup[1]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset, labels); + sharedBD = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[1]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + //cout << "num bd = " << sharedBD << endl; + subset.clear(); + subset.push_back(lookup[2]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset, labels); + sharedCD = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[2]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + + //cout << "num cd = " << sharedCD << endl; + //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, labels); + sharedABC = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup()+ "-" + lookup[2]->getGroup()<< '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + //cout << "num abc = " << sharedABC << endl; + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset, labels); + sharedACD = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + } + //cout << "num acd = " << sharedACD << endl; + subset.clear(); + subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset,labels); + sharedBCD = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + outShared << labels[labels.size()-1]; + outShared << endl; + } + //cout << "num bcd = " << sharedBCD << endl; + subset.clear(); + subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]); + data = vCalcs[i]->getValues(subset, labels); + sharedABD = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + outShared << labels[labels.size()-1]; + outShared << endl; + } +//cout << "num abd = " << sharedABD << endl; + //get estimate for all four + data = vCalcs[i]->getValues(lookup, labels); + sharedABCD = data[0]; + if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) { + outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t'; + for (int k = 0; k < labels.size()-1; k++) { + outShared << labels[k] << ","; + } + if (labels.size() != 0) { outShared << labels[labels.size()-1]; } + outShared << endl; + outShared.close(); + } + //cout << "num abcd = " << sharedABCD << endl << endl; + int sharedVal, sharedABCVal, sharedABDVal, sharedACDVal, sharedBCDVal, sharedABVal, sharedACVal, sharedADVal, sharedBCVal, sharedBDVal, sharedCDVal, numSeqsA, numSeqsB, numSeqsC, numSeqsD; + + if (nseqs) { + NSeqs* nseqsCalc = new NSeqs(); + vector sharedData = nseqsCalc->getValues(lookup); + + vector mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); + vector sharedAB = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]); + vector sharedAC = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[3]); + vector sharedAD = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]); + vector sharedBC = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]); + vector sharedBD = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]); + vector sharedCD = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]); + vector sharedABC = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]); + vector sharedABD = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]); + vector sharedACD = nseqsCalc->getValues(mysubset); + + mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]); + vector sharedBCD = nseqsCalc->getValues(mysubset); + + sharedVal = sharedData[0] + sharedData[1] + sharedData[2] + sharedData[3]; + sharedABCVal = sharedABC[0] + sharedABC[1] + sharedABC[2]; + sharedABDVal = sharedABD[0] + sharedABD[1] + sharedABD[2]; + sharedACDVal = sharedACD[0] + sharedACD[1] + sharedACD[2]; + sharedBCDVal = sharedBCD[0] + sharedBCD[1] + sharedBCD[2]; + sharedABVal = sharedAB[0] + sharedAB[1]; + sharedACVal = sharedAC[0] + sharedAC[1]; + sharedADVal = sharedAD[0] + sharedAD[1]; + sharedBCVal = sharedBC[0] + sharedBC[1]; + sharedBDVal = sharedBD[0] + sharedBD[1]; + sharedCDVal = sharedCD[0] + sharedCD[1]; + numSeqsA = sabundA->getNumSeqs(); + numSeqsB = sabundB->getNumSeqs(); + numSeqsC = sabundC->getNumSeqs(); + numSeqsD = sabundD->getNumSeqs(); + + delete nseqsCalc; + } + + + //image window + outsvg << "\n"; + outsvg << "\n"; + outsvg << ""; + outsvg << "Venn Diagram at distance " + lookup[0]->getLabel() + "\n"; + + outsvg << "The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA); + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA); } + outsvg << "\n"; + outsvg << "The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB); + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB); } + outsvg << "\n"; + outsvg << "The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC); + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC); } + outsvg << "\n"; + outsvg << "The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD); + if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsD); } + outsvg << "\n"; + + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedAD); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedADVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBD); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBDVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedCD); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedCDVal); } + outsvg << "\n"; + + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedABC); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABCVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedABD); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABDVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedACD); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACDVal); } + outsvg << "\n"; + outsvg << "The number of species shared between groups " + lookup[1]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBCD); + if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCDVal); } + outsvg << "\n"; + + //make adjustments + sharedABC = sharedABC - sharedABCD; + //cout << "num abc = " << sharedABC << endl; + sharedABD = sharedABD - sharedABCD; + //cout << "num abd = " << sharedABD << endl; + sharedACD = sharedACD - sharedABCD; + //cout << "num acd = " << sharedACD << endl; + sharedBCD = sharedBCD - sharedABCD; + //cout << "num bcd = " << sharedBCD << endl; + + sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD; //cout << "num ab = " << sharedAB << endl; + sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD; //cout << "num ac = " << sharedAC << endl; + sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD; //cout << "num ad = " << sharedAD << endl; + sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD; //cout << "num bc = " << sharedBC << endl; + sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl; + sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD; //cout << "num cd = " << sharedCD << endl; + + numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD; + //cout << "num a = " << numA << endl; + numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD; + //cout << "num b = " << numB << endl; + numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD; + //cout << "num c = " << numC << endl; + numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD; + //cout << "num d = " << numD << endl; + + //draw circles + 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=\"" + toString(int(0.11 * height)) + "\">" + lookup[0]->getGroup() + "\n"; + outsvg << "" + toString(sharedAB) + "\n"; + outsvg << "" + toString(numB) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.11 * height)) + "\">" + lookup[1]->getGroup() + "\n"; + outsvg << "" + toString(sharedAC) + "\n"; + outsvg << "" + toString(numC) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.26 * height)) + "\">" + lookup[2]->getGroup() + "\n"; + outsvg << "" + toString(sharedBD) + "\n"; + outsvg << "" + toString(numD) + "\n"; + outsvg << "getGroup().length() / 2)) + "\" y=\"" + toString(int(0.26 * height)) + "\">" + lookup[3]->getGroup() + "\n"; + outsvg << "" + toString(sharedAD) + "\n"; + outsvg << "" + toString(sharedBC) + "\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)); + if (nseqs) { outsvg << ", and the number of squences in the otus shared by all groups is " + toString(sharedVal); } + outsvg << "\n"; + + outsvg << "\n\n"; + outsvg.close(); + delete singleCalc; } } } + return outputNames; + } 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"; + m->errorOut(e, "Venn", "getPic"); 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"; - exit(1); - } - } -//********************************************************************************************************************** -