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) : outputDir(o), nseqs(n) {
22 globaldata = GlobalData::getInstance();
23 m = MothurOut::getInstance();
27 m->errorOut(e, "Venn", "Venn");
31 //**********************************************************************************************************************
32 vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
35 vector<string> outputNames;
37 for(int i=0;i<vCalcs.size();i++){
38 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg";
39 outputNames.push_back(filenamesvg);
40 m->openOutputFile(filenamesvg, outsvg);
42 if (m->control_pressed) { outsvg.close(); return outputNames; }
44 vector<double> data = vCalcs[i]->getValues(sabund);
50 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";
53 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
54 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";
55 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)) + "\"/>";
56 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";
58 if (data.size() == 3) {
59 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";
60 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";
64 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";
67 outsvg << "</g>\n</svg>\n";
74 m->errorOut(e, "Venn", "getPic");
78 //**********************************************************************************************************************
79 vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
82 vector<SharedRAbundVector*> subset;
83 vector<string> outputNames;
88 /******************* 1 Group **************************/
89 if (lookup.size() == 1) {
92 s = lookup[0]->getSAbundVector(); SAbundVector* sabund = &s;
94 //make a file for each calculator
95 for(int i=0;i<vCalcs.size();i++){
96 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg";
97 outputNames.push_back(filenamesvg);
98 m->openOutputFile(filenamesvg, outsvg);
100 if (m->control_pressed) { outsvg.close(); return outputNames; }
102 //in essence you want to run it like a single
103 if (vCalcs[i]->getName() == "sharedsobs") {
104 singleCalc = new Sobs();
105 }else if (vCalcs[i]->getName() == "sharedchao") {
106 singleCalc = new Chao1();
107 }else if (vCalcs[i]->getName() == "sharedace") {
108 singleCalc = new Ace(10);
111 vector<double> data = singleCalc->getValues(sabund);
114 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";
117 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
118 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";
119 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)) + "\"/>";
120 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";
121 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";
123 if (data.size() == 3) {
124 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";
125 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";
129 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";
132 outsvg << "</g>\n</svg>\n";
137 /******************* 2 Groups **************************/
139 }else if (lookup.size() == 2) {
140 //get sabund vector pointers so you can use the single calculators
143 SAbundVector* sabundA; SAbundVector* sabundB;
144 sabundA = new SAbundVector(lookup[0]->getSAbundVector());// sabundA = &sA;
145 sabundB = new SAbundVector(lookup[1]->getSAbundVector());// sabundB = &sB;
148 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
150 //make a file for each calculator
151 for(int i=0;i<vCalcs.size();i++){
152 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg";
154 outputNames.push_back(filenamesvg);
155 m->openOutputFile(filenamesvg, outsvg);
157 if (m->control_pressed) { outsvg.close(); return outputNames; }
159 //get estimates for sharedAB
160 vector<double> shared = vCalcs[i]->getValues(subset);
162 //in essence you want to run it like a single
163 if (vCalcs[i]->getName() == "sharedsobs") {
164 singleCalc = new Sobs();
165 }else if (vCalcs[i]->getName() == "sharedchao") {
166 singleCalc = new Chao1();
167 }//else if (vCalcs[i]->getName() == "sharedace") {
168 //singleCalc = new Ace(10);
171 int sharedVal, numSeqsA, numSeqsB, uniqSeqsToA, uniqSeqsToB;
173 NSeqs* nseqsCalc = new NSeqs();
174 vector<double> data = nseqsCalc->getValues(lookup);
175 cout << data[0] << '\t' << data[1] << endl;
176 sharedVal = data[0] + data[1];
177 numSeqsA = sabundA->getNumSeqs();
178 numSeqsB = sabundB->getNumSeqs();
179 uniqSeqsToA = numSeqsA-data[0];
180 uniqSeqsToB = numSeqsB-data[1];
186 //get estimates for numA
187 vector<double> numA = singleCalc->getValues(sabundA);
189 //get estimates for numB
190 vector<double> numB = singleCalc->getValues(sabundB);
193 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";
197 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
198 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";
199 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)) + "\"/>";
200 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)) + "\"/>";
201 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";
202 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";
203 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";
204 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";
205 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";
206 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]);
207 if (numA.size() == 3) {
208 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
210 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared"; }
211 outsvg << "</text>\n";
213 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]);
214 if (numB.size() == 3) {
215 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
217 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared"; }
218 outsvg << "</text>\n";
220 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]);
221 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal) + "; " + toString((sharedVal / (float)(numSeqsA + numSeqsB))*100) + "% of these sequences are shared"; }
222 outsvg << "</text>\n";
224 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";
226 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";;
230 outsvg << "</g>\n</svg>\n";
234 /******************* 3 Groups **************************/
236 }else if (lookup.size() == 3) {
239 int windowSize = height;
242 //get sabund vector pointers so you can use the single calculators
244 SAbundVector sA, sB, sC;
245 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
246 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
247 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
248 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
250 //make a file for each calculator
251 for(int i=0;i<vCalcs.size();i++){
253 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg";
255 outputNames.push_back(filenamesvg);
256 m->openOutputFile(filenamesvg, outsvg);
258 if (m->control_pressed) { outsvg.close(); return outputNames; }
260 int sharedVal, sharedABVal, sharedACVal, sharedBCVal, numSeqsA, numSeqsB, numSeqsC, uniqSeqsToA, uniqSeqsToB, uniqSeqsToC;
263 NSeqs* nseqsCalc = new NSeqs();
264 vector<double> sharedData = nseqsCalc->getValues(lookup);
266 vector<SharedRAbundVector*> mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]);
267 vector<double> sharedAB = nseqsCalc->getValues(mysubset);
269 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]);
270 vector<double> sharedAC = nseqsCalc->getValues(mysubset);
272 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
273 vector<double> sharedBC = nseqsCalc->getValues(mysubset);
275 sharedVal = sharedData[0] + sharedData[1] + sharedData[2];
276 sharedABVal = sharedAB[0] + sharedAB[1];
277 sharedACVal = sharedAC[0] + sharedAC[1];
278 sharedBCVal = sharedBC[0] + sharedBC[1];
279 numSeqsA = sabundA->getNumSeqs();
280 numSeqsB = sabundB->getNumSeqs();
281 numSeqsC = sabundC->getNumSeqs();
282 uniqSeqsToA = numSeqsA-sharedData[0];
283 uniqSeqsToB = numSeqsC-sharedData[1];
284 uniqSeqsToC = numSeqsB-sharedData[1];
290 if (vCalcs[i]->getName() == "sharedace") {
292 singleCalc = new Ace(10);
294 //get estimates for numA
295 vector<double> numA = singleCalc->getValues(sabundA);
297 //get estimates for numB
298 vector<double> numB = singleCalc->getValues(sabundB);
300 //get estimates for numC
301 vector<double> numC = singleCalc->getValues(sabundC);
304 //get estimates for sharedAB, sharedAC and sharedBC
306 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
307 vector<double> sharedAB = vCalcs[i]->getValues(subset);
310 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
311 vector<double> sharedAC = vCalcs[i]->getValues(subset);
314 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
315 vector<double> sharedBC = vCalcs[i]->getValues(subset);
317 vector<double> sharedAwithBC;
318 vector<double> sharedBwithAC;
319 vector<double> sharedCwithAB;
321 //find possible sharedABC values
322 float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
324 if (vCalcs[i]->getMultiple() == false) {
325 //merge BC and estimate with shared with A
326 SharedRAbundVector* merge = new SharedRAbundVector();
327 for (int j = 0; j < lookup[1]->size(); j++) {
328 merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
332 subset.push_back(lookup[0]); subset.push_back(merge);
333 sharedAwithBC = vCalcs[i]->getValues(subset);
336 //merge AC and estimate with shared with B
337 merge = new SharedRAbundVector();
338 for (int j = 0; j < lookup[0]->size(); j++) {
339 merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
343 subset.push_back(merge); subset.push_back(lookup[1]);
344 sharedBwithAC = vCalcs[i]->getValues(subset);
347 //merge AB and estimate with shared with C
348 merge = new SharedRAbundVector();
349 for (int j = 0; j < lookup[0]->size(); j++) {
350 merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), "");
354 subset.push_back(lookup[2]); subset.push_back(merge);
355 sharedCwithAB = vCalcs[i]->getValues(subset);
358 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
359 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
360 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
362 //if any of the possible m's are - throw them out
363 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
364 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
365 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
367 //sharedABC is the minimum of the 3 possibilities
368 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
369 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
370 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }
372 vector<double> data = vCalcs[i]->getValues(lookup);
374 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
375 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
376 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
380 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";
384 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
385 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";
386 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)) + "\"/>";
387 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)) + "\"/>";
388 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)) + "\"/>";
390 //place labels within overlaps
391 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";
392 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";
393 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";
394 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";
395 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";
396 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";
397 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";
398 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";
399 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";
400 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";
402 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]);
403 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
404 outsvg << "</text>\n";
405 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]);
406 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
407 outsvg << "</text>\n";
408 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]);
409 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
410 outsvg << "</text>\n";
411 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";
412 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";
413 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";
414 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]);
415 if (numA.size() == 3) {
416 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
418 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared"; }
419 outsvg << "</text>\n";
421 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]);
422 if (numB.size() == 3) {
423 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
425 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared"; }
426 outsvg << "</text>\n";
428 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]);
429 if (numC.size() == 3) {
430 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
432 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC) + "; " + toString(uniqSeqsToC) + " sequences are not shared"; }
433 outsvg << "</text>\n";
435 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";
436 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);
437 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal); }
438 outsvg << "</text>\n";
442 }else { //sharedchao and sharedsobs are multigroup
444 vector<SharedRAbundVector*> subset;
446 //get estimates for numA
447 subset.push_back(lookup[0]);
448 vector<double> numA = vCalcs[i]->getValues(subset);
450 //get estimates for numB
452 subset.push_back(lookup[1]);
453 vector<double> numB = vCalcs[i]->getValues(subset);
455 //get estimates for numC
457 subset.push_back(lookup[2]);
458 vector<double> numC = vCalcs[i]->getValues(subset);
461 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
462 vector<double> sharedab = vCalcs[i]->getValues(subset);
465 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
466 vector<double> sharedac = vCalcs[i]->getValues(subset);
469 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
470 vector<double> sharedbc = vCalcs[i]->getValues(subset);
473 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
474 vector<double> sharedabc = vCalcs[i]->getValues(subset);
477 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";
481 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
482 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";
483 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)) + "\"/>";
484 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)) + "\"/>";
485 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)) + "\"/>";
487 //place labels within overlaps
488 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";
489 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";
490 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";
491 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";
492 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";
493 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";
494 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";
495 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";
496 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";
497 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";
499 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]);
500 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
501 outsvg << "</text>\n";
502 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]);
503 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
504 outsvg << "</text>\n";
505 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]);
506 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
507 outsvg << "</text>\n";
509 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]);
510 if (numA.size() == 3) {
511 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
513 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA); }
514 outsvg << "</text>\n";
516 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]);
517 if (numB.size() == 3) {
518 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
520 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB); }
521 outsvg << "</text>\n";
523 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]);
524 if (numC.size() == 3) {
525 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
527 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC); }
528 outsvg << "</text>\n";
530 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";
531 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]);
532 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal); }
533 outsvg << "</text>\n";
538 outsvg << "</g>\n</svg>\n";
544 /******************* 4 Groups **************************/
546 }else if (lookup.size() == 4) {
550 int windowSize = height;
552 //calc the shared otu
553 float sharedABCD = 0;
554 float numA = 0; float numB = 0; float numC = 0; float numD = 0;
555 float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
556 float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
558 //get sabund vector pointers so you can use the single calculators
560 SAbundVector sA, sB, sC, sD;
561 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
562 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
563 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
564 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
565 sD = lookup[3]->getSAbundVector(); sabundD = &sD;
567 //A = red, B = green, C = blue, D = yellow
569 //make a file for each calculator
570 for(int i=0;i<vCalcs.size();i++){
572 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(); }
574 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg";
575 outputNames.push_back(filenamesvg);
576 m->openOutputFile(filenamesvg, outsvg);
578 if (m->control_pressed) { outsvg.close(); return outputNames; }
580 //in essence you want to run it like a single
581 if (vCalcs[i]->getName() == "sharedsobs") {
582 singleCalc = new Sobs();
583 }else if (vCalcs[i]->getName() == "sharedchao") {
584 singleCalc = new Chao1();
587 //get estimates for numA
588 data = singleCalc->getValues(sabundA);
590 //cout << "num a = " << numA << endl;
592 //get estimates for numB
593 data = singleCalc->getValues(sabundB);
595 //cout << "num b = " << numB << endl;
596 //get estimates for numC
597 data = singleCalc->getValues(sabundC);
599 //cout << "num c = " << numC << endl;
600 //get estimates for numD
601 data = singleCalc->getValues(sabundD);
603 //cout << "num d = " << numD << endl;
605 //get estimates for pairs
607 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
608 data = vCalcs[i]->getValues(subset);
610 //cout << "num ab = " << sharedAB << endl;
612 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
613 data = vCalcs[i]->getValues(subset);
615 //cout << "num ac = " << sharedAC << endl;
617 subset.push_back(lookup[0]); subset.push_back(lookup[3]);
618 data = vCalcs[i]->getValues(subset);
620 //cout << "num ad = " << sharedAD << endl;
622 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
623 data = vCalcs[i]->getValues(subset);
625 //cout << "num bc = " << sharedBC << endl;
627 subset.push_back(lookup[1]); subset.push_back(lookup[3]);
628 data = vCalcs[i]->getValues(subset);
630 //cout << "num bd = " << sharedBD << endl;
632 subset.push_back(lookup[2]); subset.push_back(lookup[3]);
633 data = vCalcs[i]->getValues(subset);
636 //cout << "num cd = " << sharedCD << endl;
637 //get estimates for combos of 3
639 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
640 data = vCalcs[i]->getValues(subset);
642 //cout << "num abc = " << sharedABC << endl;
644 subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
645 data = vCalcs[i]->getValues(subset);
647 //cout << "num acd = " << sharedACD << endl;
649 subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
650 data = vCalcs[i]->getValues(subset);
652 //cout << "num bcd = " << sharedBCD << endl;
654 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
655 data = vCalcs[i]->getValues(subset);
657 //cout << "num abd = " << sharedABD << endl;
658 //get estimate for all four
659 data = vCalcs[i]->getValues(lookup);
660 sharedABCD = data[0];
661 //cout << "num abcd = " << sharedABCD << endl << endl;
662 int sharedVal, sharedABCVal, sharedABDVal, sharedACDVal, sharedBCDVal, sharedABVal, sharedACVal, sharedADVal, sharedBCVal, sharedBDVal, sharedCDVal, numSeqsA, numSeqsB, numSeqsC, numSeqsD;
665 NSeqs* nseqsCalc = new NSeqs();
666 vector<double> sharedData = nseqsCalc->getValues(lookup);
668 vector<SharedRAbundVector*> mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]);
669 vector<double> sharedAB = nseqsCalc->getValues(mysubset);
671 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]);
672 vector<double> sharedAC = nseqsCalc->getValues(mysubset);
674 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[3]);
675 vector<double> sharedAD = nseqsCalc->getValues(mysubset);
677 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
678 vector<double> sharedBC = nseqsCalc->getValues(mysubset);
680 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]);
681 vector<double> sharedBD = nseqsCalc->getValues(mysubset);
683 mysubset.clear(); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
684 vector<double> sharedCD = nseqsCalc->getValues(mysubset);
686 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
687 vector<double> sharedABC = nseqsCalc->getValues(mysubset);
689 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]);
690 vector<double> sharedABD = nseqsCalc->getValues(mysubset);
692 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
693 vector<double> sharedACD = nseqsCalc->getValues(mysubset);
695 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
696 vector<double> sharedBCD = nseqsCalc->getValues(mysubset);
698 sharedVal = sharedData[0] + sharedData[1] + sharedData[2] + sharedData[3];
699 sharedABCVal = sharedABC[0] + sharedABC[1] + sharedABC[2];
700 sharedABDVal = sharedABD[0] + sharedABD[1] + sharedABD[2];
701 sharedACDVal = sharedACD[0] + sharedACD[1] + sharedACD[2];
702 sharedBCDVal = sharedBCD[0] + sharedBCD[1] + sharedBCD[2];
703 sharedABVal = sharedAB[0] + sharedAB[1];
704 sharedACVal = sharedAC[0] + sharedAC[1];
705 sharedADVal = sharedAD[0] + sharedAD[1];
706 sharedBCVal = sharedBC[0] + sharedBC[1];
707 sharedBDVal = sharedBD[0] + sharedBD[1];
708 sharedCDVal = sharedCD[0] + sharedCD[1];
709 numSeqsA = sabundA->getNumSeqs();
710 numSeqsB = sabundB->getNumSeqs();
711 numSeqsC = sabundC->getNumSeqs();
712 numSeqsD = sabundD->getNumSeqs();
719 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";
721 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(windowSize) + "\"/>";
722 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";
724 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);
725 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA); }
726 outsvg << "</text>\n";
727 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);
728 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB); }
729 outsvg << "</text>\n";
730 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);
731 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC); }
732 outsvg << "</text>\n";
733 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);
734 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsD); }
735 outsvg << "</text>\n";
737 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);
738 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
739 outsvg << "</text>\n";
740 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);
741 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
742 outsvg << "</text>\n";
743 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);
744 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedADVal); }
745 outsvg << "</text>\n";
746 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);
747 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
748 outsvg << "</text>\n";
749 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);
750 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBDVal); }
751 outsvg << "</text>\n";
752 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);
753 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedCDVal); }
754 outsvg << "</text>\n";
756 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);
757 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABCVal); }
758 outsvg << "</text>\n";
759 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);
760 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABDVal); }
761 outsvg << "</text>\n";
762 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);
763 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACDVal); }
764 outsvg << "</text>\n";
765 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);
766 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCDVal); }
767 outsvg << "</text>\n";
770 sharedABC = sharedABC - sharedABCD;
771 //cout << "num abc = " << sharedABC << endl;
772 sharedABD = sharedABD - sharedABCD;
773 //cout << "num abd = " << sharedABD << endl;
774 sharedACD = sharedACD - sharedABCD;
775 //cout << "num acd = " << sharedACD << endl;
776 sharedBCD = sharedBCD - sharedABCD;
777 //cout << "num bcd = " << sharedBCD << endl;
779 sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD; //cout << "num ab = " << sharedAB << endl;
780 sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD; //cout << "num ac = " << sharedAC << endl;
781 sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD; //cout << "num ad = " << sharedAD << endl;
782 sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD; //cout << "num bc = " << sharedBC << endl;
783 sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl;
784 sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD; //cout << "num cd = " << sharedCD << endl;
786 numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
787 //cout << "num a = " << numA << endl;
788 numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
789 //cout << "num b = " << numB << endl;
790 numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
791 //cout << "num c = " << numC << endl;
792 numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
793 //cout << "num d = " << numD << endl;
796 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 ";
797 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 ";
798 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 ";
799 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 ";
801 //A = red, B = green, C = blue, D = yellow
803 //place labels within overlaps
804 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";
805 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";
806 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";
807 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";
808 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";
809 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";
810 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";
811 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";
812 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";
813 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";
814 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";
815 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";
816 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";
817 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";
818 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";
819 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";
820 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";
821 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";
822 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";
824 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));
825 if (nseqs) { outsvg << ", and the number of squences in the otus shared by all groups is " + toString(sharedVal); }
826 outsvg << "</text>\n";
828 outsvg << "</g>\n</svg>\n";
838 catch(exception& e) {
839 m->errorOut(e, "Venn", "getPic");