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