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