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