]> git.donarmstrong.com Git - mothur.git/blobdiff - readtreecommand.cpp
changes to read.tree
[mothur.git] / readtreecommand.cpp
index 1762983a148af80403eb66b68bd2834f703a84d8..0a86f36dfdced49cb6151205e82c0372556e1209 100644 (file)
@@ -44,7 +44,7 @@ ReadTreeCommand::ReadTreeCommand(string option)  {
                                it = parameters.find("tree");
                                //user has given a template file
                                if(it != parameters.end()){ 
-                                       path = hasPath(it->second);
+                                       path = m->hasPath(it->second);
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["tree"] = inputDir + it->second;             }
                                }
@@ -52,7 +52,7 @@ ReadTreeCommand::ReadTreeCommand(string option)  {
                                it = parameters.find("group");
                                //user has given a template file
                                if(it != parameters.end()){ 
-                                       path = hasPath(it->second);
+                                       path = m->hasPath(it->second);
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["group"] = inputDir + it->second;            }
                                }
@@ -60,7 +60,7 @@ ReadTreeCommand::ReadTreeCommand(string option)  {
                                it = parameters.find("name");
                                //user has given a template file
                                if(it != parameters.end()){ 
-                                       path = hasPath(it->second);
+                                       path = m->hasPath(it->second);
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["name"] = inputDir + it->second;             }
                                }
@@ -108,8 +108,10 @@ void ReadTreeCommand::help(){
        try {
                m->mothurOut("The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. \n");
                m->mothurOut("It also must be run before using the parsimony command, unless you are using the randomtree parameter.\n");
+               m->mothurOut("The read.tree command parameters are tree, group and name.\n");
                m->mothurOut("The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n");
                m->mothurOut("The tree and group parameters are both required.\n");
+               m->mothurOut("The name parameter allows you to enter a namefile.\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n");
        }
        catch(exception& e) {
@@ -147,42 +149,50 @@ int ReadTreeCommand::execute(){
                                delete globaldata->gTreemap;
                                return 0;
                        }
-                       
+       
                        T[i]->assembleTree();
                }
 
+               
+//             Sarah, isn't this checking already done when assigning the sequences to the groups?  it makes read.tree
+//             wicked slow...  For some reason my tree is coming in here eventhough the number of sequences in the tree
+//             agrees with the number of lines in the name file and the number of sequences represented by the name file
+//             agrees with the number of sequences in the group file
+
                //output any names that are in group file but not in tree
-               if (globaldata->Treenames.size() < treeMap->getNumSeqs()) {
-                       for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) {
-                               //is that name in the tree?
-                               int count = 0;
-                               for (int j = 0; j < globaldata->Treenames.size(); j++) {
-                                       if (treeMap->namesOfSeqs[i] == globaldata->Treenames[j]) { break; } //found it
-                                       count++;
-                               }
-                               
-                               if (m->control_pressed) {  
-                                       for (int i = 0; i < T.size(); i++) {  delete T[i];  }
-                                       globaldata->gTree.clear();
-                                       delete globaldata->gTreemap;
-                                       return 0;
-                               }
-                               
-                               //then you did not find it so report it 
-                               if (count == globaldata->Treenames.size()) { 
-                                       //if it is in your namefile then don't remove
-                                       map<string, string>::iterator it = nameMap.find(treeMap->namesOfSeqs[i]);
-                                       
-                                       if (it == nameMap.end()) {
-                                               m->mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine();
-                                               treeMap->removeSeq(treeMap->namesOfSeqs[i]);
-                                               i--; //need this because removeSeq removes name from namesOfSeqs
-                                       }
-                               }
-                       }
-                       
-                       globaldata->gTreemap = treeMap;
-               }
+               
+//             if (globaldata->Treenames.size() < treeMap->getNumSeqs()) {
+//                     cout << "in here" << endl;
+//                     for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) {
+//                             //is that name in the tree?
+//                             int count = 0;
+//                             for (int j = 0; j < globaldata->Treenames.size(); j++) {
+//                                     if (treeMap->namesOfSeqs[i] == globaldata->Treenames[j]) { break; } //found it
+//                                     count++;
+//                             }
+//                             
+//                             if (m->control_pressed) {  
+//                                     for (int i = 0; i < T.size(); i++) {  delete T[i];  }
+//                                     globaldata->gTree.clear();
+//                                     delete globaldata->gTreemap;
+//                                     return 0;
+//                             }
+//                             
+//                             //then you did not find it so report it 
+//                             if (count == globaldata->Treenames.size()) { 
+//                                     //if it is in your namefile then don't remove
+//                                     map<string, string>::iterator it = nameMap.find(treeMap->namesOfSeqs[i]);
+//                                     
+//                                     if (it == nameMap.end()) {
+//                                             m->mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine();
+//                                             treeMap->removeSeq(treeMap->namesOfSeqs[i]);
+//                                             i--; //need this because removeSeq removes name from namesOfSeqs
+//                                     }
+//                             }
+//                     }
+//                     
+//                     globaldata->gTreemap = treeMap;
+//             }
                
                return 0;
        }
@@ -197,13 +207,13 @@ int ReadTreeCommand::readNamesFile() {
                globaldata->names.clear();
                
                ifstream in;
-               openInputFile(namefile, in);
+               m->openInputFile(namefile, in);
                
                string first, second;
                map<string, string>::iterator itNames;
                
                while(!in.eof()) {
-                       in >> first >> second; gobble(in);
+                       in >> first >> second; m->gobble(in);
                        
                        itNames = globaldata->names.find(first);
                        if (itNames == globaldata->names.end()) {  
@@ -211,7 +221,7 @@ int ReadTreeCommand::readNamesFile() {
                                
                                //we need a list of names in your namefile to use above when removing extra seqs above so we don't remove them
                                vector<string> dupNames;
-                               splitAtComma(second, dupNames);
+                               m->splitAtComma(second, dupNames);
                                
                                for (int i = 0; i < dupNames.size(); i++) {     nameMap[dupNames[i]] = dupNames[i];  }
                        }else {  m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); return 1; }