+ UN = (WScore[(groupA+groupB)] / D);
+
+ if (isnan(UN) || isinf(UN)) { UN = 0; }
+ data.push_back(UN);
+
+ return data;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Weighted", "getValues");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+double Weighted::getLengthToRoot(Tree* t, int v, string groupA, string groupB) {
+ try {
+
+ double sum = 0.0;
+ map<int, double> tempTotals; //maps node to total Branch Length
+ map<int, int> nodePcountSize; //maps node to pcountSize
+ map<int, int>::iterator itCount;
+
+ int index = v;
+
+ //you are a leaf
+ if(t->tree[index].getBranchLength() != -1){ sum += abs(t->tree[index].getBranchLength()); }
+ tempTotals[index] = 0.0;
+ index = t->tree[index].getParent();
+
+ //while you aren't at root
+ while(t->tree[index].getParent() != -1){
+
+ if (m->control_pressed) { return sum; }
+
+ int pcountSize = 0;
+ map<string, int>::iterator itGroup = t->tree[index].pcount.find(groupA);
+ if (itGroup != t->tree[index].pcount.end()) { pcountSize++; }
+ itGroup = t->tree[index].pcount.find(groupB);
+ if (itGroup != t->tree[index].pcount.end()) { pcountSize++; }
+
+ nodePcountSize[index] = pcountSize;
+
+ //do both your chidren have have descendants from the users groups?
+ int lc = t->tree[index].getLChild();
+ int rc = t->tree[index].getRChild();
+
+ itCount = nodePcountSize.find(lc);
+ if (itCount == nodePcountSize.end()) {
+ int LpcountSize = 0;
+ itGroup = t->tree[lc].pcount.find(groupA);
+ if (itGroup != t->tree[lc].pcount.end()) { LpcountSize++; }
+ itGroup = t->tree[lc].pcount.find(groupB);
+ if (itGroup != t->tree[lc].pcount.end()) { LpcountSize++; }
+ nodePcountSize[lc] = LpcountSize;
+ }
+
+ itCount = nodePcountSize.find(rc);
+ if (itCount == nodePcountSize.end()) {
+ int RpcountSize = 0;
+ itGroup = t->tree[rc].pcount.find(groupA);
+ if (itGroup != t->tree[rc].pcount.end()) { RpcountSize++; }
+ itGroup = t->tree[rc].pcount.find(groupB);
+ if (itGroup != t->tree[rc].pcount.end()) { RpcountSize++; }
+ nodePcountSize[rc] = RpcountSize;
+ }
+
+ //if yes, add your childrens tempTotals
+ if ((nodePcountSize[lc] != 0) && (nodePcountSize[rc] != 0)) {
+ sum += tempTotals[lc] + tempTotals[rc];
+
+ //cout << "added to total " << tempTotals[lc] << '\t' << tempTotals[rc] << endl;
+ if (t->tree[index].getBranchLength() != -1) {
+ tempTotals[index] = abs(t->tree[index].getBranchLength());
+ }else {
+ tempTotals[index] = 0.0;
+ }
+ }else { //if no, your tempTotal is your childrens temp totals + your branch length
+ tempTotals[index] = tempTotals[lc] + tempTotals[rc] + abs(t->tree[index].getBranchLength());