X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parsimony.cpp;h=9a8706e82499fb80f9c2a55d61bc92c7b2399839;hb=d873f7bf94309317a08c8757e0d0d60b06fbd473;hp=2a673b0cb622bd97b8f91dc4f1c2e9c69de19e8d;hpb=692e0c1f69a78b568dc85cbdcea9fb6c189e2e6c;p=mothur.git diff --git a/parsimony.cpp b/parsimony.cpp index 2a673b0..9a8706e 100644 --- a/parsimony.cpp +++ b/parsimony.cpp @@ -10,58 +10,125 @@ #include "parsimony.h" /**************************************************************************************************/ + EstOutput Parsimony::getValues(Tree* t) { try { globaldata = GlobalData::getInstance(); + vector groups; - data.resize(1,0); - - int score = 0; - - for(int i=t->getNumLeaves();igetNumNodes();i++){ - int lc = t->tree[i].getLChild(); - int rc = t->tree[i].getRChild(); - - int iSize = 0; - int rcSize = 0; - int lcSize = 0; - - //add in all the groups the users wanted - for (it = t->tree[i].pGroups.begin(); it != t->tree[i].pGroups.end(); it++) { - if (inUsersGroups(it->first) == true) { iSize++; } + copyTree = new Tree(); + + //if the users enters no groups then give them the score of all groups + int numGroups = globaldata->Groups.size(); + + //calculate number of comparsions + int numComp = 0; + for (int r=0; rtree[rc].pGroups.begin(); it != t->tree[rc].pGroups.end(); it++) { + //numComp+1 for AB, AC, BC, ABC + data.resize(numComp+1,0); + + int count = 0; + for (int a=0; aGroups[a]); groups.push_back(globaldata->Groups[l]); + + //copy users tree so that you can redo pgroups + copyTree->getCopy(t); - if (inUsersGroups(it->first) == true) { rcSize++; } - } + //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++){ + int lc = copyTree->tree[i].getLChild(); + int rc = copyTree->tree[i].getRChild(); - //if that leaves no groups give it 1 so it will cause no change to parent - if (rcSize == 0) { rcSize++; } - + 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++; + } + } - //add in all the groups the users wanted - for (it = t->tree[lc].pGroups.begin(); it != t->tree[lc].pGroups.end(); it++) { - - if (inUsersGroups(it->first) == true) { lcSize++; } + data[count] = score; + count++; + groups.clear(); + } + } + + 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]); + } } - //if that leaves no groups give it 1 so it will cause no change to parent - if (lcSize == 0) { lcSize++; } - - - //if you have more groups than either of your kids then theres been a change. - if(iSize > rcSize || iSize > lcSize){ - score++; - + //copy users tree so that you can redo pgroups + copyTree->getCopy(t); + int score = 0; + + //create pgroups that reflect the groups the user want to use + for(int i=copyTree->getNumLeaves();igetNumNodes();i++){ +// cout << i << "..." << endl; + copyTree->tree[i].pGroups = (copyTree->mergeUserGroups(i, groups)); } - } - data[0] = score; +// map::iterator it; + + for(int i=copyTree->getNumLeaves();igetNumNodes();i++){ + 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(); + +// cout << i+1 << '\t' << lc+1 << '\t' << rc+1 << ":\t"; + +// for(it=copyTree->tree[i].pGroups.begin();it!=copyTree->tree[i].pGroups.end();it++){ +// cout << it->first << '\t'; +// } + +// cout << " : " << iSize << '\t' << rcSize << '\t' << lcSize << '\t'; + + //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++; + } +// cout << score << endl; + } + + data[count] = score; + string hold; +// cin >> hold; + } + + delete copyTree; return data; } @@ -75,22 +142,6 @@ EstOutput Parsimony::getValues(Tree* t) { } } -/**************************************************************************************************/ -bool Parsimony::inUsersGroups(string groupname) { - try { - for (int i = 0; i < globaldata->Groups.size(); i++) { - if (groupname == globaldata->Groups[i]) { return true; } - } - return false; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Parsimony class Function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the Parsimony class function inUsersGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} /**************************************************************************************************/ +