5 * Created by Sarah Westcott on 3/30/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
15 #include "sharedchao1.h"
16 #include "sharedsobscollectsummary.h"
19 //**********************************************************************************************************************
20 Venn::Venn(string o, bool n, string f) : outputDir(o), nseqs(n), inputfile(f) {
22 m = MothurOut::getInstance();
25 m->errorOut(e, "Venn", "Venn");
29 //**********************************************************************************************************************
30 vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
33 vector<string> outputNames;
35 for(int i=0;i<vCalcs.size();i++){
36 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg";
37 outputNames.push_back(filenamesvg);
38 m->openOutputFile(filenamesvg, outsvg);
40 if (m->control_pressed) { outsvg.close(); return outputNames; }
42 vector<double> data = vCalcs[i]->getValues(sabund);
48 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(width) + " " + toString(height) + " \" >\n";
51 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
52 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.05 * height)) + "\">Venn Diagram at distance " + sabund->getLabel() + "</text>\n";
53 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"" + toString(int(0.50 * width)) + "\" cy=\"" + toString(int(0.29 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
54 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString((width / 2) - ((int)toString(data[0]).length() / 2)) + "\" y=\"" + toString(int(0.28 * height)) + "\">" + toString(data[0]) + "</text>\n";
56 if (data.size() == 3) {
57 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.35 * width)) + "\" y=\"" + toString(int(0.60 * height)) + "\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
58 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.35 * width)) + "\" y=\"" + toString(int(0.645 * height)) + "\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
62 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.35 * width)) + "\" y=\"" + toString(int(0.70 * height)) + "\">The number of sequences represented is " + toString(sabund->getNumSeqs()) + "</text>\n";
65 outsvg << "</g>\n</svg>\n";
72 m->errorOut(e, "Venn", "getPic");
76 //**********************************************************************************************************************
77 vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
80 vector<SharedRAbundVector*> subset;
81 vector<string> outputNames;
86 /******************* 1 Group **************************/
87 if (lookup.size() == 1) {
90 s = lookup[0]->getSAbundVector(); SAbundVector* sabund = &s;
92 //make a file for each calculator
93 for(int i=0;i<vCalcs.size();i++){
94 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg";
95 outputNames.push_back(filenamesvg);
96 m->openOutputFile(filenamesvg, outsvg);
98 if (m->control_pressed) { outsvg.close(); return outputNames; }
100 //in essence you want to run it like a single
101 if (vCalcs[i]->getName() == "sharedsobs") {
102 singleCalc = new Sobs();
103 }else if (vCalcs[i]->getName() == "sharedchao") {
104 singleCalc = new Chao1();
105 }else if (vCalcs[i]->getName() == "sharedace") {
106 singleCalc = new Ace(10);
109 vector<double> data = singleCalc->getValues(sabund);
112 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(width) + " " + toString(height) + " \">\n";
115 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
116 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.05 * height)) + "\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
117 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"" + toString(int(0.50 * width)) + "\" cy=\"" + toString(int(0.29 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
118 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.50 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.24 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
119 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.50 * width) - ((int)toString(data[0]).length() / 2)) + "\" y=\"" + toString(int(0.28 * height)) + "\">" + toString(data[0]) + "</text>\n";
121 if (data.size() == 3) {
122 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.35 * width)) + "\" y=\"" + toString(int(0.60 * height)) + "\" >The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
123 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.35 * width)) + "\" y=\"" + toString(int(0.645 * height)) + "\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
127 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.35 * width)) + "\" y=\"" + toString(int(0.70 * height)) + "\">The number of sequences represented is " + toString(sabund->getNumSeqs()) + "</text>\n";
130 outsvg << "</g>\n</svg>\n";
135 /******************* 2 Groups **************************/
137 }else if (lookup.size() == 2) {
138 //get sabund vector pointers so you can use the single calculators
141 SAbundVector* sabundA; SAbundVector* sabundB;
142 sabundA = new SAbundVector(lookup[0]->getSAbundVector());// sabundA = &sA;
143 sabundB = new SAbundVector(lookup[1]->getSAbundVector());// sabundB = &sB;
146 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
148 //make a file for each calculator
149 for(int i=0;i<vCalcs.size();i++){
150 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg";
152 outputNames.push_back(filenamesvg);
153 m->openOutputFile(filenamesvg, outsvg);
155 if (m->control_pressed) { outsvg.close(); return outputNames; }
157 //get estimates for sharedAB
158 vector<double> shared = vCalcs[i]->getValues(subset);
160 //in essence you want to run it like a single
161 if (vCalcs[i]->getName() == "sharedsobs") {
162 singleCalc = new Sobs();
163 }else if (vCalcs[i]->getName() == "sharedchao") {
164 singleCalc = new Chao1();
165 }//else if (vCalcs[i]->getName() == "sharedace") {
166 //singleCalc = new Ace(10);
169 int sharedVal, numSeqsA, numSeqsB, uniqSeqsToA, uniqSeqsToB;
171 NSeqs* nseqsCalc = new NSeqs();
172 vector<double> data = nseqsCalc->getValues(lookup);
173 cout << data[0] << '\t' << data[1] << endl;
174 sharedVal = data[0] + data[1];
175 numSeqsA = sabundA->getNumSeqs();
176 numSeqsB = sabundB->getNumSeqs();
177 uniqSeqsToA = numSeqsA-data[0];
178 uniqSeqsToB = numSeqsB-data[1];
184 //get estimates for numA
185 vector<double> numA = singleCalc->getValues(sabundA);
187 //get estimates for numB
188 vector<double> numB = singleCalc->getValues(sabundB);
191 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(width) + " " + toString(height) + " \" >\n";
195 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
196 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.05 * height)) + "\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
197 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"" + toString(int(0.36 * width)) + "\" cy=\"" + toString(int(0.29 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
198 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"" + toString(int(0.62 * width)) + "\" cy=\"" + toString(int(0.29 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
199 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.29 * width) - ((int)toString(numA[0]).length() / 2)) + "\" y=\"" + toString(int(0.28 * height)) + "\">" + toString(numA[0] - shared[0]) + "</text>\n";
200 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.7 * width) - ((int)toString(numB[0]).length() / 2)) + "\" y=\"" + toString(int(0.28 * height)) + "\">" + toString(numB[0] - shared[0]) + "</text>\n";
201 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.29 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.25 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
202 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.7 * width) - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.25 * height)) + "\">" + lookup[1]->getGroup() + "</text>\n";
203 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(shared[0]).length() / 2)) + "\" y=\"" + toString(int(0.28 * height)) + "\">" + toString(shared[0]) + "</text>\n";
204 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.66 * height)) + "\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
205 if (numA.size() == 3) {
206 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
208 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared"; }
209 outsvg << "</text>\n";
211 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.69 * height)) + "\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
212 if (numB.size() == 3) {
213 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
215 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared"; }
216 outsvg << "</text>\n";
218 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.72 * height)) + "\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(shared[0]);
219 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal) + "; " + toString((sharedVal / (float)(numSeqsA + numSeqsB))*100) + "% of these sequences are shared"; }
220 outsvg << "</text>\n";
222 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.75 * height)) + "\">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";
224 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.78 * height)) + "\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0]))+ "</text>\n";;
228 outsvg << "</g>\n</svg>\n";
232 /******************* 3 Groups **************************/
234 }else if (lookup.size() == 3) {
237 int windowSize = height;
240 //get sabund vector pointers so you can use the single calculators
242 SAbundVector sA, sB, sC;
243 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
244 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
245 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
246 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
248 //make a file for each calculator
249 for(int i=0;i<vCalcs.size();i++){
251 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg";
253 outputNames.push_back(filenamesvg);
254 m->openOutputFile(filenamesvg, outsvg);
256 if (m->control_pressed) { outsvg.close(); return outputNames; }
258 int sharedVal, sharedABVal, sharedACVal, sharedBCVal, numSeqsA, numSeqsB, numSeqsC, uniqSeqsToA, uniqSeqsToB, uniqSeqsToC;
261 NSeqs* nseqsCalc = new NSeqs();
262 vector<double> sharedData = nseqsCalc->getValues(lookup);
264 vector<SharedRAbundVector*> mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]);
265 vector<double> sharedAB = nseqsCalc->getValues(mysubset);
267 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]);
268 vector<double> sharedAC = nseqsCalc->getValues(mysubset);
270 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
271 vector<double> sharedBC = nseqsCalc->getValues(mysubset);
273 sharedVal = sharedData[0] + sharedData[1] + sharedData[2];
274 sharedABVal = sharedAB[0] + sharedAB[1];
275 sharedACVal = sharedAC[0] + sharedAC[1];
276 sharedBCVal = sharedBC[0] + sharedBC[1];
277 numSeqsA = sabundA->getNumSeqs();
278 numSeqsB = sabundB->getNumSeqs();
279 numSeqsC = sabundC->getNumSeqs();
280 uniqSeqsToA = numSeqsA-sharedData[0];
281 uniqSeqsToB = numSeqsC-sharedData[1];
282 uniqSeqsToC = numSeqsB-sharedData[1];
288 if (vCalcs[i]->getName() == "sharedace") {
290 singleCalc = new Ace(10);
292 //get estimates for numA
293 vector<double> numA = singleCalc->getValues(sabundA);
295 //get estimates for numB
296 vector<double> numB = singleCalc->getValues(sabundB);
298 //get estimates for numC
299 vector<double> numC = singleCalc->getValues(sabundC);
302 //get estimates for sharedAB, sharedAC and sharedBC
304 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
305 vector<double> sharedAB = vCalcs[i]->getValues(subset);
308 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
309 vector<double> sharedAC = vCalcs[i]->getValues(subset);
312 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
313 vector<double> sharedBC = vCalcs[i]->getValues(subset);
315 vector<double> sharedAwithBC;
316 vector<double> sharedBwithAC;
317 vector<double> sharedCwithAB;
319 //find possible sharedABC values
320 float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
322 if (vCalcs[i]->getMultiple() == false) {
323 //merge BC and estimate with shared with A
324 SharedRAbundVector* merge = new SharedRAbundVector();
325 for (int j = 0; j < lookup[1]->size(); j++) {
326 merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
330 subset.push_back(lookup[0]); subset.push_back(merge);
331 sharedAwithBC = vCalcs[i]->getValues(subset);
334 //merge AC and estimate with shared with B
335 merge = new SharedRAbundVector();
336 for (int j = 0; j < lookup[0]->size(); j++) {
337 merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
341 subset.push_back(merge); subset.push_back(lookup[1]);
342 sharedBwithAC = vCalcs[i]->getValues(subset);
345 //merge AB and estimate with shared with C
346 merge = new SharedRAbundVector();
347 for (int j = 0; j < lookup[0]->size(); j++) {
348 merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), "");
352 subset.push_back(lookup[2]); subset.push_back(merge);
353 sharedCwithAB = vCalcs[i]->getValues(subset);
356 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
357 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
358 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
360 //if any of the possible m's are - throw them out
361 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
362 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
363 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
365 //sharedABC is the minimum of the 3 possibilities
366 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
367 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
368 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }
370 vector<double> data = vCalcs[i]->getValues(lookup);
372 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
373 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
374 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
378 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(width) + " " + toString(windowSize) + " \" >\n";
382 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
383 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.44 * height)) + "\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
384 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"" + toString(int(0.33 * width)) + "\" cy=\"" + toString(int(0.25 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
385 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"" + toString(int(0.65 * width)) + "\" cy=\"" + toString(int(0.25 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
386 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"" + toString(int(0.5 * width)) + "\" cy=\"" + toString(int(0.5 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
388 //place labels within overlaps
389 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.33 * width) - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"" + toString(int(0.22 * height)) + "\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n";
390 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.33 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
391 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\" y=\"" + toString(int(0.22 * height)) + "\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";
392 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.7 * width) - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\" y=\"" + toString(int(0.22 * height)) + "\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";
393 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.7 * width) - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[1]->getGroup() + "</text>\n";
394 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.38 * width) - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\" y=\"" + toString(int(0.38 * height)) + "\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";
395 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\" y=\"" + toString(int(0.54 * height)) + "\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n";
396 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.52 * height)) + "\">" + lookup[2]->getGroup() + "</text>\n";
397 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.58 * width) - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"" + toString(int(0.38 * height)) + "\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";
398 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedABC).length() / 2)) + "\" y=\"" + toString(int(0.34 * height)) + "\">" + toString(sharedABC) + "</text>\n";
400 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.825 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB[0]);
401 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
402 outsvg << "</text>\n";
403 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.85 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC[0]);
404 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
405 outsvg << "</text>\n";
406 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.875 * height)) + "\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC[0]);
407 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
408 outsvg << "</text>\n";
409 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.9 * height)) + "\">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";
410 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.925 * height)) + "\">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";
411 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.95 * height)) + "\">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";
412 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.725 * height)) + "\">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]);
416 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared"; }
417 outsvg << "</text>\n";
419 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.75 * height)) + "\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
420 if (numB.size() == 3) {
421 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
423 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared"; }
424 outsvg << "</text>\n";
426 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.775 * height)) + "\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
427 if (numC.size() == 3) {
428 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
430 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC) + "; " + toString(uniqSeqsToC) + " sequences are not shared"; }
431 outsvg << "</text>\n";
433 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.80 * height)) + "\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
434 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.975 * height)) + "\">The total shared richness is " + toString(sharedABC);
435 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal); }
436 outsvg << "</text>\n";
440 }else { //sharedchao and sharedsobs are multigroup
442 vector<SharedRAbundVector*> subset;
444 //get estimates for numA
445 subset.push_back(lookup[0]);
446 vector<double> numA = vCalcs[i]->getValues(subset);
448 //get estimates for numB
450 subset.push_back(lookup[1]);
451 vector<double> numB = vCalcs[i]->getValues(subset);
453 //get estimates for numC
455 subset.push_back(lookup[2]);
456 vector<double> numC = vCalcs[i]->getValues(subset);
459 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
460 vector<double> sharedab = vCalcs[i]->getValues(subset);
463 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
464 vector<double> sharedac = vCalcs[i]->getValues(subset);
467 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
468 vector<double> sharedbc = vCalcs[i]->getValues(subset);
471 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
472 vector<double> sharedabc = vCalcs[i]->getValues(subset);
475 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(width) + " " + toString(windowSize) + " \" >\n";
479 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
480 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.05 * height)) + "\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
481 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"" + toString(int(0.33 * width)) + "\" cy=\"" + toString(int(0.25 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
482 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"" + toString(int(0.65 * width)) + "\" cy=\"" + toString(int(0.25 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
483 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"" + toString(int(0.5 * width)) + "\" cy=\"" + toString(int(0.5 * height)) + "\" r=\"" + toString(int(0.22 * width)) + "\"/>";
485 //place labels within overlaps
486 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.29 * width) - ((int)toString(numA[0]-sharedab[0]-sharedac[0]+sharedabc[0]).length() / 2)) + "\" y=\"" + toString(int(0.22 * height)) + "\">" + toString(numA[0]-sharedab[0]-sharedac[0]+sharedabc[0]) + "</text>\n";
487 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.29 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
488 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedab[0] - sharedabc[0]).length() / 2)) + "\" y=\"" + toString(int(0.22 * height)) + "\">" + toString(sharedab[0] - sharedabc[0]) + "</text>\n";
489 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.68 * width) - ((int)toString(numB[0]-sharedab[0]-sharedbc[0]+sharedabc[0]).length() / 2)) + "\" y=\"" + toString(int(0.22 * height)) + "\">" + toString(numB[0]-sharedab[0]-sharedbc[0]+sharedabc[0]) + "</text>\n";
490 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.68 * width) - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[1]->getGroup() + "</text>\n";
491 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.38 * width) - ((int)toString(sharedac[0] - sharedabc[0]).length() / 2)) + "\" y=\"" + toString(int(0.38 * height)) + "\">" + toString(sharedac[0] - sharedabc[0]) + "</text>\n";
492 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(numC[0]-sharedac[0]-sharedbc[0]+sharedabc[0]).length() / 2)) + "\" y=\"" + toString(int(0.54 * height)) + "\">" + toString(numC[0]-sharedac[0]-sharedbc[0]+sharedabc[0]) + "</text>\n";
493 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.51 * height)) + "\">" + lookup[2]->getGroup() + "</text>\n";
494 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.59 * width) - ((int)toString(sharedbc[0] - sharedabc[0]).length() / 2)) + "\" y=\"" + toString(int(0.38 * height)) + "\">" + toString(sharedbc[0] - sharedabc[0]) + "</text>\n";
495 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedabc[0]).length() / 2)) + "\" y=\"" + toString(int(0.35 * height)) + "\">" + toString(sharedabc[0]) + "</text>\n";
497 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.825 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedab[0]);
498 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
499 outsvg << "</text>\n";
500 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.85 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedac[0]);
501 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
502 outsvg << "</text>\n";
503 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.875 * height)) + "\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedbc[0]);
504 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
505 outsvg << "</text>\n";
507 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.725 * height)) + "\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
508 if (numA.size() == 3) {
509 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
511 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA); }
512 outsvg << "</text>\n";
514 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.75 * height)) + "\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
515 if (numB.size() == 3) {
516 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
518 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB); }
519 outsvg << "</text>\n";
521 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.775 * height)) + "\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
522 if (numC.size() == 3) {
523 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
525 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC); }
526 outsvg << "</text>\n";
528 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.8 * height)) + "\">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";
529 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.9 * height)) + "\">The total shared richness is " + toString(sharedabc[0]);
530 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal); }
531 outsvg << "</text>\n";
536 outsvg << "</g>\n</svg>\n";
542 /******************* 4 Groups **************************/
544 }else if (lookup.size() == 4) {
548 int windowSize = height;
550 //calc the shared otu
551 float sharedABCD = 0;
552 float numA = 0; float numB = 0; float numC = 0; float numD = 0;
553 float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
554 float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
556 //get sabund vector pointers so you can use the single calculators
558 SAbundVector sA, sB, sC, sD;
559 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
560 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
561 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
562 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
563 sD = lookup[3]->getSAbundVector(); sabundD = &sD;
565 //A = red, B = green, C = blue, D = yellow
567 //make a file for each calculator
568 for(int i=0;i<vCalcs.size();i++){
570 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(); }
572 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg";
573 outputNames.push_back(filenamesvg);
574 m->openOutputFile(filenamesvg, outsvg);
576 if (m->control_pressed) { outsvg.close(); return outputNames; }
578 //in essence you want to run it like a single
579 if (vCalcs[i]->getName() == "sharedsobs") {
580 singleCalc = new Sobs();
581 }else if (vCalcs[i]->getName() == "sharedchao") {
582 singleCalc = new Chao1();
585 //get estimates for numA
586 data = singleCalc->getValues(sabundA);
588 //cout << "num a = " << numA << endl;
590 //get estimates for numB
591 data = singleCalc->getValues(sabundB);
593 //cout << "num b = " << numB << endl;
594 //get estimates for numC
595 data = singleCalc->getValues(sabundC);
597 //cout << "num c = " << numC << endl;
598 //get estimates for numD
599 data = singleCalc->getValues(sabundD);
601 //cout << "num d = " << numD << endl;
603 //get estimates for pairs
605 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
606 data = vCalcs[i]->getValues(subset);
608 //cout << "num ab = " << sharedAB << endl;
610 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
611 data = vCalcs[i]->getValues(subset);
613 //cout << "num ac = " << sharedAC << endl;
615 subset.push_back(lookup[0]); subset.push_back(lookup[3]);
616 data = vCalcs[i]->getValues(subset);
618 //cout << "num ad = " << sharedAD << endl;
620 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
621 data = vCalcs[i]->getValues(subset);
623 //cout << "num bc = " << sharedBC << endl;
625 subset.push_back(lookup[1]); subset.push_back(lookup[3]);
626 data = vCalcs[i]->getValues(subset);
628 //cout << "num bd = " << sharedBD << endl;
630 subset.push_back(lookup[2]); subset.push_back(lookup[3]);
631 data = vCalcs[i]->getValues(subset);
634 //cout << "num cd = " << sharedCD << endl;
635 //get estimates for combos of 3
637 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
638 data = vCalcs[i]->getValues(subset);
640 //cout << "num abc = " << sharedABC << endl;
642 subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
643 data = vCalcs[i]->getValues(subset);
645 //cout << "num acd = " << sharedACD << endl;
647 subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
648 data = vCalcs[i]->getValues(subset);
650 //cout << "num bcd = " << sharedBCD << endl;
652 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
653 data = vCalcs[i]->getValues(subset);
655 //cout << "num abd = " << sharedABD << endl;
656 //get estimate for all four
657 data = vCalcs[i]->getValues(lookup);
658 sharedABCD = data[0];
659 //cout << "num abcd = " << sharedABCD << endl << endl;
660 int sharedVal, sharedABCVal, sharedABDVal, sharedACDVal, sharedBCDVal, sharedABVal, sharedACVal, sharedADVal, sharedBCVal, sharedBDVal, sharedCDVal, numSeqsA, numSeqsB, numSeqsC, numSeqsD;
663 NSeqs* nseqsCalc = new NSeqs();
664 vector<double> sharedData = nseqsCalc->getValues(lookup);
666 vector<SharedRAbundVector*> mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]);
667 vector<double> sharedAB = nseqsCalc->getValues(mysubset);
669 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]);
670 vector<double> sharedAC = nseqsCalc->getValues(mysubset);
672 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[3]);
673 vector<double> sharedAD = nseqsCalc->getValues(mysubset);
675 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
676 vector<double> sharedBC = nseqsCalc->getValues(mysubset);
678 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]);
679 vector<double> sharedBD = nseqsCalc->getValues(mysubset);
681 mysubset.clear(); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
682 vector<double> sharedCD = nseqsCalc->getValues(mysubset);
684 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
685 vector<double> sharedABC = nseqsCalc->getValues(mysubset);
687 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]);
688 vector<double> sharedABD = nseqsCalc->getValues(mysubset);
690 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
691 vector<double> sharedACD = nseqsCalc->getValues(mysubset);
693 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
694 vector<double> sharedBCD = nseqsCalc->getValues(mysubset);
696 sharedVal = sharedData[0] + sharedData[1] + sharedData[2] + sharedData[3];
697 sharedABCVal = sharedABC[0] + sharedABC[1] + sharedABC[2];
698 sharedABDVal = sharedABD[0] + sharedABD[1] + sharedABD[2];
699 sharedACDVal = sharedACD[0] + sharedACD[1] + sharedACD[2];
700 sharedBCDVal = sharedBCD[0] + sharedBCD[1] + sharedBCD[2];
701 sharedABVal = sharedAB[0] + sharedAB[1];
702 sharedACVal = sharedAC[0] + sharedAC[1];
703 sharedADVal = sharedAD[0] + sharedAD[1];
704 sharedBCVal = sharedBC[0] + sharedBC[1];
705 sharedBDVal = sharedBD[0] + sharedBD[1];
706 sharedCDVal = sharedCD[0] + sharedCD[1];
707 numSeqsA = sabundA->getNumSeqs();
708 numSeqsB = sabundB->getNumSeqs();
709 numSeqsC = sabundC->getNumSeqs();
710 numSeqsD = sabundD->getNumSeqs();
717 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(width) + " " + toString(windowSize) + " \" >\n";
719 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(windowSize) + "\"/>";
720 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.05 * height)) + "\" >Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
722 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.625 * height)) + "\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA);
723 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA); }
724 outsvg << "</text>\n";
725 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.65 * height)) + "\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB);
726 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB); }
727 outsvg << "</text>\n";
728 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.675 * height)) + "\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC);
729 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC); }
730 outsvg << "</text>\n";
731 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.7 * height)) + "\">The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD);
732 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsD); }
733 outsvg << "</text>\n";
735 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.725 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB);
736 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
737 outsvg << "</text>\n";
738 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.75 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC);
739 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
740 outsvg << "</text>\n";
741 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.775 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedAD);
742 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedADVal); }
743 outsvg << "</text>\n";
744 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.8 * height)) + "\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC);
745 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
746 outsvg << "</text>\n";
747 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.825 * height)) + "\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBD);
748 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBDVal); }
749 outsvg << "</text>\n";
750 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.85 * height)) + "\">The number of species shared between groups " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedCD);
751 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedCDVal); }
752 outsvg << "</text>\n";
754 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.875 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedABC);
755 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABCVal); }
756 outsvg << "</text>\n";
757 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.9 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedABD);
758 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABDVal); }
759 outsvg << "</text>\n";
760 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.925 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedACD);
761 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACDVal); }
762 outsvg << "</text>\n";
763 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.95 * height)) + "\">The number of species shared between groups " + lookup[1]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBCD);
764 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCDVal); }
765 outsvg << "</text>\n";
768 sharedABC = sharedABC - sharedABCD;
769 //cout << "num abc = " << sharedABC << endl;
770 sharedABD = sharedABD - sharedABCD;
771 //cout << "num abd = " << sharedABD << endl;
772 sharedACD = sharedACD - sharedABCD;
773 //cout << "num acd = " << sharedACD << endl;
774 sharedBCD = sharedBCD - sharedABCD;
775 //cout << "num bcd = " << sharedBCD << endl;
777 sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD; //cout << "num ab = " << sharedAB << endl;
778 sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD; //cout << "num ac = " << sharedAC << endl;
779 sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD; //cout << "num ad = " << sharedAD << endl;
780 sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD; //cout << "num bc = " << sharedBC << endl;
781 sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl;
782 sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD; //cout << "num cd = " << sharedCD << endl;
784 numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
785 //cout << "num a = " << numA << endl;
786 numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
787 //cout << "num b = " << numB << endl;
788 numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
789 //cout << "num c = " << numC << endl;
790 numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
791 //cout << "num d = " << numD << endl;
794 outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 " + toString(int(0.51 * width)) + " " + toString(int(0.27 * height)) + ") \" cx=\"" + toString(int(0.51 * width)) + "\" cy=\"" + toString(int(0.27 * height)) + "\" rx=\"" + toString(int(0.29 * width)) + "\" ry=\"" + toString(int(0.14 * height)) + "\"/>\n ";
795 outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 " + toString(int(0.51 * width)) + " " + toString(int(0.27 * height)) + ") \" cx=\"" + toString(int(0.51 * width)) + "\" cy=\"" + toString(int(0.27 * height)) + "\" rx=\"" + toString(int(0.29 * width)) + "\" ry=\"" + toString(int(0.14 * height)) + "\"/>\n ";
796 outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 " + toString(int(0.63 * width)) + " " + toString(int(0.36 * height)) + ") \" cx=\"" + toString(int(0.63 * width)) + "\" cy=\"" + toString(int(0.36 * height)) + "\" rx=\"" + toString(int(0.29 * width)) + "\" ry=\"" + toString(int(0.14 * height)) + "\"/>\n ";
797 outsvg << "<ellipse fill=\"yellow\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+40 " + toString(int(0.36 * width)) + " " + toString(int(0.36 * height)) + ") \" cx=\"" + toString(int(0.36 * width)) + "\" cy=\"" + toString(int(0.36 * height)) + "\" rx=\"" + toString(int(0.29 * width)) + "\" ry=\"" + toString(int(0.14 * height)) + "\"/>\n ";
799 //A = red, B = green, C = blue, D = yellow
801 //place labels within overlaps
802 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.66 * width) - ((int)toString(numA).length() / 2)) + "\" y=\"" + toString(int(0.14 * height)) + "\">" + toString(numA) + "</text>\n";
803 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.66 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.11 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
804 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedAB).length() / 2)) + "\" y=\"" + toString(int(0.2 * height)) + "\">" + toString(sharedAB) + "</text>\n";
805 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.36 * width) - ((int)toString(numB).length() / 2)) + "\" y=\"" + toString(int(0.14 * height)) + "\">" + toString(numB) + "</text>\n";
806 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.36 * width) - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.11 * height)) + "\">" + lookup[1]->getGroup() + "</text>\n";
807 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.7 * width) - ((int)toString(sharedAC).length() / 2)) + "\" y=\"" + toString(int(0.24 * height)) + "\">" + toString(sharedAC) + "</text>\n";
808 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.785 * width) - ((int)toString(numC).length() / 2)) + "\" y=\"" + toString(int(0.29 * height)) + "\">" + toString(numC) + "</text>\n";
809 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.785 * width) - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.26 * height)) + "\">" + lookup[2]->getGroup() + "</text>\n";
810 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.31 * width) - ((int)toString(sharedBD).length() / 2)) + "\" y=\"" + toString(int(0.24 * height)) + "\">" + toString(sharedBD) + "</text>\n";
811 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.22 * width) - ((int)toString(numD).length() / 2)) + "\" y=\"" + toString(int(0.29 * height)) + "\">" + toString(numD) + "</text>\n";
812 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.22 * width) - ((int)lookup[3]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.26 * height)) + "\">" + lookup[3]->getGroup() + "</text>\n";
813 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.34 * width) - ((int)toString(sharedAD).length() / 2)) + "\" y=\"" + toString(int(0.41 * height)) + "\">" + toString(sharedAD) + "</text>\n";
814 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.675 * width) - ((int)toString(sharedBC).length() / 2)) + "\" y=\"" + toString(int(0.41 * height)) + "\">" + toString(sharedBC) + "</text>\n";
815 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedCD).length() / 2)) + "\" y=\"" + toString(int(0.54 * height)) + "\">" + toString(sharedCD) + "</text>\n";
816 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.39 * width) - ((int)toString(sharedABD).length() / 2)) + "\" y=\"" + toString(int(0.3 * height)) + "\">" + toString(sharedABD) + "</text>\n";
817 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.57 * width) - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"" + toString(int(0.45 * height)) + "\">" + toString(sharedBCD) + "</text>\n";
818 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.435 * width) - ((int)toString(sharedACD).length() / 2)) + "\" y=\"" + toString(int(0.45 * height)) + "\">" + toString(sharedACD) + "</text>\n";
819 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.63 * width) - ((int)toString(sharedABC).length() / 2)) + "\" y=\"" + toString(int(0.3 * height)) + "\">" + toString(sharedABC) + "</text>\n";
820 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedABCD).length() / 2)) + "\" y=\"" + toString(int(0.4 * height)) + "\">" + toString(sharedABCD) + "</text>\n";
822 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"24\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.975 * height)) + "\">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));
823 if (nseqs) { outsvg << ", and the number of squences in the otus shared by all groups is " + toString(sharedVal); }
824 outsvg << "</text>\n";
826 outsvg << "</g>\n</svg>\n";
836 catch(exception& e) {
837 m->errorOut(e, "Venn", "getPic");