]> git.donarmstrong.com Git - mothur.git/blob - parsimony.cpp
fixed unweighted calculator
[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 EstOutput Parsimony::getValues(Tree* t) {
14         try {
15                 globaldata = GlobalData::getInstance();
16                 
17                 data.resize(1,0);
18                         
19                 int score = 0;
20                         
21                 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
22                         int lc = t->tree[i].getLChild();
23                         int rc = t->tree[i].getRChild();
24                         
25                         int iSize = 0;
26                         int rcSize = 0;
27                         int lcSize = 0;
28
29                         //add in all the groups the users wanted
30                         for (it = t->tree[i].pGroups.begin(); it != t->tree[i].pGroups.end(); it++) {
31                                 if (inUsersGroups(it->first, globaldata->Groups) == true) {  iSize++;  }
32                         }
33
34                         //if that leaves no groups give it 1 so it will cause no change to parent
35                         if (iSize == 0) { iSize++; }
36                         
37                         //add in all the groups the users wanted
38                         for (it = t->tree[rc].pGroups.begin(); it != t->tree[rc].pGroups.end(); it++) {
39
40                                 if (inUsersGroups(it->first, globaldata->Groups) == true) {  rcSize++;  }
41                         }
42                         
43                         //if that leaves no groups give it 1 so it will cause no change to parent
44                         if (rcSize == 0) { rcSize++; }
45
46                                 
47                         //add in all the groups the users wanted
48                         for (it = t->tree[lc].pGroups.begin(); it != t->tree[lc].pGroups.end(); it++) {
49
50                                 if (inUsersGroups(it->first, globaldata->Groups) == true) {  lcSize++;  }
51                         }
52                         
53                         //if that leaves no groups give it 1 so it will cause no change to parent
54                         if (lcSize == 0) { lcSize++; }
55
56
57                         //if you have more groups than either of your kids then theres been a change.
58                          if(iSize > rcSize || iSize > lcSize){
59                                 score++;
60
61                         }
62                 } 
63                 
64                 data[0] = score;
65                 
66                 return data;
67         }
68         catch(exception& e) {
69                 cout << "Standard Error: " << e.what() << " has occurred in the Parsimony class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
70                 exit(1);
71         }
72         catch(...) {
73                 cout << "An unknown error has occurred in the Parsimony class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
74                 exit(1);
75         }
76
77 }
78