]> git.donarmstrong.com Git - mothur.git/blobdiff - readtreecommand.cpp
bugs fixes while testing for 1.5 release
[mothur.git] / readtreecommand.cpp
index 6e5742ddbbc35cdc6d01b9d57b3d58a8c7856816..0f07ac2f6d66bb1e68c322f74ddfc326b9d3f47e 100644 (file)
@@ -23,27 +23,27 @@ ReadTreeCommand::ReadTreeCommand(string option){
                        string Array[] =  {"tree","group"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
-                       parser = new OptionParser();
-                       parser->parse(option, parameters);  delete parser;
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
                        
-                       ValidParameters* validParameter = new ValidParameters();
+                       ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (it = parameters.begin(); it != parameters.end(); it++) { 
-                               if (validParameter->isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        globaldata->newRead();
                        
                        //check for required parameters
-                       treefile = validParameter->validFile(parameters, "tree", true);
+                       treefile = validParameter.validFile(parameters, "tree", true);
                        if (treefile == "not open") { abort = true; }
-                       else if (treefile == "not found") { treefile = ""; cout << "tree is a required parameter for the read.tree command." << endl; abort = true;  }  
+                       else if (treefile == "not found") { treefile = ""; mothurOut("tree is a required parameter for the read.tree command."); mothurOutEndLine(); abort = true;  }   
                        else {  globaldata->setTreeFile(treefile);  globaldata->setFormat("tree");      }
                        
-                       groupfile = validParameter->validFile(parameters, "group", true);
+                       groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }  
-                       else if (groupfile == "not found") { groupfile = ""; cout << "group is a required parameter for the read.tree command." << endl; abort = true;  }
+                       else if (groupfile == "not found") { groupfile = ""; mothurOut("group is a required parameter for the read.tree command."); mothurOutEndLine(); abort = true;   }
                        else {  
                                globaldata->setGroupFile(groupfile); 
                                //read in group map info.
@@ -57,15 +57,10 @@ ReadTreeCommand::ReadTreeCommand(string option){
                                read = new ReadNewickTree(filename);
                        }
                                                
-                       delete validParameter;
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function ReadTreeCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ReadTreeCommand class function ReadTreeCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ReadTreeCommand", "ReadTreeCommand");              
                exit(1);
        }
 }
@@ -73,26 +68,22 @@ ReadTreeCommand::ReadTreeCommand(string option){
 
 void ReadTreeCommand::help(){
        try {
-               cout << "The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. " << "\n";
-               cout << "It also must be run before using the parsimony command, unless you are using the randomtree parameter." << "\n";
-               cout << "The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile)." << "\n";
-               cout << "The tree and group parameters are both required." << "\n";
-               cout << "Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile)." << "\n" << "\n";
+               mothurOut("The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. \n");
+               mothurOut("It also must be run before using the parsimony command, unless you are using the randomtree parameter.\n");
+               mothurOut("The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n");
+               mothurOut("The tree and group parameters are both required.\n");
+               mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n");
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ReadTreeCommand", "help"); 
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the ReadTreeCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 //**********************************************************************************************************************
 
 ReadTreeCommand::~ReadTreeCommand(){
-       delete read;
+       if (abort == false) { delete read; }
 }
 
 //**********************************************************************************************************************
@@ -106,10 +97,10 @@ int ReadTreeCommand::execute(){
                
                readOk = read->read(); 
                
-               if (readOk != 0) { cout << "Read Terminated." << endl; globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; }
+               if (readOk != 0) { mothurOut("Read Terminated."); mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; }
                
                vector<Tree*> T = globaldata->gTree;
-               
+
                //assemble users trees
                for (int i = 0; i < T.size(); i++) {
                        T[i]->assembleTree();
@@ -127,7 +118,8 @@ int ReadTreeCommand::execute(){
                                
                                //then you did not find it so report it 
                                if (count == globaldata->Treenames.size()) { 
-                                       cout << treeMap->namesOfSeqs[i] << " is in your namefile and not in your tree. It will be disregarded." << endl;
+                                       mothurOut(treeMap->namesOfSeqs[i] + " is in your namefile and not in your tree. It will be disregarded."); mothurOutEndLine();
+                                       treeMap->removeSeq(treeMap->namesOfSeqs[i]);
                                }
                        }
                }
@@ -135,11 +127,7 @@ int ReadTreeCommand::execute(){
                return 0;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the ReadTreeCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the ReadTreeCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "ReadTreeCommand", "execute");      
                exit(1);
        }
 }