]> git.donarmstrong.com Git - mothur.git/blobdiff - parselistcommand.cpp
fixed memory leak of groupmap in reads
[mothur.git] / parselistcommand.cpp
index 8a848e768fd5c4c2775bec636be6acf64dd5d2ac..73fb56593c781bcd0cee4e432318fd9ba82b1577 100644 (file)
@@ -27,12 +27,7 @@ ParseListCommand::ParseListCommand(){
                }
                
                //set fileroot
-               if(globaldata->getFileRoot() != ""){
-                       fileroot = globaldata->getFileRoot();
-               }
-               else{
-                       fileroot = getRootName(globaldata->getDistFile());
-               }
+               fileroot = getRootName(globaldata->getListFile());
                
                //open output list files
                for (i=0; i<groupMap->getNumGroups(); i++) {//opens an output file for each group
@@ -91,13 +86,13 @@ void ParseListCommand::parse(int index) {
 int ParseListCommand::execute(){
        try{
                        globaldata = GlobalData::getInstance();
+                       int count = 1;
                        
                        //read in listfile
                        read = new ReadPhilFile(globaldata->inputFileName);     
                        read->read(&*globaldata); 
                        input = globaldata->ginput;
-                       //list = input->getListVector();
-                       list = globaldata->glist;
+                       list = globaldata->gSharedList;
 
                        //read in group map info.
                        groupMap = new GroupMap(globaldata->getGroupFile());
@@ -107,29 +102,42 @@ int ParseListCommand::execute(){
                        int i;
                        //create new list vectors to fill with parsed data
                        for (i=0; i<groupMap->getNumGroups(); i++) {
-                               groupOfLists[groupMap->namesOfGroups[i]] = new ListVector();
+                               groupOfLists[groupMap->namesOfGroups[i]] = new SharedListVector();
                        }
                        
                        //parses and sets each groups listvector
                        while(list != NULL){
                                label = list->getLabel();
-                               for(i=0; i<list->size(); i++) {
-                                       parse(i); //parses data[i] list of sequence names
-                                       for (it=listGroups.begin(); it != listGroups.end(); it++) {  //loop through map and set new list vectors
-                                               seq = it->second;
-                                               seq = seq.substr(1, seq.length()); //rips off extra comma
-                                               groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
+                               
+                               if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(label) == 1){
+                               
+                                       for(i=0; i<list->size(); i++) {
+                                               parse(i); //parses data[i] list of sequence names
+                                               for (it=listGroups.begin(); it != listGroups.end(); it++) {  //loop through map and set new list vectors
+                                                       seq = it->second;
+                                                       seq = seq.substr(1, seq.length()); //rips off extra comma
+                                                       groupOfLists[it->first]->push_back(seq); //sets new listvector for each group
+                                               }
+                                               listGroups.clear();
                                        }
-                                       listGroups.clear();
-                               }
-                               //prints each new list file
-                               for (i=0; i<groupMap->getNumGroups(); i++) {
-                                       groupOfLists[groupMap->namesOfGroups[i]]->setLabel(label);
-                                       groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
-                                       groupOfLists[groupMap->namesOfGroups[i]]->clear();
+                                       //prints each new list file
+                                       for (i=0; i<groupMap->getNumGroups(); i++) {
+                                               groupOfLists[groupMap->namesOfGroups[i]]->setLabel(label);
+                                               groupOfLists[groupMap->namesOfGroups[i]]->print(*(filehandles[groupMap->namesOfGroups[i]]));
+                                               groupOfLists[groupMap->namesOfGroups[i]]->clear();
+                                       }
+                                       
+                                       cout << label << '\t' << count << endl;
                                }
-                               list = input->getListVector();
+                               
+                               list = input->getSharedListVector();
+                               count++;
                        }
+                       
+                       //set groupmap for .shared commands
+                       if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
+                       globaldata->gGroupmap = groupMap; 
+                       
                        return 0;
        }
        catch(exception& e) {
@@ -146,7 +154,6 @@ int ParseListCommand::execute(){
 
 ParseListCommand::~ParseListCommand(){
        delete list;
-       delete groupMap;
        delete input;
        delete read;    
 }