]> git.donarmstrong.com Git - mothur.git/blob - venn.cpp
started shared utilities, updates to venn and heatmap added tree.groups command
[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
15
16 //**********************************************************************************************************************
17 Venn::Venn(){
18         try {
19                 globaldata = GlobalData::getInstance();
20                 format = globaldata->getFormat();
21                 util = new SharedUtil();
22         }
23         catch(exception& e) {
24                 cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
25                 exit(1);
26         }
27         catch(...) {
28                 cout << "An unknown error has occurred in the Venn class function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
29                 exit(1);
30         }
31 }
32 //**********************************************************************************************************************
33 void Venn::getPic(OrderVector* order, vector<Calculator*> vCalcs) {
34         try {
35                 SAbundVector s;
36                 s = order->getSAbundVector();  sabund = &s;
37                 
38                 for(int i=0;i<vCalcs.size();i++){
39                         string filenamesvg = globaldata->inputFileName + ".venn." + order->getLabel() + vCalcs[i]->getName() + ".svg";
40                         openOutputFile(filenamesvg, outsvg);
41
42                         vector<double> data = vCalcs[i]->getValues(sabund);
43                         
44                         //svg image
45                         outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
46                         outsvg << "<g>\n";
47                                 
48                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
49                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + order->getLabel() + "</text>\n";
50                         outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
51                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
52                         
53                         if (data.size() == 3) { 
54                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
55                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
56                         }
57                         
58                         outsvg << "</g>\n</svg>\n";
59                         outsvg.close();
60                 }
61         }
62         catch(exception& e) {
63                 cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
64                 exit(1);
65         }
66         catch(...) {
67                 cout << "An unknown error has occurred in the Venn class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68                 exit(1);
69         }
70 }
71 //**********************************************************************************************************************
72 void Venn::getPic(SharedOrderVector* sharedorder, vector<Calculator*> vCalcs) {
73         try {
74                 
75                 //fills vector of sharedsabunds - lookup
76                 util->getSharedVectors(globaldata->Groups, lookup, sharedorder);  //fills group vectors from order vector.
77                 
78                 /******************* 1 Group **************************/
79                 if (lookup.size() == 1) {
80                                         
81                         SAbundVector s;
82                         s = lookup[0]->getSAbundVector();  sabund = &s;
83                         
84                         //make a file for each calculator
85                         for(int i=0;i<vCalcs.size();i++){
86                                 string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
87                                 openOutputFile(filenamesvg, outsvg);
88                         
89                                 //in essence you want to run it like a single 
90                                 if (vCalcs[i]->getName() == "SharedSobs") {
91                                         delete vCalcs[i];
92                                         vCalcs[i] = new Sobs();
93                                 }else if (vCalcs[i]->getName() == "SharedChao") {
94                                         delete vCalcs[i];
95                                         vCalcs[i] = new Chao1();
96                                 }else if (vCalcs[i]->getName() == "SharedAce") {
97                                         delete vCalcs[i];
98                                         vCalcs[i] = new Ace(10);
99                                 }
100                                 
101                                 vector<double> data = vCalcs[i]->getValues(sabund);
102                         
103                                 //svg image
104                                 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
105                                 outsvg << "<g>\n";
106                                 
107                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
108                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
109                                 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"350\" cy=\"200\" r=\"150\"/>"; 
110                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"165\">" + lookup[0]->getGroup() + "</text>\n";
111                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(data[0]).length() / 2)) + "\" y=\"195\">" + toString(data[0]) + "</text>\n";  
112                         
113                                 if (data.size() == 3) { 
114                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"380\">The lower bound of the confidence interval is " + toString(data[1]) + "</text>\n";
115                                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"200\" y=\"410\">The upper bound of the confidence interval is " + toString(data[2]) + "</text>\n";
116                                 }
117                         
118                                 outsvg << "</g>\n</svg>\n";
119                                 outsvg.close();
120                         }
121                         
122                 /******************* 2 Groups **************************/       
123                 
124                 }else if (lookup.size() == 2) {
125                         //get sabund vector pointers so you can use the single calculators
126                         //one for each group
127                         SAbundVector sA, sB;
128                         SAbundVector* sabundA; SAbundVector* sabundB;
129                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
130                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
131                         
132                         //make a file for each calculator
133                         for(int i=0;i<vCalcs.size();i++){
134                                 string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
135                                 openOutputFile(filenamesvg, outsvg);
136                                 
137                                 //get estimates for sharedAB
138                                 vector<double> shared = vCalcs[i]->getValues(lookup[0], lookup[1]);
139                                 
140                                 //in essence you want to run it like a single 
141                                 if (vCalcs[i]->getName() == "SharedSobs") {
142                                         delete vCalcs[i];
143                                         vCalcs[i] = new Sobs();
144                                 }else if (vCalcs[i]->getName() == "SharedChao") {
145                                         delete vCalcs[i];
146                                         vCalcs[i] = new Chao1();
147                                 }else if (vCalcs[i]->getName() == "SharedAce") {
148                                         delete vCalcs[i];
149                                         vCalcs[i] = new Ace(10);
150                                 }
151                                 
152                                 //get estimates for numA
153                                 vector<double> numA = vCalcs[i]->getValues(sabundA);
154                                 
155                                 //get estimates for numB
156                                 vector<double> numB = vCalcs[i]->getValues(sabundB);
157                                 
158                                                 
159                                 //image window
160                                 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
161                                 outsvg << "<g>\n";
162
163                                 //draw circles
164                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
165                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
166                                 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"250\" cy=\"200\" r=\"150\"/>"; 
167                                 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"435\" cy=\"200\" r=\"150\"/>"; 
168                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]).length() / 2)) + "\" y=\"195\">" + toString(numA[0] - shared[0]) + "</text>\n";
169                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(numB[0]).length() / 2)) + "\" y=\"195\">" + toString(numB[0] - shared[0]) + "</text>\n"; 
170                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[0]->getGroup() + "</text>\n";
171                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)lookup[1]->getGroup().length() / 2)) + "\" y=\"175\">" + lookup[1]->getGroup() + "</text>\n"; 
172                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(shared[0]).length() / 2)) + "\" y=\"195\">" + toString(shared[0]) + "</text>\n";  
173                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"460\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]);
174                                 if (numA.size() == 3) { 
175                                         outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
176                                 }else { outsvg << "</text>\n"; }
177                 
178                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"480\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]);
179                                 if (numB.size() == 3) { 
180                                         outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
181                                 }else { outsvg << "</text>\n"; }
182
183                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"500\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(shared[0]) + "</text>\n";
184                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"520\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString((shared[0] / (float)(numA[0] + numB[0] - shared[0]))) + "</text>\n";
185                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"540\">The total richness for all groups is " + toString((float)(numA[0] + numB[0] - shared[0])) + "</text>\n";
186                                 
187                                 //close file
188                                 outsvg << "</g>\n</svg>\n";
189                                 outsvg.close();
190
191                         }
192                         
193                 /******************* 3 Groups **************************/
194                                                 
195                 }else if (lookup.size() == 3) {
196                         //get sabund vector pointers so you can use the single calculators
197                         //one for each group
198                         SAbundVector sA, sB, sC;
199                         SAbundVector* sabundA; SAbundVector* sabundB; SAbundVector* sabundC;
200                         sA = lookup[0]->getSAbundVector();  sabundA = &sA;
201                         sB = lookup[1]->getSAbundVector();  sabundB = &sB;
202                         sC = lookup[2]->getSAbundVector();  sabundC = &sC;
203                         
204                         //make a file for each calculator
205                         for(int i=0;i<vCalcs.size();i++){
206                                 string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg";
207                                 openOutputFile(filenamesvg, outsvg);
208                                 
209                                 //get estimates for sharedAB, sharedAC and sharedBC
210                                 vector<double> sharedAB = vCalcs[i]->getValues(lookup[0], lookup[1]);
211                                 vector<double> sharedAC = vCalcs[i]->getValues(lookup[0], lookup[2]);
212                                 vector<double> sharedBC = vCalcs[i]->getValues(lookup[1], lookup[2]);
213                         
214                                 //merge BC and estimate with shared with A
215                                 SharedRAbundVector* merge = new SharedRAbundVector();
216                                 for (int j = 0; j < lookup[1]->size(); j++) {
217                                         merge->push_back((lookup[1]->getAbundance(j) + lookup[2]->getAbundance(j)), j, "");
218                                 }
219                                 
220                                 vector<double> sharedAwithBC = vCalcs[i]->getValues(lookup[0], merge);
221                         
222                                 delete merge;
223                                 //merge AC and estimate with shared with B
224                                 merge = new SharedRAbundVector();
225                                 for (int j = 0; j < lookup[0]->size(); j++) {
226                                         merge->push_back((lookup[0]->getAbundance(j) + lookup[2]->getAbundance(j)), j, "");
227                                 }
228                 
229                                 vector<double> sharedBwithAC = vCalcs[i]->getValues(lookup[1], merge);
230                         
231                                 delete merge;
232                                 //merge AB and estimate with shared with C
233                                 merge = new SharedRAbundVector();
234                                 for (int j = 0; j < lookup[0]->size(); j++) {
235                                         merge->push_back((lookup[0]->getAbundance(j) + lookup[1]->getAbundance(j)), j, "");
236                                 }
237                                 
238                                 vector<double> sharedCwithAB = vCalcs[i]->getValues(lookup[2], merge);
239                                 
240                                 
241                                 //in essence you want to run it like a single 
242                                 if (vCalcs[i]->getName() == "SharedSobs") {
243                                         delete vCalcs[i];
244                                         vCalcs[i] = new Sobs();
245                                 }else if (vCalcs[i]->getName() == "SharedChao") {
246                                         delete vCalcs[i];
247                                         vCalcs[i] = new Chao1();
248                                 }else if (vCalcs[i]->getName() == "SharedAce") {
249                                         delete vCalcs[i];
250                                         vCalcs[i] = new Ace(10);
251                                 }
252                                 
253                                 //get estimates for numA
254                                 vector<double> numA = vCalcs[i]->getValues(sabundA);
255                         
256                                 //get estimates for numB
257                                 vector<double> numB = vCalcs[i]->getValues(sabundB);
258                                 
259                                 //get estimates for numC
260                                 vector<double> numC = vCalcs[i]->getValues(sabundC);
261                                 
262                                 //find possible sharedABC values
263                                 float sharedABC1, sharedABC2, sharedABC3, sharedABC;
264                                 
265                                 sharedABC1 = sharedAB[0] + sharedAC[0] - sharedAwithBC[0];
266                                 sharedABC2 = sharedAB[0] + sharedBC[0] - sharedBwithAC[0];
267                                 sharedABC3 = sharedAC[0] + sharedBC[0] - sharedCwithAB[0];
268  
269                                 //if any of the possible m's are - throw them out
270                                 if (sharedABC1 < 0.0) { sharedABC1 = 0; }
271                                 if (sharedABC2 < 0.0) { sharedABC2 = 0; }
272                                 if (sharedABC3 < 0.0) { sharedABC3 = 0; }
273                 
274                                 //sharedABC is the minimum of the 3 possibilities
275                                 if ((sharedABC1 < sharedABC2) && (sharedABC1 < sharedABC3)) { sharedABC = sharedABC1; }
276                                 else if ((sharedABC2 < sharedABC1) && (sharedABC2 < sharedABC3)) { sharedABC = sharedABC2; }
277                                 else if ((sharedABC3 < sharedABC1) && (sharedABC3 < sharedABC2)) { sharedABC = sharedABC3; }    
278                         
279                                 //image window
280                                 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 800 800\" >\n";
281                                 outsvg << "<g>\n";
282
283                                 //draw circles
284                                 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"800\" height=\"800\"/>"; 
285                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
286                                 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>"; 
287                                 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>"; 
288                                 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>"; 
289                         
290                                 //place labels within overlaps
291                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA[0]-sharedAwithBC[0]).length() / 2)) + "\" y=\"170\">" + toString(numA[0]-sharedAwithBC[0]) + "</text>\n"; 
292                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"150\">" + lookup[0]->getGroup() + "</text>\n";  
293                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB[0] - sharedABC).length() / 2)) + "\"  y=\"170\">" + toString(sharedAB[0] - sharedABC) + "</text>\n";  
294                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB[0]-sharedBwithAC[0]).length() / 2)) + "\"  y=\"170\">" + toString(numB[0]-sharedBwithAC[0]) + "</text>\n";
295                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"150\">" + lookup[1]->getGroup() + "</text>\n";  
296                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC[0] - sharedABC).length() / 2)) + "\"  y=\"305\">" + toString(sharedAC[0] - sharedABC) + "</text>\n";  
297                                 outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)toString(numC[0]-sharedCwithAB[0]).length() / 2)) + "\"   y=\"430\">" + toString(numC[0]-sharedCwithAB[0]) + "</text>\n"; 
298                                 outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(343 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"410\">" + lookup[2]->getGroup() + "</text>\n"; 
299                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC[0] - sharedABC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC[0] - sharedABC) + "</text>\n";  
300                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"280\">" + toString(sharedABC) + "</text>\n"; 
301                         
302                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"660\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString(sharedAB[0]) + "</text>\n";
303                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"680\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(sharedAC[0]) + "</text>\n";
304                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"700\">The number of sepecies shared between groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(sharedBC[0]) + "</text>\n";
305                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"720\">The number of sepecies shared between groups " + globaldata->Groups[0] + " and combined groups " + globaldata->Groups[1] + globaldata->Groups[2] + " is " + toString(sharedAwithBC[0]) + "</text>\n";
306                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"740\">The number of sepecies shared between groups " + globaldata->Groups[1] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[2] + " is " + toString(sharedBwithAC[0]) + "</text>\n";
307                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"760\">The number of sepecies shared between groups " + globaldata->Groups[2] + " and combined groups " + globaldata->Groups[0] + globaldata->Groups[1] + " is " + toString(sharedCwithAB[0]) + "</text>\n";
308                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"580\">The number of species in group " + globaldata->Groups[0] + " is " + toString(numA[0]);
309                                 if (numA.size() == 3) { 
310                                         outsvg << " the lci is " + toString(numA[1]) + " and the hci is " + toString(numA[2]) + "</text>\n";
311                                 }else { outsvg << "</text>\n"; }
312                 
313                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"600\">The number of species in group " + globaldata->Groups[1] + " is " + toString(numB[0]);
314                                 if (numB.size() == 3) { 
315                                         outsvg << " the lci is " + toString(numB[1]) + " and the hci is " + toString(numB[2]) + "</text>\n";
316                                 }else { outsvg << "</text>\n"; }
317                                 
318                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"620\">The number of species in group " + globaldata->Groups[2] + " is " + toString(numC[0]);
319                                 if (numC.size() == 3) { 
320                                         outsvg << " the lci is " + toString(numC[1]) + " and the hci is " + toString(numC[2]) + "</text>\n";
321                                 }else { outsvg << "</text>\n"; }
322
323                                 outsvg << "<text fill=\"black\" class=\"seri\" x=\"175\" y=\"640\">The total richness of all the groups is " + toString(numA[0] + numB[0] + numC[0] - sharedAB[0] - sharedAC[0] - sharedBC[0] + sharedABC) + "</text>\n";
324                                 
325                                 //close file
326                                 outsvg << "</g>\n</svg>\n";
327                                 outsvg.close();
328                         }
329                         
330                 /******************* 4 Groups **************************/
331                 
332                 }else if (lookup.size() == 4) {
333                         //calc the shared otu
334                         int sharedABCD = 0;
335                         int numA = 0; int numB = 0; int numC = 0; int numD = 0;
336                         int sharedAB = 0; int sharedAC = 0; int sharedBC = 0; int sharedAD = 0; int sharedBD = 0; int sharedCD = 0;
337                         int sharedABC = 0; int sharedACD = 0; int sharedBCD = 0; int sharedABD = 0;
338                         
339                         //A = red, B = green, C = blue, D = yellow
340                         
341                         if ((vCalcs.size() > 1) || (vCalcs[0]->getName() != "SharedSobs")) { cout << "The only calculator able to be used with 4 groups is sharedsobs. I will run that for you. " << endl; }
342                         
343                         //for each bin
344                         for (int i = 0; i < lookup[0]->size(); i++) {
345                                 //are they only in one
346                                 if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { numA++; }
347                                 if ((lookup[1]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { numB++; }
348                                 if ((lookup[2]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { numC++; }
349                                 if ((lookup[3]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[2]->getAbundance(i) == 0)) { numD++; }
350                                 //are they shared by 2
351                                 if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { sharedAB++; }
352                                 if ((lookup[0]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { sharedAC++; }
353                                 if ((lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0) && (lookup[3]->getAbundance(i) == 0)) { sharedBC++; }
354                                 if ((lookup[0]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[1]->getAbundance(i) == 0)) { sharedAD++; }
355                                 if ((lookup[3]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0) && (lookup[0]->getAbundance(i) == 0)) { sharedBD++; }
356                                 if ((lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0) && (lookup[0]->getAbundance(i) == 0)) { sharedCD++; }
357                                 //are they shared by 3
358                                 if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) == 0)) { sharedABC++; }
359                                 if ((lookup[0]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) == 0)) { sharedACD++; }
360                                 if ((lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[0]->getAbundance(i) == 0)) { sharedBCD++; }
361                                 if ((lookup[0]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) == 0)) { sharedABD++; }
362                                 //are they shared by all
363                                 if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0) && (lookup[3]->getAbundance(i) != 0)) { sharedABCD++; }
364                         }
365                                 
366                         string filenamesvg = getRootName(globaldata->inputFileName) + sharedorder->getLabel() + ".venn.SharedSobs.svg";
367                         openOutputFile(filenamesvg, outsvg);
368                 
369                         //image window
370                         outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
371                         outsvg << "<g>\n";
372
373                         //draw circles
374                         outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>"; 
375                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
376                         outsvg << "<ellipse fill=\"red\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n "; 
377                         outsvg << "<ellipse fill=\"green\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+45 355 215) \" cx=\"355\" cy=\"215\" rx=\"200\" ry=\"115\"/>\n ";
378                         outsvg << "<ellipse fill=\"blue\" stroke=\"black\" opacity=\".35\" transform=\"rotate(-40 440 315) \" cx=\"440\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
379                         outsvg << "<ellipse fill=\"yellow\" stroke=\"black\" opacity=\".35\" transform=\"rotate(+40 270 315) \" cx=\"270\" cy=\"315\" rx=\"200\" ry=\"115\"/>\n ";
380                         
381                         //A = red, B = green, C = blue, D = yellow
382                         
383                         //place labels within overlaps
384                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)toString(numA).length() / 2)) + "\" y=\"110\">" + toString(numA) + "</text>\n"; 
385                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(460 - ((int)lookup[0]->getGroup().length() / 2)) + "\" y=\"90\">" + lookup[0]->getGroup() + "</text>\n";  
386                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedAB).length() / 2)) + "\"  y=\"160\">" + toString(sharedAB) + "</text>\n";  
387                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)toString(numB).length() / 2)) + "\"  y=\"110\">" + toString(numB) + "</text>\n";  
388                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(250 - ((int)lookup[1]->getGroup().length() / 2)) + "\"  y=\"90\">" + lookup[1]->getGroup() + "</text>\n"; 
389                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(490 - ((int)toString(sharedAC).length() / 2)) + "\"  y=\"190\">" + toString(sharedAC) + "</text>\n";  
390                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)toString(numC).length() / 2)) + "\"   y=\"230\">" + toString(numC) + "</text>\n";  
391                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(550 - ((int)lookup[2]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[2]->getGroup() + "</text>\n";
392                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(215 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"190\">" + toString(sharedBC) + "</text>\n";  
393                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)toString(numD).length() / 2)) + "\"   y=\"230\">" + toString(numD) + "</text>\n";  
394                         outsvg << "<text fill=\"black\" class=\"seri\"  x=\"" + toString(150 - ((int)lookup[3]->getGroup().length() / 2)) + "\"   y=\"210\">" + lookup[3]->getGroup() + "</text>\n"; 
395                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(240 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedAD) + "</text>\n"; 
396                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(470 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"325\">" + toString(sharedBD) + "</text>\n";
397                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedCD).length() / 2)) + "\" y=\"430\">" + toString(sharedCD) + "</text>\n"; 
398                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(275 - ((int)toString(sharedABD).length() / 2)) + "\" y=\"240\">" + toString(sharedABD) + "</text>\n"; 
399                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(400 - ((int)toString(sharedBCD).length() / 2)) + "\" y=\"360\">" + toString(sharedBCD) + "</text>\n";
400                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(305 - ((int)toString(sharedACD).length() / 2)) + "\" y=\"360\">" + toString(sharedACD) + "</text>\n"; 
401                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(440 - ((int)toString(sharedABC).length() / 2)) + "\"  y=\"240\">" + toString(sharedABC) + "</text>\n"; 
402                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(350 - ((int)toString(sharedABCD).length() / 2)) + "\"  y=\"320\">" + toString(sharedABCD) + "</text>\n"; 
403                         outsvg << "<text fill=\"black\" class=\"seri\" x=\"250\" y=\"490\">The total richness of all the groups is " + toString((float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD)) + "</text>\n";
404                         
405                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"510\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString(((sharedAC + sharedACD + sharedABC + sharedABCD) / (float)(numA + numC + sharedAB + sharedAC + sharedAD + sharedBC + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
406                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"530\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[3] + " is " + toString(((sharedAD + sharedACD + sharedABD + sharedABCD) / (float)(numA + numD + sharedAB + sharedAC + sharedAD + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
407                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"550\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedBC + sharedABC + sharedBCD + sharedABCD) / (float)(numB + numC + sharedAB + sharedAC + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
408                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"570\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[3] + " is " + toString(((sharedBD + sharedABD + sharedBCD + sharedABCD) / (float)(numB + numD + sharedAB + sharedAD + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
409                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"590\">Percentage of species that are shared in groups " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedCD + sharedBCD + sharedACD + sharedABCD) / (float)(numC + numD + sharedAC + sharedAD + sharedCD + sharedBD + sharedBC + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
410                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"610\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString(((sharedABC + sharedABCD) / (float)(numA + numB + numC + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
411                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"630\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[3] + " is " + toString(((sharedABD + sharedABCD) / (float)(numA + numB + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
412                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"650\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedACD + sharedABCD) / (float)(numA + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
413                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"670\">Percentage of species that are shared in groups " + globaldata->Groups[1] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString(((sharedBCD + sharedABCD) / (float)(numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
414                         //outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"690\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + ", " + globaldata->Groups[2] + " and " + globaldata->Groups[3] + " is " + toString((sharedABCD / (float)(numA + numB + numC + numD + sharedAB + sharedAC + sharedAD + sharedBC + sharedBD + sharedCD + sharedABC + sharedABD + sharedACD + sharedBCD + sharedABCD))) + "</text>\n";
415                 
416                         outsvg << "</g>\n</svg>\n";
417                         outsvg.close();
418
419                 }
420                 
421         }
422         catch(exception& e) {
423                 cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
424                 exit(1);
425         }
426         catch(...) {
427                 cout << "An unknown error has occurred in the Venn class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
428                 exit(1);
429         }
430 }
431
432