]> git.donarmstrong.com Git - mothur.git/blobdiff - collectsharedcommand.cpp
fixed some bugs and added scriptengine
[mothur.git] / collectsharedcommand.cpp
index 2b6cbacd2afed90b8a23674c49171da9654a6033..6127c2d6da7717112fb2c7fdb5c82910f03f8323 100644 (file)
@@ -44,6 +44,7 @@ CollectSharedCommand::CollectSharedCommand(string option){
                lines.clear();
                labels.clear();
                Estimators.clear();
+               Groups.clear();
                
                //allow user to run help
                if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; }
@@ -53,14 +54,14 @@ CollectSharedCommand::CollectSharedCommand(string option){
                        string Array[] =  {"freq","line","label","calc","groups"};
                        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;  }
                        }
                        
                        //make sure the user has already run the read.otu command
@@ -72,14 +73,14 @@ CollectSharedCommand::CollectSharedCommand(string option){
                        
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
-                       line = validParameter->validFile(parameters, "line", false);                            
+                       line = validParameter.validFile(parameters, "line", false);                             
                        if (line == "not found") { line = "";  }
                        else { 
                                if(line != "all") {  splitAtDash(line, lines);  allLines = 0;  }
                                else { allLines = 1;  }
                        }
                        
-                       label = validParameter->validFile(parameters, "label", false);                  
+                       label = validParameter.validFile(parameters, "label", false);                   
                        if (label == "not found") { label = ""; }
                        else { 
                                if(label != "all") {  splitAtDash(label, labels);  allLines = 0;  }
@@ -95,30 +96,28 @@ CollectSharedCommand::CollectSharedCommand(string option){
                                lines = globaldata->lines;
                        }
                                
-                       calc = validParameter->validFile(parameters, "calc", false);                    
+                       calc = validParameter.validFile(parameters, "calc", false);                     
                        if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
                        else { 
                                 if (calc == "default")  {  calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
                        }
                        splitAtDash(calc, Estimators);
                        
-                       groups = validParameter->validFile(parameters, "groups", false);                        
+                       groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                splitAtDash(groups, Groups);
-                               globaldata->Groups = Groups;
                        }
+                       globaldata->Groups = Groups;
                        
                        string temp;
-                       temp = validParameter->validFile(parameters, "freq", false);                    if (temp == "not found") { temp = "100"; }
+                       temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
                        convert(temp, freq); 
-                       
-                       delete validParameter;
-                       
+                                               
                        if (abort == false) {
                        
                                string fileNameRoot = getRootName(globaldata->inputFileName);
-                               format = globaldata->getFormat();
+//                             format = globaldata->getFormat();
                                int i;
                                
                                validCalculator = new ValidCalculators();
@@ -244,16 +243,16 @@ int CollectSharedCommand::execute(){
                
                //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
                set<string> processedLabels;
-               set<string> userLabels = globaldata->labels;
-               set<int> userLines = globaldata->lines;
+               set<string> userLabels = labels;
+               set<int> userLines = lines;
                                
                //set users groups
                util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
                util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
 
-               while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
+               while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
 
-                       if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
+                       if(allLines == 1 || lines.count(count) == 1 || labels.count(order->getLabel()) == 1){
                                
                                //create collectors curve
                                cCurve = new Collect(order, cDisplays);