5 * Created by Sarah Westcott on 3/30/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
14 #include "sharedchao1.h"
15 #include "sharedsobscollectsummary.h"
18 //**********************************************************************************************************************
19 Venn::Venn(string o) : outputDir(o) {
21 globaldata = GlobalData::getInstance();
25 errorOut(e, "Venn", "Venn");
29 //**********************************************************************************************************************
30 void Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
33 for(int i=0;i<vCalcs.size();i++){
34 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
35 openOutputFile(filenamesvg, outsvg);
37 vector<double> data = vCalcs[i]->getValues(sabund);
40 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
43 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
44 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sabund->getLabel() + "</text>\n";
45 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>";
46 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";
48 if (data.size() == 3) {
49 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
50 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
53 outsvg << "</g>\n</svg>\n";
58 errorOut(e, "Venn", "getPic");
62 //**********************************************************************************************************************
63 void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
66 vector<SharedRAbundVector*> subset;
68 /******************* 1 Group **************************/
69 if (lookup.size() == 1) {
72 s = lookup[0]->getSAbundVector(); SAbundVector* sabund = &s;
74 //make a file for each calculator
75 for(int i=0;i<vCalcs.size();i++){
76 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
77 openOutputFile(filenamesvg, outsvg);
79 //in essence you want to run it like a single
80 if (vCalcs[i]->getName() == "sharedsobs") {
81 singleCalc = new Sobs();
82 }else if (vCalcs[i]->getName() == "sharedchao") {
83 singleCalc = new Chao1();
84 }else if (vCalcs[i]->getName() == "sharedace") {
85 singleCalc = new Ace(10);
88 vector<double> data = singleCalc->getValues(sabund);
91 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
94 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
95 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
96 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>";
97 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "</text>\n";
98 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";
100 if (data.size() == 3) {
101 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
102 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
105 outsvg << "</g>\n</svg>\n";
110 /******************* 2 Groups **************************/
112 }else if (lookup.size() == 2) {
113 //get sabund vector pointers so you can use the single calculators
116 SAbundVector* sabundA; SAbundVector* sabundB;
117 sabundA = new SAbundVector(lookup[0]->getSAbundVector());// sabundA = &sA;
118 sabundB = new SAbundVector(lookup[1]->getSAbundVector());// sabundB = &sB;
121 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
123 //make a file for each calculator
124 for(int i=0;i<vCalcs.size();i++){
125 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
126 openOutputFile(filenamesvg, outsvg);
128 //get estimates for sharedAB
129 vector<double> shared = vCalcs[i]->getValues(subset);
131 //in essence you want to run it like a single
132 if (vCalcs[i]->getName() == "sharedsobs") {
133 singleCalc = new Sobs();
134 }else if (vCalcs[i]->getName() == "sharedchao") {
135 singleCalc = new Chao1();
136 }//else if (vCalcs[i]->getName() == "sharedace") {
137 //singleCalc = new Ace(10);
140 //get estimates for numA
141 vector<double> numA = singleCalc->getValues(sabundA);
143 //get estimates for numB
144 vector<double> numB = singleCalc->getValues(sabundB);
147 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
151 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
152 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
153 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>";
154 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>";
155 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
156 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n";
157 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "</text>\n";
158 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "</text>\n";
159 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";
160 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
161 if (numA.size() == 3) {
162 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
163 }else { outsvg << "</text>\n"; }
165 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
166 if (numB.size() == 3) {
167 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
168 }else { outsvg << "</text>\n"; }
170 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"500\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(shared[0]) + "</text>\n";
171 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))*100) + "</text>\n";
172 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"540\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0])) + "</text>\n";
175 outsvg << "</g>\n</svg>\n";
179 /******************* 3 Groups **************************/
181 }else if (lookup.size() == 3) {
182 //get sabund vector pointers so you can use the single calculators
184 SAbundVector sA, sB, sC;
185 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
186 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
187 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
188 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
190 //make a file for each calculator
191 for(int i=0;i<vCalcs.size();i++){
194 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
195 openOutputFile(filenamesvg, outsvg);
197 if (vCalcs[i]->getName() == "sharedace") {
199 singleCalc = new Ace(10);
201 //get estimates for numA
202 vector<double> numA = singleCalc->getValues(sabundA);
204 //get estimates for numB
205 vector<double> numB = singleCalc->getValues(sabundB);
207 //get estimates for numC
208 vector<double> numC = singleCalc->getValues(sabundC);
211 //get estimates for sharedAB, sharedAC and sharedBC
213 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
214 vector<double> sharedAB = vCalcs[i]->getValues(subset);
217 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
218 vector<double> sharedAC = vCalcs[i]->getValues(subset);
221 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
222 vector<double> sharedBC = vCalcs[i]->getValues(subset);
224 vector<double> sharedAwithBC;
225 vector<double> sharedBwithAC;
226 vector<double> sharedCwithAB;
228 //find possible sharedABC values
229 float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
231 if (vCalcs[i]->getMultiple() == false) {
232 //merge BC and estimate with shared with A
233 SharedRAbundVector* merge = new SharedRAbundVector();
234 for (int j = 0; j < lookup[1]->size(); j++) {
235 merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
239 subset.push_back(lookup[0]); subset.push_back(merge);
240 sharedAwithBC = vCalcs[i]->getValues(subset);
243 //merge AC and estimate with shared with B
244 merge = new SharedRAbundVector();
245 for (int j = 0; j < lookup[0]->size(); j++) {
246 merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
250 subset.push_back(merge); subset.push_back(lookup[1]);
251 sharedBwithAC = vCalcs[i]->getValues(subset);
254 //merge AB and estimate with shared with C
255 merge = new SharedRAbundVector();
256 for (int j = 0; j < lookup[0]->size(); j++) {
257 merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), "");
261 subset.push_back(lookup[2]); subset.push_back(merge);
262 sharedCwithAB = vCalcs[i]->getValues(subset);
265 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
266 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
267 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
269 //if any of the possible m's are - throw them out
270 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
271 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
272 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
274 //sharedABC is the minimum of the 3 possibilities
275 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
276 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
277 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }
279 vector<double> data = vCalcs[i]->getValues(lookup);
281 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
282 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
283 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
287 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";
291 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>";
292 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
293 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>";
294 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>";
295 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>";
297 //place labels within overlaps
298 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";
299 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";
300 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\" y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";
301 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";
302 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</text>\n";
303 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";
304 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";
305 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</text>\n";
306 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";
307 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"280\">" + toString(sharedABC) + "</text>\n";
309 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";
310 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";
311 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";
312 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";
313 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";
314 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";
315 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
316 if (numA.size() == 3) {
317 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
318 }else { outsvg << "</text>\n"; }
320 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
321 if (numB.size() == 3) {
322 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
323 }else { outsvg << "</text>\n"; }
325 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
326 if (numC.size() == 3) {
327 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
328 }else { outsvg << "</text>\n"; }
330 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";
331 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"780\">The total shared richness is " + toString(sharedABC) + "</text>\n";
335 }else { //sharedchao and sharedsobs are multigroup
337 vector<SharedRAbundVector*> subset;
339 //get estimates for numA
340 subset.push_back(lookup[0]);
341 vector<double> numA = vCalcs[i]->getValues(subset);
343 //get estimates for numB
345 subset.push_back(lookup[1]);
346 vector<double> numB = vCalcs[i]->getValues(subset);
348 //get estimates for numC
350 subset.push_back(lookup[2]);
351 vector<double> numC = vCalcs[i]->getValues(subset);
354 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
355 vector<double> sharedab = vCalcs[i]->getValues(subset);
358 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
359 vector<double> sharedac = vCalcs[i]->getValues(subset);
362 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
363 vector<double> sharedbc = vCalcs[i]->getValues(subset);
366 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
367 vector<double> sharedabc = vCalcs[i]->getValues(subset);
370 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";
374 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>";
375 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
376 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>";
377 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>";
378 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>";
380 //place labels within overlaps
381 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";
382 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";
383 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";
384 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";
385 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</text>\n";
386 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";
387 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";
388 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</text>\n";
389 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";
390 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedabc[0]).length() / 2)) + "\" y=\"280\">" + toString(sharedabc[0]) + "</text>\n";
392 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";
393 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";
394 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";
395 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
396 if (numA.size() == 3) {
397 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
398 }else { outsvg << "</text>\n"; }
400 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
401 if (numB.size() == 3) {
402 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
403 }else { outsvg << "</text>\n"; }
405 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
406 if (numC.size() == 3) {
407 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
408 }else { outsvg << "</text>\n"; }
410 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";
411 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The total shared richness is " + toString(sharedabc[0]) + "</text>\n";
418 outsvg << "</g>\n</svg>\n";
424 /******************* 4 Groups **************************/
426 }else if (lookup.size() == 4) {
427 //calc the shared otu
428 float sharedABCD = 0;
429 float numA = 0; float numB = 0; float numC = 0; float numD = 0;
430 float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
431 float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
433 //get sabund vector pointers so you can use the single calculators
435 SAbundVector sA, sB, sC, sD;
436 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
437 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
438 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
439 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
440 sD = lookup[3]->getSAbundVector(); sabundD = &sD;
442 //A = red, B = green, C = blue, D = yellow
444 //make a file for each calculator
445 for(int i=0;i<vCalcs.size();i++){
447 if ((vCalcs[i]->getName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups. It will be disregarded. "); mothurOutEndLine(); }
449 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
450 openOutputFile(filenamesvg, outsvg);
453 //in essence you want to run it like a single
454 if (vCalcs[i]->getName() == "sharedsobs") {
455 singleCalc = new Sobs();
456 }else if (vCalcs[i]->getName() == "sharedchao") {
457 singleCalc = new Chao1();
460 //get estimates for numA
461 data = singleCalc->getValues(sabundA);
463 //cout << "num a = " << numA << endl;
465 //get estimates for numB
466 data = singleCalc->getValues(sabundB);
468 //cout << "num b = " << numB << endl;
469 //get estimates for numC
470 data = singleCalc->getValues(sabundC);
472 //cout << "num c = " << numC << endl;
473 //get estimates for numD
474 data = singleCalc->getValues(sabundD);
476 //cout << "num d = " << numD << endl;
478 //get estimates for pairs
480 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
481 data = vCalcs[i]->getValues(subset);
483 //cout << "num ab = " << sharedAB << endl;
485 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
486 data = vCalcs[i]->getValues(subset);
488 //cout << "num ac = " << sharedAC << endl;
490 subset.push_back(lookup[0]); subset.push_back(lookup[3]);
491 data = vCalcs[i]->getValues(subset);
493 //cout << "num ad = " << sharedAD << endl;
495 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
496 data = vCalcs[i]->getValues(subset);
498 //cout << "num bc = " << sharedBC << endl;
500 subset.push_back(lookup[1]); subset.push_back(lookup[3]);
501 data = vCalcs[i]->getValues(subset);
503 //cout << "num bd = " << sharedBD << endl;
505 subset.push_back(lookup[2]); subset.push_back(lookup[3]);
506 data = vCalcs[i]->getValues(subset);
509 //cout << "num cd = " << sharedCD << endl;
510 //get estimates for combos of 3
512 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
513 data = vCalcs[i]->getValues(subset);
515 //cout << "num abc = " << sharedABC << endl;
517 subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
518 data = vCalcs[i]->getValues(subset);
520 //cout << "num acd = " << sharedACD << endl;
522 subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
523 data = vCalcs[i]->getValues(subset);
525 //cout << "num bcd = " << sharedBCD << endl;
527 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
528 data = vCalcs[i]->getValues(subset);
530 //cout << "num abd = " << sharedABD << endl;
531 //get estimate for all four
532 data = vCalcs[i]->getValues(lookup);
533 sharedABCD = data[0];
534 //cout << "num abcd = " << sharedABCD << endl << endl;
539 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 700 800\" >\n";
541 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"800\"/>";
542 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
544 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"490\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA) + "</text>\n";
545 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"510\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB) + "</text>\n";
546 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"530\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC) + "</text>\n";
547 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"550\">The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD) + "</text>\n";
549 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"570\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB) + "</text>\n";
550 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"590\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC) + "</text>\n";
551 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"610\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedAD) + "</text>\n";
552 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"630\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC) + "</text>\n";
553 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"650\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBD) + "</text>\n";
554 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"670\">The number of species shared between groups " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedCD) + "</text>\n";
556 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"690\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedABC) + "</text>\n";
557 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"710\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedABD) + "</text>\n";
558 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"730\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedACD) + "</text>\n";
559 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"750\">The number of species shared between groups " + lookup[1]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBCD) + "</text>\n";
562 sharedABC = sharedABC - sharedABCD;
563 //cout << "num abc = " << sharedABC << endl;
564 sharedABD = sharedABD - sharedABCD;
565 //cout << "num abd = " << sharedABD << endl;
566 sharedACD = sharedACD - sharedABCD;
567 //cout << "num acd = " << sharedACD << endl;
568 sharedBCD = sharedBCD - sharedABCD;
569 //cout << "num bcd = " << sharedBCD << endl;
571 sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD; //cout << "num ab = " << sharedAB << endl;
572 sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD; //cout << "num ac = " << sharedAC << endl;
573 sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD; //cout << "num ad = " << sharedAD << endl;
574 sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD; //cout << "num bc = " << sharedBC << endl;
575 sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl;
576 sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD; //cout << "num cd = " << sharedCD << endl;
578 numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
579 //cout << "num a = " << numA << endl;
580 numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
581 //cout << "num b = " << numB << endl;
582 numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
583 //cout << "num c = " << numC << endl;
584 numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
585 //cout << "num d = " << numD << endl;
588 outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
589 outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
590 outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 440 315) \" cx=\"440\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
591 outsvg << "<ellipse fill=\"yellow\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+40 270 315) \" cx=\"270\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
593 //A = red, B = green, C = blue, D = yellow
595 //place labels within overlaps
596 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n";
597 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";
598 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\" y=\"160\">" + toString(sharedAB) + "</text>\n";
599 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\" y=\"110\">" + toString(numB) + "</text>\n";
600 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[1]->getGroup() + "</text>\n";
601 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\" y=\"190\">" + toString(sharedAC) + "</text>\n";
602 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\" y=\"230\">" + toString(numC) + "</text>\n";
603 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
604 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBD).length() / 2)) + "\" y=\"190\">" + toString(sharedBD) + "</text>\n";
605 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\" y=\"230\">" + toString(numD) + "</text>\n";
606 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\" y=\"210\">" + lookup[3]->getGroup() + "</text>\n";
607 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedAD).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n";
608 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBC) + "</text>\n";
609 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n";
610 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(275 - ((int)toString(sharedABD).length() / 2)) + "\" y=\"240\">" + toString(sharedABD) + "</text>\n";
611 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(400 - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"360\">" + toString(sharedBCD) + "</text>\n";
612 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n";
613 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"240\">" + toString(sharedABC) + "</text>\n";
614 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\" y=\"320\">" + toString(sharedABCD) + "</text>\n";
618 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"770\">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)) + "</text>\n";
621 outsvg << "</g>\n</svg>\n";
629 catch(exception& e) {
630 errorOut(e, "Venn", "getPic");