X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=phylodiversity.cpp;h=86dc539b8e1a6e1385d178ab0473bcc966a71705;hb=515c3398ea27e2105f616fc5662b2a7ceb486aa0;hp=37884c483619887bcc478b6fdf7e77be08424cd4;hpb=0b99c6b6ea875e13febda76903fd4d9cda7add7d;p=mothur.git diff --git a/phylodiversity.cpp b/phylodiversity.cpp index 37884c4..86dc539 100644 --- a/phylodiversity.cpp +++ b/phylodiversity.cpp @@ -9,8 +9,8 @@ #include "phylodiversity.h" -/**************************************************************************************************/ -EstOutput PhyloDiversity::getValues(Tree* t, vector treeNodes) { +/************************************************************************************************** +EstOutput PhyloDiversity::getValues(Tree* t, vector treeNodes, vector< vector >& data) { try { map DScore; @@ -20,57 +20,52 @@ EstOutput PhyloDiversity::getValues(Tree* t, vector treeNodes) { //initialize Dscore for (int i=0; iGroups.size(); i++) { DScore[globaldata->Groups[i]] = 0.0; } - /********************************************************/ + /******************************************************** //calculate a D value for each group for(int v=0;vcontrol_pressed) { return data; } - //is this node from a sequence which is in one of the users groups - if (inUsersGroups(t->tree[treeNodes[v]].getGroup(), globaldata->Groups) == true) { - - //calc the branch length - //while you aren't at root - float sum = 0.0; - int index = treeNodes[v]; + //calc the branch length + //while you aren't at root + float sum = 0.0; + int index = treeNodes[v]; - while(t->tree[index].getParent() != -1){ - - //if you have a BL - if(t->tree[index].getBranchLength() != -1){ - sum += abs(t->tree[index].getBranchLength()); - } - index = t->tree[index].getParent(); - } - - //get last breanch length added + while(t->tree[index].getParent() != -1){ + + //if you have a BL if(t->tree[index].getBranchLength() != -1){ sum += abs(t->tree[index].getBranchLength()); } - - //for each group in the groups update the total branch length accounting for the names file - vector groups = t->tree[treeNodes[v]].getGroup(); - for (int j = 0; j < groups.size(); j++) { - int numSeqsInGroupJ = 0; - map::iterator it; - it = t->tree[treeNodes[v]].pcount.find(groups[j]); - if (it != t->tree[treeNodes[v]].pcount.end()) { //this leaf node contains seqs from group j - numSeqsInGroupJ = it->second; - } - - //add branch length to total for group - DScore[groups[j]] += (numSeqsInGroupJ * sum); + index = t->tree[index].getParent(); + } + + //get last breanch length added + if(t->tree[index].getBranchLength() != -1){ + sum += abs(t->tree[index].getBranchLength()); + } + + //for each group in the groups update the total branch length accounting for the names file + vector groups = t->tree[treeNodes[v]].getGroup(); + for (int j = 0; j < groups.size(); j++) { + int numSeqsInGroupJ = 0; + map::iterator it; + it = t->tree[treeNodes[v]].pcount.find(groups[j]); + if (it != t->tree[treeNodes[v]].pcount.end()) { //this leaf node contains seqs from group j + numSeqsInGroupJ = it->second; } + + //add branch length to total for group + DScore[groups[j]] += (numSeqsInGroupJ * sum); } + } for (int i=0; iGroups.size(); i++) { - //if (groupTotals[globaldata->Groups[i]] != 0.0) { //avoid divide by zero error - //float percent = DScore[globaldata->Groups[i]] / groupTotals[globaldata->Groups[i]]; float percent = DScore[globaldata->Groups[i]]; data.push_back(percent); - //}else { data.push_back(0.0); } + } return data; @@ -81,62 +76,6 @@ EstOutput PhyloDiversity::getValues(Tree* t, vector treeNodes) { } } /**************************************************************************************************/ -void PhyloDiversity::setTotalGroupBranchLengths(Tree* t) { - try { - - groupTotals.clear(); - - //initialize group totals - for (int i=0; iGroups.size(); i++) { groupTotals[globaldata->Groups[i]] = 0.0; } - - - /********************************************************/ - //calculate a D value for each group - for(int v=0;vgetNumLeaves();v++){ - - //is this node from a sequence which is in one of the users groups - if (inUsersGroups(t->tree[v].getGroup(), globaldata->Groups) == true) { - - //calc the branch length - int index = v; - float sum = 0.0; - - while(t->tree[index].getParent() != -1){ //while you aren't at root - - //if you have a BL - if(t->tree[index].getBranchLength() != -1){ - sum += abs(t->tree[index].getBranchLength()); - } - index = t->tree[index].getParent(); - } - - //get last breanch length added - if(t->tree[index].getBranchLength() != -1){ - sum += abs(t->tree[index].getBranchLength()); - } - - //account for the names file - vector groups = t->tree[v].getGroup(); - for (int j = 0; j < groups.size(); j++) { - int numSeqsInGroupJ = 0; - map::iterator it; - it = t->tree[v].pcount.find(groups[j]); - if (it != t->tree[v].pcount.end()) { //this leaf node contains seqs from group j - numSeqsInGroupJ = it->second; - } - //add branch length to total for group - groupTotals[groups[j]] += (numSeqsInGroupJ * sum); - }//end for - }//end if - }//end for - - } - catch(exception& e) { - m->errorOut(e, "PhyloDiversity", "setTotalGroupBranchLengths"); - exit(1); - } -} -/**************************************************************************************************/