]> git.donarmstrong.com Git - mothur.git/blob - venn.cpp
fixed bug in libshuff
[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 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";
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 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";
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 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";
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]))*100) + "</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                                                                                                 
194                                 string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
195                                 openOutputFile(filenamesvg, outsvg);
196                                 
197                                 if (vCalcs[i]->getName() == "sharedace") {
198                                 
199                                         singleCalc = new Ace(10);
200                                         
201                                         //get estimates for numA
202                                         vector<double> numA = singleCalc->getValues(sabundA);
203                         
204                                         //get estimates for numB
205                                         vector<double> numB = singleCalc->getValues(sabundB);
206                                 
207                                         //get estimates for numC
208                                         vector<double> numC = singleCalc->getValues(sabundC);
209
210
211                                         //get estimates for sharedAB, sharedAC and sharedBC
212                                         subset.clear();
213                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
214                                         vector<double> sharedAB = vCalcs[i]->getValues(subset);
215                                         
216                                         subset.clear();
217                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
218                                         vector<double> sharedAC = vCalcs[i]->getValues(subset);
219                                         
220                                         subset.clear();
221                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
222                                         vector<double> sharedBC = vCalcs[i]->getValues(subset);
223                                         
224                                         vector<double> sharedAwithBC;
225                                         vector<double> sharedBwithAC;
226                                         vector<double> sharedCwithAB;
227                                         
228                                         //find possible sharedABC values
229                                         float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
230
231                                         if (vCalcs[i]->getMultiple() == false) {
232                                                 //merge BC and estimate with shared with A
233                                                 SharedRAbundVector* merge = new SharedRAbundVector();
234                                                 for (int j = 0; j < lookup[1]->size(); j++) {
235                                                         merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), j, "");
236                                                 }
237                                         
238                                                 subset.clear();
239                                                 subset.push_back(lookup[0]); subset.push_back(merge);
240                                                 sharedAwithBC = vCalcs[i]->getValues(subset);
241                                 
242                                                 delete merge;
243                                                 //merge AC and estimate with shared with B
244                                                 merge = new SharedRAbundVector();
245                                                 for (int j = 0; j < lookup[0]->size(); j++) {
246                                                         merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), j, "");
247                                                 }
248                                         
249                                                 subset.clear();
250                                                 subset.push_back(merge); subset.push_back(lookup[1]);
251                                                 sharedBwithAC = vCalcs[i]->getValues(subset);
252                                 
253                                                 delete merge;
254                                                 //merge AB and estimate with shared with C
255                                                 merge = new SharedRAbundVector();
256                                                 for (int j = 0; j < lookup[0]->size(); j++) {
257                                                         merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), j, "");
258                                                 }
259                                         
260                                                 subset.clear();
261                                                 subset.push_back(lookup[2]); subset.push_back(merge);
262                                                 sharedCwithAB = vCalcs[i]->getValues(subset);
263                                                 delete merge;
264                                         
265                                                 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
266                                                 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
267                                                 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
268          
269                                                 //if any of the possible m's are - throw them out
270                                                 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
271                                                 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
272                                                 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
273                         
274                                                 //sharedABC is the minimum of the 3 possibilities
275                                                 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
276                                                 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
277                                                 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }    
278                                         }else{
279                                                 vector<double> data = vCalcs[i]->getValues(lookup);
280                                                 sharedABC = data[0];
281                                                 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
282                                                 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
283                                                 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
284                                         }
285                                         
286                                         //image window
287                                         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";
288                                         outsvg << "<g>\n";
289
290                                         //draw circles
291                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>"; 
292                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
293                                         outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
294                                         outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
295                                         outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
296
297                                         //place labels within overlaps
298                                         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"; 
299                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";  
300                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\"  y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";  
301                                         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";
302                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"150\">" + lookup[1]->getGroup() + "</text>\n";  
303                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\"  y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";  
304                                         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"; 
305                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"410\">" + lookup[2]->getGroup() + "</text>\n"; 
306                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";  
307                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"280\">" + toString(sharedABC) + "</text>\n"; 
308                                 
309                                         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";
310                                         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";
311                                         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";
312                                         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";
313                                         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";
314                                         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";
315                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
316                                         if (numA.size() == 3) { 
317                                                 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
318                                         }else { outsvg << "</text>\n"; }
319                         
320                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
321                                         if (numB.size() == 3) { 
322                                                 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
323                                         }else { outsvg << "</text>\n"; }
324                                         
325                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
326                                         if (numC.size() == 3) { 
327                                                 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
328                                         }else { outsvg << "</text>\n"; }
329
330                                         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";
331                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"780\">The total shared richness is " + toString(sharedABC) + "</text>\n";
332                                         
333                                         delete singleCalc;
334                                         
335                                 }else { //sharedchao and sharedsobs are multigroup
336                                         
337                                         vector<SharedRAbundVector*> subset;
338
339                                         //get estimates for numA
340                                         subset.push_back(lookup[0]);
341                                         vector<double> numA = vCalcs[i]->getValues(subset);
342                         
343                                         //get estimates for numB
344                                         subset.clear();
345                                         subset.push_back(lookup[1]);
346                                         vector<double> numB = vCalcs[i]->getValues(subset);
347                                 
348                                         //get estimates for numC
349                                         subset.clear();
350                                         subset.push_back(lookup[2]);
351                                         vector<double> numC = vCalcs[i]->getValues(subset);
352
353                                         subset.clear();
354                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
355                                         vector<double> sharedab =  vCalcs[i]->getValues(subset);
356                                         
357                                         subset.clear(); 
358                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
359                                         vector<double> sharedac =  vCalcs[i]->getValues(subset);
360                                         
361                                         subset.clear(); 
362                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
363                                         vector<double> sharedbc =  vCalcs[i]->getValues(subset);
364                                         
365                                         subset.clear(); 
366                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
367                                         vector<double> sharedabc =  vCalcs[i]->getValues(subset);
368                                         
369                                         //image window
370                                         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";
371                                         outsvg << "<g>\n";
372
373                                         //draw circles
374                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>"; 
375                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
376                                         outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
377                                         outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
378                                         outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
379
380                                         //place labels within overlaps
381                                         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"; 
382                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";  
383                                         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";  
384                                         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";
385                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"150\">" + lookup[1]->getGroup() + "</text>\n";  
386                                         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";  
387                                         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"; 
388                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"410\">" + lookup[2]->getGroup() + "</text>\n"; 
389                                         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";  
390                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedabc[0]).length() / 2)) + "\"  y=\"280\">" + toString(sharedabc[0]) + "</text>\n"; 
391                                 
392                                         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";
393                                         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";
394                                         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";
395                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA[0]);
396                                         if (numA.size() == 3) { 
397                                                 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
398                                         }else { outsvg << "</text>\n"; }
399                         
400                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB[0]);
401                                         if (numB.size() == 3) { 
402                                                 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
403                                         }else { outsvg << "</text>\n"; }
404                                         
405                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC[0]);
406                                         if (numC.size() == 3) { 
407                                                 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
408                                         }else { outsvg << "</text>\n"; }
409
410                                         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";
411                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The total shared richness is " + toString(sharedabc[0]) + "</text>\n";
412
413
414                                 }
415                 
416                                                                 
417                                 //close file
418                                 outsvg << "</g>\n</svg>\n";
419                                 outsvg.close();
420                                 
421
422                         }
423                         
424                 /******************* 4 Groups **************************/
425                 
426                 }else if (lookup.size() == 4) {
427                         //calc the shared otu
428                         float sharedABCD = 0;
429                         float numA = 0; float numB = 0; float numC = 0; float numD = 0;
430                         float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
431                         float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
432                         vector<double> data;
433                         //get sabund vector pointers so you can use the single calculators
434                         //one for each group
435                         SAbundVector sA, sB, sC, sD;
436                         SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
437                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
438                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
439                         sC = lookup[2]->getSAbundVector();  sabundC = &sC;
440                         sD = lookup[3]->getSAbundVector();  sabundD = &sD;
441                         
442                         //A = red, B = green, C = blue, D = yellow
443                         
444                         //make a file for each calculator
445                         for(int i=0;i<vCalcs.size();i++){
446                                 
447                                 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(); }
448                                 else{
449                                         string filenamesvg = getRootName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
450                                         openOutputFile(filenamesvg, outsvg);
451
452                                 
453                                         //in essence you want to run it like a single 
454                                         if (vCalcs[i]->getName() == "sharedsobs") {
455                                                 singleCalc = new Sobs();
456                                         }else if (vCalcs[i]->getName() == "sharedchao") {
457                                                 singleCalc = new Chao1();
458                                         }
459                                 
460                                         //get estimates for numA
461                                         data = singleCalc->getValues(sabundA);
462                                         numA = data[0];
463         //cout << "num a = " << numA << endl;   
464                         
465                                         //get estimates for numB
466                                         data = singleCalc->getValues(sabundB);
467                                         numB = data[0];
468         //cout << "num b = " << numB << endl;                           
469                                         //get estimates for numC
470                                         data = singleCalc->getValues(sabundC);
471                                         numC = data[0];
472         //cout << "num c = " << numC << endl;                           
473                                         //get estimates for numD
474                                         data = singleCalc->getValues(sabundD);
475                                         numD = data[0];
476 //cout << "num d = " << numD << endl;   
477
478                                         //get estimates for pairs
479                                         subset.clear();
480                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
481                                         data = vCalcs[i]->getValues(subset);
482                                         sharedAB = data[0];
483         //cout << "num ab = " << sharedAB << endl;                      
484                                         subset.clear();
485                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
486                                         data = vCalcs[i]->getValues(subset);
487                                         sharedAC = data[0];
488         //cout << "num ac = " << sharedAC << endl;                              
489                                         subset.clear();
490                                         subset.push_back(lookup[0]); subset.push_back(lookup[3]);
491                                         data = vCalcs[i]->getValues(subset);
492                                         sharedAD = data[0];
493         //cout << "num ad = " << sharedAD << endl;                      
494                                         subset.clear();
495                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
496                                         data = vCalcs[i]->getValues(subset);
497                                         sharedBC = data[0];
498         //cout << "num bc = " << sharedBC << endl;                              
499                                         subset.clear();
500                                         subset.push_back(lookup[1]); subset.push_back(lookup[3]);
501                                         data = vCalcs[i]->getValues(subset);
502                                         sharedBD = data[0];
503                 //cout << "num bd = " << sharedBD << endl;                                              
504                                         subset.clear();
505                                         subset.push_back(lookup[2]); subset.push_back(lookup[3]);
506                                         data = vCalcs[i]->getValues(subset);
507                                         sharedCD = data[0];
508                                                 
509         //cout << "num cd = " << sharedCD << endl;                              
510                                         //get estimates for combos of 3
511                                         subset.clear();
512                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
513                                         data = vCalcs[i]->getValues(subset);
514                                         sharedABC = data[0];
515                 //cout << "num abc = " << sharedABC << endl;                                    
516                                         subset.clear();
517                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
518                                         data = vCalcs[i]->getValues(subset);
519                                         sharedACD = data[0];
520                         //cout << "num acd = " << sharedACD << endl;    
521                                         subset.clear();
522                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
523                                         data = vCalcs[i]->getValues(subset);
524                                         sharedBCD = data[0];
525                 //cout << "num bcd = " << sharedBCD << endl;            
526                                         subset.clear();
527                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
528                                         data = vCalcs[i]->getValues(subset);
529                                         sharedABD = data[0];
530 //cout << "num abd = " << sharedABD << endl;
531                                         //get estimate for all four
532                                         data = vCalcs[i]->getValues(lookup);
533                                         sharedABCD = data[0];
534                 //cout << "num abcd = " << sharedABCD << endl << endl;  
535                 
536                                 
537                                                 
538                                         //image window
539                                         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";
540                                         outsvg << "<g>\n";
541                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"800\"/>"; 
542                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + lookup[0]->getLabel() + "</text>\n";
543
544                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"490\">The number of species in group " + lookup[0]->getGroup() + " is " + toString(numA) + "</text>\n";
545                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"510\">The number of species in group " + lookup[1]->getGroup() + " is " + toString(numB) + "</text>\n";
546                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"530\">The number of species in group " + lookup[2]->getGroup() + " is " + toString(numC) + "</text>\n";
547                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"550\">The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD) + "</text>\n";
548                                         
549                                         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";
550                                         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";
551                                         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";
552                                         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";
553                                         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";
554                                         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";
555                                         
556                                         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";
557                                         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";
558                                         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";
559                                         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";
560                                                                         
561                                         //make adjustments
562                                         sharedABC = sharedABC - sharedABCD;
563                         //cout << "num abc = " << sharedABC << endl;            
564                                         sharedABD = sharedABD - sharedABCD;
565                                 //cout << "num abd = " << sharedABD << endl;
566                                         sharedACD = sharedACD - sharedABCD;
567                                 //cout << "num acd = " << sharedACD << endl;
568                                         sharedBCD = sharedBCD - sharedABCD;
569                                 //cout << "num bcd = " << sharedBCD << endl;
570                                         
571                                         sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD;  //cout << "num ab = " << sharedAB << endl;
572                                         sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD;  //cout << "num ac = " << sharedAC << endl;
573                                         sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD;  //cout << "num ad = " << sharedAD << endl;                           
574                                         sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD;  //cout << "num bc = " << sharedBC << endl;
575                                         sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl; 
576                                         sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD;  //cout << "num cd = " << sharedCD << endl;
577                                         
578                                         numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
579                         //cout << "num a = " << numA << endl;           
580                                         numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
581                         //cout << "num b = " << numB << endl;           
582                                         numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
583                         //cout << "num c = " << numC << endl;           
584                                         numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
585                         //cout << "num d = " << numD << endl;           
586                                         
587                                         //draw circles
588                                         outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n "; 
589                                         outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
590                                         outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 440 315) \" cx=\"440\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
591                                         outsvg << "<ellipse fill=\"yellow\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+40 270 315) \" cx=\"270\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
592                         
593                                         //A = red, B = green, C = blue, D = yellow
594                         
595                                         //place labels within overlaps
596                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA)  + "</text>\n"; 
597                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";  
598                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\"  y=\"160\">" + toString(sharedAB) + "</text>\n";  
599                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\"  y=\"110\">" + toString(numB)  + "</text>\n";  
600                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"90\">" + lookup[1]->getGroup() + "</text>\n"; 
601                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\"  y=\"190\">" + toString(sharedAC) + "</text>\n";  
602                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\"   y=\"230\">" + toString(numC) + "</text>\n";  
603                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
604                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBD).length() / 2)) + "\" y=\"190\">" + toString(sharedBD) + "</text>\n";  
605                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\"   y=\"230\">" + toString(numD) + "</text>\n";  
606                                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[3]->getGroup() + "</text>\n"; 
607                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedAD).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n"; 
608                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBC) + "</text>\n";
609                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n"; 
610                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(275 - ((int)toString(sharedABD).length() / 2)) + "\" y=\"240\">" + toString(sharedABD) + "</text>\n"; 
611                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(400 - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"360\">" + toString(sharedBCD) + "</text>\n";
612                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n"; 
613                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"240\">" + toString(sharedABC) + "</text>\n"; 
614                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\"  y=\"320\">" + toString(sharedABCD) + "</text>\n"; 
615                                         
616                                         
617                                                                                 
618                                         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";
619                                         
620
621                                         outsvg << "</g>\n</svg>\n";
622                                         outsvg.close();
623                                         delete singleCalc;
624                                 }
625                         }
626                 }
627                 
628         }
629         catch(exception& e) {
630                 errorOut(e, "Venn", "getPic");
631                 exit(1);
632         }
633 }
634
635