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 float UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group
22 float totalBL = 0.00; //all branch lengths
23 float UW = 0.00; //Unweighted Value = UniqueBL / totalBL;
25 map<string, int>::iterator it; //iterator to traverse pgroups
26 map<string, int> copyLCpcount;
27 map<string, int> copyRCpcount;
28 map<string, int> copyIpcount;
30 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
32 int lc = t->tree[i].getLChild(); //lc = vector index of left child
33 int rc = t->tree[i].getRChild(); //rc = vector index of right child
35 /**********************************************************************/
36 //This section adds in all lengths that are non leaf
38 //copy left childs pGroups and remove groups that the user doesn't want
39 copyIpcount = t->tree[i].pcount;
40 for (it = copyIpcount.begin(); it != copyIpcount.end(); it++) {
41 if (inUsersGroups(it->first, globaldata->Groups) != true) { copyIpcount.erase(it->first); }
44 //copy left childs pGroups and remove groups that the user doesn't want
45 copyLCpcount = t->tree[lc].pcount;
46 for (it = copyLCpcount.begin(); it != copyLCpcount.end(); it++) {
47 if (inUsersGroups(it->first, globaldata->Groups) != true) { copyLCpcount.erase(it->first); }
50 //copy right childs pGroups and remove groups that the user doesn't want
51 copyRCpcount = t->tree[rc].pcount;
52 for (it = copyRCpcount.begin(); it != copyRCpcount.end(); it++) {
53 if (inUsersGroups(it->first, globaldata->Groups) != true) { copyRCpcount.erase(it->first); }
56 //if i's children are from the same group and i has a BL then add i's length to unique
57 //if copyRCpcount.size() = 0 && copyLCpcount.size() = 0 they are from a branch that is entirely from a group the user doesn't want
58 if ((copyRCpcount.size() == 0) && (copyLCpcount.size() == 0)) { }
60 if ((copyRCpcount == copyLCpcount) && (t->tree[i].getBranchLength() != -1)) { UniqueBL += t->tree[i].getBranchLength(); }
61 //if either childs groups = 0 then all of there groups were not valid making the parent unique
62 else if (((copyRCpcount.size() == 0) || (copyLCpcount.size() == 0)) && (t->tree[i].getBranchLength() != -1)) { UniqueBL += t->tree[i].getBranchLength(); }
65 //add i's BL to total if it is from the groups the user wants
66 if ((t->tree[i].getBranchLength() != -1) && (copyIpcount.size() != 0)) {
67 totalBL += t->tree[i].getBranchLength();
70 /**********************************************************************/
71 //This section adds in all lengths that are leaf
73 //if i's chidren are leaves
74 if (t->tree[rc].getRChild() == -1) {
75 //if rc is a valid group and rc has a BL
76 if ((inUsersGroups(t->tree[rc].getGroup(), globaldata->Groups) == true) && (t->tree[rc].getBranchLength() != -1)) {
77 UniqueBL += t->tree[rc].getBranchLength();
78 totalBL += t->tree[rc].getBranchLength();
82 if (t->tree[lc].getLChild() == -1) {
83 //if lc is a valid group and lc has a BL
84 if ((inUsersGroups(t->tree[lc].getGroup(), globaldata->Groups) == true) && (t->tree[lc].getBranchLength() != -1)) {
85 UniqueBL += t->tree[lc].getBranchLength();
86 totalBL += t->tree[lc].getBranchLength();
90 /**********************************************************************/
94 UW = (UniqueBL / totalBL);
96 if (isnan(UW) || isinf(UW)) { UW = 0; }
103 catch(exception& e) {
104 cout << "Standard Error: " << e.what() << " has occurred in the Unweighted class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
108 cout << "An unknown error has occurred in the Unweighted class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";