]> git.donarmstrong.com Git - mothur.git/blobdiff - getoturepcommand.cpp
fixed memory leak in rarefact
[mothur.git] / getoturepcommand.cpp
index ea53f25ed4cd9d215869349fa9159f03deda6258..45f34fef5a444eb66e78788b9107152cd2b20a7d 100644 (file)
@@ -20,11 +20,19 @@ GetOTURepCommand::GetOTURepCommand(){
                if(globaldata->gListVector != NULL)             {       
                        listOfNames = new ListVector(*globaldata->gListVector); 
                        
+                       vector<string> names;
+                       string binnames;
                        //map names to rows in sparsematrix
                        for (int i = 0; i < listOfNames->size(); i++) {
-                               nameToIndex[listOfNames->get(i)] = i;
+                               names.clear();
+                               binnames = listOfNames->get(i);
+                               splitAtComma(binnames, names);
+                               
+                               for (int j = 0; j < names.size(); j++) {
+                                       nameToIndex[names[j]] = i;
+                               }
                        }
-               }else { cout << "error" << endl; }
+               }else { cout << "error, no listvector." << endl; }
 
                
                fastafile = globaldata->getFastaFile();
@@ -72,7 +80,7 @@ int GetOTURepCommand::execute(){
                }
                
                //read list file
-               read = new ReadPhilFile(globaldata->getListFile());     
+               read = new ReadOTUFile(globaldata->getListFile());      
                read->read(&*globaldata); 
                
                input = globaldata->ginput;
@@ -83,7 +91,7 @@ int GetOTURepCommand::execute(){
                        if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
                                
                                //create output file
-                               string outputFileName = getRootName(globaldata->getListFile()) + list->getLabel() + ".fastarep";
+                               string outputFileName = getRootName(globaldata->getListFile()) + list->getLabel() + ".rep.fasta";
                                openOutputFile(outputFileName, out);
 
                                cout << list->getLabel() << '\t' << count << endl;
@@ -96,7 +104,7 @@ int GetOTURepCommand::execute(){
                                        sequence = fasta->getSequence(nameRep);
 
                                        if (sequence != "not found") {
-                                               nameRep = nameRep + "bin" + toString(i+1);
+                                               nameRep = nameRep + "|" + toString(i+1);
                                                out << ">" << nameRep << endl;
                                                out << sequence << endl;
                                        }else { 
@@ -105,6 +113,8 @@ int GetOTURepCommand::execute(){
                                                return 0;
                                        }
                                }
+                               
+                               out.close();
                        }
                        
                        list = input->getListVector();
@@ -174,7 +184,7 @@ string GetOTURepCommand::FindRep(int bin) {
                string minName;
                
                binnames = list->get(bin);
-               
+       
                //parse names into vector
                splitAtComma(binnames, names);
                
@@ -184,6 +194,7 @@ string GetOTURepCommand::FindRep(int bin) {
                        //fill binMap
                        for (int i = 0; i < names.size(); i++) {
                                for (it3 = nameToIndex.begin(); it3 != nameToIndex.end(); it3++) {
+
                                        if (it3->first == names[i]) {  
                                                binMap[it3->second] = it3->first;