]> git.donarmstrong.com Git - mothur.git/blobdiff - parselistcommand.cpp
fixing minor bugs
[mothur.git] / parselistcommand.cpp
index 20f92f73b3e8107bd47a1e99f253779e67d2a423..5de3b72daa63b962ff9be84b5665e7230fb2470b 100644 (file)
@@ -15,10 +15,8 @@ ParseListCommand::ParseListCommand(){
                globaldata = GlobalData::getInstance();
                
                //read in group map info.
-               groupMap = new GroupMap(globaldata->getGroupFile());
-               groupMap->readMap();
+               groupMap = globaldata->gGroupmap;
 
-               
                //fill filehandles with neccessary ofstreams
                int i;
                ofstream* temp;
@@ -86,7 +84,6 @@ void ParseListCommand::parse(int index, SharedListVector* list) {
 
 int ParseListCommand::execute(){
        try{
-                       globaldata = GlobalData::getInstance();
                        int count = 1;
                        
                        //read in listfile
@@ -99,10 +96,7 @@ int ParseListCommand::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;
-
-                       //read in group map info.
-                       groupMap = new GroupMap(globaldata->getGroupFile());
-                       groupMap->readMap();
+                       set<int> userLines = globaldata->lines;
                        
                        //create new list vectors to fill with parsed data
                        for (int i=0; i<groupMap->getNumGroups(); i++) {
@@ -112,7 +106,7 @@ int ParseListCommand::execute(){
                                                
                        //parses and sets each groups listvector
                        //as long as you are not at the end of the file or done wih the lines you want
-                       while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
+                       while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
                                                                
                                if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
                                        cout << list->getLabel() << '\t' << count << endl;
@@ -120,6 +114,7 @@ int ParseListCommand::execute(){
                                        
                                        processedLabels.insert(list->getLabel());
                                        userLabels.erase(list->getLabel());
+                                       userLines.erase(count);
                                }
                                
                                if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
@@ -161,6 +156,18 @@ int ParseListCommand::execute(){
                        if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
                        globaldata->gGroupmap = groupMap; 
                        
+                       //close files
+                       for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { 
+                               ofstream* temp = it3->second;
+                               (*temp).close(); 
+                               delete it3->second;
+                       }
+                       
+                       //delete list vectors to fill with parsed data
+                       for (it2 = groupOfLists.begin(); it2 != groupOfLists.end(); it2++) {
+                               delete it2->second;
+                       }
+
                        return 0;
        }
        catch(exception& e) {