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
21 double UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group
22 double totalBL = 0.00; //all branch lengths
23 double UW = 0.00; //Unweighted Value = UniqueBL / totalBL;
25 map<string, int>::iterator it; //iterator to traverse pgroups
26 map<string, int> copyIpcount;
28 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
30 int lc = t->tree[i].getLChild(); //lc = vector index of left child
31 int rc = t->tree[i].getRChild(); //rc = vector index of right child
33 /**********************************************************************/
34 //This section adds in all lengths that are non leaf
36 copyIpcount = t->tree[i].pcount;
37 for (it = copyIpcount.begin(); it != copyIpcount.end(); it++) {
38 if (inUsersGroups(it->first, globaldata->Groups) != true) { copyIpcount.erase(it->first); }
41 //if i's children are from the same group then i's pcount size will be 1
42 //if copyIpcount.size() = 0 they are from a branch that is entirely from a group the user doesn't want
43 if (copyIpcount.size() == 0) { }
44 else if ((t->tree[i].getBranchLength() != -1) && (copyIpcount.size() == 1)) { UniqueBL += t->tree[i].getBranchLength(); }
46 //add i's BL to total if it is from the groups the user wants
47 if ((t->tree[i].getBranchLength() != -1) && (copyIpcount.size() != 0)) {
48 totalBL += t->tree[i].getBranchLength();
51 /**********************************************************************/
52 //This section adds in all lengths that are leaf
54 //if i's chidren are leaves
55 if (t->tree[rc].getRChild() == -1) {
56 //if rc is a valid group and rc has a BL
57 if ((inUsersGroups(t->tree[rc].getGroup(), globaldata->Groups) == true) && (t->tree[rc].getBranchLength() != -1)) {
58 UniqueBL += t->tree[rc].getBranchLength();
59 totalBL += t->tree[rc].getBranchLength();
63 if (t->tree[lc].getLChild() == -1) {
64 //if lc is a valid group and lc has a BL
65 if ((inUsersGroups(t->tree[lc].getGroup(), globaldata->Groups) == true) && (t->tree[lc].getBranchLength() != -1)) {
66 UniqueBL += t->tree[lc].getBranchLength();
67 totalBL += t->tree[lc].getBranchLength();
71 /**********************************************************************/
74 UW = (UniqueBL / totalBL);
76 if (isnan(UW) || isinf(UW)) { UW = 0; }
84 cout << "Standard Error: " << e.what() << " has occurred in the Unweighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
88 cout << "An unknown error has occurred in the Unweighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";