From 99d8e5dde3ee76ae28ead4070d321da195c595c9 Mon Sep 17 00:00:00 2001 From: westcott Date: Mon, 23 Feb 2009 13:55:04 +0000 Subject: [PATCH] fixed unweighted calculator --- unweighted.cpp | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/unweighted.cpp b/unweighted.cpp index 1a2573b..b224996 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -18,15 +18,13 @@ EstOutput Unweighted::getValues(Tree* t) { //clear out old values data.resize(1,0); - float UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group - float totalBL = 0.00; //all branch lengths - float UW = 0.00; //Unweighted Value = UniqueBL / totalBL; + double UniqueBL=0.0000; //a branch length is unique if it's chidren are from the same group + double totalBL = 0.00; //all branch lengths + double UW = 0.00; //Unweighted Value = UniqueBL / totalBL; map::iterator it; //iterator to traverse pgroups - map copyLCpcount; - map copyRCpcount; map copyIpcount; - + for(int i=t->getNumLeaves();igetNumNodes();i++){ int lc = t->tree[i].getLChild(); //lc = vector index of left child @@ -35,32 +33,15 @@ EstOutput Unweighted::getValues(Tree* t) { /**********************************************************************/ //This section adds in all lengths that are non leaf - //copy left childs pGroups and remove groups that the user doesn't want copyIpcount = t->tree[i].pcount; for (it = copyIpcount.begin(); it != copyIpcount.end(); it++) { if (inUsersGroups(it->first, globaldata->Groups) != true) { copyIpcount.erase(it->first); } } - - //copy left childs pGroups and remove groups that the user doesn't want - copyLCpcount = t->tree[lc].pcount; - for (it = copyLCpcount.begin(); it != copyLCpcount.end(); it++) { - if (inUsersGroups(it->first, globaldata->Groups) != true) { copyLCpcount.erase(it->first); } - } - - //copy right childs pGroups and remove groups that the user doesn't want - copyRCpcount = t->tree[rc].pcount; - for (it = copyRCpcount.begin(); it != copyRCpcount.end(); it++) { - if (inUsersGroups(it->first, globaldata->Groups) != true) { copyRCpcount.erase(it->first); } - } - - //if i's children are from the same group and i has a BL then add i's length to unique - //if copyRCpcount.size() = 0 && copyLCpcount.size() = 0 they are from a branch that is entirely from a group the user doesn't want - if ((copyRCpcount.size() == 0) && (copyLCpcount.size() == 0)) { } - else { - if ((copyRCpcount == copyLCpcount) && (t->tree[i].getBranchLength() != -1)) { UniqueBL += t->tree[i].getBranchLength(); } - //if either childs groups = 0 then all of there groups were not valid making the parent unique - else if (((copyRCpcount.size() == 0) || (copyLCpcount.size() == 0)) && (t->tree[i].getBranchLength() != -1)) { UniqueBL += t->tree[i].getBranchLength(); } - } + + //if i's children are from the same group then i's pcount size will be 1 + //if copyIpcount.size() = 0 they are from a branch that is entirely from a group the user doesn't want + if (copyIpcount.size() == 0) { } + else if ((t->tree[i].getBranchLength() != -1) && (copyIpcount.size() == 1)) { UniqueBL += t->tree[i].getBranchLength(); } //add i's BL to total if it is from the groups the user wants if ((t->tree[i].getBranchLength() != -1) && (copyIpcount.size() != 0)) { @@ -88,7 +69,6 @@ EstOutput Unweighted::getValues(Tree* t) { } /**********************************************************************/ - } UW = (UniqueBL / totalBL); -- 2.39.2