]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed some bugs and added scriptengine
authorwestcott <westcott>
Tue, 16 Jun 2009 19:01:09 +0000 (19:01 +0000)
committerwestcott <westcott>
Tue, 16 Jun 2009 19:01:09 +0000 (19:01 +0000)
engine.cpp
engine.hpp
mothur.cpp
parselistcommand.cpp
readotucommand.cpp
readtreecommand.cpp
tree.cpp
treegroupscommand.cpp

index df65678912b1f3bd112e630b13ef934eebc5e219..03422e20790a96159eaa68ad569ae4a15a5d94aa 100644 (file)
@@ -103,6 +103,7 @@ bool InteractEngine::getInput(){
 BatchEngine::BatchEngine(string path, string batchFileName){
        try {
                globaldata = GlobalData::getInstance();
+       
                openedBatch = openInputFile(batchFileName, inputBatchFile);
                globaldata->argv = path;
 
@@ -140,6 +141,7 @@ bool BatchEngine::getInput(){
                string input = "";
                string commandName = "";
                string options = "";
+               //int count = 1;
                
                //CommandFactory cFactory;
                int quitCommandCalled = 0;
@@ -149,6 +151,8 @@ bool BatchEngine::getInput(){
                        if (inputBatchFile.eof()) { input = "quit()"; }
                        else { getline(inputBatchFile, input); }
                        
+                       //cout << "command number" << count << endl; count++;
+                       
                        if (input[0] != '#') {
                        
                                cout << endl << "mothur > " << input << endl;
@@ -185,4 +189,112 @@ bool BatchEngine::getInput(){
 
 
 /***********************************************************************/
+/***********************************************************************/
+//This function opens the batchfile to be used by BatchEngine::getInput.
+ScriptEngine::ScriptEngine(string path, string commandString){
+       try {
+               globaldata = GlobalData::getInstance();
+               
+               //remove quotes
+               listOfCommands = commandString.substr(1, (commandString.length()-1));
+
+               globaldata->argv = path;
 
+               system("clear");
+       
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ScriptEngine class Function ScriptEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ScriptEngine class function ScriptEngine. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+
+/***********************************************************************/
+
+ScriptEngine::~ScriptEngine(){
+       }
+
+/***********************************************************************/
+//This Function allows the user to run a batchfile containing several commands on Dotur
+bool ScriptEngine::getInput(){
+       try {
+                       
+               string input = "";
+               string commandName = "";
+               string options = "";
+               //int count = 1;
+               
+               //CommandFactory cFactory;
+               int quitCommandCalled = 0;
+       
+               while(quitCommandCalled == 0){
+               
+                       input = getNextCommand(listOfCommands); 
+                       
+                       if (input == "") { input = "quit()"; }
+                       //cout << "command number" << count << endl; count++;
+                       
+                       cout << endl << "mothur > " << input << endl;
+                               
+                       //allow user to omit the () on the quit command
+                       if (input == "quit") { input = "quit()"; }
+
+                       CommandOptionParser parser(input);
+                       commandName = parser.getCommandString();
+                       options = parser.getOptionString();
+                                                                               
+                       if (commandName != "") {
+
+                               //executes valid command
+                               CommandFactory cFactory;
+                               Command* command = cFactory.getCommand(commandName, options);
+                               quitCommandCalled = command->execute();
+                       }else {         cout << "Invalid." << endl;             }
+                       
+               }
+               
+               return 1;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ScriptEngine class Function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ScriptEngine class function getInput. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
+string ScriptEngine::getNextCommand(string& commandString) {
+       try {
+               string nextcommand = "";
+               
+               nextcommand = commandString.substr(0,commandString.find_first_of(';'));
+
+                               
+               if ((commandString.find_first_of(';')+1) <= commandString.length()) {
+                       commandString = commandString.substr(commandString.find_first_of(';')+1, commandString.length());
+               }else { commandString = ""; } //you have reached the last command.
+               
+               //get rid of any extra spaces in between commands
+               //string space = " ";
+               
+               //while(commandString.at(0) == ' ')
+                       //commandString = commandString.substr(1, commandString.length());
+                       
+               return nextcommand;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the ScriptEngine class Function getNextCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the ScriptEngine class function getNextCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
+/***********************************************************************/
\ No newline at end of file
index d169905b54d5364a6e4819b109372c708513defd..603ff0a1c65fa528439b7a8f456991ae600c26ef 100644 (file)
@@ -57,4 +57,18 @@ private:
 };
 
 
+class ScriptEngine : public Engine {
+public:
+       ScriptEngine(string, string);
+       ~ScriptEngine();
+       virtual bool getInput();
+       int openedBatch;
+private:
+       GlobalData* globaldata;
+       string listOfCommands;
+       string getNextCommand(string&);
+
+};
+
+
 #endif
index 8d0e507a8f35bc7d9ee8664765194c546d736c1b..59837dd72d7dc8dbe76ee3125052461a9e7b580a 100644 (file)
@@ -22,9 +22,16 @@ int main(int argc, char *argv[]){
 
                Engine* mothur;
                bool bail = 0;
+               string input;
 
                if(argc>1){
-                       mothur = new BatchEngine(argv[0], argv[1]);
+                       input = argv[1];
+
+                       if (input[0] == '#') {
+                               mothur = new ScriptEngine(argv[0], argv[1]);
+                       }else{
+                               mothur = new BatchEngine(argv[0], argv[1]);
+                       }
                }
                else{
                        mothur = new InteractEngine(argv[0]);           
index 5de3b72daa63b962ff9be84b5665e7230fb2470b..332074d14ee990c00e6a444e235af111121d778d 100644 (file)
@@ -15,7 +15,8 @@ ParseListCommand::ParseListCommand(){
                globaldata = GlobalData::getInstance();
                
                //read in group map info.
-               groupMap = globaldata->gGroupmap;
+               groupMap = new GroupMap(globaldata->getGroupFile());
+               groupMap->readMap();
 
                //fill filehandles with neccessary ofstreams
                int i;
index ba7eae42a668e7fa9bf3a9f8d33c4746b55ce810..2df74e4e6c3283db6808754ede700c66d9c56b6e 100644 (file)
@@ -64,6 +64,7 @@ ReadOtuCommand::ReadOtuCommand(string option){
                                globaldata->setGroupFile(groupfile); 
                                groupMap = new GroupMap(groupfile);
                                groupMap->readMap();
+                               globaldata->gGroupmap = groupMap;
                        }
 
                        //you are doing a list and group shared
@@ -168,10 +169,7 @@ int ReadOtuCommand::execute(){
                
                //read->read(&*globaldata); 
                if (globaldata->getFormat() == "shared") {
-                       groupMap->readMap();
-                       
-                       //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap;  }
-                       globaldata->gGroupmap = groupMap;
+                       //groupMap->readMap();
                        
                        parselist = new ParseListCommand();
                        parselist->execute();
index b030542ef8f7e5933f2bf32c4c6bf6ba9e051ee0..88e34ff5c7e3f2c243eb7e0dac56b7d11fcb39b4 100644 (file)
@@ -33,6 +33,7 @@ ReadTreeCommand::ReadTreeCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       globaldata->runParse = true;
                        globaldata->newRead();
                        
                        //check for required parameters
index 656d4ccb6051793053ab1db194195688b913903f..c078f4f0728f0f35a9f2bc75f6174fb3eef38979 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -495,6 +495,7 @@ void Tree::createNewickFile(string f) {
                int root = findRoot();
                //filename = getRootName(globaldata->getTreeFile()) + "newick";
                filename = f;
+
                openOutputFile(filename, out);
                
                printBranch(root, out, "branch");
index 484b5536ec668fbf60b94cba6ae5244570d2f111..0f106c493d1d55f7e742ed1195e1557f435d6e49 100644 (file)
@@ -66,7 +66,7 @@ TreeGroupCommand::TreeGroupCommand(string option){
                        else if (namefile == "not found") { namefile = ""; }
                        else {  globaldata->setNameFile(namefile);      }
                        
-//                     format = globaldata->getFormat();
+                       format = globaldata->getFormat();
                        
                        //error checking on files                       
                        if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == "")))  { cout << "You must run the read.otu command or provide a distance file before running the tree.shared command." << endl; abort = true; }
@@ -234,6 +234,8 @@ int TreeGroupCommand::execute(){
                        
                        if (lookup.size() < 2) { cout << "You have not provided enough valid groups.  I cannot run the command." << endl; return 0; }
                
+                       globaldata->runParse = false;
+                       
                        //create tree file
                        makeSimsShared();
                }else{
@@ -269,7 +271,9 @@ int TreeGroupCommand::execute(){
                
                        //fills globaldatas tree names
                        globaldata->Treenames = globaldata->Groups;
-
+                       
+                       globaldata->runParse = false;
+                       
                        makeSimsDist();
 
                        //create a new filename
@@ -562,7 +566,7 @@ void TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                                        }
                                                }
                                        }
-                                       
+                               
                                        //creates tree from similarity matrix and write out file
                                        createTree();
                                }