+}
+/**************************************************************************************************/
+double Weighted::getLengthToRoot(Tree* t, int v, string groupA, string groupB) {
+ try {
+
+ double sum = 0.0;
+ int index = v;
+
+ //you are a leaf
+ if(t->tree[index].getBranchLength() != -1){ sum += abs(t->tree[index].getBranchLength()); }
+ double tempTotal = 0.0;
+ index = t->tree[index].getParent();
+
+ vector<string> grouping; grouping.push_back(groupA); grouping.push_back(groupB);
+
+ rootForGrouping[grouping].insert(index);
+
+ //while you aren't at root
+ while(t->tree[index].getParent() != -1){
+
+ if (m->control_pressed) { return sum; }
+
+ int parent = t->tree[index].getParent();
+
+ if (includeRoot) { //add everyone
+ if(t->tree[index].getBranchLength() != -1){ sum += abs(t->tree[index].getBranchLength()); }
+ }else {
+
+ //am I the root for this grouping? if so I want to stop "early"
+ //does my sibling have descendants from the users groups?
+ int lc = t->tree[parent].getLChild();
+ int rc = t->tree[parent].getRChild();
+
+ int sib = lc;
+ if (lc == index) { sib = rc; }
+
+ map<string, int>::iterator itGroup;
+ int pcountSize = 0;
+ itGroup = t->tree[sib].pcount.find(groupA);
+ if (itGroup != t->tree[sib].pcount.end()) { pcountSize++; }
+ itGroup = t->tree[sib].pcount.find(groupB);
+ if (itGroup != t->tree[sib].pcount.end()) { pcountSize++; }
+
+ //if yes, I am not the root so add me
+ if (pcountSize != 0) {
+ if (t->tree[index].getBranchLength() != -1) {
+ sum += abs(t->tree[index].getBranchLength()) + tempTotal;
+ tempTotal = 0.0;
+ }else {
+ sum += tempTotal;
+ tempTotal = 0.0;
+ }
+ rootForGrouping[grouping].clear();
+ rootForGrouping[grouping].insert(parent);
+ }else { //if no, I may be the root so add my br to tempTotal until I am proven innocent
+ if (t->tree[index].getBranchLength() != -1) {
+ tempTotal += abs(t->tree[index].getBranchLength());
+ }
+ }
+ }
+
+ index = parent;
+ }
+
+ //get all nodes above the root to add so we don't add their u values above
+ index = *(rootForGrouping[grouping].begin());
+
+ while(t->tree[index].getParent() != -1){
+ int parent = t->tree[index].getParent();
+ rootForGrouping[grouping].insert(parent);
+ index = parent;
+ }
+ return sum;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Weighted", "getBranchLengthSums");