]> git.donarmstrong.com Git - mothur.git/blob - venn.cpp
created mothurOut class to handle logfiles
[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(string o) : outputDir(o) {
20         try {
21                 globaldata = GlobalData::getInstance();
22                 m = MothurOut::getInstance();
23
24         }
25         catch(exception& e) {
26                 m->errorOut(e, "Venn", "Venn");
27                 exit(1);
28         }
29 }
30 //**********************************************************************************************************************
31 vector<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
32         try {
33                 
34                 vector<string> outputNames;
35                 
36                 for(int i=0;i<vCalcs.size();i++){
37                         string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg";
38                         outputNames.push_back(filenamesvg);
39                         openOutputFile(filenamesvg, outsvg);
40
41                         vector<double> data = vCalcs[i]->getValues(sabund);
42                         
43                         //svg image
44                         outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
45                         outsvg << "<g>\n";
46                                 
47                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
48                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sabund->getLabel() + "</text>\n";
49                         outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
50                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
51                         
52                         if (data.size() == 3) { 
53                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
54                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
55                         }
56                         
57                         outsvg << "</g>\n</svg>\n";
58                         outsvg.close();
59                 }
60                 
61                 return outputNames;
62         }
63         catch(exception& e) {
64                 m->errorOut(e, "Venn", "getPic");
65                 exit(1);
66         }
67 }
68 //**********************************************************************************************************************
69 vector<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculator*> vCalcs) {
70         try {
71                 
72                 vector<SharedRAbundVector*> subset;
73                 vector<string> outputNames;
74                 
75                 /******************* 1 Group **************************/
76                 if (lookup.size() == 1) {
77                                         
78                         SAbundVector s;
79                         s = lookup[0]->getSAbundVector();  SAbundVector* sabund = &s;
80                         
81                         //make a file for each calculator
82                         for(int i=0;i<vCalcs.size();i++){
83                                 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
84                                 outputNames.push_back(filenamesvg);
85                                 openOutputFile(filenamesvg, outsvg);
86                         
87                                 //in essence you want to run it like a single 
88                                 if (vCalcs[i]->getName() == "sharedsobs") {
89                                         singleCalc = new Sobs();
90                                 }else if (vCalcs[i]->getName() == "sharedchao") {
91                                         singleCalc = new Chao1();
92                                 }else if (vCalcs[i]->getName() == "sharedace") {
93                                         singleCalc = new Ace(10);
94                                 }
95                                 
96                                 vector<double> data = singleCalc->getValues(sabund);
97                         
98                                 //svg image
99                                 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
100                                 outsvg << "<g>\n";
101                                 
102                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
103                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
104                                 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
105                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "</text>\n";
106                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
107                         
108                                 if (data.size() == 3) { 
109                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
110                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
111                                 }
112                         
113                                 outsvg << "</g>\n</svg>\n";
114                                 outsvg.close();
115                                 delete singleCalc;
116                                 
117                         }
118                 /******************* 2 Groups **************************/       
119                 
120                 }else if (lookup.size() == 2) {
121                         //get sabund vector pointers so you can use the single calculators
122                         //one for each group
123                         SAbundVector sA, sB;
124                         SAbundVector* sabundA; SAbundVector* sabundB;
125                         sabundA = new SAbundVector(lookup[0]->getSAbundVector());//  sabundA = &sA;
126                         sabundB = new SAbundVector(lookup[1]->getSAbundVector());//  sabundB = &sB;
127                         
128                         subset.clear();
129                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
130                         
131                         //make a file for each calculator
132                         for(int i=0;i<vCalcs.size();i++){
133                                 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
134                                 outputNames.push_back(filenamesvg);
135                                 openOutputFile(filenamesvg, outsvg);
136                                 
137                                 //get estimates for sharedAB
138                                 vector<double> shared = vCalcs[i]->getValues(subset);
139                                 
140                                 //in essence you want to run it like a single 
141                                 if (vCalcs[i]->getName() == "sharedsobs") {
142                                         singleCalc = new Sobs();
143                                 }else if (vCalcs[i]->getName() == "sharedchao") {
144                                         singleCalc = new Chao1();
145                                 }//else if (vCalcs[i]->getName() == "sharedace") {
146                                         //singleCalc = new Ace(10);
147                                 //}
148                                 
149                                 //get estimates for numA
150                                 vector<double> numA = singleCalc->getValues(sabundA);
151
152                                 //get estimates for numB
153                                 vector<double> numB = singleCalc->getValues(sabundB);
154                                                 
155                                 //image window
156                                 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
157                                 outsvg << "<g>\n";
158
159                                 //draw circles
160                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
161                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
162                                 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>"; 
163                                 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>"; 
164                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
165                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n"; 
166                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "</text>\n";
167                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "</text>\n"; 
168                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";  
169                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
170                                 if (numA.size() == 3) { 
171                                         outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
172                                 }else { outsvg << "</text>\n"; }
173                 
174                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
175                                 if (numB.size() == 3) { 
176                                         outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
177                                 }else { outsvg << "</text>\n"; }
178
179                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"500\">The number of sepecies shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(shared[0]) + "</text>\n";
180                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))*100) + "</text>\n";
181                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"540\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0])) + "</text>\n";
182                                 
183                                 //close file
184                                 outsvg << "</g>\n</svg>\n";
185                                 outsvg.close();
186                                 delete singleCalc;
187                         }
188                 /******************* 3 Groups **************************/
189                                                 
190                 }else if (lookup.size() == 3) {
191                         //get sabund vector pointers so you can use the single calculators
192                         //one for each group
193                         SAbundVector sA, sB, sC;
194                         SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
195                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
196                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
197                         sC = lookup[2]->getSAbundVector();  sabundC = &sC;
198                 
199                         //make a file for each calculator
200                         for(int i=0;i<vCalcs.size();i++){
201                         
202                                 string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
203                                 outputNames.push_back(filenamesvg);
204                                 openOutputFile(filenamesvg, outsvg);
205                                 
206                                 if (vCalcs[i]->getName() == "sharedace") {
207                                 
208                                         singleCalc = new Ace(10);
209                                         
210                                         //get estimates for numA
211                                         vector<double> numA = singleCalc->getValues(sabundA);
212                         
213                                         //get estimates for numB
214                                         vector<double> numB = singleCalc->getValues(sabundB);
215                                 
216                                         //get estimates for numC
217                                         vector<double> numC = singleCalc->getValues(sabundC);
218
219
220                                         //get estimates for sharedAB, sharedAC and sharedBC
221                                         subset.clear();
222                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
223                                         vector<double> sharedAB = vCalcs[i]->getValues(subset);
224                                         
225                                         subset.clear();
226                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
227                                         vector<double> sharedAC = vCalcs[i]->getValues(subset);
228                                         
229                                         subset.clear();
230                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
231                                         vector<double> sharedBC = vCalcs[i]->getValues(subset);
232                                         
233                                         vector<double> sharedAwithBC;
234                                         vector<double> sharedBwithAC;
235                                         vector<double> sharedCwithAB;
236                                         
237                                         //find possible sharedABC values
238                                         float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
239
240                                         if (vCalcs[i]->getMultiple() == false) {
241                                                 //merge BC and estimate with shared with A
242                                                 SharedRAbundVector* merge = new SharedRAbundVector();
243                                                 for (int j = 0; j < lookup[1]->size(); j++) {
244                                                         merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
245                                                 }
246                                         
247                                                 subset.clear();
248                                                 subset.push_back(lookup[0]); subset.push_back(merge);
249                                                 sharedAwithBC = vCalcs[i]->getValues(subset);
250                                 
251                                                 delete merge;
252                                                 //merge AC and estimate with shared with B
253                                                 merge = new SharedRAbundVector();
254                                                 for (int j = 0; j < lookup[0]->size(); j++) {
255                                                         merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
256                                                 }
257                                         
258                                                 subset.clear();
259                                                 subset.push_back(merge); subset.push_back(lookup[1]);
260                                                 sharedBwithAC = vCalcs[i]->getValues(subset);
261                                 
262                                                 delete merge;
263                                                 //merge AB and estimate with shared with C
264                                                 merge = new SharedRAbundVector();
265                                                 for (int j = 0; j < lookup[0]->size(); j++) {
266                                                         merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), "");
267                                                 }
268                                         
269                                                 subset.clear();
270                                                 subset.push_back(lookup[2]); subset.push_back(merge);
271                                                 sharedCwithAB = vCalcs[i]->getValues(subset);
272                                                 delete merge;
273                                         
274                                                 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
275                                                 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
276                                                 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
277          
278                                                 //if any of the possible m's are - throw them out
279                                                 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
280                                                 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
281                                                 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
282                         
283                                                 //sharedABC is the minimum of the 3 possibilities
284                                                 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
285                                                 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
286                                                 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }    
287                                         }else{
288                                                 vector<double> data = vCalcs[i]->getValues(lookup);
289                                                 sharedABC = data[0];
290                                                 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
291                                                 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
292                                                 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
293                                         }
294                                         
295                                         //image window
296                                         outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 800 800\" >\n";
297                                         outsvg << "<g>\n";
298
299                                         //draw circles
300                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>"; 
301                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
302                                         outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
303                                         outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
304                                         outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
305
306                                         //place labels within overlaps
307                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n"; 
308                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";  
309                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\"  y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";  
310                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\"  y=\"170\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";
311                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"150\">" + lookup[1]->getGroup() + "</text>\n";  
312                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\"  y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";  
313                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\"   y=\"430\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n"; 
314                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"410\">" + lookup[2]->getGroup() + "</text>\n"; 
315                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";  
316                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"280\">" + toString(sharedABC) + "</text>\n"; 
317                                 
318                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"660\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB[0]) + "</text>\n";
319                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"680\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC[0]) + "</text>\n";
320                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"700\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC[0]) + "</text>\n";
321                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The number of species shared between groups " + lookup[0]->getGroup() + " and combined groups " + lookup[1]->getGroup() + lookup[2]->getGroup() + " is " + toString(sharedAwithBC[0]) + "</text>\n";
322                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"740\">The number of species shared between groups " + lookup[1]->getGroup() + " and combined groups " + lookup[0]->getGroup() + lookup[2]->getGroup() + " is " + toString(sharedBwithAC[0]) + "</text>\n";
323                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"760\">The number of species shared between groups " + lookup[2]->getGroup() + " and combined groups " + lookup[0]->getGroup() + lookup[1]->getGroup() + " is " + toString(sharedCwithAB[0]) + "</text>\n";
324                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
325                                         if (numA.size() == 3) { 
326                                                 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
327                                         }else { outsvg << "</text>\n"; }
328                         
329                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
330                                         if (numB.size() == 3) { 
331                                                 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
332                                         }else { outsvg << "</text>\n"; }
333                                         
334                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
335                                         if (numC.size() == 3) { 
336                                                 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
337                                         }else { outsvg << "</text>\n"; }
338
339                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
340                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"780\">The total shared richness is " + toString(sharedABC) + "</text>\n";
341                                         
342                                         delete singleCalc;
343                                         
344                                 }else { //sharedchao and sharedsobs are multigroup
345                                         
346                                         vector<SharedRAbundVector*> subset;
347
348                                         //get estimates for numA
349                                         subset.push_back(lookup[0]);
350                                         vector<double> numA = vCalcs[i]->getValues(subset);
351                         
352                                         //get estimates for numB
353                                         subset.clear();
354                                         subset.push_back(lookup[1]);
355                                         vector<double> numB = vCalcs[i]->getValues(subset);
356                                 
357                                         //get estimates for numC
358                                         subset.clear();
359                                         subset.push_back(lookup[2]);
360                                         vector<double> numC = vCalcs[i]->getValues(subset);
361
362                                         subset.clear();
363                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
364                                         vector<double> sharedab =  vCalcs[i]->getValues(subset);
365                                         
366                                         subset.clear(); 
367                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
368                                         vector<double> sharedac =  vCalcs[i]->getValues(subset);
369                                         
370                                         subset.clear(); 
371                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
372                                         vector<double> sharedbc =  vCalcs[i]->getValues(subset);
373                                         
374                                         subset.clear(); 
375                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
376                                         vector<double> sharedabc =  vCalcs[i]->getValues(subset);
377                                         
378                                         //image window
379                                         outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 800 800\" >\n";
380                                         outsvg << "<g>\n";
381
382                                         //draw circles
383                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>"; 
384                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
385                                         outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
386                                         outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
387                                         outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
388
389                                         //place labels within overlaps
390                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedab[0]-sharedac[0]+sharedabc[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedab[0]-sharedac[0]+sharedabc[0]) + "</text>\n"; 
391                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";  
392                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedab[0] - sharedabc[0]).length() / 2)) + "\"  y=\"170\">" + toString(sharedab[0] - sharedabc[0]) + "</text>\n";  
393                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedab[0]-sharedbc[0]+sharedabc[0]).length() / 2)) + "\"  y=\"170\">" + toString(numB[0]-sharedab[0]-sharedbc[0]+sharedabc[0]) + "</text>\n";
394                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"150\">" + lookup[1]->getGroup() + "</text>\n";  
395                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedac[0] - sharedabc[0]).length() / 2)) + "\"  y=\"305\">" + toString(sharedac[0] - sharedabc[0]) + "</text>\n";  
396                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)toString(numC[0]-sharedac[0]-sharedbc[0]+sharedabc[0]).length() / 2)) + "\"   y=\"430\">" + toString(numC[0]-sharedac[0]-sharedbc[0]+sharedabc[0]) + "</text>\n"; 
397                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"410\">" + lookup[2]->getGroup() + "</text>\n"; 
398                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedbc[0] - sharedabc[0]).length() / 2)) + "\" y=\"305\">" + toString(sharedbc[0] - sharedabc[0]) + "</text>\n";  
399                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedabc[0]).length() / 2)) + "\"  y=\"280\">" + toString(sharedabc[0]) + "</text>\n"; 
400                                 
401                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"660\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedab[0]) + "</text>\n";
402                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"680\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedac[0]) + "</text>\n";
403                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"700\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedbc[0]) + "</text>\n";
404                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
405                                         if (numA.size() == 3) { 
406                                                 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
407                                         }else { outsvg << "</text>\n"; }
408                         
409                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
410                                         if (numB.size() == 3) { 
411                                                 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
412                                         }else { outsvg << "</text>\n"; }
413                                         
414                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
415                                         if (numC.size() == 3) { 
416                                                 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
417                                         }else { outsvg << "</text>\n"; }
418
419                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedab[0] - sharedac[0] - sharedbc[0] + sharedabc[0]) + "</text>\n";
420                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The total shared richness is " + toString(sharedabc[0]) + "</text>\n";
421
422
423                                 }
424                 
425                                                                 
426                                 //close file
427                                 outsvg << "</g>\n</svg>\n";
428                                 outsvg.close();
429                                 
430
431                         }
432                         
433                 /******************* 4 Groups **************************/
434                 
435                 }else if (lookup.size() == 4) {
436                         //calc the shared otu
437                         float sharedABCD = 0;
438                         float numA = 0; float numB = 0; float numC = 0; float numD = 0;
439                         float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
440                         float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
441                         vector<double> data;
442                         //get sabund vector pointers so you can use the single calculators
443                         //one for each group
444                         SAbundVector sA, sB, sC, sD;
445                         SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
446                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
447                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
448                         sC = lookup[2]->getSAbundVector();  sabundC = &sC;
449                         sD = lookup[3]->getSAbundVector();  sabundD = &sD;
450                         
451                         //A = red, B = green, C = blue, D = yellow
452                         
453                         //make a file for each calculator
454                         for(int i=0;i<vCalcs.size();i++){
455                                 
456                                 if ((vCalcs[i]->getName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { m->mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups.  It will be disregarded. "); m->mothurOutEndLine(); }
457                                 else{
458                                         string filenamesvg = outputDir + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
459                                         outputNames.push_back(filenamesvg);
460                                         openOutputFile(filenamesvg, outsvg);
461
462                                 
463                                         //in essence you want to run it like a single 
464                                         if (vCalcs[i]->getName() == "sharedsobs") {
465                                                 singleCalc = new Sobs();
466                                         }else if (vCalcs[i]->getName() == "sharedchao") {
467                                                 singleCalc = new Chao1();
468                                         }
469                                 
470                                         //get estimates for numA
471                                         data = singleCalc->getValues(sabundA);
472                                         numA = data[0];
473         //cout << "num a = " << numA << endl;   
474                         
475                                         //get estimates for numB
476                                         data = singleCalc->getValues(sabundB);
477                                         numB = data[0];
478         //cout << "num b = " << numB << endl;                           
479                                         //get estimates for numC
480                                         data = singleCalc->getValues(sabundC);
481                                         numC = data[0];
482         //cout << "num c = " << numC << endl;                           
483                                         //get estimates for numD
484                                         data = singleCalc->getValues(sabundD);
485                                         numD = data[0];
486 //cout << "num d = " << numD << endl;   
487
488                                         //get estimates for pairs
489                                         subset.clear();
490                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
491                                         data = vCalcs[i]->getValues(subset);
492                                         sharedAB = data[0];
493         //cout << "num ab = " << sharedAB << endl;                      
494                                         subset.clear();
495                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
496                                         data = vCalcs[i]->getValues(subset);
497                                         sharedAC = data[0];
498         //cout << "num ac = " << sharedAC << endl;                              
499                                         subset.clear();
500                                         subset.push_back(lookup[0]); subset.push_back(lookup[3]);
501                                         data = vCalcs[i]->getValues(subset);
502                                         sharedAD = data[0];
503         //cout << "num ad = " << sharedAD << endl;                      
504                                         subset.clear();
505                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
506                                         data = vCalcs[i]->getValues(subset);
507                                         sharedBC = data[0];
508         //cout << "num bc = " << sharedBC << endl;                              
509                                         subset.clear();
510                                         subset.push_back(lookup[1]); subset.push_back(lookup[3]);
511                                         data = vCalcs[i]->getValues(subset);
512                                         sharedBD = data[0];
513                 //cout << "num bd = " << sharedBD << endl;                                              
514                                         subset.clear();
515                                         subset.push_back(lookup[2]); subset.push_back(lookup[3]);
516                                         data = vCalcs[i]->getValues(subset);
517                                         sharedCD = data[0];
518                                                 
519         //cout << "num cd = " << sharedCD << endl;                              
520                                         //get estimates for combos of 3
521                                         subset.clear();
522                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
523                                         data = vCalcs[i]->getValues(subset);
524                                         sharedABC = data[0];
525                 //cout << "num abc = " << sharedABC << endl;                                    
526                                         subset.clear();
527                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
528                                         data = vCalcs[i]->getValues(subset);
529                                         sharedACD = data[0];
530                         //cout << "num acd = " << sharedACD << endl;    
531                                         subset.clear();
532                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
533                                         data = vCalcs[i]->getValues(subset);
534                                         sharedBCD = data[0];
535                 //cout << "num bcd = " << sharedBCD << endl;            
536                                         subset.clear();
537                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
538                                         data = vCalcs[i]->getValues(subset);
539                                         sharedABD = data[0];
540 //cout << "num abd = " << sharedABD << endl;
541                                         //get estimate for all four
542                                         data = vCalcs[i]->getValues(lookup);
543                                         sharedABCD = data[0];
544                 //cout << "num abcd = " << sharedABCD << endl << endl;  
545                 
546                                 
547                                                 
548                                         //image window
549                                         outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 700 800\" >\n";
550                                         outsvg << "<g>\n";
551                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"800\"/>"; 
552                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
553
554                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"490\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA) + "</text>\n";
555                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"510\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB) + "</text>\n";
556                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"530\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC) + "</text>\n";
557                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"550\">The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD) + "</text>\n";
558                                         
559                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"570\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[1]->getGroup() + " is " + toString(sharedAB) + "</text>\n";
560                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"590\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedAC) + "</text>\n";
561                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"610\">The number of species shared between groups " + lookup[0]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedAD) + "</text>\n";
562                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"630\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC) + "</text>\n";
563                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"650\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBD) + "</text>\n";
564                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"670\">The number of species shared between groups " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedCD) + "</text>\n";
565                                         
566                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"690\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedABC) + "</text>\n";
567                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"710\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedABD) + "</text>\n";
568                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"730\">The number of species shared between groups " + lookup[0]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedACD) + "</text>\n";
569                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"750\">The number of species shared between groups " + lookup[1]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBCD) + "</text>\n";
570                                                                         
571                                         //make adjustments
572                                         sharedABC = sharedABC - sharedABCD;
573                         //cout << "num abc = " << sharedABC << endl;            
574                                         sharedABD = sharedABD - sharedABCD;
575                                 //cout << "num abd = " << sharedABD << endl;
576                                         sharedACD = sharedACD - sharedABCD;
577                                 //cout << "num acd = " << sharedACD << endl;
578                                         sharedBCD = sharedBCD - sharedABCD;
579                                 //cout << "num bcd = " << sharedBCD << endl;
580                                         
581                                         sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD;  //cout << "num ab = " << sharedAB << endl;
582                                         sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD;  //cout << "num ac = " << sharedAC << endl;
583                                         sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD;  //cout << "num ad = " << sharedAD << endl;                           
584                                         sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD;  //cout << "num bc = " << sharedBC << endl;
585                                         sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl; 
586                                         sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD;  //cout << "num cd = " << sharedCD << endl;
587                                         
588                                         numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
589                         //cout << "num a = " << numA << endl;           
590                                         numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
591                         //cout << "num b = " << numB << endl;           
592                                         numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
593                         //cout << "num c = " << numC << endl;           
594                                         numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
595                         //cout << "num d = " << numD << endl;           
596                                         
597                                         //draw circles
598                                         outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n "; 
599                                         outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
600                                         outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 440 315) \" cx=\"440\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
601                                         outsvg << "<ellipse fill=\"yellow\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+40 270 315) \" cx=\"270\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
602                         
603                                         //A = red, B = green, C = blue, D = yellow
604                         
605                                         //place labels within overlaps
606                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA)  + "</text>\n"; 
607                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";  
608                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\"  y=\"160\">" + toString(sharedAB) + "</text>\n";  
609                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\"  y=\"110\">" + toString(numB)  + "</text>\n";  
610                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"90\">" + lookup[1]->getGroup() + "</text>\n"; 
611                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\"  y=\"190\">" + toString(sharedAC) + "</text>\n";  
612                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\"   y=\"230\">" + toString(numC) + "</text>\n";  
613                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
614                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBD).length() / 2)) + "\" y=\"190\">" + toString(sharedBD) + "</text>\n";  
615                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\"   y=\"230\">" + toString(numD) + "</text>\n";  
616                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[3]->getGroup() + "</text>\n"; 
617                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedAD).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n"; 
618                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBC) + "</text>\n";
619                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n"; 
620                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(275 - ((int)toString(sharedABD).length() / 2)) + "\" y=\"240\">" + toString(sharedABD) + "</text>\n"; 
621                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(400 - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"360\">" + toString(sharedBCD) + "</text>\n";
622                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n"; 
623                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"240\">" + toString(sharedABC) + "</text>\n"; 
624                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\"  y=\"320\">" + toString(sharedABCD) + "</text>\n"; 
625                                         
626                                         
627                                                                                 
628                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"770\">The total richness of all the groups is " + toString((float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD)) + "</text>\n";
629                                         
630
631                                         outsvg << "</g>\n</svg>\n";
632                                         outsvg.close();
633                                         delete singleCalc;
634                                 }
635                         }
636                 }
637                 
638                 return outputNames;
639                 
640         }
641         catch(exception& e) {
642                 m->errorOut(e, "Venn", "getPic");
643                 exit(1);
644         }
645 }
646
647