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 numGroups = globaldata->Groups.size();
22 //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3;
24 for (int i=0; i<numGroups; i++) {
25 for (int l = i+1; l < numGroups; l++) {
26 //initialize weighted scores
27 WScore[globaldata->Groups[i]+globaldata->Groups[l]] = 0.0;
29 D.push_back(0.0000); //initialize a spot in D for each combination
31 /********************************************************/
32 //calculate a D value for each group combo
33 for(int v=0;v<t->getNumLeaves();v++){
37 //while you aren't at root
38 while(t->tree[index].getParent() != -1){
41 if(t->tree[index].getBranchLength() != -1){
42 sum += abs(t->tree[index].getBranchLength());
44 index = t->tree[index].getParent();
47 //get last breanch length added
48 if(t->tree[index].getBranchLength() != -1){
49 sum += abs(t->tree[index].getBranchLength());
52 //is this sum from a sequence which is in one of the users groups
53 if (inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) {
54 //is this sum from a sequence which is in this groupCombo
55 if ((t->tree[v].getGroup() == globaldata->Groups[i]) || (t->tree[v].getGroup() == globaldata->Groups[l])) {
56 sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
61 /*********************************************************/
66 data.clear(); //clear out old values
68 for(int i=0;i<t->getNumNodes();i++){
69 //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC.
70 for (int b=0; b<numGroups; b++) {
71 for (int l = b+1; l < numGroups; l++) {
72 //calculate a u value for each combo
74 //does this node have descendants from group b-1
75 it = t->tree[i].pcount.find(globaldata->Groups[b]);
76 //if it does u = # of its descendants with a certain group / total number in tree with a certain group
77 if (it != t->tree[i].pcount.end()) {
78 u = (double) t->tree[i].pcount[globaldata->Groups[b]] / (double) tmap->seqsPerGroup[globaldata->Groups[b]];
81 //does this node have descendants from group l
82 it = t->tree[i].pcount.find(globaldata->Groups[l]);
83 //if it does subtract their percentage from u
84 if (it != t->tree[i].pcount.end()) {
85 u -= (double) t->tree[i].pcount[globaldata->Groups[l]] / (double) tmap->seqsPerGroup[globaldata->Groups[l]];
88 u = abs(u * t->tree[i].getBranchLength());
90 //save groupcombs u value
91 WScore[globaldata->Groups[b]+globaldata->Groups[l]] += u;
92 /*********************************************************/
97 //calculate weighted score for each group combination
100 for (int i=0; i<numGroups; i++) {
101 for (int l = i+1; l < numGroups; l++) {
102 UN = (WScore[globaldata->Groups[i]+globaldata->Groups[l]] / D[count]);
104 if (isnan(UN) || isinf(UN)) { UN = 0; }
111 catch(exception& e) {
112 cout << "Standard Error: " << e.what() << " has occurred in the Weighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
116 cout << "An unknown error has occurred in the Weighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122 /**************************************************************************************************/
123 EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) {
125 globaldata = GlobalData::getInstance();
127 data.clear(); //clear out old values
129 //initialize weighted score
130 WScore[(groupA+groupB)] = 0.0;
134 /********************************************************/
135 //calculate a D value for the group combo
136 for(int v=0;v<t->getNumLeaves();v++){
140 //while you aren't at root
141 while(t->tree[index].getParent() != -1){
144 if(t->tree[index].getBranchLength() != -1){
145 sum += abs(t->tree[index].getBranchLength());
147 index = t->tree[index].getParent();
150 //get last breanch length added
151 if(t->tree[index].getBranchLength() != -1){
152 sum += abs(t->tree[index].getBranchLength());
155 if ((t->tree[v].getGroup() == groupA) || (t->tree[v].getGroup() == groupB)) {
156 sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
160 /********************************************************/
162 //calculate u for the group comb
163 for(int i=0;i<t->getNumNodes();i++){
165 //does this node have descendants from groupA
166 it = t->tree[i].pcount.find(groupA);
167 //if it does u = # of its descendants with a certain group / total number in tree with a certain group
168 if (it != t->tree[i].pcount.end()) {
169 u = (double) t->tree[i].pcount[groupA] / (double) tmap->seqsPerGroup[groupA];
173 //does this node have descendants from group l
174 it = t->tree[i].pcount.find(groupB);
175 //if it does subtract their percentage from u
176 if (it != t->tree[i].pcount.end()) {
177 u -= (double) t->tree[i].pcount[groupB] / (double) tmap->seqsPerGroup[groupB];
180 u = abs(u * t->tree[i].getBranchLength());
182 //save groupcombs u value
183 WScore[(groupA+groupB)] += u;
186 /********************************************************/
188 //calculate weighted score for the group combination
190 UN = (WScore[(groupA+groupB)] / D);
192 if (isnan(UN) || isinf(UN)) { UN = 0; }
197 catch(exception& e) {
198 cout << "Standard Error: " << e.what() << " has occurred in the Weighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
202 cout << "An unknown error has occurred in the Weighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";