]> git.donarmstrong.com Git - mothur.git/blobdiff - parsimony.cpp
changed unifrac.weighted()
[mothur.git] / parsimony.cpp
index 2a673b0cb622bd97b8f91dc4f1c2e9c69de19e8d..da8412ce71d590fe57366fb453126db00ff0f715 100644 (file)
@@ -17,50 +17,34 @@ EstOutput Parsimony::getValues(Tree* t) {
                data.resize(1,0);
                        
                int score = 0;
-                       
+               
+               //create pgroups that reflect the groups the user want to use
+               for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
+                       t->tree[i].pGroups = (t->mergeUserGroups(i));
+               }
+               
                for(int i=t->getNumLeaves();i<t->getNumNodes();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++;  }
-                       }
-
-                       //if that leaves no groups give it 1 so it will cause no change to parent
-                       if (iSize == 0) { iSize++; }
-                       
-                       //add in all the groups the users wanted
-                       for (it = t->tree[rc].pGroups.begin(); it != t->tree[rc].pGroups.end(); it++) {
-
-                               if (inUsersGroups(it->first) == true) {  rcSize++;  }
-                       }
-                       
-                       //if that leaves no groups give it 1 so it will cause no change to parent
-                       if (rcSize == 0) { rcSize++; }
-
-                               
-                       //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++;  }
-                       }
-                       
-                       //if that leaves no groups give it 1 so it will cause no change to parent
-                       if (lcSize == 0) { lcSize++; }
-
-
+                       int iSize = t->tree[i].pGroups.size();
+                       int rcSize = t->tree[rc].pGroups.size();
+                       int lcSize = t->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.
-                        if(iSize > rcSize || iSize > lcSize){
+                       else if(iSize > rcSize || iSize > lcSize){
                                score++;
-
                        }
+                       cout << i << ' ' << score << ": ";
+                       t->tree[i].printNode();
                } 
                
+               //string hold;
+               //cin >> hold;
+               
                data[0] = score;
                
                return data;
@@ -75,22 +59,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);
-       }
-}
 /**************************************************************************************************/
+