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