5 * Created by Sarah Westcott on 2/9/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12 /**************************************************************************************************/
14 EstOutput Weighted::getValues(Tree* t) {
16 globaldata = GlobalData::getInstance();
20 //if the user has not entered specific groups to analyze then do them all
21 if (globaldata->Groups.size() == 0) {
22 numGroups = tmap->getNumGroups();
24 numGroups = globaldata->Groups.size();
27 //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3;
30 for (int i=1; i<numGroups; i++) {
31 for (int l = n; l < numGroups; l++) {
32 //initialize weighted scores
33 if (globaldata->Groups.size() == 0) {
34 WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] = 0.0;
36 WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] = 0.0;
39 D.push_back(0.0000); //initialize a spot in D for each combination
41 /********************************************************/
42 //calculate a D value for each group combo
43 for(int v=0;v<t->getNumLeaves();v++){
47 //while you aren't at root
48 while(t->tree[index].getParent() != -1){
51 if(t->tree[index].getBranchLength() != -1){
52 sum += t->tree[index].getBranchLength();
54 index = t->tree[index].getParent();
57 //get last breanch length added
58 if(t->tree[index].getBranchLength() != -1){
59 sum += t->tree[index].getBranchLength();
62 if (globaldata->Groups.size() == 0) {
63 //is this sum from a sequence which is in one of the users groups
64 if (inUsersGroups(t->tree[v].getGroup(), tmap->namesOfGroups) == true) {
65 //is this sum from a sequence which is in this groupCombo
66 if ((t->tree[v].getGroup() == tmap->namesOfGroups[i-1]) || (t->tree[v].getGroup() == tmap->namesOfGroups[l])) {
67 sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
72 //is this sum from a sequence which is in one of the users groups
73 if (inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) {
74 //is this sum from a sequence which is in this groupCombo
75 if ((t->tree[v].getGroup() == globaldata->Groups[i-1]) || (t->tree[v].getGroup() == globaldata->Groups[l])) {
76 sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
82 /*********************************************************/
88 data.clear(); //clear out old values
90 for(int i=0;i<t->getNumNodes();i++){
91 //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC.
93 for (int b=1; b<numGroups; b++) {
94 for (int l = n; l < numGroups; l++) {
95 //calculate a u value for each combo
97 //the user has not entered specific groups
98 if (globaldata->Groups.size() == 0) {
99 //does this node have descendants from group b-1
100 it = t->tree[i].pcount.find(tmap->namesOfGroups[b-1]);
101 //if it does u = # of its descendants with a certain group / total number in tree with a certain group
102 if (it != t->tree[i].pcount.end()) {
103 u = (double) t->tree[i].pcount[tmap->namesOfGroups[b-1]] / (double) tmap->seqsPerGroup[tmap->namesOfGroups[b-1]];
106 //does this node have descendants from group l
107 it = t->tree[i].pcount.find(tmap->namesOfGroups[l]);
108 //if it does subtract their percentage from u
109 if (it != t->tree[i].pcount.end()) {
110 u -= (double) t->tree[i].pcount[tmap->namesOfGroups[l]] / (double) tmap->seqsPerGroup[tmap->namesOfGroups[l]];
113 u = abs(u) * t->tree[i].getBranchLength();
115 //save groupcombs u value
116 WScore[tmap->namesOfGroups[b-1]+tmap->namesOfGroups[l]] += u;
118 //the user has entered specific groups
120 //does this node have descendants from group b-1
121 it = t->tree[i].pcount.find(globaldata->Groups[b-1]);
122 //if it does u = # of its descendants with a certain group / total number in tree with a certain group
123 if (it != t->tree[i].pcount.end()) {
124 u = (double) t->tree[i].pcount[globaldata->Groups[b-1]] / (double) tmap->seqsPerGroup[globaldata->Groups[b-1]];
127 //does this node have descendants from group l
128 it = t->tree[i].pcount.find(globaldata->Groups[l]);
129 //if it does subtract their percentage from u
130 if (it != t->tree[i].pcount.end()) {
131 u -= (double) t->tree[i].pcount[globaldata->Groups[l]] / (double) tmap->seqsPerGroup[globaldata->Groups[l]];
134 u = abs(u) * t->tree[i].getBranchLength();
136 //save groupcombs u value
137 WScore[globaldata->Groups[b-1]+globaldata->Groups[l]] += u;
139 /*********************************************************/
145 //calculate weighted score for each group combination
149 for (int i=1; i<numGroups; i++) {
150 for (int l = n; l < numGroups; l++) {
151 //the user has not entered specific groups
152 if (globaldata->Groups.size() == 0) {
153 UN = (WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] / D[count]);
154 }else {//they have entered specific groups
155 UN = (WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] / D[count]);
157 if (isnan(UN) || isinf(UN)) { UN = 0; }
165 catch(exception& e) {
166 cout << "Standard Error: " << e.what() << " has occurred in the Weighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
170 cout << "An unknown error has occurred in the Weighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
176 /**************************************************************************************************/
177 EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) {
179 globaldata = GlobalData::getInstance();
181 data.clear(); //clear out old values
183 //initialize weighted score
184 WScore[(groupA+groupB)] = 0.0;
188 /********************************************************/
189 //calculate a D value for the group combo
190 for(int v=0;v<t->getNumLeaves();v++){
194 //while you aren't at root
195 while(t->tree[index].getParent() != -1){
198 if(t->tree[index].getBranchLength() != -1){
199 sum += t->tree[index].getBranchLength();
201 index = t->tree[index].getParent();
204 //get last breanch length added
205 if(t->tree[index].getBranchLength() != -1){
206 sum += t->tree[index].getBranchLength();
209 if ((t->tree[v].getGroup() == groupA) || (t->tree[v].getGroup() == groupB)) {
210 sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
214 /********************************************************/
216 //calculate u for the group comb
217 for(int i=0;i<t->getNumNodes();i++){
219 //does this node have descendants from groupA
220 it = t->tree[i].pcount.find(groupA);
221 //if it does u = # of its descendants with a certain group / total number in tree with a certain group
222 if (it != t->tree[i].pcount.end()) {
223 u = (double) t->tree[i].pcount[groupA] / (double) tmap->seqsPerGroup[groupA];
227 //does this node have descendants from group l
228 it = t->tree[i].pcount.find(groupB);
229 //if it does subtract their percentage from u
230 if (it != t->tree[i].pcount.end()) {
231 u -= (double) t->tree[i].pcount[groupB] / (double) tmap->seqsPerGroup[groupB];
234 u = abs(u) * t->tree[i].getBranchLength();
236 //save groupcombs u value
237 WScore[(groupA+groupB)] += u;
240 /********************************************************/
242 //calculate weighted score for the group combination
244 UN = (WScore[(groupA+groupB)] / D);
246 if (isnan(UN) || isinf(UN)) { UN = 0; }
251 catch(exception& e) {
252 cout << "Standard Error: " << e.what() << " has occurred in the Weighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
256 cout << "An unknown error has occurred in the Weighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";