]> git.donarmstrong.com Git - mothur.git/blobdiff - binsequencecommand.cpp
version working on mac with .tellg changed to unget for windows
[mothur.git] / binsequencecommand.cpp
index c2fd6fadb9b4bb6b3cffdebd38bc513a68f8b8d7..1627b42d7bec5090a708c77d7491b93fa3bc7cdd 100644 (file)
@@ -26,14 +26,14 @@ BinSeqCommand::BinSeqCommand(string option){
                        string AlignArray[] =  {"fasta","line","label","name", "group"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/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
@@ -41,26 +41,20 @@ BinSeqCommand::BinSeqCommand(string option){
                        
                        
                        //check for required parameters
-                       fastafile = validParameter->validFile(parameters, "fasta", true);
+                       fastafile = validParameter.validFile(parameters, "fasta", true);
                        if (fastafile == "not found") { cout << "fasta is a required parameter for the bin.seqs command." << endl; abort = true; }
                        else if (fastafile == "not open") { abort = true; }     
-                       else { 
-                               globaldata->setFastaFile(fastafile);
-                               openInputFile(fastafile, in);
-                               fasta = new FastaMap();
-                       }
-               
                
                        //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;  }
@@ -76,20 +70,23 @@ BinSeqCommand::BinSeqCommand(string option){
                                lines = globaldata->lines;
                        }
                        
-                       namesfile = validParameter->validFile(parameters, "name", true);
+                       namesfile = validParameter.validFile(parameters, "name", true);
                        if (namesfile == "not open") { abort = true; }  
                        else if (namesfile == "not found") { namesfile = ""; }
 
-                       groupfile = validParameter->validFile(parameters, "group", true);
+                       groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }
                        else if (groupfile == "not found") { groupfile = ""; }
-                       else {
-                               //read in group map info.
-                               groupMap = new GroupMap(groupfile);
-                               groupMap->readMap();
+                       
+                       if (abort == false) { 
+                               openInputFile(fastafile, in);
+                               fasta = new FastaMap();
+                               if (groupfile != "") {
+                                       groupMap = new GroupMap(groupfile);
+                                       groupMap->readMap();
+                               }
                        }
        
-                       delete validParameter;
                }
        }
        catch(exception& e) {
@@ -132,24 +129,18 @@ void BinSeqCommand::help(){
 BinSeqCommand::~BinSeqCommand(){
        //made new in execute
        if (abort == false) {
-               delete input;
+               delete input;  globaldata->ginput = NULL;
                delete read;
-               delete list;
-       }
-       
-       //made new in constructor
-       delete fasta;
-       if (groupfile != "") {
-                       delete groupMap;
+               globaldata->gListVector = NULL;
+               delete fasta;
+               if (groupfile != "") {  delete groupMap;  globaldata->gGroupmap = NULL; }
        }
-
 }
 
 //**********************************************************************************************************************
 
 int BinSeqCommand::execute(){
        try {
-       
                if (abort == true) {    return 0;       }
        
                int count = 1;
@@ -158,8 +149,10 @@ int BinSeqCommand::execute(){
                //read fastafile
                fasta->readFastaFile(in);
                
+               in.close();
+               
                //set format to list so input can get listvector
-               globaldata->setFormat("list");
+//             globaldata->setFormat("list");
                
                //if user gave a namesfile then use it
                if (namesfile != "") {