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 vector<double> data = vCalcs[i]->getValues(sabund);
44 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";
47 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
48 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sabund->getLabel() + "</text>\n";
49 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>";
50 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";
52 if (data.size() == 3) {
53 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
54 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
57 outsvg << "</g>\n</svg>\n";
64 m->errorOut(e, "Venn", "getPic");
68 //**********************************************************************************************************************
69 vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
72 vector<SharedRAbundVector*> subset;
73 vector<string> outputNames;
75 /******************* 1 Group **************************/
76 if (lookup.size() == 1) {
79 s = lookup[0]->getSAbundVector(); SAbundVector* sabund = &s;
81 //make a file for each calculator
82 for(int i=0;i<vCalcs.size();i++){
83 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
84 outputNames.push_back(filenamesvg);
85 openOutputFile(filenamesvg, outsvg);
87 //in essence you want to run it like a single
88 if (vCalcs[i]->getName() == "sharedsobs") {
89 singleCalc = new Sobs();
90 }else if (vCalcs[i]->getName() == "sharedchao") {
91 singleCalc = new Chao1();
92 }else if (vCalcs[i]->getName() == "sharedace") {
93 singleCalc = new Ace(10);
96 vector<double> data = singleCalc->getValues(sabund);
99 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";
102 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
103 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
104 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>";
105 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "</text>\n";
106 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";
108 if (data.size() == 3) {
109 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
110 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
113 outsvg << "</g>\n</svg>\n";
118 /******************* 2 Groups **************************/
120 }else if (lookup.size() == 2) {
121 //get sabund vector pointers so you can use the single calculators
124 SAbundVector* sabundA; SAbundVector* sabundB;
125 sabundA = new SAbundVector(lookup[0]->getSAbundVector());// sabundA = &sA;
126 sabundB = new SAbundVector(lookup[1]->getSAbundVector());// sabundB = &sB;
129 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
131 //make a file for each calculator
132 for(int i=0;i<vCalcs.size();i++){
133 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
134 outputNames.push_back(filenamesvg);
135 openOutputFile(filenamesvg, outsvg);
137 //get estimates for sharedAB
138 vector<double> shared = vCalcs[i]->getValues(subset);
140 //in essence you want to run it like a single
141 if (vCalcs[i]->getName() == "sharedsobs") {
142 singleCalc = new Sobs();
143 }else if (vCalcs[i]->getName() == "sharedchao") {
144 singleCalc = new Chao1();
145 }//else if (vCalcs[i]->getName() == "sharedace") {
146 //singleCalc = new Ace(10);
149 //get estimates for numA
150 vector<double> numA = singleCalc->getValues(sabundA);
152 //get estimates for numB
153 vector<double> numB = singleCalc->getValues(sabundB);
156 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";
160 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
161 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
162 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>";
163 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>";
164 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
165 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n";
166 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "</text>\n";
167 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "</text>\n";
168 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";
169 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
170 if (numA.size() == 3) {
171 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
172 }else { outsvg << "</text>\n"; }
174 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
175 if (numB.size() == 3) {
176 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
177 }else { outsvg << "</text>\n"; }
179 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";
180 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";
181 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";
184 outsvg << "</g>\n</svg>\n";
188 /******************* 3 Groups **************************/
190 }else if (lookup.size() == 3) {
191 //get sabund vector pointers so you can use the single calculators
193 SAbundVector sA, sB, sC;
194 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
195 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
196 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
197 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
199 //make a file for each calculator
200 for(int i=0;i<vCalcs.size();i++){
202 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
203 outputNames.push_back(filenamesvg);
204 openOutputFile(filenamesvg, outsvg);
206 if (vCalcs[i]->getName() == "sharedace") {
208 singleCalc = new Ace(10);
210 //get estimates for numA
211 vector<double> numA = singleCalc->getValues(sabundA);
213 //get estimates for numB
214 vector<double> numB = singleCalc->getValues(sabundB);
216 //get estimates for numC
217 vector<double> numC = singleCalc->getValues(sabundC);
220 //get estimates for sharedAB, sharedAC and sharedBC
222 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
223 vector<double> sharedAB = vCalcs[i]->getValues(subset);
226 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
227 vector<double> sharedAC = vCalcs[i]->getValues(subset);
230 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
231 vector<double> sharedBC = vCalcs[i]->getValues(subset);
233 vector<double> sharedAwithBC;
234 vector<double> sharedBwithAC;
235 vector<double> sharedCwithAB;
237 //find possible sharedABC values
238 float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
240 if (vCalcs[i]->getMultiple() == false) {
241 //merge BC and estimate with shared with A
242 SharedRAbundVector* merge = new SharedRAbundVector();
243 for (int j = 0; j < lookup[1]->size(); j++) {
244 merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
248 subset.push_back(lookup[0]); subset.push_back(merge);
249 sharedAwithBC = vCalcs[i]->getValues(subset);
252 //merge AC and estimate with shared with B
253 merge = new SharedRAbundVector();
254 for (int j = 0; j < lookup[0]->size(); j++) {
255 merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
259 subset.push_back(merge); subset.push_back(lookup[1]);
260 sharedBwithAC = vCalcs[i]->getValues(subset);
263 //merge AB and estimate with shared with C
264 merge = new SharedRAbundVector();
265 for (int j = 0; j < lookup[0]->size(); j++) {
266 merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), "");
270 subset.push_back(lookup[2]); subset.push_back(merge);
271 sharedCwithAB = vCalcs[i]->getValues(subset);
274 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
275 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
276 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
278 //if any of the possible m's are - throw them out
279 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
280 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
281 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
283 //sharedABC is the minimum of the 3 possibilities
284 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
285 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
286 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }
288 vector<double> data = vCalcs[i]->getValues(lookup);
290 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
291 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
292 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
296 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";
300 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>";
301 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
302 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>";
303 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>";
304 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>";
306 //place labels within overlaps
307 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";
308 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";
309 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\" y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";
310 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";
311 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</text>\n";
312 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";
313 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";
314 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</text>\n";
315 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";
316 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"280\">" + toString(sharedABC) + "</text>\n";
318 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";
319 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";
320 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";
321 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";
322 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";
323 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";
324 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
325 if (numA.size() == 3) {
326 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
327 }else { outsvg << "</text>\n"; }
329 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
330 if (numB.size() == 3) {
331 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
332 }else { outsvg << "</text>\n"; }
334 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
335 if (numC.size() == 3) {
336 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
337 }else { outsvg << "</text>\n"; }
339 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";
340 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"780\">The total shared richness is " + toString(sharedABC) + "</text>\n";
344 }else { //sharedchao and sharedsobs are multigroup
346 vector<SharedRAbundVector*> subset;
348 //get estimates for numA
349 subset.push_back(lookup[0]);
350 vector<double> numA = vCalcs[i]->getValues(subset);
352 //get estimates for numB
354 subset.push_back(lookup[1]);
355 vector<double> numB = vCalcs[i]->getValues(subset);
357 //get estimates for numC
359 subset.push_back(lookup[2]);
360 vector<double> numC = vCalcs[i]->getValues(subset);
363 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
364 vector<double> sharedab = vCalcs[i]->getValues(subset);
367 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
368 vector<double> sharedac = vCalcs[i]->getValues(subset);
371 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
372 vector<double> sharedbc = vCalcs[i]->getValues(subset);
375 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
376 vector<double> sharedabc = vCalcs[i]->getValues(subset);
379 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";
383 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>";
384 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
385 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>";
386 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>";
387 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>";
389 //place labels within overlaps
390 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";
391 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";
392 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";
393 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";
394 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[1]->getGroup() + "</text>\n";
395 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";
396 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";
397 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"410\">" + lookup[2]->getGroup() + "</text>\n";
398 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";
399 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedabc[0]).length() / 2)) + "\" y=\"280\">" + toString(sharedabc[0]) + "</text>\n";
401 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";
402 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";
403 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";
404 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
405 if (numA.size() == 3) {
406 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
407 }else { outsvg << "</text>\n"; }
409 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
410 if (numB.size() == 3) {
411 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
412 }else { outsvg << "</text>\n"; }
414 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
415 if (numC.size() == 3) {
416 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
417 }else { outsvg << "</text>\n"; }
419 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";
420 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The total shared richness is " + toString(sharedabc[0]) + "</text>\n";
427 outsvg << "</g>\n</svg>\n";
433 /******************* 4 Groups **************************/
435 }else if (lookup.size() == 4) {
436 //calc the shared otu
437 float sharedABCD = 0;
438 float numA = 0; float numB = 0; float numC = 0; float numD = 0;
439 float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
440 float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
442 //get sabund vector pointers so you can use the single calculators
444 SAbundVector sA, sB, sC, sD;
445 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
446 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
447 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
448 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
449 sD = lookup[3]->getSAbundVector(); sabundD = &sD;
451 //A = red, B = green, C = blue, D = yellow
453 //make a file for each calculator
454 for(int i=0;i<vCalcs.size();i++){
456 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(); }
458 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
459 outputNames.push_back(filenamesvg);
460 openOutputFile(filenamesvg, outsvg);
463 //in essence you want to run it like a single
464 if (vCalcs[i]->getName() == "sharedsobs") {
465 singleCalc = new Sobs();
466 }else if (vCalcs[i]->getName() == "sharedchao") {
467 singleCalc = new Chao1();
470 //get estimates for numA
471 data = singleCalc->getValues(sabundA);
473 //cout << "num a = " << numA << endl;
475 //get estimates for numB
476 data = singleCalc->getValues(sabundB);
478 //cout << "num b = " << numB << endl;
479 //get estimates for numC
480 data = singleCalc->getValues(sabundC);
482 //cout << "num c = " << numC << endl;
483 //get estimates for numD
484 data = singleCalc->getValues(sabundD);
486 //cout << "num d = " << numD << endl;
488 //get estimates for pairs
490 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
491 data = vCalcs[i]->getValues(subset);
493 //cout << "num ab = " << sharedAB << endl;
495 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
496 data = vCalcs[i]->getValues(subset);
498 //cout << "num ac = " << sharedAC << endl;
500 subset.push_back(lookup[0]); subset.push_back(lookup[3]);
501 data = vCalcs[i]->getValues(subset);
503 //cout << "num ad = " << sharedAD << endl;
505 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
506 data = vCalcs[i]->getValues(subset);
508 //cout << "num bc = " << sharedBC << endl;
510 subset.push_back(lookup[1]); subset.push_back(lookup[3]);
511 data = vCalcs[i]->getValues(subset);
513 //cout << "num bd = " << sharedBD << endl;
515 subset.push_back(lookup[2]); subset.push_back(lookup[3]);
516 data = vCalcs[i]->getValues(subset);
519 //cout << "num cd = " << sharedCD << endl;
520 //get estimates for combos of 3
522 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
523 data = vCalcs[i]->getValues(subset);
525 //cout << "num abc = " << sharedABC << endl;
527 subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
528 data = vCalcs[i]->getValues(subset);
530 //cout << "num acd = " << sharedACD << endl;
532 subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
533 data = vCalcs[i]->getValues(subset);
535 //cout << "num bcd = " << sharedBCD << endl;
537 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
538 data = vCalcs[i]->getValues(subset);
540 //cout << "num abd = " << sharedABD << endl;
541 //get estimate for all four
542 data = vCalcs[i]->getValues(lookup);
543 sharedABCD = data[0];
544 //cout << "num abcd = " << sharedABCD << endl << endl;
549 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";
551 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"800\"/>";
552 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
554 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"490\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA) + "</text>\n";
555 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"510\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB) + "</text>\n";
556 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"530\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC) + "</text>\n";
557 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"550\">The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD) + "</text>\n";
559 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";
560 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";
561 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";
562 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";
563 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";
564 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";
566 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";
567 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";
568 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";
569 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";
572 sharedABC = sharedABC - sharedABCD;
573 //cout << "num abc = " << sharedABC << endl;
574 sharedABD = sharedABD - sharedABCD;
575 //cout << "num abd = " << sharedABD << endl;
576 sharedACD = sharedACD - sharedABCD;
577 //cout << "num acd = " << sharedACD << endl;
578 sharedBCD = sharedBCD - sharedABCD;
579 //cout << "num bcd = " << sharedBCD << endl;
581 sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD; //cout << "num ab = " << sharedAB << endl;
582 sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD; //cout << "num ac = " << sharedAC << endl;
583 sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD; //cout << "num ad = " << sharedAD << endl;
584 sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD; //cout << "num bc = " << sharedBC << endl;
585 sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl;
586 sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD; //cout << "num cd = " << sharedCD << endl;
588 numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
589 //cout << "num a = " << numA << endl;
590 numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
591 //cout << "num b = " << numB << endl;
592 numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
593 //cout << "num c = " << numC << endl;
594 numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
595 //cout << "num d = " << numD << endl;
598 outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
599 outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
600 outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 440 315) \" cx=\"440\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
601 outsvg << "<ellipse fill=\"yellow\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+40 270 315) \" cx=\"270\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
603 //A = red, B = green, C = blue, D = yellow
605 //place labels within overlaps
606 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n";
607 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";
608 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\" y=\"160\">" + toString(sharedAB) + "</text>\n";
609 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\" y=\"110\">" + toString(numB) + "</text>\n";
610 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[1]->getGroup() + "</text>\n";
611 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\" y=\"190\">" + toString(sharedAC) + "</text>\n";
612 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\" y=\"230\">" + toString(numC) + "</text>\n";
613 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
614 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBD).length() / 2)) + "\" y=\"190\">" + toString(sharedBD) + "</text>\n";
615 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\" y=\"230\">" + toString(numD) + "</text>\n";
616 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\" y=\"210\">" + lookup[3]->getGroup() + "</text>\n";
617 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedAD).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n";
618 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBC) + "</text>\n";
619 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n";
620 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(275 - ((int)toString(sharedABD).length() / 2)) + "\" y=\"240\">" + toString(sharedABD) + "</text>\n";
621 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(400 - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"360\">" + toString(sharedBCD) + "</text>\n";
622 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n";
623 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"240\">" + toString(sharedABC) + "</text>\n";
624 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\" y=\"320\">" + toString(sharedABCD) + "</text>\n";
628 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";
631 outsvg << "</g>\n</svg>\n";
641 catch(exception& e) {
642 m->errorOut(e, "Venn", "getPic");