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();
22 m = MothurOut::getInstance();
26 m->errorOut(e, "Venn", "Venn");
30 //**********************************************************************************************************************
31 vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
34 vector<string> outputNames;
36 for(int i=0;i<vCalcs.size();i++){
37 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
38 outputNames.push_back(filenamesvg);
39 openOutputFile(filenamesvg, outsvg);
41 if (m->control_pressed) { outsvg.close(); return outputNames; }
43 vector<double> data = vCalcs[i]->getValues(sabund);
46 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";
49 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
50 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sabund->getLabel() + "</text>\n";
51 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>";
52 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";
54 if (data.size() == 3) {
55 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
56 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
59 outsvg << "</g>\n</svg>\n";
66 m->errorOut(e, "Venn", "getPic");
70 //**********************************************************************************************************************
71 vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
74 vector<SharedRAbundVector*> subset;
75 vector<string> outputNames;
77 /******************* 1 Group **************************/
78 if (lookup.size() == 1) {
81 s = lookup[0]->getSAbundVector(); SAbundVector* sabund = &s;
83 //make a file for each calculator
84 for(int i=0;i<vCalcs.size();i++){
85 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
86 outputNames.push_back(filenamesvg);
87 openOutputFile(filenamesvg, outsvg);
89 if (m->control_pressed) { outsvg.close(); return outputNames; }
91 //in essence you want to run it like a single
92 if (vCalcs[i]->getName() == "sharedsobs") {
93 singleCalc = new Sobs();
94 }else if (vCalcs[i]->getName() == "sharedchao") {
95 singleCalc = new Chao1();
96 }else if (vCalcs[i]->getName() == "sharedace") {
97 singleCalc = new Ace(10);
100 vector<double> data = singleCalc->getValues(sabund);
103 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";
106 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
107 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
108 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>";
109 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "</text>\n";
110 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";
112 if (data.size() == 3) {
113 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
114 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
117 outsvg << "</g>\n</svg>\n";
122 /******************* 2 Groups **************************/
124 }else if (lookup.size() == 2) {
125 //get sabund vector pointers so you can use the single calculators
128 SAbundVector* sabundA; SAbundVector* sabundB;
129 sabundA = new SAbundVector(lookup[0]->getSAbundVector());// sabundA = &sA;
130 sabundB = new SAbundVector(lookup[1]->getSAbundVector());// sabundB = &sB;
133 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
135 //make a file for each calculator
136 for(int i=0;i<vCalcs.size();i++){
137 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
138 outputNames.push_back(filenamesvg);
139 openOutputFile(filenamesvg, outsvg);
141 if (m->control_pressed) { outsvg.close(); return outputNames; }
143 //get estimates for sharedAB
144 vector<double> shared = vCalcs[i]->getValues(subset);
146 //in essence you want to run it like a single
147 if (vCalcs[i]->getName() == "sharedsobs") {
148 singleCalc = new Sobs();
149 }else if (vCalcs[i]->getName() == "sharedchao") {
150 singleCalc = new Chao1();
151 }//else if (vCalcs[i]->getName() == "sharedace") {
152 //singleCalc = new Ace(10);
155 //get estimates for numA
156 vector<double> numA = singleCalc->getValues(sabundA);
158 //get estimates for numB
159 vector<double> numB = singleCalc->getValues(sabundB);
162 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";
166 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
167 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
168 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>";
169 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>";
170 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
171 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n";
172 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "</text>\n";
173 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "</text>\n";
174 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";
175 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
176 if (numA.size() == 3) {
177 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
178 }else { outsvg << "</text>\n"; }
180 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
181 if (numB.size() == 3) {
182 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
183 }else { outsvg << "</text>\n"; }
185 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";
186 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";
187 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";
190 outsvg << "</g>\n</svg>\n";
194 /******************* 3 Groups **************************/
196 }else if (lookup.size() == 3) {
197 //get sabund vector pointers so you can use the single calculators
199 SAbundVector sA, sB, sC;
200 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
201 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
202 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
203 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
205 //make a file for each calculator
206 for(int i=0;i<vCalcs.size();i++){
208 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
209 outputNames.push_back(filenamesvg);
210 openOutputFile(filenamesvg, outsvg);
212 if (m->control_pressed) { outsvg.close(); return outputNames; }
214 if (vCalcs[i]->getName() == "sharedace") {
216 singleCalc = new Ace(10);
218 //get estimates for numA
219 vector<double> numA = singleCalc->getValues(sabundA);
221 //get estimates for numB
222 vector<double> numB = singleCalc->getValues(sabundB);
224 //get estimates for numC
225 vector<double> numC = singleCalc->getValues(sabundC);
228 //get estimates for sharedAB, sharedAC and sharedBC
230 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
231 vector<double> sharedAB = vCalcs[i]->getValues(subset);
234 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
235 vector<double> sharedAC = vCalcs[i]->getValues(subset);
238 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
239 vector<double> sharedBC = vCalcs[i]->getValues(subset);
241 vector<double> sharedAwithBC;
242 vector<double> sharedBwithAC;
243 vector<double> sharedCwithAB;
245 //find possible sharedABC values
246 float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
248 if (vCalcs[i]->getMultiple() == false) {
249 //merge BC and estimate with shared with A
250 SharedRAbundVector* merge = new SharedRAbundVector();
251 for (int j = 0; j < lookup[1]->size(); j++) {
252 merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
256 subset.push_back(lookup[0]); subset.push_back(merge);
257 sharedAwithBC = vCalcs[i]->getValues(subset);
260 //merge AC and estimate with shared with B
261 merge = new SharedRAbundVector();
262 for (int j = 0; j < lookup[0]->size(); j++) {
263 merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
267 subset.push_back(merge); subset.push_back(lookup[1]);
268 sharedBwithAC = vCalcs[i]->getValues(subset);
271 //merge AB and estimate with shared with C
272 merge = new SharedRAbundVector();
273 for (int j = 0; j < lookup[0]->size(); j++) {
274 merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), "");
278 subset.push_back(lookup[2]); subset.push_back(merge);
279 sharedCwithAB = vCalcs[i]->getValues(subset);
282 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
283 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
284 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
286 //if any of the possible m's are - throw them out
287 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
288 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
289 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
291 //sharedABC is the minimum of the 3 possibilities
292 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
293 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
294 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }
296 vector<double> data = vCalcs[i]->getValues(lookup);
298 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
299 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
300 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
304 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";
308 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>";
309 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
310 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>";
311 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>";
312 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>";
314 //place labels within overlaps
315 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";
316 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";
317 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\" y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";
318 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";
319 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</text>\n";
320 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";
321 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";
322 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</text>\n";
323 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";
324 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"280\">" + toString(sharedABC) + "</text>\n";
326 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";
327 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";
328 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";
329 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";
330 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";
331 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";
332 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
333 if (numA.size() == 3) {
334 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
335 }else { outsvg << "</text>\n"; }
337 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
338 if (numB.size() == 3) {
339 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
340 }else { outsvg << "</text>\n"; }
342 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
343 if (numC.size() == 3) {
344 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
345 }else { outsvg << "</text>\n"; }
347 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";
348 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"780\">The total shared richness is " + toString(sharedABC) + "</text>\n";
352 }else { //sharedchao and sharedsobs are multigroup
354 vector<SharedRAbundVector*> subset;
356 //get estimates for numA
357 subset.push_back(lookup[0]);
358 vector<double> numA = vCalcs[i]->getValues(subset);
360 //get estimates for numB
362 subset.push_back(lookup[1]);
363 vector<double> numB = vCalcs[i]->getValues(subset);
365 //get estimates for numC
367 subset.push_back(lookup[2]);
368 vector<double> numC = vCalcs[i]->getValues(subset);
371 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
372 vector<double> sharedab = vCalcs[i]->getValues(subset);
375 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
376 vector<double> sharedac = vCalcs[i]->getValues(subset);
379 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
380 vector<double> sharedbc = vCalcs[i]->getValues(subset);
383 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
384 vector<double> sharedabc = vCalcs[i]->getValues(subset);
387 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";
391 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>";
392 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
393 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>";
394 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>";
395 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>";
397 //place labels within overlaps
398 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";
399 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";
400 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";
401 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";
402 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</text>\n";
403 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";
404 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";
405 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</text>\n";
406 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";
407 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedabc[0]).length() / 2)) + "\" y=\"280\">" + toString(sharedabc[0]) + "</text>\n";
409 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";
410 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";
411 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";
412 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
413 if (numA.size() == 3) {
414 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
415 }else { outsvg << "</text>\n"; }
417 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
418 if (numB.size() == 3) {
419 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
420 }else { outsvg << "</text>\n"; }
422 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
423 if (numC.size() == 3) {
424 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
425 }else { outsvg << "</text>\n"; }
427 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";
428 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The total shared richness is " + toString(sharedabc[0]) + "</text>\n";
435 outsvg << "</g>\n</svg>\n";
441 /******************* 4 Groups **************************/
443 }else if (lookup.size() == 4) {
444 //calc the shared otu
445 float sharedABCD = 0;
446 float numA = 0; float numB = 0; float numC = 0; float numD = 0;
447 float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
448 float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
450 //get sabund vector pointers so you can use the single calculators
452 SAbundVector sA, sB, sC, sD;
453 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
454 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
455 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
456 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
457 sD = lookup[3]->getSAbundVector(); sabundD = &sD;
459 //A = red, B = green, C = blue, D = yellow
461 //make a file for each calculator
462 for(int i=0;i<vCalcs.size();i++){
464 if ((vCalcs[i]->getName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { m->mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups. It will be disregarded. "); m->mothurOutEndLine(); }
466 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
467 outputNames.push_back(filenamesvg);
468 openOutputFile(filenamesvg, outsvg);
470 if (m->control_pressed) { outsvg.close(); return outputNames; }
472 //in essence you want to run it like a single
473 if (vCalcs[i]->getName() == "sharedsobs") {
474 singleCalc = new Sobs();
475 }else if (vCalcs[i]->getName() == "sharedchao") {
476 singleCalc = new Chao1();
479 //get estimates for numA
480 data = singleCalc->getValues(sabundA);
482 //cout << "num a = " << numA << endl;
484 //get estimates for numB
485 data = singleCalc->getValues(sabundB);
487 //cout << "num b = " << numB << endl;
488 //get estimates for numC
489 data = singleCalc->getValues(sabundC);
491 //cout << "num c = " << numC << endl;
492 //get estimates for numD
493 data = singleCalc->getValues(sabundD);
495 //cout << "num d = " << numD << endl;
497 //get estimates for pairs
499 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
500 data = vCalcs[i]->getValues(subset);
502 //cout << "num ab = " << sharedAB << endl;
504 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
505 data = vCalcs[i]->getValues(subset);
507 //cout << "num ac = " << sharedAC << endl;
509 subset.push_back(lookup[0]); subset.push_back(lookup[3]);
510 data = vCalcs[i]->getValues(subset);
512 //cout << "num ad = " << sharedAD << endl;
514 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
515 data = vCalcs[i]->getValues(subset);
517 //cout << "num bc = " << sharedBC << endl;
519 subset.push_back(lookup[1]); subset.push_back(lookup[3]);
520 data = vCalcs[i]->getValues(subset);
522 //cout << "num bd = " << sharedBD << endl;
524 subset.push_back(lookup[2]); subset.push_back(lookup[3]);
525 data = vCalcs[i]->getValues(subset);
528 //cout << "num cd = " << sharedCD << endl;
529 //get estimates for combos of 3
531 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
532 data = vCalcs[i]->getValues(subset);
534 //cout << "num abc = " << sharedABC << endl;
536 subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
537 data = vCalcs[i]->getValues(subset);
539 //cout << "num acd = " << sharedACD << endl;
541 subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
542 data = vCalcs[i]->getValues(subset);
544 //cout << "num bcd = " << sharedBCD << endl;
546 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
547 data = vCalcs[i]->getValues(subset);
549 //cout << "num abd = " << sharedABD << endl;
550 //get estimate for all four
551 data = vCalcs[i]->getValues(lookup);
552 sharedABCD = data[0];
553 //cout << "num abcd = " << sharedABCD << endl << endl;
558 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";
560 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"800\"/>";
561 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
563 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"490\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA) + "</text>\n";
564 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"510\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB) + "</text>\n";
565 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"530\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC) + "</text>\n";
566 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"550\">The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD) + "</text>\n";
568 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";
569 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";
570 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";
571 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";
572 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";
573 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";
575 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";
576 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";
577 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";
578 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";
581 sharedABC = sharedABC - sharedABCD;
582 //cout << "num abc = " << sharedABC << endl;
583 sharedABD = sharedABD - sharedABCD;
584 //cout << "num abd = " << sharedABD << endl;
585 sharedACD = sharedACD - sharedABCD;
586 //cout << "num acd = " << sharedACD << endl;
587 sharedBCD = sharedBCD - sharedABCD;
588 //cout << "num bcd = " << sharedBCD << endl;
590 sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD; //cout << "num ab = " << sharedAB << endl;
591 sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD; //cout << "num ac = " << sharedAC << endl;
592 sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD; //cout << "num ad = " << sharedAD << endl;
593 sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD; //cout << "num bc = " << sharedBC << endl;
594 sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl;
595 sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD; //cout << "num cd = " << sharedCD << endl;
597 numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
598 //cout << "num a = " << numA << endl;
599 numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
600 //cout << "num b = " << numB << endl;
601 numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
602 //cout << "num c = " << numC << endl;
603 numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
604 //cout << "num d = " << numD << endl;
607 outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
608 outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
609 outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 440 315) \" cx=\"440\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
610 outsvg << "<ellipse fill=\"yellow\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+40 270 315) \" cx=\"270\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
612 //A = red, B = green, C = blue, D = yellow
614 //place labels within overlaps
615 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n";
616 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";
617 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\" y=\"160\">" + toString(sharedAB) + "</text>\n";
618 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\" y=\"110\">" + toString(numB) + "</text>\n";
619 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[1]->getGroup() + "</text>\n";
620 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\" y=\"190\">" + toString(sharedAC) + "</text>\n";
621 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\" y=\"230\">" + toString(numC) + "</text>\n";
622 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
623 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBD).length() / 2)) + "\" y=\"190\">" + toString(sharedBD) + "</text>\n";
624 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\" y=\"230\">" + toString(numD) + "</text>\n";
625 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\" y=\"210\">" + lookup[3]->getGroup() + "</text>\n";
626 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedAD).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n";
627 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBC) + "</text>\n";
628 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n";
629 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(275 - ((int)toString(sharedABD).length() / 2)) + "\" y=\"240\">" + toString(sharedABD) + "</text>\n";
630 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(400 - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"360\">" + toString(sharedBCD) + "</text>\n";
631 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n";
632 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"240\">" + toString(sharedABC) + "</text>\n";
633 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\" y=\"320\">" + toString(sharedABCD) + "</text>\n";
637 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";
640 outsvg << "</g>\n</svg>\n";
650 catch(exception& e) {
651 m->errorOut(e, "Venn", "getPic");