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++){
53 if (m->control_pressed) { return data; }
55 int lc = copyTree->tree[i].getLChild();
56 int rc = copyTree->tree[i].getRChild();
58 int iSize = copyTree->tree[i].pGroups.size();
59 int rcSize = copyTree->tree[rc].pGroups.size();
60 int lcSize = copyTree->tree[lc].pGroups.size();
62 //if isize are 0 then that branch is to be ignored
64 else if ((rcSize == 0) || (lcSize == 0)) { }
65 //if you have more groups than either of your kids then theres been a change.
66 else if(iSize > rcSize || iSize > lcSize){
79 //get score for all users groups
80 for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
81 if (tmap->namesOfGroups[i] != "xxx") {
82 groups.push_back(tmap->namesOfGroups[i]);
86 for (int i = 0; i < globaldata->Groups.size(); i++) {
87 groups.push_back(globaldata->Groups[i]);
91 //copy users tree so that you can redo pgroups
95 //create pgroups that reflect the groups the user want to use
96 for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
97 copyTree->tree[i].pGroups = (copyTree->mergeUserGroups(i, groups));
100 // map<string,int>::iterator it;
102 for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
104 if (m->control_pressed) { return data; }
106 int lc = copyTree->tree[i].getLChild();
107 int rc = copyTree->tree[i].getRChild();
109 int iSize = copyTree->tree[i].pGroups.size();
110 int rcSize = copyTree->tree[rc].pGroups.size();
111 int lcSize = copyTree->tree[lc].pGroups.size();
114 //if isize are 0 then that branch is to be ignored
116 else if ((rcSize == 0) || (lcSize == 0)) { }
117 //if you have more groups than either of your kids then theres been a change.
118 else if(iSize > rcSize || iSize > lcSize){
131 catch(exception& e) {
132 m->errorOut(e, "Parsimony", "getValues");
137 /**************************************************************************************************/