]> git.donarmstrong.com Git - mothur.git/blob - parsimony.cpp
fixed parsimony for groups
[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                 //create pgroups that reflect the groups the user want to use
22                 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
23                         t->tree[i].pGroups = (t->mergeUserGroups(i));
24                 }
25
26                 for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
27                         int lc = t->tree[i].getLChild();
28                         int rc = t->tree[i].getRChild();
29                         
30                         int iSize = t->tree[i].pGroups.size();
31                         int rcSize = t->tree[rc].pGroups.size();
32                         int lcSize = t->tree[lc].pGroups.size();
33 cout << " i groups ";                   
34                         //add in all the groups the users wanted
35                         for (it = t->tree[i].pGroups.begin(); it != t->tree[i].pGroups.end(); it++) {
36 cout << it->first << " ";
37                         //      if (inUsersGroups(it->first, globaldata->Groups) != true) {  iSize--;  }
38                         }
39 cout << endl << " rc groups ";
40                         //add in all the groups the users wanted
41                         for (it = t->tree[rc].pGroups.begin(); it != t->tree[rc].pGroups.end(); it++) {
42 cout << it->first << " ";
43                                 //if (inUsersGroups(it->first, globaldata->Groups) != true) {  rcSize--;  }
44                         }
45 cout << endl << " lc groups ";                  
46                         //add in all the groups the users wanted
47                         for (it = t->tree[lc].pGroups.begin(); it != t->tree[lc].pGroups.end(); it++) {
48 cout << it->first << " ";
49                                 //if (inUsersGroups(it->first, globaldata->Groups) != true) {  lcSize--;  }
50                         }
51 cout << endl;                   
52                         //if isize are 0 then that branch is to be ignored
53                         if (iSize == 0) { }
54                         else if ((rcSize == 0) || (lcSize == 0)) { }
55                         //if you have more groups than either of your kids then theres been a change.
56                         else if(iSize > rcSize || iSize > lcSize){
57                                 score++;
58                         }
59                 } 
60                 
61                 data[0] = score;
62                 
63                 return data;
64         }
65         catch(exception& e) {
66                 cout << "Standard Error: " << e.what() << " has occurred in the Parsimony class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
67                 exit(1);
68         }
69         catch(...) {
70                 cout << "An unknown error has occurred in the Parsimony class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71                 exit(1);
72         }
73
74 }
75