5 * Created by Sarah Westcott on 2/9/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "unweighted.h"
12 /**************************************************************************************************/
14 EstOutput Unweighted::getValues(Tree* t) {
16 globaldata = GlobalData::getInstance();
18 //clear out old values
20 penalty.resize(t->getNumLeaves(), 0);
22 map<string,double> unique; //group, total of all branch lengths of nodes with that group.
23 double shared = 0.0000;
26 //add up the branch lengths for each group.
27 for(int i=0;i<t->getNumLeaves();i++){
28 if(t->tree[i].pGroups.size() > 0){
29 unique[t->tree[i].pGroups.begin()->first] += t->tree[i].getBranchLength();
33 //for each non-leaf node
34 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
36 int lc = t->tree[i].getLChild(); //lc = vector index of left child
37 int rc = t->tree[i].getRChild(); //rc = vector index of right child
40 if(t->tree[rc].pGroups.size() == 0 || t->tree[lc].pGroups.size() == 0){
41 penalty.push_back(penalty[t->tree[rc].getIndex()]+penalty[t->tree[lc].getIndex()]);
43 else if(t->tree[i].pGroups.size() > t->tree[rc].pGroups.size() || t->tree[i].pGroups.size() > t->tree[lc].pGroups.size()){
44 penalty.push_back(penalty[t->tree[rc].getIndex()]+penalty[t->tree[lc].getIndex()]+1);
47 penalty.push_back(penalty[t->tree[rc].getIndex()]+penalty[t->tree[lc].getIndex()]);
50 //not sure when this would ever be true??? if your parent is root could be, but pGroups.size() should never be 0.
51 if(t->tree[i].getParent() == -1 && (t->tree[lc].pGroups.size() == 0 || t->tree[rc].pGroups.size() == 0)){
54 else if(penalty[i] != 0 && t->tree[i].pGroups.size() != 0){
55 shared += t->tree[i].getBranchLength();
57 else if( t->tree[i].pGroups.size() != 0){
58 unique[t->tree[i].pGroups.begin()->first] += t->tree[i].getBranchLength();
62 map<string,double>::iterator pos;
63 for(pos=unique.begin();pos!=unique.end();pos++){
64 if((pos->first!="xxx") && (inUsersGroups(pos->first))){
65 UW += unique[pos->first];
71 if (isnan(UW) || isinf(UW)) { UW = 0; }
79 cout << "Standard Error: " << e.what() << " has occurred in the Unweighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
83 cout << "An unknown error has occurred in the Unweighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
89 /**************************************************************************************************/
90 bool Unweighted::inUsersGroups(string groupname) {
92 for (int i = 0; i < globaldata->Groups.size(); i++) {
93 if (groupname == globaldata->Groups[i]) { return true; }
98 cout << "Standard Error: " << e.what() << " has occurred in the Unweighted class Function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
102 cout << "An unknown error has occurred in the Unweighted class function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";