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