- leavesSampled.push_back(randomLeaf[k]);
-
- if((k == 0) || (k+1) % increment == 0){ //ready to calc?
-
- data = phylo.getValues(trees[i], leavesSampled);
-
- //datas results are in the same order as globaldatas groups
- for (int h = 0; h < data.size(); h++) { diversity[h][count] += data[h]; }
-
- count++;
+ //calc branch length of randomLeaf k
+ float br = calcBranchLength(trees[i], randomLeaf[k]);
+
+ //for each group in the groups update the total branch length accounting for the names file
+ vector<string> groups = trees[i]->tree[randomLeaf[k]].getGroup();
+ for (int j = 0; j < groups.size(); j++) {
+ int numSeqsInGroupJ = 0;
+ map<string, int>::iterator it;
+ it = trees[i]->tree[randomLeaf[k]].pcount.find(groups[j]);
+ if (it != trees[i]->tree[randomLeaf[k]].pcount.end()) { //this leaf node contains seqs from group j
+ numSeqsInGroupJ = it->second;
+ }
+
+ for (int s = (counts[groups[j]]+1); s <= (counts[groups[j]]+numSeqsInGroupJ); s++) {
+ diversity[groups[j]][s] = diversity[groups[j]][s-1] + (numSeqsInGroupJ * br);
+ }
+ counts[groups[j]] += numSeqsInGroupJ;