]> git.donarmstrong.com Git - mothur.git/blob - parsimony.cpp
fix weighted unifrac bug in findIndex and randomize labels
[mothur.git] / parsimony.cpp
1 /*
2  *  parsimony.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 1/26/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "parsimony.h"
11
12 /**************************************************************************************************/
13
14 EstOutput Parsimony::getValues(Tree* t) {
15         try {
16                 globaldata = GlobalData::getInstance();
17                 
18                 data.resize(1,0);
19                         
20                 int score = 0;
21                 
22                 //create pgroups that reflect the groups the user want to use
23                 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
24                         t->tree[i].pGroups = (t->mergeUserGroups(i));
25                 }
26                 
27                 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
28                         int lc = t->tree[i].getLChild();
29                         int rc = t->tree[i].getRChild();
30                         
31                         int iSize = t->tree[i].pGroups.size();
32                         int rcSize = t->tree[rc].pGroups.size();
33                         int lcSize = t->tree[lc].pGroups.size();
34                 
35                         //if isize are 0 then that branch is to be ignored
36                         if (iSize == 0) { }
37                         else if ((rcSize == 0) || (lcSize == 0)) { }
38                         //if you have more groups than either of your kids then theres been a change.
39                         else if(iSize > rcSize || iSize > lcSize){
40                                 score++;
41                         }
42                 } 
43                 
44                 
45                 data[0] = score;
46                 
47                 return data;
48         }
49         catch(exception& e) {
50                 cout << "Standard Error: " << e.what() << " has occurred in the Parsimony class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
51                 exit(1);
52         }
53         catch(...) {
54                 cout << "An unknown error has occurred in the Parsimony class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55                 exit(1);
56         }
57
58 }
59
60 /**************************************************************************************************/
61