]> git.donarmstrong.com Git - mothur.git/blob - venn.cpp
added logfile feature
[mothur.git] / venn.cpp
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 "sharedchao1.h"
15 #include "sharedsobscollectsummary.h"
16
17
18 //**********************************************************************************************************************
19 Venn::Venn(){
20         try {
21                 globaldata = GlobalData::getInstance();
22
23         }
24         catch(exception& e) {
25                 errorOut(e, "Venn", "Venn");
26                 exit(1);
27         }
28 }
29 //**********************************************************************************************************************
30 void Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
31         try {
32                                 
33                 for(int i=0;i<vCalcs.size();i++){
34                         string filenamesvg = globaldata->inputFileName + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
35                         openOutputFile(filenamesvg, outsvg);
36
37                         vector<double> data = vCalcs[i]->getValues(sabund);
38                         
39                         //svg image
40                         outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
41                         outsvg << "<g>\n";
42                                 
43                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
44                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sabund->getLabel() + "</text>\n";
45                         outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
46                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
47                         
48                         if (data.size() == 3) { 
49                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
50                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
51                         }
52                         
53                         outsvg << "</g>\n</svg>\n";
54                         outsvg.close();
55                 }
56         }
57         catch(exception& e) {
58                 errorOut(e, "Venn", "getPic");
59                 exit(1);
60         }
61 }
62 //**********************************************************************************************************************
63 void Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
64         try {
65                 
66                 vector<SharedRAbundVector*> subset;
67                 
68                 /******************* 1 Group **************************/
69                 if (lookup.size() == 1) {
70                                         
71                         SAbundVector s;
72                         s = lookup[0]->getSAbundVector();  SAbundVector* sabund = &s;
73                         
74                         //make a file for each calculator
75                         for(int i=0;i<vCalcs.size();i++){
76                                 string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
77                                 openOutputFile(filenamesvg, outsvg);
78                         
79                                 //in essence you want to run it like a single 
80                                 if (vCalcs[i]->getName() == "sharedsobs") {
81                                         singleCalc = new Sobs();
82                                 }else if (vCalcs[i]->getName() == "sharedchao") {
83                                         singleCalc = new Chao1();
84                                 }else if (vCalcs[i]->getName() == "sharedace") {
85                                         singleCalc = new Ace(10);
86                                 }
87                                 
88                                 vector<double> data = singleCalc->getValues(sabund);
89                         
90                                 //svg image
91                                 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
92                                 outsvg << "<g>\n";
93                                 
94                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
95                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
96                                 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
97                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "</text>\n";
98                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
99                         
100                                 if (data.size() == 3) { 
101                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
102                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
103                                 }
104                         
105                                 outsvg << "</g>\n</svg>\n";
106                                 outsvg.close();
107                                 delete singleCalc;
108                                 
109                         }
110                 /******************* 2 Groups **************************/       
111                 
112                 }else if (lookup.size() == 2) {
113                         //get sabund vector pointers so you can use the single calculators
114                         //one for each group
115                         SAbundVector sA, sB;
116                         SAbundVector* sabundA; SAbundVector* sabundB;
117                         sabundA = new SAbundVector(lookup[0]->getSAbundVector());//  sabundA = &sA;
118                         sabundB = new SAbundVector(lookup[1]->getSAbundVector());//  sabundB = &sB;
119                         
120                         subset.clear();
121                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
122                         
123                         //make a file for each calculator
124                         for(int i=0;i<vCalcs.size();i++){
125                                 string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
126                                 openOutputFile(filenamesvg, outsvg);
127                                 
128                                 //get estimates for sharedAB
129                                 vector<double> shared = vCalcs[i]->getValues(subset);
130                                 
131                                 //in essence you want to run it like a single 
132                                 if (vCalcs[i]->getName() == "sharedsobs") {
133                                         singleCalc = new Sobs();
134                                 }else if (vCalcs[i]->getName() == "sharedchao") {
135                                         singleCalc = new Chao1();
136                                 }else if (vCalcs[i]->getName() == "sharedace") {
137                                         singleCalc = new Ace(10);
138                                 }
139                                 
140                                 //get estimates for numA
141                                 vector<double> numA = singleCalc->getValues(sabundA);
142
143                                 //get estimates for numB
144                                 vector<double> numB = singleCalc->getValues(sabundB);
145                                                 
146                                 //image window
147                                 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
148                                 outsvg << "<g>\n";
149
150                                 //draw circles
151                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
152                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
153                                 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>"; 
154                                 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>"; 
155                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
156                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n"; 
157                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "</text>\n";
158                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "</text>\n"; 
159                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";  
160                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
161                                 if (numA.size() == 3) { 
162                                         outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
163                                 }else { outsvg << "</text>\n"; }
164                 
165                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
166                                 if (numB.size() == 3) { 
167                                         outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
168                                 }else { outsvg << "</text>\n"; }
169
170                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"500\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(shared[0]) + "</text>\n";
171                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))) + "</text>\n";
172                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"540\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0])) + "</text>\n";
173                                 
174                                 //close file
175                                 outsvg << "</g>\n</svg>\n";
176                                 outsvg.close();
177                                 delete singleCalc;
178                         }
179                 /******************* 3 Groups **************************/
180                                                 
181                 }else if (lookup.size() == 3) {
182                         //get sabund vector pointers so you can use the single calculators
183                         //one for each group
184                         SAbundVector sA, sB, sC;
185                         SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
186                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
187                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
188                         sC = lookup[2]->getSAbundVector();  sabundC = &sC;
189                 
190                         //make a file for each calculator
191                         for(int i=0;i<vCalcs.size();i++){
192                         
193                                 //in essence you want to run it like a single 
194                                 if (vCalcs[i]->getName() == "sharedsobs") {
195                                         singleCalc = new Sobs();
196                                 }else if (vCalcs[i]->getName() == "sharedchao") {
197                                         singleCalc = new Chao1();
198                                 }else if (vCalcs[i]->getName() == "sharedace") {
199                                         singleCalc = new Ace(10);
200                                 }
201                                 
202                                 //get estimates for numA
203                                 vector<double> numA = singleCalc->getValues(sabundA);
204                         
205                                 //get estimates for numB
206                                 vector<double> numB = singleCalc->getValues(sabundB);
207                                 
208                                 //get estimates for numC
209                                 vector<double> numC = singleCalc->getValues(sabundC);
210
211                                 
212                                 string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
213                                 openOutputFile(filenamesvg, outsvg);
214
215                                 //get estimates for sharedAB, sharedAC and sharedBC
216                                 subset.clear();
217                                 subset.push_back(lookup[0]); subset.push_back(lookup[1]);
218                                 vector<double> sharedAB = vCalcs[i]->getValues(subset);
219                                 
220                                 subset.clear();
221                                 subset.push_back(lookup[0]); subset.push_back(lookup[2]);
222                                 vector<double> sharedAC = vCalcs[i]->getValues(subset);
223                                 
224                                 subset.clear();
225                                 subset.push_back(lookup[1]); subset.push_back(lookup[2]);
226                                 vector<double> sharedBC = vCalcs[i]->getValues(subset);
227                                 
228                                 vector<double> sharedAwithBC;
229                                 vector<double> sharedBwithAC;
230                                 vector<double> sharedCwithAB;
231                                 
232                                 //find possible sharedABC values
233                                 float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
234
235                                 if (vCalcs[i]->getMultiple() == false) {
236                                         //merge BC and estimate with shared with A
237                                         SharedRAbundVector* merge = new SharedRAbundVector();
238                                         for (int j = 0; j < lookup[1]->size(); j++) {
239                                                 merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), j, "");
240                                         }
241                                 
242                                         subset.clear();
243                                         subset.push_back(lookup[0]); subset.push_back(merge);
244                                         sharedAwithBC = vCalcs[i]->getValues(subset);
245                         
246                                         delete merge;
247                                         //merge AC and estimate with shared with B
248                                         merge = new SharedRAbundVector();
249                                         for (int j = 0; j < lookup[0]->size(); j++) {
250                                                 merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), j, "");
251                                         }
252                                 
253                                         subset.clear();
254                                         subset.push_back(merge); subset.push_back(lookup[1]);
255                                         sharedBwithAC = vCalcs[i]->getValues(subset);
256                         
257                                         delete merge;
258                                         //merge AB and estimate with shared with C
259                                         merge = new SharedRAbundVector();
260                                         for (int j = 0; j < lookup[0]->size(); j++) {
261                                                 merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), j, "");
262                                         }
263                                 
264                                         subset.clear();
265                                         subset.push_back(lookup[2]); subset.push_back(merge);
266                                         sharedCwithAB = vCalcs[i]->getValues(subset);
267                                         delete merge;
268                                 
269                                         sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
270                                         sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
271                                         sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
272  
273                                         //if any of the possible m's are - throw them out
274                                         if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
275                                         if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
276                                         if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
277                 
278                                         //sharedABC is the minimum of the 3 possibilities
279                                         if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
280                                         else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
281                                         else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }    
282                                 }else{
283                                         vector<double> data = vCalcs[i]->getValues(lookup);
284                                         sharedABC = data[0];
285                                         sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
286                                         sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
287                                         sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
288                                 }
289                 
290                                 //image window
291                                 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 800 800\" >\n";
292                                 outsvg << "<g>\n";
293
294                                 //draw circles
295                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>"; 
296                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
297                                 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
298                                 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
299                                 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
300
301                                 //place labels within overlaps
302                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n"; 
303                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";  
304                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\"  y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";  
305                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\"  y=\"170\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";
306                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"150\">" + lookup[1]->getGroup() + "</text>\n";  
307                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\"  y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";  
308                                 outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\"   y=\"430\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n"; 
309                                 outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"410\">" + lookup[2]->getGroup() + "</text>\n"; 
310                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";  
311                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"280\">" + toString(sharedABC) + "</text>\n"; 
312                         
313                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"660\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB[0]) + "</text>\n";
314                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"680\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC[0]) + "</text>\n";
315                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"700\">The number of sepecies shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC[0]) + "</text>\n";
316                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and combined groups " + lookup[1]->getGroup() + lookup[2]->getGroup() + " is " + toString(sharedAwithBC[0]) + "</text>\n";
317                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"740\">The number of sepecies shared between groups " + lookup[1]->getGroup() + " and combined groups " + lookup[0]->getGroup() + lookup[2]->getGroup() + " is " + toString(sharedBwithAC[0]) + "</text>\n";
318                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"760\">The number of sepecies shared between groups " + lookup[2]->getGroup() + " and combined groups " + lookup[0]->getGroup() + lookup[1]->getGroup() + " is " + toString(sharedCwithAB[0]) + "</text>\n";
319                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
320                                 if (numA.size() == 3) { 
321                                         outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
322                                 }else { outsvg << "</text>\n"; }
323                 
324                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
325                                 if (numB.size() == 3) { 
326                                         outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
327                                 }else { outsvg << "</text>\n"; }
328                                 
329                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
330                                 if (numC.size() == 3) { 
331                                         outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
332                                 }else { outsvg << "</text>\n"; }
333
334                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
335                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"780\">The total shared richness is " + toString(sharedABC) + "</text>\n";
336                                 
337                                 //close file
338                                 outsvg << "</g>\n</svg>\n";
339                                 outsvg.close();
340                                 delete singleCalc;
341
342                         }
343                         
344                 /******************* 4 Groups **************************/
345                 
346                 }else if (lookup.size() == 4) {
347                         //calc the shared otu
348                         float sharedABCD = 0;
349                         float numA = 0; float numB = 0; float numC = 0; float numD = 0;
350                         float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
351                         float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
352                         vector<double> data;
353                         //get sabund vector pointers so you can use the single calculators
354                         //one for each group
355                         SAbundVector sA, sB, sC, sD;
356                         SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
357                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
358                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
359                         sC = lookup[2]->getSAbundVector();  sabundC = &sC;
360                         sD = lookup[3]->getSAbundVector();  sabundD = &sD;
361                         
362                         //A = red, B = green, C = blue, D = yellow
363                         
364                         //make a file for each calculator
365                         for(int i=0;i<vCalcs.size();i++){
366                                 
367                                 if ((vCalcs[i]->getName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups.  It will be disregarded. "); mothurOutEndLine(); }
368                                 else{
369                                         string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
370                                         openOutputFile(filenamesvg, outsvg);
371
372                                 
373                                         //in essence you want to run it like a single 
374                                         if (vCalcs[i]->getName() == "sharedsobs") {
375                                                 singleCalc = new Sobs();
376                                         }else if (vCalcs[i]->getName() == "sharedchao") {
377                                                 singleCalc = new Chao1();
378                                         }
379                                 
380                                         //get estimates for numA
381                                         data = singleCalc->getValues(sabundA);
382                                         numA = data[0];
383                         
384                                         //get estimates for numB
385                                         data = singleCalc->getValues(sabundB);
386                                         numB = data[0];
387                                 
388                                         //get estimates for numC
389                                         data = singleCalc->getValues(sabundC);
390                                         numC = data[0];
391                                 
392                                         //get estimates for numD
393                                         data = singleCalc->getValues(sabundD);
394                                         numD = data[0];
395
396
397                                         //get estimates for pairs
398                                         subset.clear();
399                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
400                                         data = vCalcs[i]->getValues(subset);
401                                         sharedAB = data[0];
402                                 
403                                         subset.clear();
404                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
405                                         data = vCalcs[i]->getValues(subset);
406                                         sharedAC = data[0];
407                                 
408                                         subset.clear();
409                                         subset.push_back(lookup[0]); subset.push_back(lookup[3]);
410                                         data = vCalcs[i]->getValues(subset);
411                                         sharedAD = data[0];
412                                 
413                                         subset.clear();
414                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
415                                         data = vCalcs[i]->getValues(subset);
416                                         sharedBC = data[0];
417                                 
418                                         subset.clear();
419                                         subset.push_back(lookup[1]); subset.push_back(lookup[3]);
420                                         data = vCalcs[i]->getValues(subset);
421                                         sharedBD = data[0];
422                                 
423                                         subset.clear();
424                                         subset.push_back(lookup[2]); subset.push_back(lookup[3]);
425                                         data = vCalcs[i]->getValues(subset);
426                                         sharedCD = data[0];
427                                 
428                                 
429                                         //get estimates for combos of 3
430                                         subset.clear();
431                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
432                                         data = vCalcs[i]->getValues(subset);
433                                         sharedABC = data[0];
434                                 
435                                         subset.clear();
436                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
437                                         data = vCalcs[i]->getValues(subset);
438                                         sharedACD = data[0];
439                                 
440                                         subset.clear();
441                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
442                                         data = vCalcs[i]->getValues(subset);
443                                         sharedBCD = data[0];
444                                 
445                                         subset.clear();
446                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
447                                         data = vCalcs[i]->getValues(subset);
448                                         sharedABD = data[0];
449
450                                         //get estimate for all four
451                                         data = vCalcs[i]->getValues(lookup);
452                                         sharedABCD = data[0];
453
454                 
455                                         //image window
456                                         outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
457                                         outsvg << "<g>\n";
458
459                                         //draw circles
460                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
461                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
462                                         outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n "; 
463                                         outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
464                                         outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 440 315) \" cx=\"440\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
465                                         outsvg << "<ellipse fill=\"yellow\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+40 270 315) \" cx=\"270\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
466                         
467                                         //A = red, B = green, C = blue, D = yellow
468                         
469                                         //place labels within overlaps
470                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n"; 
471                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";  
472                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\"  y=\"160\">" + toString(sharedAB) + "</text>\n";  
473                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\"  y=\"110\">" + toString(numB) + "</text>\n";  
474                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"90\">" + lookup[1]->getGroup() + "</text>\n"; 
475                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\"  y=\"190\">" + toString(sharedAC) + "</text>\n";  
476                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\"   y=\"230\">" + toString(numC) + "</text>\n";  
477                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
478                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"190\">" + toString(sharedBC) + "</text>\n";  
479                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\"   y=\"230\">" + toString(numD) + "</text>\n";  
480                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[3]->getGroup() + "</text>\n"; 
481                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n"; 
482                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBD) + "</text>\n";
483                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n"; 
484                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(275 - ((int)toString(sharedABD).length() / 2)) + "\" y=\"240\">" + toString(sharedABD) + "</text>\n"; 
485                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(400 - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"360\">" + toString(sharedBCD) + "</text>\n";
486                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n"; 
487                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"240\">" + toString(sharedABC) + "</text>\n"; 
488                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\"  y=\"320\">" + toString(sharedABCD) + "</text>\n"; 
489                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"250\" y=\"490\">The total richness of all the groups is " + toString((float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD)) + "</text>\n";
490                         
491                                         outsvg << "</g>\n</svg>\n";
492                                         outsvg.close();
493                                         delete singleCalc;
494                                 }
495                         }
496                 }
497                 
498         }
499         catch(exception& e) {
500                 errorOut(e, "Venn", "getPic");
501                 exit(1);
502         }
503 }
504
505