]> git.donarmstrong.com Git - mothur.git/blobdiff - summarysharedcommand.cpp
version 1.4
[mothur.git] / summarysharedcommand.cpp
index 363506c406490e999a2700974e538489616b8d5a..4006b2d661ab02dc01c1e0f2c0a1fbee9f147fa7 100644 (file)
@@ -52,33 +52,31 @@ SummarySharedCommand::SummarySharedCommand(string option){
                        string Array[] =  {"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
                        if (globaldata->getSharedFile() == "") {
-                               if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the summary.shared command." << endl; abort = true; }
-                               else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the summary.shared command." << endl; abort = true; }
+                                cout << "You must read a list and a group, or a shared before you can use the summary.shared command." << endl; abort = true; 
                        }
-
                        
                        //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;  }
@@ -94,22 +92,20 @@ SummarySharedCommand::SummarySharedCommand(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;
                        }
                        
-                       delete validParameter;
-                       
                        if (abort == false) {
                        
                                validCalculator = new ValidCalculators();
@@ -165,11 +161,9 @@ SummarySharedCommand::SummarySharedCommand(string option){
                                
                                outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary");
                                openOutputFile(outputFileName, outputFileHandle);
-                               format = globaldata->getFormat();
                                mult = false;
                        }
                }
-
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -210,9 +204,10 @@ void SummarySharedCommand::help(){
 //**********************************************************************************************************************
 
 SummarySharedCommand::~SummarySharedCommand(){
-       delete input;
-       delete read;
-       delete validCalculator;
+       if (abort == false) {
+               delete read;
+               delete validCalculator;
+       }
 }
 
 //**********************************************************************************************************************
@@ -339,6 +334,10 @@ int SummarySharedCommand::execute(){
                //close files
                outputFileHandle.close();
                if (mult == true) {  outAll.close();  }
+               
+               for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
+               
+               delete input;  globaldata->ginput = NULL;
 
                return 0;
        }