X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parsimony.cpp;h=0487822764bbf36e11da5bd8faada1bba34a63c4;hb=b8f3e71c8a0310e25261464d27e6fcfe891483b0;hp=93efe2858aba11e852bd716f365bc653beea8b0d;hpb=0190105145fbd3e02da8f23cb50841229e5d696f;p=mothur.git diff --git a/parsimony.cpp b/parsimony.cpp index 93efe28..0487822 100644 --- a/parsimony.cpp +++ b/parsimony.cpp @@ -10,54 +10,128 @@ #include "parsimony.h" /**************************************************************************************************/ + EstOutput Parsimony::getValues(Tree* t) { try { globaldata = GlobalData::getInstance(); + vector groups; + + copyTree = new Tree(); + + //if the users enters no groups then give them the score of all groups + int numGroups = globaldata->Groups.size(); - data.resize(1,0); + //calculate number of comparsions + int numComp = 0; + for (int r=0; rGroups[a]); groups.push_back(globaldata->Groups[l]); + + //copy users tree so that you can redo pgroups + copyTree->getCopy(t); + + //create pgroups that reflect the groups the user want to use + for(int i=copyTree->getNumLeaves();igetNumNodes();i++){ + copyTree->tree[i].pGroups = (copyTree->mergeUserGroups(i, groups)); + } + + for(int i=copyTree->getNumLeaves();igetNumNodes();i++){ + + if (m->control_pressed) { return data; } + + int lc = copyTree->tree[i].getLChild(); + int rc = copyTree->tree[i].getRChild(); - int score = 0; + int iSize = copyTree->tree[i].pGroups.size(); + int rcSize = copyTree->tree[rc].pGroups.size(); + int lcSize = copyTree->tree[lc].pGroups.size(); - //create pgroups that reflect the groups the user want to use - for(int i=t->getNumLeaves();igetNumNodes();i++){ - t->tree[i].pGroups = (t->mergeUserGroups(i)); + //if isize are 0 then that branch is to be ignored + if (iSize == 0) { } + else if ((rcSize == 0) || (lcSize == 0)) { } + //if you have more groups than either of your kids then theres been a change. + else if(iSize > rcSize || iSize > lcSize){ + score++; + } + } + + data[count] = score; + count++; + groups.clear(); + } } - //hjkl - for(int i=t->getNumLeaves();igetNumNodes();i++){ - int lc = t->tree[i].getLChild(); - int rc = t->tree[i].getRChild(); + + if (numComp != 1) { + if (numGroups == 0) { + //get score for all users groups + for (int i = 0; i < tmap->namesOfGroups.size(); i++) { + if (tmap->namesOfGroups[i] != "xxx") { + groups.push_back(tmap->namesOfGroups[i]); + } + } + }else { + for (int i = 0; i < globaldata->Groups.size(); i++) { + groups.push_back(globaldata->Groups[i]); + } + } - int iSize = t->tree[i].pGroups.size(); - int rcSize = t->tree[rc].pGroups.size(); - int lcSize = t->tree[lc].pGroups.size(); + //copy users tree so that you can redo pgroups + copyTree->getCopy(t); + int score = 0; - //if isize are 0 then that branch is to be ignored - if (iSize == 0) { } - else if ((rcSize == 0) || (lcSize == 0)) { } - //if you have more groups than either of your kids then theres been a change. - else if(iSize > rcSize || iSize > lcSize){ - score++; + //create pgroups that reflect the groups the user want to use + for(int i=copyTree->getNumLeaves();igetNumNodes();i++){ + copyTree->tree[i].pGroups = (copyTree->mergeUserGroups(i, groups)); } - cout << i << ' ' << score << ": "; - t->tree[i].printNode(); - } - string hold; - cin >> hold; +// map::iterator it; + + for(int i=copyTree->getNumLeaves();igetNumNodes();i++){ + + if (m->control_pressed) { return data; } + + int lc = copyTree->tree[i].getLChild(); + int rc = copyTree->tree[i].getRChild(); + + int iSize = copyTree->tree[i].pGroups.size(); + int rcSize = copyTree->tree[rc].pGroups.size(); + int lcSize = copyTree->tree[lc].pGroups.size(); + + + //if isize are 0 then that branch is to be ignored + if (iSize == 0) { } + else if ((rcSize == 0) || (lcSize == 0)) { } + //if you have more groups than either of your kids then theres been a change. + else if(iSize > rcSize || iSize > lcSize){ + score++; + } + } + + data[count] = score; + + } - data[0] = score; + delete copyTree; return data; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Parsimony class Function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "Parsimony", "getValues"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the Parsimony class function getValues. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - } /**************************************************************************************************/