1 /*
2 * venn.cpp
3 * Mothur
4 *
5 * Created by Sarah Westcott on 3/30/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7 *
8 */
9
10 #include "venn.h"
11 #include "ace.h"
12 #include "sobs.h"
13 #include "chao1.h"
14 #include "nseqs.h"
15 #include "sharedchao1.h"
16 #include "sharedsobscollectsummary.h"
17
18
19 //**********************************************************************************************************************
Venn(string o,bool n,string f,int fs,bool so)20 Venn::Venn(string o, bool n, string f, int fs, bool so) : outputDir(o), nseqs(n), inputfile(f), fontSize(fs), sharedOtus(so) {
21 try {
22 m = MothurOut::getInstance();
23 }
24 catch(exception& e) {
25 m->errorOut(e, "Venn", "Venn");
26 exit(1);
27 }
28 }
29 //**********************************************************************************************************************
getPic(SAbundVector * sabund,vector<Calculator * > vCalcs)30 vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
31 try {
32
33 vector<string> outputNames;
34
35 for(int i=0;i<vCalcs.size();i++){
36 string filenamesvg = outputDir + util.getRootName(util.getSimpleName(inputfile)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg";
37 outputNames.push_back(filenamesvg);
38 util.openOutputFile(filenamesvg, outsvg);
39
40 if (m->getControl_pressed()) { outsvg.close(); return outputNames; }
41
42 vector<double> data = vCalcs[i]->getValues(sabund);
43
44 int width = 1500;
45 int height = 1500;
46
47 //svg image
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";
49 outsvg << "<g>\n";
50
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=\"" + toString(fontSize) + "\" 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=\"" + toString(fontSize) + "\" x=\"" + toString((width / 2) - ((int)toString(data[0]).length() / 2)) + "\" y=\"" + toString(int(0.28 * height)) + "\">" + toString(data[0]) + "</text>\n";
55
56 if (data.size() == 3) {
57 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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=\"" + toString(fontSize) + "\" 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";
59 }
60
61 if (nseqs) {
62 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.35 * width)) + "\" y=\"" + toString(int(0.70 * height)) + "\">The number of sequences represented is " + toString(sabund->getNumSeqs()) + "</text>\n";
63 }
64
65 outsvg << "</g>\n</svg>\n";
66 outsvg.close();
67 }
68
69 return outputNames;
70 }
71 catch(exception& e) {
72 m->errorOut(e, "Venn", "getPic");
73 exit(1);
74 }
75 }
76 //**********************************************************************************************************************
getPic(vector<SharedRAbundVector * > lookup,vector<Calculator * > vCalcs,vector<string> thisOtuLabels)77 vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs, vector<string> thisOtuLabels) {
78 try {
79
80 vector<SharedRAbundVector*> subset;
81 vector<string> outputNames;
82
83 int width = 1500;
84 int height = 1500;
85
86 /******************* 1 Group **************************/
87 if (lookup.size() == 1) {
88
89 SAbundVector s;
90 s = lookup[0]->getSAbundVector(); SAbundVector* sabund = &s;
91
92 //make a file for each calculator
93 for(int i=0;i<vCalcs.size();i++){
94 string filenamesvg = outputDir + util.getRootName(util.getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg";
95 outputNames.push_back(filenamesvg);
96 util.openOutputFile(filenamesvg, outsvg);
97
98 if (m->getControl_pressed()) { outsvg.close(); return outputNames; }
99
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);
107 }
108
109 vector<double> data = singleCalc->getValues(sabund);
110
111 //svg image
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";
113 outsvg << "<g>\n";
114
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=\"" + toString(fontSize) + "\" 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=\"" + toString(fontSize) + "\" 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=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.50 * width) - ((int)toString(data[0]).length() / 2)) + "\" y=\"" + toString(int(0.28 * height)) + "\">" + toString(data[0]) + "</text>\n";
120
121 if (data.size() == 3) {
122 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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=\"" + toString(fontSize) + "\" 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";
124 }
125
126 if (nseqs) {
127 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.35 * width)) + "\" y=\"" + toString(int(0.70 * height)) + "\">The number of sequences represented is " + toString(sabund->getNumSeqs()) + "</text>\n";
128 }
129
130 outsvg << "</g>\n</svg>\n";
131 outsvg.close();
132 delete singleCalc;
133
134 }
135 /******************* 2 Groups **************************/
136
137 }else if (lookup.size() == 2) {
138 //get sabund vector pointers so you can use the single calculators
139 //one for each group
140 SAbundVector sA, sB;
141 SAbundVector* sabundA; SAbundVector* sabundB;
142 sabundA = new SAbundVector(lookup[0]->getSAbundVector());// sabundA = &sA;
143 sabundB = new SAbundVector(lookup[1]->getSAbundVector());// sabundB = &sB;
144
145 subset.clear();
146 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
147
148 //make a file for each calculator
149 for(int i=0;i<vCalcs.size();i++){
150 string filenamesvg = outputDir + util.getRootName(util.getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg";
151
152 outputNames.push_back(filenamesvg);
153 util.openOutputFile(filenamesvg, outsvg);
154
155 if (m->getControl_pressed()) { outsvg.close(); delete sabundA; delete sabundB; return outputNames; }
156
157 //get estimates for sharedAB
158 vector<string> labels;
159 vector<double> shared = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
160
161 //in essence you want to run it like a single
162 if (vCalcs[i]->getName() == "sharedsobs") {
163 singleCalc = new Sobs();
164 if (sharedOtus && (labels.size() != 0)) {
165 string groupsTag = "";
166 for (int h = 0; h < lookup.size()-1; h++) { groupsTag += lookup[h]->getGroup() + "-"; } groupsTag += lookup[lookup.size()-1]->getGroup();
167 string filenameShared = outputDir + util.getRootName(util.getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + groupsTag + ".sharedotus";
168
169 outputNames.push_back(filenameShared);
170 ofstream outShared;
171 util.openOutputFile(filenameShared, outShared);
172 outShared << "Groups\tNumShared\tOTULabels\n";
173 outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t' << labels.size() << '\t';
174 for (int k = 0; k < labels.size()-1; k++) {
175 outShared << labels[k] << ",";
176 }
177 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
178 outShared << endl;
179 outShared.close();
180 }
181 }else if (vCalcs[i]->getName() == "sharedchao") {
182 singleCalc = new Chao1();
183 }
184
185 int sharedVal, numSeqsA, numSeqsB, uniqSeqsToA, uniqSeqsToB;
186 if (nseqs) {
187 NSeqs* nseqsCalc = new NSeqs();
188 vector<double> data = nseqsCalc->getValues(lookup);
189 sharedVal = data[0] + data[1];
190 numSeqsA = sabundA->getNumSeqs();
191 numSeqsB = sabundB->getNumSeqs();
192 uniqSeqsToA = numSeqsA-data[0];
193 uniqSeqsToB = numSeqsB-data[1];
194
195 delete nseqsCalc;
196 }
197
198
199 //get estimates for numA
200 vector<double> numA = singleCalc->getValues(sabundA);
201
202 //get estimates for numB
203 vector<double> numB = singleCalc->getValues(sabundB);
204
205 //image window
206 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";
207 outsvg << "<g>\n";
208
209 //draw circles
210 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
211 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.05 * height)) + "\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
212 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)) + "\"/>";
213 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)) + "\"/>";
214 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
215 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
216 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.29 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.25 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
217 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.7 * width) - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.25 * height)) + "\">" + lookup[1]->getGroup() + "</text>\n";
218 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.5 * width) - ((int)toString(shared[0]).length() / 2)) + "\" y=\"" + toString(int(0.28 * height)) + "\">" + toString(shared[0]) + "</text>\n";
219 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
220 if (numA.size() == 3) {
221 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
222 }
223 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared"; }
224 outsvg << "</text>\n";
225
226 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
227 if (numB.size() == 3) {
228 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
229 }
230 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared"; }
231 outsvg << "</text>\n";
232
233 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.72 * height)) + "\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(shared[0]);
234 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal) + "; " + toString((sharedVal / (float)(numSeqsA + numSeqsB))*100) + "% of these sequences are shared"; }
235 outsvg << "</text>\n";
236
237 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
238
239 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";;
240
241
242 //close file
243 outsvg << "</g>\n</svg>\n";
244 outsvg.close();
245 delete singleCalc;
246 }
247 /******************* 3 Groups **************************/
248
249 }else if (lookup.size() == 3) {
250
251 height = 1600;
252 int windowSize = height;
253
254
255 //get sabund vector pointers so you can use the single calculators
256 //one for each group
257 SAbundVector sA, sB, sC;
258 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
259 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
260 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
261 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
262
263 //make a file for each calculator
264 for(int i=0;i<vCalcs.size();i++){
265
266 string filenamesvg = outputDir + util.getRootName(util.getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg";
267
268 outputNames.push_back(filenamesvg);
269 util.openOutputFile(filenamesvg, outsvg);
270
271 if (m->getControl_pressed()) { outsvg.close(); return outputNames; }
272
273 int sharedVal, sharedABVal, sharedACVal, sharedBCVal, numSeqsA, numSeqsB, numSeqsC, uniqSeqsToA, uniqSeqsToB, uniqSeqsToC;
274
275 if (nseqs) {
276 NSeqs* nseqsCalc = new NSeqs();
277 vector<double> sharedData = nseqsCalc->getValues(lookup);
278
279 vector<SharedRAbundVector*> mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]);
280 vector<double> sharedAB = nseqsCalc->getValues(mysubset);
281
282 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]);
283 vector<double> sharedAC = nseqsCalc->getValues(mysubset);
284
285 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
286 vector<double> sharedBC = nseqsCalc->getValues(mysubset);
287
288 sharedVal = sharedData[0] + sharedData[1] + sharedData[2];
289 sharedABVal = sharedAB[0] + sharedAB[1];
290 sharedACVal = sharedAC[0] + sharedAC[1];
291 sharedBCVal = sharedBC[0] + sharedBC[1];
292 numSeqsA = sabundA->getNumSeqs();
293 numSeqsB = sabundB->getNumSeqs();
294 numSeqsC = sabundC->getNumSeqs();
295 uniqSeqsToA = numSeqsA-sharedData[0];
296 uniqSeqsToB = numSeqsC-sharedData[1];
297 uniqSeqsToC = numSeqsB-sharedData[1];
298
299 delete nseqsCalc;
300 }
301
302
303 if (vCalcs[i]->getName() == "sharedace") {
304
305 singleCalc = new Ace(10);
306
307 //get estimates for numA
308 vector<double> numA = singleCalc->getValues(sabundA);
309
310 //get estimates for numB
311 vector<double> numB = singleCalc->getValues(sabundB);
312
313 //get estimates for numC
314 vector<double> numC = singleCalc->getValues(sabundC);
315
316
317 //get estimates for sharedAB, sharedAC and sharedBC
318 subset.clear();
319 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
320 vector<double> sharedAB = vCalcs[i]->getValues(subset);
321
322 subset.clear();
323 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
324 vector<double> sharedAC = vCalcs[i]->getValues(subset);
325
326 subset.clear();
327 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
328 vector<double> sharedBC = vCalcs[i]->getValues(subset);
329
330 vector<double> sharedAwithBC;
331 vector<double> sharedBwithAC;
332 vector<double> sharedCwithAB;
333
334 //find possible sharedABC values
335 float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
336
337 if (vCalcs[i]->getMultiple() == false) {
338 //merge BC and estimate with shared with A
339 SharedRAbundVector* merge = new SharedRAbundVector();
340 for (int j = 0; j < lookup[1]->size(); j++) { merge->push_back((lookup[1]->get(j) + lookup[2]->get(j))); }
341
342 subset.clear();
343 subset.push_back(lookup[0]); subset.push_back(merge);
344 sharedAwithBC = vCalcs[i]->getValues(subset);
345
346 delete merge;
347 //merge AC and estimate with shared with B
348 merge = new SharedRAbundVector();
349 for (int j = 0; j < lookup[0]->size(); j++) { merge->push_back((lookup[0]->get(j) + lookup[2]->get(j))); }
350
351 subset.clear();
352 subset.push_back(merge); subset.push_back(lookup[1]);
353 sharedBwithAC = vCalcs[i]->getValues(subset);
354
355 delete merge;
356 //merge AB and estimate with shared with C
357 merge = new SharedRAbundVector();
358 for (int j = 0; j < lookup[0]->size(); j++) { merge->push_back((lookup[0]->get(j) + lookup[1]->get(j))); }
359
360 subset.clear();
361 subset.push_back(lookup[2]); subset.push_back(merge);
362 sharedCwithAB = vCalcs[i]->getValues(subset);
363 delete merge;
364
365 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
366 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
367 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
368
369 //if any of the possible m's are - throw them out
370 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
371 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
372 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
373
374 //sharedABC is the minimum of the 3 possibilities
375 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
376 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
377 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }
378 }else{
379 vector<double> data = vCalcs[i]->getValues(lookup);
380 sharedABC = data[0];
381 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
382 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
383 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
384 }
385
386 //image window
387 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(width) + " " + toString(windowSize) + " \" >\n";
388 outsvg << "<g>\n";
389
390 //draw circles
391 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
392 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.44 * height)) + "\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
393 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)) + "\"/>";
394 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)) + "\"/>";
395 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)) + "\"/>";
396
397 //place labels within overlaps
398 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
399 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.33 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
400 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
401 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
402 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.7 * width) - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[1]->getGroup() + "</text>\n";
403 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
404 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
405 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.5 * width) - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.52 * height)) + "\">" + lookup[2]->getGroup() + "</text>\n";
406 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
407 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedABC).length() / 2)) + "\" y=\"" + toString(int(0.34 * height)) + "\">" + toString(sharedABC) + "</text>\n";
408
409 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
410 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
411 outsvg << "</text>\n";
412 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
413 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
414 outsvg << "</text>\n";
415 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
416 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
417 outsvg << "</text>\n";
418 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
419 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
420 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
421 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
422 if (numA.size() == 3) {
423 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
424 }
425 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared"; }
426 outsvg << "</text>\n";
427
428 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
429 if (numB.size() == 3) {
430 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
431 }
432 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared"; }
433 outsvg << "</text>\n";
434
435 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
436 if (numC.size() == 3) {
437 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
438 }
439 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC) + "; " + toString(uniqSeqsToC) + " sequences are not shared"; }
440 outsvg << "</text>\n";
441
442 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
443 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.975 * height)) + "\">The total shared richness is " + toString(sharedABC);
444 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal); }
445 outsvg << "</text>\n";
446
447 delete singleCalc;
448
449 }else { //sharedchao and sharedsobs are multigroup
450
451 ofstream outShared;
452 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
453 string groupsTag = "";
454 for (int h = 0; h < lookup.size()-1; h++) { groupsTag += lookup[h]->getGroup() + "-"; } groupsTag += lookup[lookup.size()-1]->getGroup();
455 string filenameShared = outputDir + util.getRootName(util.getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + groupsTag + ".sharedotus";
456
457 outputNames.push_back(filenameShared);
458
459 util.openOutputFile(filenameShared, outShared);
460 outShared << "Groups\tNumShared\tOTULabels\n";
461 }
462 vector<SharedRAbundVector*> subset;
463
464 //get estimates for numA
465 subset.push_back(lookup[0]);
466 vector<double> numA = vCalcs[i]->getValues(subset);
467
468 //get estimates for numB
469 subset.clear();
470 subset.push_back(lookup[1]);
471 vector<double> numB = vCalcs[i]->getValues(subset);
472
473 //get estimates for numC
474 subset.clear();
475 subset.push_back(lookup[2]);
476 vector<double> numC = vCalcs[i]->getValues(subset);
477
478 subset.clear();
479 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
480 vector<string> labels;
481 vector<double> sharedab = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
482 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
483 outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t' << labels.size() << '\t';
484 for (int k = 0; k < labels.size()-1; k++) {
485 outShared << labels[k] << ",";
486 }
487 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
488 outShared << endl;
489 }
490
491 subset.clear();
492 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
493 vector<double> sharedac = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
494 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
495 outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
496 for (int k = 0; k < labels.size()-1; k++) {
497 outShared << labels[k] << ",";
498 }
499 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
500 outShared << endl;
501 }
502
503 subset.clear();
504 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
505 vector<double> sharedbc = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
506 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
507 outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
508 for (int k = 0; k < labels.size()-1; k++) {
509 outShared << labels[k] << ",";
510 }
511 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
512 outShared << endl;
513 }
514
515
516 subset.clear();
517 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
518 vector<double> sharedabc = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
519 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
520 outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
521 for (int k = 0; k < labels.size()-1; k++) {
522 outShared << labels[k] << ",";
523 }
524 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
525 outShared << endl;
526 outShared.close();
527 }
528
529 //image window
530 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";
531 outsvg << "<g>\n";
532
533 //draw circles
534 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(height) + "\"/>";
535 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.05 * height)) + "\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
536 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)) + "\"/>";
537 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)) + "\"/>";
538 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)) + "\"/>";
539
540 //place labels within overlaps
541 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
542 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.29 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
543 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
544 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
545 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.68 * width) - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.19 * height)) + "\">" + lookup[1]->getGroup() + "</text>\n";
546 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
547 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
548 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.5 * width) - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.51 * height)) + "\">" + lookup[2]->getGroup() + "</text>\n";
549 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
550 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedabc[0]).length() / 2)) + "\" y=\"" + toString(int(0.35 * height)) + "\">" + toString(sharedabc[0]) + "</text>\n";
551
552 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
553 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
554 outsvg << "</text>\n";
555 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
556 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
557 outsvg << "</text>\n";
558 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
559 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
560 outsvg << "</text>\n";
561
562 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
563 if (numA.size() == 3) {
564 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
565 }
566 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA); }
567 outsvg << "</text>\n";
568
569 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
570 if (numB.size() == 3) {
571 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
572 }
573 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB); }
574 outsvg << "</text>\n";
575
576 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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]);
577 if (numC.size() == 3) {
578 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
579 }
580 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC); }
581 outsvg << "</text>\n";
582
583 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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";
584 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.9 * height)) + "\">The total shared richness is " + toString(sharedabc[0]);
585 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedVal); }
586 outsvg << "</text>\n";
587
588 }
589
590 //close file
591 outsvg << "</g>\n</svg>\n";
592 outsvg.close();
593
594
595 }
596
597 /******************* 4 Groups **************************/
598
599 }else if (lookup.size() == 4) {
600
601 height = 1600;
602
603 int windowSize = height;
604
605 //calc the shared otu
606 float sharedABCD = 0;
607 float numA = 0; float numB = 0; float numC = 0; float numD = 0;
608 float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
609 float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
610 vector<double> data;
611 //get sabund vector pointers so you can use the single calculators
612 //one for each group
613 SAbundVector sA, sB, sC, sD;
614 SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
615 sA = lookup[0]->getSAbundVector(); sabundA = &sA;
616 sB = lookup[1]->getSAbundVector(); sabundB = &sB;
617 sC = lookup[2]->getSAbundVector(); sabundC = &sC;
618 sD = lookup[3]->getSAbundVector(); sabundD = &sD;
619
620 //A = red, B = green, C = blue, D = yellow
621
622 //make a file for each calculator
623 for(int i=0;i<vCalcs.size();i++){
624
625 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. \n"); }
626 else{
627 string filenamesvg = outputDir + util.getRootName(util.getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg";
628 outputNames.push_back(filenamesvg);
629 util.openOutputFile(filenamesvg, outsvg);
630
631 if (m->getControl_pressed()) { outsvg.close(); return outputNames; }
632
633 //in essence you want to run it like a single
634 if (vCalcs[i]->getName() == "sharedsobs") {
635 singleCalc = new Sobs();
636 }else if (vCalcs[i]->getName() == "sharedchao") {
637 singleCalc = new Chao1();
638 }
639
640 //get estimates for numA
641 data = singleCalc->getValues(sabundA);
642 numA = data[0];
643
644
645 //get estimates for numB
646 data = singleCalc->getValues(sabundB);
647 numB = data[0];
648
649 //get estimates for numC
650 data = singleCalc->getValues(sabundC);
651 numC = data[0];
652
653 //get estimates for numD
654 data = singleCalc->getValues(sabundD);
655 numD = data[0];
656
657 ofstream outShared;
658 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
659 string groupsTag = "";
660 for (int h = 0; h < lookup.size()-1; h++) { groupsTag += lookup[h]->getGroup() + "-"; } groupsTag += lookup[lookup.size()-1]->getGroup();
661 string filenameShared = outputDir + util.getRootName(util.getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + groupsTag + ".sharedotus";
662
663 outputNames.push_back(filenameShared);
664
665 util.openOutputFile(filenameShared, outShared);
666 outShared << "Groups\tNumShared\tOTULabels\n";
667 }
668
669 //get estimates for pairs
670 subset.clear();
671 vector<string> labels;
672 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
673 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
674 sharedAB = data[0];
675 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
676 outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t'<< labels.size() << '\t';
677 for (int k = 0; k < labels.size()-1; k++) {
678 outShared << labels[k] << ",";
679 }
680 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
681 outShared << endl;
682 }
683
684 subset.clear();
685 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
686 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
687 sharedAC = data[0];
688 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
689 outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
690 for (int k = 0; k < labels.size()-1; k++) {
691 outShared << labels[k] << ",";
692 }
693 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
694 outShared << endl;
695 }
696
697 subset.clear();
698 subset.push_back(lookup[0]); subset.push_back(lookup[3]);
699 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
700 sharedAD = data[0];
701 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
702 outShared << lookup[0]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
703 for (int k = 0; k < labels.size()-1; k++) {
704 outShared << labels[k] << ",";
705 }
706 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
707 outShared << endl;
708 }
709
710 subset.clear();
711 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
712 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
713 sharedBC = data[0];
714 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
715 outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
716 for (int k = 0; k < labels.size()-1; k++) {
717 outShared << labels[k] << ",";
718 }
719 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
720 outShared << endl;
721 }
722
723 subset.clear();
724 subset.push_back(lookup[1]); subset.push_back(lookup[3]);
725 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
726 sharedBD = data[0];
727 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
728 outShared << lookup[1]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
729 for (int k = 0; k < labels.size()-1; k++) {
730 outShared << labels[k] << ",";
731 }
732 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
733 outShared << endl;
734 }
735
736 subset.clear();
737 subset.push_back(lookup[2]); subset.push_back(lookup[3]);
738 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
739 sharedCD = data[0];
740 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
741 outShared << lookup[2]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
742 for (int k = 0; k < labels.size()-1; k++) {
743 outShared << labels[k] << ",";
744 }
745 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
746 outShared << endl;
747 }
748
749
750 //get estimates for combos of 3
751 subset.clear();
752 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
753 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
754 sharedABC = data[0];
755 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
756 outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup()+ "-" + lookup[2]->getGroup()<< '\t'<< labels.size() << '\t';
757 for (int k = 0; k < labels.size()-1; k++) {
758 outShared << labels[k] << ",";
759 }
760 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
761 outShared << endl;
762 }
763
764 subset.clear();
765 subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
766 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
767 sharedACD = data[0];
768 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
769 outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
770 for (int k = 0; k < labels.size()-1; k++) {
771 outShared << labels[k] << ",";
772 }
773 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
774 outShared << endl;
775 }
776
777 subset.clear();
778 subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
779 data = vCalcs[i]->getValues(subset,labels, thisOtuLabels);
780 sharedBCD = data[0];
781 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
782 outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
783 for (int k = 0; k < labels.size()-1; k++) {
784 outShared << labels[k] << ",";
785 }
786 outShared << labels[labels.size()-1];
787 outShared << endl;
788 }
789
790 subset.clear();
791 subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
792 data = vCalcs[i]->getValues(subset, labels, thisOtuLabels);
793 sharedABD = data[0];
794 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
795 outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
796 for (int k = 0; k < labels.size()-1; k++) {
797 outShared << labels[k] << ",";
798 }
799 outShared << labels[labels.size()-1];
800 outShared << endl;
801 }
802
803 //get estimate for all four
804 data = vCalcs[i]->getValues(lookup, labels, thisOtuLabels);
805 sharedABCD = data[0];
806 if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") && (labels.size() != 0)) {
807 outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
808 for (int k = 0; k < labels.size()-1; k++) {
809 outShared << labels[k] << ",";
810 }
811 if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
812 outShared << endl;
813 outShared.close();
814 }
815
816 int sharedVal, sharedABCVal, sharedABDVal, sharedACDVal, sharedBCDVal, sharedABVal, sharedACVal, sharedADVal, sharedBCVal, sharedBDVal, sharedCDVal, numSeqsA, numSeqsB, numSeqsC, numSeqsD;
817
818 if (nseqs) {
819 NSeqs* nseqsCalc = new NSeqs();
820 vector<double> sharedData = nseqsCalc->getValues(lookup);
821
822 vector<SharedRAbundVector*> mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]);
823 vector<double> sharedAB = nseqsCalc->getValues(mysubset);
824
825 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]);
826 vector<double> sharedAC = nseqsCalc->getValues(mysubset);
827
828 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[3]);
829 vector<double> sharedAD = nseqsCalc->getValues(mysubset);
830
831 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
832 vector<double> sharedBC = nseqsCalc->getValues(mysubset);
833
834 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]);
835 vector<double> sharedBD = nseqsCalc->getValues(mysubset);
836
837 mysubset.clear(); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
838 vector<double> sharedCD = nseqsCalc->getValues(mysubset);
839
840 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
841 vector<double> sharedABC = nseqsCalc->getValues(mysubset);
842
843 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]);
844 vector<double> sharedABD = nseqsCalc->getValues(mysubset);
845
846 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
847 vector<double> sharedACD = nseqsCalc->getValues(mysubset);
848
849 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
850 vector<double> sharedBCD = nseqsCalc->getValues(mysubset);
851
852 sharedVal = sharedData[0] + sharedData[1] + sharedData[2] + sharedData[3];
853 sharedABCVal = sharedABC[0] + sharedABC[1] + sharedABC[2];
854 sharedABDVal = sharedABD[0] + sharedABD[1] + sharedABD[2];
855 sharedACDVal = sharedACD[0] + sharedACD[1] + sharedACD[2];
856 sharedBCDVal = sharedBCD[0] + sharedBCD[1] + sharedBCD[2];
857 sharedABVal = sharedAB[0] + sharedAB[1];
858 sharedACVal = sharedAC[0] + sharedAC[1];
859 sharedADVal = sharedAD[0] + sharedAD[1];
860 sharedBCVal = sharedBC[0] + sharedBC[1];
861 sharedBDVal = sharedBD[0] + sharedBD[1];
862 sharedCDVal = sharedCD[0] + sharedCD[1];
863 numSeqsA = sabundA->getNumSeqs();
864 numSeqsB = sabundB->getNumSeqs();
865 numSeqsC = sabundC->getNumSeqs();
866 numSeqsD = sabundD->getNumSeqs();
867
868 delete nseqsCalc;
869 }
870
871
872 //image window
873 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";
874 outsvg << "<g>\n";
875 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(width) + "\" height=\"" + toString(windowSize) + "\"/>";
876 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.40 * width)) + "\" y=\"" + toString(int(0.05 * height)) + "\" >Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
877
878 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.625 * height)) + "\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA);
879 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsA); }
880 outsvg << "</text>\n";
881 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.65 * height)) + "\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB);
882 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsB); }
883 outsvg << "</text>\n";
884 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.675 * height)) + "\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC);
885 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsC); }
886 outsvg << "</text>\n";
887 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.25 * width)) + "\" y=\"" + toString(int(0.7 * height)) + "\">The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD);
888 if (nseqs) { outsvg << ", and the number of squences is " + toString(numSeqsD); }
889 outsvg << "</text>\n";
890
891 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
892 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABVal); }
893 outsvg << "</text>\n";
894 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
895 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACVal); }
896 outsvg << "</text>\n";
897 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
898 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedADVal); }
899 outsvg << "</text>\n";
900 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
901 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCVal); }
902 outsvg << "</text>\n";
903 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
904 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBDVal); }
905 outsvg << "</text>\n";
906 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
907 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedCDVal); }
908 outsvg << "</text>\n";
909
910 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
911 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABCVal); }
912 outsvg << "</text>\n";
913 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
914 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedABDVal); }
915 outsvg << "</text>\n";
916 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
917 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedACDVal); }
918 outsvg << "</text>\n";
919 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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);
920 if (nseqs) { outsvg << ", and the number of squences is " + toString(sharedBCDVal); }
921 outsvg << "</text>\n";
922
923 //make adjustments
924 sharedABC = sharedABC - sharedABCD;
925
926 sharedABD = sharedABD - sharedABCD;
927
928 sharedACD = sharedACD - sharedABCD;
929
930 sharedBCD = sharedBCD - sharedABCD;
931
932
933 sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD;
934 sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD;
935 sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD;
936 sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD;
937 sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD;
938 sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD;
939
940 numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
941 numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
942 numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
943 numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
944
945
946 //draw circles
947 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 ";
948 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 ";
949 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 ";
950 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 ";
951
952 //A = red, B = green, C = blue, D = yellow
953
954 //place labels within overlaps
955 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.66 * width) - ((int)toString(numA).length() / 2)) + "\" y=\"" + toString(int(0.14 * height)) + "\">" + toString(numA) + "</text>\n";
956 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.66 * width) - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.11 * height)) + "\">" + lookup[0]->getGroup() + "</text>\n";
957 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedAB).length() / 2)) + "\" y=\"" + toString(int(0.2 * height)) + "\">" + toString(sharedAB) + "</text>\n";
958 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.36 * width) - ((int)toString(numB).length() / 2)) + "\" y=\"" + toString(int(0.14 * height)) + "\">" + toString(numB) + "</text>\n";
959 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.36 * width) - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.11 * height)) + "\">" + lookup[1]->getGroup() + "</text>\n";
960 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.7 * width) - ((int)toString(sharedAC).length() / 2)) + "\" y=\"" + toString(int(0.24 * height)) + "\">" + toString(sharedAC) + "</text>\n";
961 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.785 * width) - ((int)toString(numC).length() / 2)) + "\" y=\"" + toString(int(0.29 * height)) + "\">" + toString(numC) + "</text>\n";
962 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.785 * width) - ((int)lookup[2]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.26 * height)) + "\">" + lookup[2]->getGroup() + "</text>\n";
963 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.31 * width) - ((int)toString(sharedBD).length() / 2)) + "\" y=\"" + toString(int(0.24 * height)) + "\">" + toString(sharedBD) + "</text>\n";
964 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.22 * width) - ((int)toString(numD).length() / 2)) + "\" y=\"" + toString(int(0.29 * height)) + "\">" + toString(numD) + "</text>\n";
965 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.22 * width) - ((int)lookup[3]->getGroup().length() / 2)) + "\" y=\"" + toString(int(0.26 * height)) + "\">" + lookup[3]->getGroup() + "</text>\n";
966 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.34 * width) - ((int)toString(sharedAD).length() / 2)) + "\" y=\"" + toString(int(0.41 * height)) + "\">" + toString(sharedAD) + "</text>\n";
967 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.675 * width) - ((int)toString(sharedBC).length() / 2)) + "\" y=\"" + toString(int(0.41 * height)) + "\">" + toString(sharedBC) + "</text>\n";
968 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedCD).length() / 2)) + "\" y=\"" + toString(int(0.54 * height)) + "\">" + toString(sharedCD) + "</text>\n";
969 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.39 * width) - ((int)toString(sharedABD).length() / 2)) + "\" y=\"" + toString(int(0.3 * height)) + "\">" + toString(sharedABD) + "</text>\n";
970 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.57 * width) - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"" + toString(int(0.45 * height)) + "\">" + toString(sharedBCD) + "</text>\n";
971 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.435 * width) - ((int)toString(sharedACD).length() / 2)) + "\" y=\"" + toString(int(0.45 * height)) + "\">" + toString(sharedACD) + "</text>\n";
972 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.63 * width) - ((int)toString(sharedABC).length() / 2)) + "\" y=\"" + toString(int(0.3 * height)) + "\">" + toString(sharedABC) + "</text>\n";
973 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(int(0.5 * width) - ((int)toString(sharedABCD).length() / 2)) + "\" y=\"" + toString(int(0.4 * height)) + "\">" + toString(sharedABCD) + "</text>\n";
974
975 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" 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));
976 if (nseqs) { outsvg << ", and the number of squences in the otus shared by all groups is " + toString(sharedVal); }
977 outsvg << "</text>\n";
978
979 outsvg << "</g>\n</svg>\n";
980 outsvg.close();
981 delete singleCalc;
982 }
983 }
984 }
985
986 return outputNames;
987
988 }
989 catch(exception& e) {
990 m->errorOut(e, "Venn", "getPic");
991 exit(1);
992 }
993 }
994
995
996