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