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) {
17 //clear out old values
19 penalty.resize(t->getNumLeaves(), 0);
21 map<string,double> unique; //group, total of all branch lengths of nodes with that group.
22 double shared = 0.0000;
25 //add up the branch lengths for each group.
26 for(int i=0;i<t->getNumLeaves();i++){
27 if(t->tree[i].pGroups.size() > 0){
28 unique[t->tree[i].pGroups.begin()->first] += t->tree[i].getBranchLength();
32 //for each non-leaf node
33 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
35 int lc = t->tree[i].getLChild(); //lc = vector index of left child
36 int rc = t->tree[i].getRChild(); //rc = vector index of right child
39 if(t->tree[rc].pGroups.size() == 0 || t->tree[lc].pGroups.size() == 0){
40 penalty.push_back(penalty[t->tree[rc].getIndex()]+penalty[t->tree[lc].getIndex()]);
42 else if(t->tree[i].pGroups.size() > t->tree[rc].pGroups.size() || t->tree[i].pGroups.size() > t->tree[lc].pGroups.size()){
43 penalty.push_back(penalty[t->tree[rc].getIndex()]+penalty[t->tree[lc].getIndex()]+1);
46 penalty.push_back(penalty[t->tree[rc].getIndex()]+penalty[t->tree[lc].getIndex()]);
49 //not sure when this would ever be true??? if your parent is root could be, but pGroups.size() should never be 0.
50 if(t->tree[i].getParent() == -1 && (t->tree[lc].pGroups.size() == 0 || t->tree[rc].pGroups.size() == 0)){
53 else if(penalty[i] != 0 && t->tree[i].pGroups.size() != 0){
54 shared += t->tree[i].getBranchLength();
56 else if( t->tree[i].pGroups.size() != 0){
57 unique[t->tree[i].pGroups.begin()->first] += t->tree[i].getBranchLength();
61 map<string,double>::iterator pos;
62 for(pos=unique.begin();pos!=unique.end();pos++){
63 if(pos->first!="xxx"){
64 UW += unique[pos->first];
70 if (isnan(UW) || isinf(UW)) { UW = 0; }
78 cout << "Standard Error: " << e.what() << " has occurred in the Unweighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82 cout << "An unknown error has occurred in the Unweighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
88 /**************************************************************************************************/