+}
+/**************************************************************************************************/
+EstOutput Weighted::driver(Tree* t, vector< vector<string> > namesOfGroupCombos, int start, int num, CountTable* ct) {
+ try {
+ EstOutput results;
+ vector<double> D;
+
+ int count = 0;
+ for (int h = start; h < (start+num); h++) {
+
+ if (m->control_pressed) { return results; }
+
+ //initialize weighted score
+ string groupA = namesOfGroupCombos[h][0];
+ string groupB = namesOfGroupCombos[h][1];
+
+ set<int> validBranches;
+ WScore[groupA+groupB] = 0.0;
+ D.push_back(0.0000); //initialize a spot in D for each combination
+
+ //adding the wieghted sums from group i
+ for (int j = 0; j < t->groupNodeInfo[groupA].size(); j++) { //the leaf nodes that have seqs from group i
+ map<string, int>::iterator it = t->tree[t->groupNodeInfo[groupA][j]].pcount.find(groupA);
+ int numSeqsInGroupI = it->second;
+
+ double sum = getLengthToRoot(t, t->groupNodeInfo[groupA][j], groupA, groupB);
+ double weightedSum = ((numSeqsInGroupI * sum) / (double)ct->getGroupCount(groupA));
+
+ D[count] += weightedSum;
+ }
+
+ //adding the wieghted sums from group l
+ for (int j = 0; j < t->groupNodeInfo[groupB].size(); j++) { //the leaf nodes that have seqs from group l
+ map<string, int>::iterator it = t->tree[t->groupNodeInfo[groupB][j]].pcount.find(groupB);
+ int numSeqsInGroupL = it->second;
+
+ double sum = getLengthToRoot(t, t->groupNodeInfo[groupB][j], groupA, groupB);
+ double weightedSum = ((numSeqsInGroupL * sum) / (double)ct->getGroupCount(groupB));
+
+ D[count] += weightedSum;
+ }
+ count++;
+ }
+
+ //calculate u for the group comb
+ for (int h = start; h < (start+num); h++) {
+ //report progress
+ //m->mothurOut("Processing combo: " + toString(h)); m->mothurOutEndLine();
+
+ string groupA = namesOfGroupCombos[h][0];
+ string groupB = namesOfGroupCombos[h][1];
+
+ //calculate u for the group comb
+ for(int i=0;i<t->getNumNodes();i++){
+
+ if (m->control_pressed) { return data; }
+
+ double u;
+ //int pcountSize = 0;
+ //does this node have descendants from groupA
+ it = t->tree[i].pcount.find(groupA);
+ //if it does u = # of its descendants with a certain group / total number in tree with a certain group
+ if (it != t->tree[i].pcount.end()) {
+ u = (double) t->tree[i].pcount[groupA] / (double) ct->getGroupCount(groupA);
+ }else { u = 0.00; }
+
+
+ //does this node have descendants from group l
+ it = t->tree[i].pcount.find(groupB);
+
+ //if it does subtract their percentage from u
+ if (it != t->tree[i].pcount.end()) {
+ u -= (double) t->tree[i].pcount[groupB] / (double) ct->getGroupCount(groupB);
+ }
+
+ if (includeRoot) {
+ if (t->tree[i].getBranchLength() != -1) {
+ u = abs(u * t->tree[i].getBranchLength());
+ WScore[(groupA+groupB)] += u;
+ }
+ }else {
+ //if this is not the root then add it
+ if (rootForGrouping[namesOfGroupCombos[h]].count(i) == 0) {
+ if (t->tree[i].getBranchLength() != -1) {
+ u = abs(u * t->tree[i].getBranchLength());
+ WScore[(groupA+groupB)] += u;
+ }
+ }
+ }
+ }
+
+ }
+
+ /********************************************************/
+ //calculate weighted score for the group combination
+ double UN;
+ count = 0;
+ for (int h = start; h < (start+num); h++) {
+ UN = (WScore[namesOfGroupCombos[h][0]+namesOfGroupCombos[h][1]] / D[count]);
+ if (isnan(UN) || isinf(UN)) { UN = 0; }
+ results.push_back(UN);
+ count++;
+ }
+
+ return results;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "Weighted", "driver");