5 * Created by Sarah Westcott on 1/26/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "parsimony.h"
12 /**************************************************************************************************/
14 EstOutput Parsimony::getValues(Tree* t) {
16 globaldata = GlobalData::getInstance();
17 vector<string> groups;
19 copyTree = new Tree();
21 //if the users enters no groups then give them the score of all groups
22 int numGroups = globaldata->Groups.size();
24 //calculate number of comparsions
26 for (int r=0; r<numGroups; r++) {
27 for (int l = r+1; l < numGroups; l++) {
32 //numComp+1 for AB, AC, BC, ABC
33 data.resize(numComp+1,0);
36 for (int a=0; a<numGroups; a++) {
37 for (int l = a+1; l < numGroups; l++) {
40 //groups in this combo
41 groups.push_back(globaldata->Groups[a]); groups.push_back(globaldata->Groups[l]);
43 //copy users tree so that you can redo pgroups
46 //create pgroups that reflect the groups the user want to use
47 for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
48 copyTree->tree[i].pGroups = (copyTree->mergeUserGroups(i, groups));
51 for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
52 int lc = copyTree->tree[i].getLChild();
53 int rc = copyTree->tree[i].getRChild();
55 int iSize = copyTree->tree[i].pGroups.size();
56 int rcSize = copyTree->tree[rc].pGroups.size();
57 int lcSize = copyTree->tree[lc].pGroups.size();
59 //if isize are 0 then that branch is to be ignored
61 else if ((rcSize == 0) || (lcSize == 0)) { }
62 //if you have more groups than either of your kids then theres been a change.
63 else if(iSize > rcSize || iSize > lcSize){
76 //get score for all users groups
77 for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
78 if (tmap->namesOfGroups[i] != "xxx") {
79 groups.push_back(tmap->namesOfGroups[i]);
83 for (int i = 0; i < globaldata->Groups.size(); i++) {
84 groups.push_back(globaldata->Groups[i]);
88 //copy users tree so that you can redo pgroups
92 //create pgroups that reflect the groups the user want to use
93 for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
94 // cout << i << "..." << endl;
95 copyTree->tree[i].pGroups = (copyTree->mergeUserGroups(i, groups));
98 // map<string,int>::iterator it;
100 for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
101 int lc = copyTree->tree[i].getLChild();
102 int rc = copyTree->tree[i].getRChild();
104 int iSize = copyTree->tree[i].pGroups.size();
105 int rcSize = copyTree->tree[rc].pGroups.size();
106 int lcSize = copyTree->tree[lc].pGroups.size();
108 // cout << i+1 << '\t' << lc+1 << '\t' << rc+1 << ":\t";
110 // for(it=copyTree->tree[i].pGroups.begin();it!=copyTree->tree[i].pGroups.end();it++){
111 // cout << it->first << '\t';
114 // cout << " : " << iSize << '\t' << rcSize << '\t' << lcSize << '\t';
116 //if isize are 0 then that branch is to be ignored
118 else if ((rcSize == 0) || (lcSize == 0)) { }
119 //if you have more groups than either of your kids then theres been a change.
120 else if(iSize > rcSize || iSize > lcSize){
123 // cout << score << endl;
135 catch(exception& e) {
136 cout << "Standard Error: " << e.what() << " has occurred in the Parsimony class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
140 cout << "An unknown error has occurred in the Parsimony class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
146 /**************************************************************************************************/