]> git.donarmstrong.com Git - mothur.git/blob - venn.cpp
sffinfo bug with flow grams right index when clipQualRight=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 filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
166                         
167                         outputNames.push_back(filenameShared);
168                         ofstream outShared;
169                         m->openOutputFile(filenameShared, outShared);
170                         outShared << "Groups\tNumShared\tOTULabels\n";
171                         outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t' << labels.size() << '\t';
172                         for (int k = 0; k < labels.size()-1; k++) {
173                             outShared << labels[k] << ",";
174                         }
175                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
176                         outShared  << endl;
177                         outShared.close();
178                     }
179                                 }else if (vCalcs[i]->getName() == "sharedchao") {
180                                         singleCalc = new Chao1();
181                                 }
182                                 
183                                 int sharedVal, numSeqsA, numSeqsB, uniqSeqsToA, uniqSeqsToB;
184                                 if (nseqs) {
185                                         NSeqs* nseqsCalc = new NSeqs();
186                                         vector<double> data = nseqsCalc->getValues(lookup);
187                                         cout << data[0] << '\t' << data[1] << endl;
188                                         sharedVal = data[0] + data[1];
189                                         numSeqsA = sabundA->getNumSeqs();
190                                         numSeqsB = sabundB->getNumSeqs();
191                                         uniqSeqsToA = numSeqsA-data[0];
192                                         uniqSeqsToB = numSeqsB-data[1];
193                                         
194                                         delete nseqsCalc;
195                                 }
196                                 
197                                 
198                                 //get estimates for numA
199                                 vector<double> numA = singleCalc->getValues(sabundA);
200
201                                 //get estimates for numB
202                                 vector<double> numB = singleCalc->getValues(sabundB);
203                                                 
204                                 //image window
205                                 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";
206                                 outsvg << "<g>\n";
207
208                                 //draw circles
209                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" +  toString(width) +  "\" height=\"" +  toString(height) +  "\"/>"; 
210                                 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";
211                                 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)) +  "\"/>"; 
212                                 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)) +  "\"/>"; 
213                                 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";
214                                 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"; 
215                                 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";
216                                 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"; 
217                                 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";  
218                                 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]);
219                                 if (numA.size() == 3) { 
220                                         outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
221                                 }
222                                 if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared";  }  
223                                 outsvg << "</text>\n";
224                 
225                                 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]);
226                                 if (numB.size() == 3) { 
227                                         outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
228                                 }
229                                 if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared";  }  
230                                 outsvg << "</text>\n";
231
232                                 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]);
233                                 if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedVal) + "; " + toString((sharedVal / (float)(numSeqsA + numSeqsB))*100) + "% of these sequences are shared";  }  
234                                 outsvg << "</text>\n";
235                                 
236                                 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";
237                                 
238                                 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";;
239                                 
240                                 
241                                 //close file
242                                 outsvg << "</g>\n</svg>\n";
243                                 outsvg.close();
244                                 delete singleCalc;
245                         }
246                 /******************* 3 Groups **************************/
247                                                 
248                 }else if (lookup.size() == 3) {
249                         
250                         height = 1600;
251                         int windowSize = height;
252         
253                         
254                         //get sabund vector pointers so you can use the single calculators
255                         //one for each group
256                         SAbundVector sA, sB, sC;
257                         SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
258                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
259                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
260                         sC = lookup[2]->getSAbundVector();  sabundC = &sC;
261                 
262                         //make a file for each calculator
263                         for(int i=0;i<vCalcs.size();i++){
264                         
265                                 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg";
266
267                                 outputNames.push_back(filenamesvg);
268                                 m->openOutputFile(filenamesvg, outsvg);
269                                 
270                                 if (m->control_pressed) { outsvg.close(); return outputNames; }
271                                 
272                                 int sharedVal, sharedABVal, sharedACVal, sharedBCVal, numSeqsA, numSeqsB, numSeqsC, uniqSeqsToA, uniqSeqsToB, uniqSeqsToC;
273                                 
274                                 if (nseqs) {
275                                         NSeqs* nseqsCalc = new NSeqs();
276                                         vector<double> sharedData = nseqsCalc->getValues(lookup);
277                                                 
278                                         vector<SharedRAbundVector*> mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]);
279                                         vector<double> sharedAB = nseqsCalc->getValues(mysubset);
280                                                 
281                                         mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]);
282                                         vector<double> sharedAC = nseqsCalc->getValues(mysubset);
283                                                 
284                                         mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
285                                         vector<double> sharedBC = nseqsCalc->getValues(mysubset);
286                                                 
287                                         sharedVal = sharedData[0] + sharedData[1] + sharedData[2];
288                                         sharedABVal = sharedAB[0] + sharedAB[1];
289                                         sharedACVal = sharedAC[0] + sharedAC[1];
290                                         sharedBCVal = sharedBC[0] + sharedBC[1];
291                                         numSeqsA = sabundA->getNumSeqs();
292                                         numSeqsB = sabundB->getNumSeqs();
293                                         numSeqsC = sabundC->getNumSeqs();
294                                         uniqSeqsToA = numSeqsA-sharedData[0];
295                                         uniqSeqsToB = numSeqsC-sharedData[1];
296                                         uniqSeqsToC = numSeqsB-sharedData[1];
297
298                                         delete nseqsCalc;
299                                 }
300
301                                 
302                                 if (vCalcs[i]->getName() == "sharedace") {
303                                 
304                                         singleCalc = new Ace(10);
305                                         
306                                         //get estimates for numA
307                                         vector<double> numA = singleCalc->getValues(sabundA);
308                         
309                                         //get estimates for numB
310                                         vector<double> numB = singleCalc->getValues(sabundB);
311                                 
312                                         //get estimates for numC
313                                         vector<double> numC = singleCalc->getValues(sabundC);
314
315
316                                         //get estimates for sharedAB, sharedAC and sharedBC
317                                         subset.clear();
318                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
319                                         vector<double> sharedAB = vCalcs[i]->getValues(subset);
320                                         
321                                         subset.clear();
322                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
323                                         vector<double> sharedAC = vCalcs[i]->getValues(subset);
324                                         
325                                         subset.clear();
326                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
327                                         vector<double> sharedBC = vCalcs[i]->getValues(subset);
328                                         
329                                         vector<double> sharedAwithBC;
330                                         vector<double> sharedBwithAC;
331                                         vector<double> sharedCwithAB;
332                                         
333                                         //find possible sharedABC values
334                                         float sharedABC1 = 0.0; float sharedABC2 = 0.0; float sharedABC3 = 0.0; float sharedABC = 0.0;
335
336                                         if (vCalcs[i]->getMultiple() == false) {
337                                                 //merge BC and estimate with shared with A
338                                                 SharedRAbundVector* merge = new SharedRAbundVector();
339                                                 for (int j = 0; j < lookup[1]->size(); j++) {
340                                                         merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
341                                                 }
342                                         
343                                                 subset.clear();
344                                                 subset.push_back(lookup[0]); subset.push_back(merge);
345                                                 sharedAwithBC = vCalcs[i]->getValues(subset);
346                                 
347                                                 delete merge;
348                                                 //merge AC and estimate with shared with B
349                                                 merge = new SharedRAbundVector();
350                                                 for (int j = 0; j < lookup[0]->size(); j++) {
351                                                         merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), "");
352                                                 }
353                                         
354                                                 subset.clear();
355                                                 subset.push_back(merge); subset.push_back(lookup[1]);
356                                                 sharedBwithAC = vCalcs[i]->getValues(subset);
357                                 
358                                                 delete merge;
359                                                 //merge AB and estimate with shared with C
360                                                 merge = new SharedRAbundVector();
361                                                 for (int j = 0; j < lookup[0]->size(); j++) {
362                                                         merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), "");
363                                                 }
364                                         
365                                                 subset.clear();
366                                                 subset.push_back(lookup[2]); subset.push_back(merge);
367                                                 sharedCwithAB = vCalcs[i]->getValues(subset);
368                                                 delete merge;
369                                         
370                                                 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
371                                                 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
372                                                 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
373          
374                                                 //if any of the possible m's are - throw them out
375                                                 if (sharedABC1 < 0.00001) { sharedABC1 = 0; }
376                                                 if (sharedABC2 < 0.00001) { sharedABC2 = 0; }
377                                                 if (sharedABC3 < 0.00001) { sharedABC3 = 0; }
378                         
379                                                 //sharedABC is the minimum of the 3 possibilities
380                                                 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
381                                                 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
382                                                 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }    
383                                         }else{
384                                                 vector<double> data = vCalcs[i]->getValues(lookup);
385                                                 sharedABC = data[0];
386                                                 sharedAwithBC.push_back(sharedAB[0] + sharedAC[0] - sharedABC);
387                                                 sharedBwithAC.push_back(sharedAB[0] + sharedBC[0] - sharedABC);
388                                                 sharedCwithAB.push_back(sharedAC[0] + sharedBC[0] - sharedABC);
389                                         }
390                                         
391                                         //image window
392                                         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";
393                                         outsvg << "<g>\n";
394
395                                         //draw circles
396                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" +  toString(width) +  "\" height=\"" +  toString(height) +  "\"/>"; 
397                                         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";
398                                         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)) +  "\"/>"; 
399                                         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)) +  "\"/>"; 
400                                         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)) +  "\"/>"; 
401
402                                         //place labels within overlaps
403                                         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"; 
404                                         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";  
405                                         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";  
406                                         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";
407                                         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";  
408                                         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";  
409                                         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"; 
410                                         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"; 
411                                         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";  
412                                         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"; 
413                                 
414                                         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]);
415                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedABVal);  }  
416                                         outsvg << "</text>\n";
417                                         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]);
418                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedACVal);  }  
419                                         outsvg << "</text>\n";
420                                         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]);
421                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedBCVal);  }  
422                                         outsvg << "</text>\n";
423                                         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";
424                                         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";
425                                         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";
426                                         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]);
427                                         if (numA.size() == 3) { 
428                                                 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
429                                         } 
430                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsA) + "; " + toString(uniqSeqsToA) + " sequences are not shared";  }  
431                                         outsvg << "</text>\n";
432                         
433                                         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]);
434                                         if (numB.size() == 3) { 
435                                                 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
436                                         }
437                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsB) + "; " + toString(uniqSeqsToB) + " sequences are not shared";  }  
438                                         outsvg << "</text>\n";
439                                         
440                                         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]);
441                                         if (numC.size() == 3) { 
442                                                 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
443                                         }
444                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsC) + "; " + toString(uniqSeqsToC) + " sequences are not shared";  }  
445                                         outsvg << "</text>\n";
446
447                                         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";
448                                         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);
449                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedVal);  }  
450                                         outsvg << "</text>\n";
451                                         
452                                         delete singleCalc;
453                                         
454                                 }else { //sharedchao and sharedsobs are multigroup
455                                         
456                     ofstream outShared;
457                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
458                         string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
459                         
460                         outputNames.push_back(filenameShared);
461                        
462                         m->openOutputFile(filenameShared, outShared);
463                         outShared << "Groups\tNumShared\tOTULabels\n";
464                     }
465                                         vector<SharedRAbundVector*> subset;
466
467                                         //get estimates for numA
468                                         subset.push_back(lookup[0]);
469                                         vector<double> numA = vCalcs[i]->getValues(subset);
470                         
471                                         //get estimates for numB
472                                         subset.clear();
473                                         subset.push_back(lookup[1]);
474                                         vector<double> numB = vCalcs[i]->getValues(subset);
475                                 
476                                         //get estimates for numC
477                                         subset.clear();
478                                         subset.push_back(lookup[2]);
479                                         vector<double> numC = vCalcs[i]->getValues(subset);
480
481                                         subset.clear();
482                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
483                     vector<string> labels;
484                                         vector<double> sharedab =  vCalcs[i]->getValues(subset, labels);
485                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
486                         outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t' << labels.size() << '\t';
487                         for (int k = 0; k < labels.size()-1; k++) {
488                             outShared << labels[k] << ",";
489                         }
490                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
491                         outShared << endl;
492                     }
493                                         
494                                         subset.clear(); 
495                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
496                                         vector<double> sharedac =  vCalcs[i]->getValues(subset, labels);
497                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
498                         outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
499                         for (int k = 0; k < labels.size()-1; k++) {
500                             outShared << labels[k] << ",";
501                         }
502                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
503                         outShared << endl;
504                     }
505                                         
506                                         subset.clear(); 
507                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
508                                         vector<double> sharedbc =  vCalcs[i]->getValues(subset, labels);
509                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
510                         outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
511                         for (int k = 0; k < labels.size()-1; k++) {
512                             outShared << labels[k] << ",";
513                         }
514                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
515                         outShared << endl;
516                     }
517
518                                         
519                                         subset.clear(); 
520                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
521                                         vector<double> sharedabc =  vCalcs[i]->getValues(subset, labels);
522                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
523                         outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
524                         for (int k = 0; k < labels.size()-1; k++) {
525                             outShared << labels[k] << ",";
526                         }
527                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
528                         outShared << endl;
529                         outShared.close();
530                     }
531                                         
532                                         //image window
533                                         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";
534                                         outsvg << "<g>\n";
535
536                                         //draw circles
537                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" +  toString(width) +  "\" height=\"" +  toString(height) +  "\"/>"; 
538                                         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";
539                                         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)) +  "\"/>"; 
540                                         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)) +  "\"/>"; 
541                                         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)) +  "\"/>"; 
542
543                                         //place labels within overlaps
544                                         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"; 
545                                         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";  
546                                         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";  
547                                         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";
548                                         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";  
549                                         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";  
550                                         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"; 
551                                         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"; 
552                                         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";  
553                                         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"; 
554                                 
555                                         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]);
556                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedABVal);  }  
557                                         outsvg << "</text>\n";
558                                         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]);
559                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedACVal);  }  
560                                         outsvg << "</text>\n";
561                                         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]);
562                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedBCVal);  }  
563                                         outsvg << "</text>\n";
564                                         
565                                         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]);
566                                         if (numA.size() == 3) { 
567                                                 outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]);
568                                         }
569                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsA);  }  
570                                         outsvg << "</text>\n";
571                         
572                                         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]);
573                                         if (numB.size() == 3) { 
574                                                 outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]);
575                                         }
576                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsB);  }  
577                                         outsvg << "</text>\n";
578                                                                                 
579                                         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]);
580                                         if (numC.size() == 3) { 
581                                                 outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]);
582                                         }
583                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsC);  }  
584                                         outsvg << "</text>\n";
585
586                                         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";
587                                         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]);
588                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedVal);  }  
589                                         outsvg << "</text>\n";
590
591                                 }
592                                                                 
593                                 //close file
594                                 outsvg << "</g>\n</svg>\n";
595                                 outsvg.close();
596                                 
597
598                         }
599                         
600                 /******************* 4 Groups **************************/
601                 
602                 }else if (lookup.size() == 4) {
603                         
604                         height = 1600;
605                         
606                         int windowSize = height;
607                 
608                         //calc the shared otu
609                         float sharedABCD = 0;
610                         float numA = 0; float numB = 0; float numC = 0; float numD = 0;
611                         float sharedAB = 0; float sharedAC = 0; float sharedBC = 0; float sharedAD = 0; float sharedBD = 0; float sharedCD = 0;
612                         float sharedABC = 0; float sharedACD = 0; float sharedBCD = 0; float sharedABD = 0;
613                         vector<double> data;
614                         //get sabund vector pointers so you can use the single calculators
615                         //one for each group
616                         SAbundVector sA, sB, sC, sD;
617                         SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC; SAbundVector* sabundD;
618                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
619                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
620                         sC = lookup[2]->getSAbundVector();  sabundC = &sC;
621                         sD = lookup[3]->getSAbundVector();  sabundD = &sD;
622                         
623                         //A = red, B = green, C = blue, D = yellow
624                         
625                         //make a file for each calculator
626                         for(int i=0;i<vCalcs.size();i++){
627                                 
628                                 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(); }
629                                 else{
630                                         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";
631                                         outputNames.push_back(filenamesvg);
632                                         m->openOutputFile(filenamesvg, outsvg);
633
634                                         if (m->control_pressed) { outsvg.close(); return outputNames; }
635                                         
636                                         //in essence you want to run it like a single 
637                                         if (vCalcs[i]->getName() == "sharedsobs") {
638                                                 singleCalc = new Sobs();
639                                         }else if (vCalcs[i]->getName() == "sharedchao") {
640                                                 singleCalc = new Chao1();
641                                         }
642                                 
643                                         //get estimates for numA
644                                         data = singleCalc->getValues(sabundA);
645                                         numA = data[0];
646         //cout << "num a = " << numA << endl;   
647                         
648                                         //get estimates for numB
649                                         data = singleCalc->getValues(sabundB);
650                                         numB = data[0];
651         //cout << "num b = " << numB << endl;                           
652                                         //get estimates for numC
653                                         data = singleCalc->getValues(sabundC);
654                                         numC = data[0];
655         //cout << "num c = " << numC << endl;                           
656                                         //get estimates for numD
657                                         data = singleCalc->getValues(sabundD);
658                                         numD = data[0];
659 //cout << "num d = " << numD << endl;   
660                     
661                     ofstream outShared;
662                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs")) {
663                         string filenameShared = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + ".sharedotus";
664                         
665                         outputNames.push_back(filenameShared);
666                         
667                         m->openOutputFile(filenameShared, outShared);
668                         outShared << "Groups\tNumShared\tOTULabels\n";
669                     }
670
671                                         //get estimates for pairs
672                                         subset.clear();
673                     vector<string> labels;
674                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]);
675                                         data = vCalcs[i]->getValues(subset, labels);
676                                         sharedAB = data[0];
677                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
678                         outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() << '\t'<< labels.size() << '\t';
679                         for (int k = 0; k < labels.size()-1; k++) {
680                             outShared << labels[k] << ",";
681                         }
682                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
683                         outShared << endl;
684                     }
685         //cout << "num ab = " << sharedAB << endl;                      
686                                         subset.clear();
687                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]);
688                                         data = vCalcs[i]->getValues(subset, labels);
689                                         sharedAC = data[0];
690                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
691                         outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
692                         for (int k = 0; k < labels.size()-1; k++) {
693                             outShared << labels[k] << ",";
694                         }
695                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
696                         outShared << endl;
697                     }
698         //cout << "num ac = " << sharedAC << endl;                              
699                                         subset.clear();
700                                         subset.push_back(lookup[0]); subset.push_back(lookup[3]);
701                                         data = vCalcs[i]->getValues(subset, labels);
702                                         sharedAD = data[0];
703                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
704                         outShared << lookup[0]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
705                         for (int k = 0; k < labels.size()-1; k++) {
706                             outShared << labels[k] << ",";
707                         }
708                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
709                         outShared << endl;
710                     }
711         //cout << "num ad = " << sharedAD << endl;                      
712                                         subset.clear();
713                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]);
714                                         data = vCalcs[i]->getValues(subset, labels);
715                                         sharedBC = data[0];
716                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
717                         outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup() << '\t'<< labels.size() << '\t';
718                         for (int k = 0; k < labels.size()-1; k++) {
719                             outShared << labels[k] << ",";
720                         }
721                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
722                         outShared << endl;
723                     }
724         //cout << "num bc = " << sharedBC << endl;                              
725                                         subset.clear();
726                                         subset.push_back(lookup[1]); subset.push_back(lookup[3]);
727                                         data = vCalcs[i]->getValues(subset, labels);
728                                         sharedBD = data[0];
729                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
730                         outShared << lookup[1]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
731                         for (int k = 0; k < labels.size()-1; k++) {
732                             outShared << labels[k] << ",";
733                         }
734                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
735                         outShared << endl;
736                     }
737                 //cout << "num bd = " << sharedBD << endl;                                              
738                                         subset.clear();
739                                         subset.push_back(lookup[2]); subset.push_back(lookup[3]);
740                                         data = vCalcs[i]->getValues(subset, labels);
741                                         sharedCD = data[0];
742                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
743                         outShared << lookup[2]->getGroup() + "-" + lookup[3]->getGroup() << '\t'<< labels.size() << '\t';
744                         for (int k = 0; k < labels.size()-1; k++) {
745                             outShared << labels[k] << ",";
746                         }
747                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
748                         outShared << endl;
749                     }
750                                                 
751         //cout << "num cd = " << sharedCD << endl;                              
752                                         //get estimates for combos of 3
753                                         subset.clear();
754                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[2]);
755                                         data = vCalcs[i]->getValues(subset, labels);
756                                         sharedABC = data[0];
757                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
758                         outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup()+ "-" + lookup[2]->getGroup()<< '\t'<< labels.size() << '\t';
759                         for (int k = 0; k < labels.size()-1; k++) {
760                             outShared << labels[k] << ",";
761                         }
762                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
763                         outShared << endl;
764                     }
765                 //cout << "num abc = " << sharedABC << endl;                                    
766                                         subset.clear();
767                                         subset.push_back(lookup[0]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
768                                         data = vCalcs[i]->getValues(subset, labels);
769                                         sharedACD = data[0];
770                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
771                         outShared << lookup[0]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
772                         for (int k = 0; k < labels.size()-1; k++) {
773                             outShared << labels[k] << ",";
774                         }
775                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
776                         outShared << endl;
777                     }
778                         //cout << "num acd = " << sharedACD << endl;    
779                                         subset.clear();
780                                         subset.push_back(lookup[1]); subset.push_back(lookup[2]); subset.push_back(lookup[3]);
781                                         data = vCalcs[i]->getValues(subset,labels);
782                                         sharedBCD = data[0];
783                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
784                         outShared << lookup[1]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
785                         for (int k = 0; k < labels.size()-1; k++) {
786                             outShared << labels[k] << ",";
787                         }
788                         outShared << labels[labels.size()-1]; 
789                         outShared << endl;
790                     }
791                 //cout << "num bcd = " << sharedBCD << endl;            
792                                         subset.clear();
793                                         subset.push_back(lookup[0]); subset.push_back(lookup[1]); subset.push_back(lookup[3]);
794                                         data = vCalcs[i]->getValues(subset, labels);
795                                         sharedABD = data[0];
796                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
797                         outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
798                         for (int k = 0; k < labels.size()-1; k++) {
799                             outShared << labels[k] << ",";
800                         }
801                         outShared << labels[labels.size()-1]; 
802                         outShared << endl;
803                     }
804 //cout << "num abd = " << sharedABD << endl;
805                                         //get estimate for all four
806                                         data = vCalcs[i]->getValues(lookup, labels);
807                                         sharedABCD = data[0];
808                     if (sharedOtus && (vCalcs[i]->getName() == "sharedsobs") &&  (labels.size() != 0)) {
809                         outShared << lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup()+ "-" + lookup[3]->getGroup()<< '\t'<< labels.size() << '\t';
810                         for (int k = 0; k < labels.size()-1; k++) {
811                             outShared << labels[k] << ",";
812                         }
813                         if (labels.size() != 0) { outShared << labels[labels.size()-1]; }
814                         outShared << endl;
815                         outShared.close();
816                     }
817                 //cout << "num abcd = " << sharedABCD << endl << endl;  
818                                         int sharedVal, sharedABCVal, sharedABDVal, sharedACDVal, sharedBCDVal, sharedABVal, sharedACVal, sharedADVal, sharedBCVal, sharedBDVal, sharedCDVal, numSeqsA, numSeqsB, numSeqsC, numSeqsD;
819                                                                                                 
820                                         if (nseqs) {
821                                                 NSeqs* nseqsCalc = new NSeqs();
822                                                 vector<double> sharedData = nseqsCalc->getValues(lookup);
823                                                 
824                                                 vector<SharedRAbundVector*> mysubset; mysubset.push_back(lookup[0]); mysubset.push_back(lookup[1]);
825                                                 vector<double> sharedAB = nseqsCalc->getValues(mysubset);
826                                                 
827                                                 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[2]);
828                                                 vector<double> sharedAC = nseqsCalc->getValues(mysubset);
829                                                 
830                                                 mysubset.clear(); mysubset.push_back(lookup[0]); mysubset.push_back(lookup[3]);
831                                                 vector<double> sharedAD = nseqsCalc->getValues(mysubset);
832                                                 
833                                                 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
834                                                 vector<double> sharedBC = nseqsCalc->getValues(mysubset);
835                                                 
836                                                 mysubset.clear(); mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]);
837                                                 vector<double> sharedBD = nseqsCalc->getValues(mysubset);
838                                                 
839                                                 mysubset.clear(); mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
840                                                 vector<double> sharedCD = nseqsCalc->getValues(mysubset);
841                                                 
842                                                 mysubset.clear(); mysubset.push_back(lookup[0]);  mysubset.push_back(lookup[1]); mysubset.push_back(lookup[2]);
843                                                 vector<double> sharedABC = nseqsCalc->getValues(mysubset);
844                                                 
845                                                 mysubset.clear(); mysubset.push_back(lookup[0]);  mysubset.push_back(lookup[1]); mysubset.push_back(lookup[3]);
846                                                 vector<double> sharedABD = nseqsCalc->getValues(mysubset);
847
848                                                 mysubset.clear(); mysubset.push_back(lookup[0]);  mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
849                                                 vector<double> sharedACD = nseqsCalc->getValues(mysubset);
850
851                                                 mysubset.clear(); mysubset.push_back(lookup[1]);  mysubset.push_back(lookup[2]); mysubset.push_back(lookup[3]);
852                                                 vector<double> sharedBCD = nseqsCalc->getValues(mysubset);
853                                                 
854                                                 sharedVal = sharedData[0] + sharedData[1] + sharedData[2] + sharedData[3];
855                                                 sharedABCVal = sharedABC[0] + sharedABC[1] + sharedABC[2];
856                                                 sharedABDVal = sharedABD[0] + sharedABD[1] + sharedABD[2];
857                                                 sharedACDVal = sharedACD[0] + sharedACD[1] + sharedACD[2];
858                                                 sharedBCDVal = sharedBCD[0] + sharedBCD[1] + sharedBCD[2];
859                                                 sharedABVal = sharedAB[0] + sharedAB[1];
860                                                 sharedACVal = sharedAC[0] + sharedAC[1];
861                                                 sharedADVal = sharedAD[0] + sharedAD[1];
862                                                 sharedBCVal = sharedBC[0] + sharedBC[1];
863                                                 sharedBDVal = sharedBD[0] + sharedBD[1];
864                                                 sharedCDVal = sharedCD[0] + sharedCD[1];
865                                                 numSeqsA = sabundA->getNumSeqs(); 
866                                                 numSeqsB = sabundB->getNumSeqs(); 
867                                                 numSeqsC = sabundC->getNumSeqs(); 
868                                                 numSeqsD = sabundD->getNumSeqs(); 
869                                                 
870                                                 delete nseqsCalc;
871                                         }
872
873                                                 
874                                         //image window
875                                         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";
876                                         outsvg << "<g>\n";
877                                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" +  toString(width) +  "\" height=\"" +  toString(windowSize) +  "\"/>"; 
878                                         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";
879
880                                         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); 
881                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsA);  }  
882                                         outsvg << "</text>\n";
883                                         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);
884                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsB);  }  
885                                         outsvg << "</text>\n";
886                                         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);
887                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsC);  }  
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.7 * height)) +  "\">The number of species in group " + lookup[3]->getGroup() + " is " + toString(numD);
890                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(numSeqsD);  }  
891                                         outsvg << "</text>\n";
892                                         
893                                         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);
894                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedABVal);  }  
895                                         outsvg << "</text>\n";
896                                         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);
897                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedACVal);  }  
898                                         outsvg << "</text>\n";
899                                         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);
900                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedADVal);  }  
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.8 * height)) +  "\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[2]->getGroup() + " is " + toString(sharedBC);
903                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedBCVal);  }  
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.825 * height)) +  "\">The number of species shared between groups " + lookup[1]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBD);
906                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedBDVal);  }  
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.85 * height)) +  "\">The number of species shared between groups " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedCD);
909                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedCDVal);  }  
910                                         outsvg << "</text>\n";
911                                         
912                                         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);
913                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedABCVal);  }  
914                                         outsvg << "</text>\n";
915                                         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);
916                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedABDVal);  }  
917                                         outsvg << "</text>\n";
918                                         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);
919                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedACDVal);  }  
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.95 * height)) +  "\">The number of species shared between groups " + lookup[1]->getGroup() + ", " + lookup[2]->getGroup() + " and " + lookup[3]->getGroup() + " is " + toString(sharedBCD);
922                                         if (nseqs) {  outsvg << ", and the number of squences is " + toString(sharedBCDVal);  }  
923                                         outsvg << "</text>\n";
924                                                                         
925                                         //make adjustments
926                                         sharedABC = sharedABC - sharedABCD;
927                         //cout << "num abc = " << sharedABC << endl;            
928                                         sharedABD = sharedABD - sharedABCD;
929                                 //cout << "num abd = " << sharedABD << endl;
930                                         sharedACD = sharedACD - sharedABCD;
931                                 //cout << "num acd = " << sharedACD << endl;
932                                         sharedBCD = sharedBCD - sharedABCD;
933                                 //cout << "num bcd = " << sharedBCD << endl;
934                                         
935                                         sharedAB = sharedAB - sharedABC - sharedABCD - sharedABD;  //cout << "num ab = " << sharedAB << endl;
936                                         sharedAC = sharedAC - sharedABC - sharedABCD - sharedACD;  //cout << "num ac = " << sharedAC << endl;
937                                         sharedAD = sharedAD - sharedABD - sharedABCD - sharedACD;  //cout << "num ad = " << sharedAD << endl;                           
938                                         sharedBC = sharedBC - sharedABC - sharedABCD - sharedBCD;  //cout << "num bc = " << sharedBC << endl;
939                                         sharedBD = sharedBD - sharedABD - sharedABCD - sharedBCD; // cout << "num bd = " << sharedBD << endl; 
940                                         sharedCD = sharedCD - sharedACD - sharedABCD - sharedBCD;  //cout << "num cd = " << sharedCD << endl;
941                                         
942                                         numA = numA - sharedAB - sharedAC - sharedAD - sharedABCD - sharedABC - sharedACD - sharedABD;
943                         //cout << "num a = " << numA << endl;           
944                                         numB = numB - sharedAB - sharedBC - sharedBD - sharedABCD - sharedABC - sharedABD - sharedBCD;
945                         //cout << "num b = " << numB << endl;           
946                                         numC = numC - sharedAC - sharedBC - sharedCD - sharedABCD - sharedABC - sharedACD - sharedBCD;
947                         //cout << "num c = " << numC << endl;           
948                                         numD = numD - sharedAD - sharedBD - sharedCD - sharedABCD - sharedBCD - sharedACD - sharedABD;
949                         //cout << "num d = " << numD << endl;           
950                                         
951                                         //draw circles
952                                         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 "; 
953                                         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 ";
954                                         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 ";
955                                         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 ";
956                         
957                                         //A = red, B = green, C = blue, D = yellow
958                         
959                                         //place labels within overlaps
960                                         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"; 
961                                         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";  
962                                         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";  
963                                         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";  
964                                         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"; 
965                                         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";  
966                                         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";  
967                                         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";
968                                         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";  
969                                         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";  
970                                         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"; 
971                                         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"; 
972                                         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";
973                                         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"; 
974                                         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"; 
975                                         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";
976                                         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"; 
977                                         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"; 
978                                         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"; 
979                                         
980                                         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));
981                                         if (nseqs) {  outsvg << ", and the number of squences in the otus shared by all groups is " + toString(sharedVal);  }  
982                                         outsvg << "</text>\n";
983                                         
984                                         outsvg << "</g>\n</svg>\n";
985                                         outsvg.close();
986                                         delete singleCalc;
987                                 }
988                         }
989                 }
990                 
991                 return outputNames;
992                 
993         }
994         catch(exception& e) {
995                 m->errorOut(e, "Venn", "getPic");
996                 exit(1);
997         }
998 }
999
1000