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;
29 for (int i=1; i<numGroups; i++) {
30 for (int l = n; l < numGroups; l++) {
31 //initialize weighted scores
32 if (globaldata->Groups.size() == 0) {
33 WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] = 0.0;
34 D.push_back(0.0000); //initialize a spot in D for each combination
36 WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] = 0.0;
37 D.push_back(0.0000); //initialize a spot in D for each combination
42 data.clear(); //clear out old values
44 for(int i=0;i<t->getNumNodes();i++){
45 //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC.
47 for (int b=1; b<numGroups; b++) {
48 for (int l = n; l < numGroups; l++) {
50 /********************************************************/
51 //calculate a D value for each group combo
52 for(int v=0;v<t->getNumLeaves();v++){
56 //while you aren't at root
57 while(t->tree[index].getParent() != -1){
60 if(t->tree[index].getBranchLength() != -1){
61 sum += t->tree[index].getBranchLength();
64 index = t->tree[index].getParent();
67 //get last breanch length added
68 if(t->tree[index].getBranchLength() != -1){
69 sum += t->tree[index].getBranchLength();
72 if (globaldata->Groups.size() == 0) {
73 //is this sum from a sequence which is in one of the users groups
74 if (inUsersGroups(t->tree[v].getGroup(), tmap->namesOfGroups) == true) {
75 //is this sum from a sequence which is in this groupCombo
76 if ((t->tree[v].getGroup() == tmap->namesOfGroups[b-1]) || (t->tree[v].getGroup() == tmap->namesOfGroups[l])) {
77 sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
82 //is this sum from a sequence which is in one of the users groups
83 if (inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) {
84 //is this sum from a sequence which is in this groupCombo
85 if ((t->tree[v].getGroup() == globaldata->Groups[b-1]) || (t->tree[v].getGroup() == globaldata->Groups[l])) {
86 sum /= (double)tmap->seqsPerGroup[t->tree[v].getGroup()];
92 /*********************************************************/
93 //calculate a u value for each combo
95 //the user has not entered specific groups
96 if (globaldata->Groups.size() == 0) {
97 //does this node have descendants from group b-1
98 it = t->tree[i].pcount.find(tmap->namesOfGroups[b-1]);
99 //if it does u = # of its descendants with a certain group / total number in tree with a certain group
100 if (it != t->tree[i].pcount.end()) {
101 u = (double) t->tree[i].pcount[tmap->namesOfGroups[b-1]] / (double) tmap->seqsPerGroup[tmap->namesOfGroups[b-1]];
104 //does this node have descendants from group l
105 it = t->tree[i].pcount.find(tmap->namesOfGroups[l]);
106 //if it does subtract their percentage from u
107 if (it != t->tree[i].pcount.end()) {
108 u -= (double) t->tree[i].pcount[tmap->namesOfGroups[l]] / (double) tmap->seqsPerGroup[tmap->namesOfGroups[l]];
111 u = abs(u) * t->tree[i].getBranchLength();
113 //save groupcombs u value
114 WScore[tmap->namesOfGroups[b-1]+tmap->namesOfGroups[l]] += u;
116 //the user has entered specific groups
118 //does this node have descendants from group b-1
119 it = t->tree[i].pcount.find(globaldata->Groups[b-1]);
120 //if it does u = # of its descendants with a certain group / total number in tree with a certain group
121 if (it != t->tree[i].pcount.end()) {
122 u = (double) t->tree[i].pcount[globaldata->Groups[b-1]] / (double) tmap->seqsPerGroup[globaldata->Groups[b-1]];
125 //does this node have descendants from group l
126 it = t->tree[i].pcount.find(globaldata->Groups[l]);
127 //if it does subtract their percentage from u
128 if (it != t->tree[i].pcount.end()) {
129 u -= (double) t->tree[i].pcount[globaldata->Groups[l]] / (double) tmap->seqsPerGroup[globaldata->Groups[l]];
132 u = abs(u) * t->tree[i].getBranchLength();
134 //save groupcombs u value
135 WScore[globaldata->Groups[b-1]+globaldata->Groups[l]] += u;
137 /*********************************************************/
143 //calculate weighted score for each group combination
146 for (int i=1; i<numGroups; i++) {
147 for (int l = n; l < numGroups; l++) {
148 //the user has not entered specific groups
149 if (globaldata->Groups.size() == 0) {
150 UN = (WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] / D[n-1]);
151 }else {//they have entered specific groups
152 UN = (WScore[globaldata->Groups[i-1]+globaldata->Groups[l]] / D[n-1]);
154 if (isnan(UN) || isinf(UN)) { UN = 0; }
161 catch(exception& e) {
162 cout << "Standard Error: " << e.what() << " has occurred in the Weighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
166 cout << "An unknown error has occurred in the Weighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
172 /**************************************************************************************************/