]> git.donarmstrong.com Git - mothur.git/blob - phylodiversity.cpp
removed unused copy constructors and comments within comments that where causing...
[mothur.git] / phylodiversity.cpp
1 /*
2  *  phylodiversity.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 4/30/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "phylodiversity.h"
11
12 /**************************************************************************************************
13 EstOutput PhyloDiversity::getValues(Tree* t, vector<int> treeNodes, vector< vector<float> >& data) {
14     try {
15                 
16                 map<string, float> DScore;
17                 float totalLength = 0.0;
18                 data.clear();
19                 
20                 //initialize Dscore
21                 for (int i=0; i<globaldata->Groups.size(); i++) {               DScore[globaldata->Groups[i]] = 0.0;    }
22         
23                 ********************************************************
24                 //calculate a D value for each group 
25                 for(int v=0;v<treeNodes.size();v++){
26                                 
27                         if (m->control_pressed) { return data; }
28                         
29                         //calc the branch length
30                         //while you aren't at root
31                         float sum = 0.0;
32                         int index = treeNodes[v];
33
34                         while(t->tree[index].getParent() != -1){
35                                 
36                                 //if you have a BL
37                                 if(t->tree[index].getBranchLength() != -1){
38                                         sum += abs(t->tree[index].getBranchLength());
39                                 }
40                                 index = t->tree[index].getParent();
41                         }
42                                 
43                         //get last breanch length added
44                         if(t->tree[index].getBranchLength() != -1){
45                                 sum += abs(t->tree[index].getBranchLength());
46                         }
47                                 
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;
56                                 }
57
58                                 //add branch length to total for group
59                                 DScore[groups[j]] += (numSeqsInGroupJ * sum);
60                         }
61                         
62                 }
63                 
64         
65                 for (int i=0; i<globaldata->Groups.size(); i++) {   
66                         float percent = DScore[globaldata->Groups[i]]; 
67                         data.push_back(percent);  
68                         
69                 }
70                 
71                 return data;
72         }
73         catch(exception& e) {
74                 m->errorOut(e, "PhyloDiversity", "getValues");
75                 exit(1);
76         }
77 }
78 **************************************************************************************************/
79
80
81