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