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) {
17 int numGroups = tmap->getNumGroups();
19 //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3;
21 for (int i=1; i<numGroups; i++) {
22 for (int l = n; l < numGroups; l++) {
23 //initialize weighted scores
24 WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] = 0.0;
28 data.clear(); //clear out old values
32 for(int i=0;i<t->getNumLeaves();i++){
36 //while you aren't at root
37 while(t->tree[index].getParent() != -1){
39 if(t->tree[index].pGroups.size() != 0){
40 sum += t->tree[index].getBranchLength();
44 int old_index = index;
46 index = t->tree[index].getParent();
48 //if you grandparent is the root
49 if(t->tree[index].getParent() == -1 && t->tree[old_index].pGroups.size() != 0){
50 int lc = t->tree[t->tree[index].getLChild()].pGroups.size();
51 int rc = t->tree[t->tree[index].getRChild()].pGroups.size();
54 if(lc == 0 || rc == 0){
55 sum -= t->tree[old_index].getBranchLength();
60 if(t->tree[i].getGroup() != ""){
61 sum /= (double)tmap->seqsPerGroup[t->tree[i].getGroup()];
67 for(int i=0;i<t->getNumNodes();i++){
68 //calculate weighted score for each of the group comb i.e. with groups A,B,C = AB, AC, BC.
70 for (int b=1; b<numGroups; b++) {
71 for (int l = n; l < numGroups; l++) {
73 //does this node have descendants from group b-1
74 it = t->tree[i].pcount.find(tmap->namesOfGroups[b-1]);
75 //if it does u = # of its descendants with a certain group / total number in tree with a certain group
76 if (it != t->tree[i].pcount.end()) {
77 u = (double) t->tree[i].pcount[tmap->namesOfGroups[b-1]] / (double) tmap->seqsPerGroup[tmap->namesOfGroups[b-1]];
80 //does this node have descendants from group l
81 it = t->tree[i].pcount.find(tmap->namesOfGroups[l]);
82 //if it does subtract their percentage from u
83 if (it != t->tree[i].pcount.end()) {
84 u -= (double) t->tree[i].pcount[tmap->namesOfGroups[l]] / (double) tmap->seqsPerGroup[tmap->namesOfGroups[l]];
87 u = abs(u) * t->tree[i].getBranchLength();
89 //save groupcombs u value
90 WScore[tmap->namesOfGroups[b-1]+tmap->namesOfGroups[l]] += u;
97 //calculate weighted score for each group combination
100 for (int i=1; i<numGroups; i++) {
101 for (int l = n; l < numGroups; l++) {
102 UN = (WScore[tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]] / D);
103 if (isnan(UN) || isinf(UN)) { UN = 0; }
110 catch(exception& e) {
111 cout << "Standard Error: " << e.what() << " has occurred in the Weighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
115 cout << "An unknown error has occurred in the Weighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 /**************************************************************************************************/