]> git.donarmstrong.com Git - mothur.git/commitdiff
worked on unifrac.unweighted()
authorwestcott <westcott>
Mon, 2 Mar 2009 16:01:29 +0000 (16:01 +0000)
committerwestcott <westcott>
Mon, 2 Mar 2009 16:01:29 +0000 (16:01 +0000)
tree.cpp
tree.h
unifracunweightedcommand.cpp
unweighted.cpp

index 5029438b6e632e0274f88dca33ba121ec238bf26..642c6658739dd5252b2d61083ce6af2b872785ec 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -303,12 +303,9 @@ map<string,int> Tree::mergeGcounts(int position) {
 }
 /**************************************************************************************************/
 
-void Tree::randomLabels() {
+void Tree::randomLabels(vector<string> g) {
        try {
                
-               //set up the groups the user wants to include
-               setGroups();
-               
                for(int i = 0; i < numLeaves; i++){
                        int z;
                        //get random index to switch with
@@ -318,8 +315,8 @@ void Tree::randomLabels() {
                        //if either of the leaf nodes you are about to switch are not in the users groups then you don't want to switch them.
                        bool treez, treei;
                
-                       treez = inUsersGroups(tree[z].getGroup(), globaldata->Groups);
-                       treei = inUsersGroups(tree[i].getGroup(), globaldata->Groups);
+                       treez = inUsersGroups(tree[z].getGroup(), g);
+                       treei = inUsersGroups(tree[i].getGroup(), g);
                        
                        if ((treez == true) && (treei == true)) {
                                //switches node i and node z's info.
@@ -405,8 +402,8 @@ void Tree::randomBlengths()  {
        }               
 }
 /*************************************************************************************************/
-void Tree::assembleRandomUnifracTree() {
-       randomLabels();
+void Tree::assembleRandomUnifracTree(vector<string> g) {
+       randomLabels(g);
        assembleTree();
 }
 /*************************************************************************************************/
@@ -538,46 +535,6 @@ void Tree::printBranch(int node) {
 
 /*****************************************************************/
 
-void Tree::setGroups() {
-       try {
-               //if the user has not entered specific groups to analyze then do them all
-               if (globaldata->Groups.size() != 0) {
-                       //check that groups are valid
-                       for (int i = 0; i < globaldata->Groups.size(); i++) {
-                               if (globaldata->gTreemap->isValidGroup(globaldata->Groups[i]) != true) {
-                                       cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
-                                       // erase the invalid group from globaldata->Groups
-                                       globaldata->Groups.erase (globaldata->Groups.begin()+i);
-                               }
-                       }
-                       
-                       //if the user only entered invalid groups
-                       if (globaldata->Groups.size() == 0) { 
-                               cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile." << endl; 
-                               for (int i = 0; i < globaldata->gTreemap->namesOfGroups.size(); i++) {
-                                       globaldata->Groups.push_back(globaldata->gTreemap->namesOfGroups[i]);
-                               }
-                       }
-                                       
-               }else {
-                       for (int i = 0; i < globaldata->gTreemap->namesOfGroups.size(); i++) {
-                               globaldata->Groups.push_back(globaldata->gTreemap->namesOfGroups[i]);
-                       }
-               }
-       }
-       catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the Tree class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the Tree class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }               
-
-}
-
-/*****************************************************************/
-
 void Tree::printTree() {
        
        for(int i=0;i<numNodes;i++){
diff --git a/tree.h b/tree.h
index 733f3a082a87525dc1db339ccd5f983b9f2c4206..d6a3b556f09ca251a2cbad64e07c0187dd50e6b4 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -25,7 +25,7 @@ public:
        
        void getCopy(Tree*);  //makes tree a copy of the one passed in.
        void assembleRandomTree();
-       void assembleRandomUnifracTree();
+       void assembleRandomUnifracTree(vector<string>);
        void assembleRandomUnifracTree(string, string);
        void createNewickFile(string);
        int getIndex(string);
@@ -51,11 +51,10 @@ private:
        map<string,int> Tree::mergeGcounts(int);
        void randomTopology();
        void randomBlengths();
-       void randomLabels();
+       void randomLabels(vector<string>);
        void randomLabels(string, string);
        int findRoot();  //return index of root node
        void printBranch(int);  //recursively print out tree
-       void setGroups();
 };
 
 #endif
index c345ca16bc478ee9635846c54abb8ab68ec67b69..f1326a82ca524a396f102bdeb8fa53f7264d971f 100644 (file)
@@ -85,24 +85,21 @@ int UnifracUnweightedCommand::execute() {
                        
                        //get unweighted scores for random trees
                        for (int j = 0; j < iters; j++) {
-                               int count = 0;
-                               for (int r=0; r<numGroups; r++) { 
-                                       for (int l = r+1; l < numGroups; l++) {
-                                               //we need a different getValues because when we swap the labels we only want to swap those in each parwise comparison
-                                               randomData = unweighted->getValues(randT, "", "");
-                       
-                                               //add trees unweighted score to map of scores
-                                               it2 = rscoreFreq[count].find(randomData[count]);
-                                               if (it2 != rscoreFreq[count].end()) {//already have that score
-                                                       rscoreFreq[count][randomData[count]]++;
-                                               }else{//first time we have seen this score
-                                                       rscoreFreq[count][randomData[count]] = 1;
-                                               }
+                               //we need a different getValues because when we swap the labels we only want to swap those in each parwise comparison
+                               randomData = unweighted->getValues(randT, "", "");
                                
-                                               //add randoms score to validscores
-                                               validScores[count][randomData[count]] = randomData[count];
-                                               count++;
+                               for(int k = 0; k < numComp; k++) {      
+cout << "iter " << j << " comp " << k << " = " << randomData[k] << endl;
+                                       //add trees unweighted score to map of scores
+                                       it2 = rscoreFreq[k].find(randomData[k]);
+                                       if (it2 != rscoreFreq[k].end()) {//already have that score
+                                               rscoreFreq[k][randomData[k]]++;
+                                       }else{//first time we have seen this score
+                                               rscoreFreq[k][randomData[k]] = 1;
                                        }
+                               
+                                       //add randoms score to validscores
+                                       validScores[k][randomData[k]] = randomData[k];
                                }
                        }
                
@@ -235,7 +232,7 @@ void UnifracUnweightedCommand::setGroups() {
                                        }
                                }else {
                                        for (int i = 0; i < globaldata->Groups.size(); i++) {
-                                               allGroups += tmap->namesOfGroups[i];
+                                               allGroups += globaldata->Groups[i];
                                                numGroups++;
                                        }
                                }
index b038f388af1c3ef027c66339523ce8bc87b55661..16a2203274f325ffc8d8b5febfea903597340093 100644 (file)
@@ -205,7 +205,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) {
 
                //if the users enters no groups then give them the score of all groups
                int numGroups = globaldata->Groups.size();
-               
+cout << "NumGroups = " << numGroups << endl;
                //calculate number of comparsions
                int numComp = 0;
                for (int r=0; r<numGroups; r++) { 
@@ -227,12 +227,13 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) {
                                
                                //copy random tree passed in
                                copyTree->getCopy(t);
-                               
-                               //swap labels in the groups you want to compare
-                               copyTree->assembleRandomUnifracTree(globaldata->Groups[a], globaldata->Groups[l]);
-                               
+                                                               
                                //groups in this combo
                                groups.push_back(globaldata->Groups[a]); groups.push_back(globaldata->Groups[l]);
+                               
+                               //swap labels in the groups you want to compare
+                               copyTree->assembleRandomUnifracTree(groups[0], groups[1]);
+
                
                                for(int i=t->getNumLeaves();i<t->getNumNodes();i++){
                
@@ -312,7 +313,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) {
                        copyTree->getCopy(t);
                                
                        //swap labels in all the groups you want to compare
-                       copyTree->assembleRandomUnifracTree();
+                       copyTree->assembleRandomUnifracTree(groups);
 
                        for(int i=t->getNumLeaves();i<t->getNumNodes();i++){