+ //get estimates for sharedAB, sharedAC and sharedBC
+ subset.clear();
+ subset.push_back(lookup[0]); subset.push_back(lookup[1]);
+ vector<double> sharedAB = vCalcs[i]->getValues(subset);
+
+ subset.clear();
+ subset.push_back(lookup[0]); subset.push_back(lookup[2]);
+ vector<double> sharedAC = vCalcs[i]->getValues(subset);
+
+ subset.clear();
+ subset.push_back(lookup[1]); subset.push_back(lookup[2]);
+ vector<double> sharedBC = vCalcs[i]->getValues(subset);
+
+ vector<double> sharedAwithBC;
+ vector<double> sharedBwithAC;
+ vector<double> 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; }
+
+ //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<double> 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 << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/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 " + lookup[0]->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(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</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(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</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(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</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 species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"680\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"700\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The number of species shared between groups " + lookup[0]->getGroup() + " and combined groups " + lookup[1]->getGroup() + lookup[2]->getGroup() + " is " + toString(sharedAwithBC[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"740\">The number of species shared between groups " + lookup[1]->getGroup() + " and combined groups " + lookup[0]->getGroup() + lookup[2]->getGroup() + " is " + toString(sharedBwithAC[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"760\">The number of species shared between groups " + lookup[2]->getGroup() + " and combined groups " + lookup[0]->getGroup() + lookup[1]->getGroup() + " is " + toString(sharedCwithAB[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">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]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">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]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">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]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"780\">The total shared richness is " + toString(sharedABC) + "</text>\n";
+
+ delete singleCalc;
+
+ }else { //sharedchao and sharedsobs are multigroup
+
+ vector<SharedRAbundVector*> subset;
+
+ //get estimates for numA
+ subset.push_back(lookup[0]);
+ vector<double> numA = vCalcs[i]->getValues(subset);
+
+ //get estimates for numB
+ subset.clear();
+ subset.push_back(lookup[1]);
+ vector<double> numB = vCalcs[i]->getValues(subset);
+
+ //get estimates for numC
+ subset.clear();
+ subset.push_back(lookup[2]);
+ vector<double> numC = vCalcs[i]->getValues(subset);
+
+ subset.clear();
+ subset.push_back(lookup[0]); subset.push_back(lookup[1]);
+ vector<double> sharedab = vCalcs[i]->getValues(subset);
+
+ subset.clear();
+ subset.push_back(lookup[0]); subset.push_back(lookup[2]);
+ vector<double> sharedac = vCalcs[i]->getValues(subset);
+
+ subset.clear();
+ subset.push_back(lookup[1]); subset.push_back(lookup[2]);
+ vector<double> sharedbc = vCalcs[i]->getValues(subset);
+
+ subset.clear();
+ subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
+ vector<double> sharedabc = vCalcs[i]->getValues(subset);
+
+ //image window
+ outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/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 " + lookup[0]->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]-sharedab[0]-sharedac[0]+sharedabc[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedab[0]-sharedac[0]+sharedabc[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedab[0] - sharedabc[0]).length() / 2)) + "\" y=\"170\">" + toString(sharedab[0] - sharedabc[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedab[0]-sharedbc[0]+sharedabc[0]).length() / 2)) + "\" y=\"170\">" + toString(numB[0]-sharedab[0]-sharedbc[0]+sharedabc[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedac[0] - sharedabc[0]).length() / 2)) + "\" y=\"305\">" + toString(sharedac[0] - sharedabc[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(numC[0]-sharedac[0]-sharedbc[0]+sharedabc[0]).length() / 2)) + "\" y=\"430\">" + toString(numC[0]-sharedac[0]-sharedbc[0]+sharedabc[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedbc[0] - sharedabc[0]).length() / 2)) + "\" y=\"305\">" + toString(sharedbc[0] - sharedabc[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedabc[0]).length() / 2)) + "\" y=\"280\">" + toString(sharedabc[0]) + "</text>\n";
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"660\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedab[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"680\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedac[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"700\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedbc[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">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]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">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]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">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]) + "</text>\n";
+ }else { outsvg << "</text>\n"; }
+
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedab[0] - sharedac[0] - sharedbc[0] + sharedabc[0]) + "</text>\n";
+ outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The total shared richness is " + toString(sharedabc[0]) + "</text>\n";
+
+
+ }