5 * Created by Sarah Westcott on 3/30/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12 //**********************************************************************************************************************
15 globaldata = GlobalData::getInstance();
16 format = globaldata->getFormat();
20 cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
24 cout << "An unknown error has occurred in the Venn class function Venn. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
28 //**********************************************************************************************************************
29 void Venn::getPic(OrderVector* order) {
32 rabund = order->getRAbundVector();
34 string filenamesvg = globaldata->inputFileName + ".venn." + order->getLabel() + ".svg";
36 openOutputFile(filenamesvg, outsvg);
40 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 200 200\" >\n";
43 outsvg << "<circle fill=\"red\" stroke=\"black\" cx=\"150\" cy=\"150\" r=\"100\"/>";
44 outsvg << "<text fill=\"black\" class=\"seri\" x=\"140\" y=\"150\">" + toString(rabund.getNumBins()) + "</text>\n";
45 outsvg << "</g>\n</svg>\n";
50 cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54 cout << "An unknown error has occurred in the Venn class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
58 //**********************************************************************************************************************
59 void Venn::getPic(SharedOrderVector* sharedorder) {
62 //fills vector of sharedsabunds - lookup
63 getSharedVectors(sharedorder);
65 string filenamesvg = globaldata->inputFileName + ".venn." + sharedorder->getLabel() + "." + groupComb + ".svg";
66 openOutputFile(filenamesvg, outsvg);
69 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 700 700\" >\n";
72 if (lookup.size() == 1) {
73 outsvg << "<circle fill=\"red\" opacity=\".5\" stroke=\"black\" cx=\"150\" cy=\"150\" r=\"100\"/>";
74 outsvg << "<text fill=\"black\" class=\"seri\" x=\"140\" y=\"150\">" + toString(lookup[0]->getNumBins()) + "</text>\n";
75 outsvg << "</g>\n</svg>\n";
77 }else if (lookup.size() == 2) {
86 for (int i = 0; i < lookup[0]->size(); i++) {
87 if (lookup[0]->getAbundance(i) != 0) { numA++; }
88 if (lookup[1]->getAbundance(i) != 0) { numB++; }
90 if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { shared++; }
93 if (numA > numB) { rScaler = 150 / float(numA); }
94 else { rScaler = 150 / float(numB); }
96 //to determine how far over to overlap b onto a.
97 float percentOverlap = shared / (float) numA;
99 int bx = 200 + (numA * rScaler) - ((2 * (numA * rScaler)) * percentOverlap) + (numB * rScaler);
100 int leftedgeB = bx - (numB * rScaler); //center b - b's radius
101 int leftedgeA = 200 - (numA * rScaler); //center a - a's radius
102 int rightedgeB = bx + (numB * rScaler); //center b + b's radius
103 int rightedgeA = 200 + (numA * rScaler); //center a + a's radius
105 int mida = leftedgeA + ((leftedgeB - leftedgeA) / 2);
106 int midb = rightedgeA + ((rightedgeB - rightedgeA) / 2);
107 int midab = leftedgeB + ((rightedgeA - leftedgeB) / 2);
110 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
111 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(leftedgeA + ((rightedgeB - leftedgeA) / 2) - 70) + "\" y=\"50\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
112 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".5\" stroke=\"black\" cx=\"200\" cy=\"250\" r=\"" + toString(numA * rScaler) + "\"/>";
113 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".5\" stroke=\"black\" cx=\"" + toString(bx) + "\" cy=\"250\" r=\"" + toString(numB * rScaler) + "\"/>";
114 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(mida) + "\" y=\"250\">" + toString(numA-shared) + "</text>\n";
115 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(midab) + "\" y=\"250\">" + toString(shared) + "</text>\n";
116 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(midb) + "\" y=\"250\">" + toString(numB-shared) + "</text>\n";
117 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(mida) + "\" y=\"500\">Percentage of species that are shared is " + toString((shared / (float)(numA + numB - shared))) + "</text>\n";
119 }else if (lookup.size() == 3) {
120 //calc the shared otu
122 int numA = 0; int numB = 0; int numC = 0;
123 int sharedAB = 0; int sharedAC = 0; int sharedBC = 0;
128 for (int i = 0; i < lookup[0]->size(); i++) {
129 if (lookup[0]->getAbundance(i) != 0) { numA++; }
130 if (lookup[1]->getAbundance(i) != 0) { numB++; }
131 if (lookup[2]->getAbundance(i) != 0) { numC++; }
132 //are they shared by 2
133 if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { sharedAB++; }
134 if ((lookup[0]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0)) { sharedAC++; }
135 if ((lookup[2]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0)) { sharedBC++; }
137 //are they shared by all
138 if ((lookup[0]->getAbundance(i) != 0) && (lookup[1]->getAbundance(i) != 0) && (lookup[2]->getAbundance(i) != 0)) { sharedABC++; }
142 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"700\" height=\"700\"/>";
143 outsvg << "<text fill=\"black\" class=\"seri\" x=\"265\" y=\"30\">Venn Diagram at distance " + sharedorder->getLabel() + "</text>\n";
144 outsvg << "<circle fill=\"rgb(255,0,0)\" opacity=\".3\" stroke=\"black\" cx=\"230\" cy=\"200\" r=\"150\"/>";
145 outsvg << "<circle fill=\"rgb(0,255,0)\" opacity=\".3\" stroke=\"black\" cx=\"455\" cy=\"200\" r=\"150\"/>";
146 outsvg << "<circle fill=\"rgb(0,0,255)\" opacity=\".3\" stroke=\"black\" cx=\"343\" cy=\"400\" r=\"150\"/>";
148 //place labels within overlaps
149 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(200 - ((int)toString(numA-sharedAB-sharedAC+sharedABC).length() / 2)) + "\" y=\"170\">" + toString(numA-sharedAB-sharedAC+sharedABC) + "</text>\n";
150 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedAB).length() / 2)) + "\" y=\"170\">" + toString(sharedAB) + "</text>\n";
151 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(485 - ((int)toString(numB-sharedAB-sharedBC+sharedABC).length() / 2)) + "\" y=\"170\">" + toString(numB-sharedAB-sharedBC+sharedABC) + "</text>\n";
152 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(268 - ((int)toString(sharedAC).length() / 2)) + "\" y=\"305\">" + toString(sharedAC) + "</text>\n";
153 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(numC-sharedAC-sharedBC+sharedABC).length() / 2)) + "\" y=\"430\">" + toString(numC-sharedAC-sharedBC+sharedABC) + "</text>\n";
154 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(408 - ((int)toString(sharedBC).length() / 2)) + "\" y=\"305\">" + toString(sharedBC) + "</text>\n";
155 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(343 - ((int)toString(sharedABC).length() / 2)) + "\" y=\"280\">" + toString(sharedABC) + "</text>\n";
157 outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"580\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[1] + " is " + toString((sharedAB / (float)(numA + numB - sharedAB))) + "</text>\n";
158 outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"610\">Percentage of species that are shared in groups " + globaldata->Groups[0] + " and " + globaldata->Groups[2] + " is " + toString((sharedAC / (float)(numA + numC - sharedAC))) + "</text>\n";
159 outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"640\">Percentage of species that are shared in groups " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString((sharedBC / (float)(numB + numC - sharedBC))) + "</text>\n";
160 outsvg << "<text fill=\"black\" class=\"seri\" x=\"100\" y=\"670\">Percentage of species that are shared in groups " + globaldata->Groups[0] + ", " + globaldata->Groups[1] + " and " + globaldata->Groups[2] + " is " + toString((sharedABC / (float)(numA + numB + numC - sharedAB - sharedAC - sharedBC - (2 * sharedABC)))) + "</text>\n";
163 outsvg << "</g>\n</svg>\n";
169 catch(exception& e) {
170 cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
174 cout << "An unknown error has occurred in the Venn class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
178 //**********************************************************************************************************************
179 void Venn::getSharedVectors(SharedOrderVector* order){
183 for (int j = 0; j < lookup.size(); j++) {
191 //create and initialize vector of sharedvectors, one for each group
192 for (int i = 0; i < globaldata->Groups.size(); i++) {
193 SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
194 temp->setLabel(order->getLabel());
195 temp->setGroup(globaldata->Groups[i]);
196 groupComb += globaldata->Groups[i];
197 lookup.push_back(temp);
200 int numSeqs = order->size();
201 //sample all the members
202 for(int i=0;i<numSeqs;i++){
204 individual chosen = order->get(i);
207 //set info for sharedvector in chosens group
208 for (int j = 0; j < lookup.size(); j++) {
209 if (chosen.group == lookup[j]->getGroup()) {
210 abundance = lookup[j]->getAbundance(chosen.bin);
211 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
218 catch(exception& e) {
219 cout << "Standard Error: " << e.what() << " has occurred in the Venn class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
223 cout << "An unknown error has occurred in the Venn class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
228 //**********************************************************************************************************************