5 * Created by westcott on 4/30/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "phylodiversity.h"
12 /**************************************************************************************************
13 EstOutput PhyloDiversity::getValues(Tree* t, vector<int> treeNodes, vector< vector<float> >& data) {
16 map<string, float> DScore;
17 float totalLength = 0.0;
21 for (int i=0; i<globaldata->Groups.size(); i++) { DScore[globaldata->Groups[i]] = 0.0; }
23 /********************************************************
24 //calculate a D value for each group
25 for(int v=0;v<treeNodes.size();v++){
27 if (m->control_pressed) { return data; }
29 //calc the branch length
30 //while you aren't at root
32 int index = treeNodes[v];
34 while(t->tree[index].getParent() != -1){
37 if(t->tree[index].getBranchLength() != -1){
38 sum += abs(t->tree[index].getBranchLength());
40 index = t->tree[index].getParent();
43 //get last breanch length added
44 if(t->tree[index].getBranchLength() != -1){
45 sum += abs(t->tree[index].getBranchLength());
48 //for each group in the groups update the total branch length accounting for the names file
49 vector<string> groups = t->tree[treeNodes[v]].getGroup();
50 for (int j = 0; j < groups.size(); j++) {
51 int numSeqsInGroupJ = 0;
52 map<string, int>::iterator it;
53 it = t->tree[treeNodes[v]].pcount.find(groups[j]);
54 if (it != t->tree[treeNodes[v]].pcount.end()) { //this leaf node contains seqs from group j
55 numSeqsInGroupJ = it->second;
58 //add branch length to total for group
59 DScore[groups[j]] += (numSeqsInGroupJ * sum);
65 for (int i=0; i<globaldata->Groups.size(); i++) {
66 float percent = DScore[globaldata->Groups[i]];
67 data.push_back(percent);
74 m->errorOut(e, "PhyloDiversity", "getValues");
78 /**************************************************************************************************/