]> git.donarmstrong.com Git - mothur.git/commitdiff
bugs fixes while testing for 1.5 release
authorwestcott <westcott>
Sat, 1 Aug 2009 21:28:33 +0000 (21:28 +0000)
committerwestcott <westcott>
Sat, 1 Aug 2009 21:28:33 +0000 (21:28 +0000)
14 files changed:
bootstrapsharedcommand.cpp
getseqscommand.cpp
globaldata.cpp
heatmapcommand.cpp
inputdata.cpp
pintail.cpp
rabundvector.cpp
readotu.cpp
readtree.cpp
removeseqscommand.cpp
sharedcommand.cpp
sharedrabundvector.cpp
tree.cpp
tree.h

index db1fa9e0dcfef20edc426e9053e4bac128e17f82..a3717fe621057f9b8b9a88f09545c79438a2c032 100644 (file)
@@ -447,8 +447,8 @@ void BootSharedCommand::process(SharedOrderVector* order) {
                                
                                mothurOut("\tDone."); mothurOutEndLine();
                                //delete globaldata's tree
-                               for (int m = 0; m < globaldata->gTree.size(); m++) {  delete globaldata->gTree[m];  }
-                               globaldata->clear();
+                               //for (int m = 0; m < globaldata->gTree.size(); m++) {  delete globaldata->gTree[m];  }
+                               //globaldata->gTree.clear();
                                
                                
                                //create consensus trees for each bootstrapped tree set
@@ -465,8 +465,8 @@ void BootSharedCommand::process(SharedOrderVector* order) {
                                        delete consensus;
                                        
                                        //delete globaldata's tree
-                                       for (int m = 0; m < globaldata->gTree.size(); m++) {  delete globaldata->gTree[m];  }
-                                       globaldata->clear();
+                                       //for (int m = 0; m < globaldata->gTree.size(); m++) {  delete globaldata->gTree[m];  }
+                                       //globaldata->gTree.clear();
                                        
                                }
                                
index 509241d87fb2207c30ce1c7db0133a2a59f357da..04b254599f46ef00081a3f153c0e097fea665cf4 100644 (file)
@@ -155,7 +155,7 @@ void GetSeqsCommand::readFasta(){
 void GetSeqsCommand::readName(){
        try {
        
-               string outputFileName = getRootName(namefile) + "pick" +  getExtension(namefile);;
+               string outputFileName = getRootName(namefile) + "pick" +  getExtension(namefile);
                ofstream out;
                openOutputFile(outputFileName, out);
 
@@ -186,7 +186,6 @@ void GetSeqsCommand::readName(){
                        for (int i = 0; i < parsedNames.size(); i++) {
                                if (names.count(parsedNames[i]) == 1) {
                                        validSecond.push_back(parsedNames[i]);
-                                       names.erase(parsedNames[i]);
                                }
                        }
 
@@ -202,7 +201,6 @@ void GetSeqsCommand::readName(){
                                for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
                                out << validSecond[validSecond.size()-1] << endl;
                                
-                               names.erase(firstCol);
                        
                        //make first name in set you come to first column and then add the remaining names to second column
                        }else {
index cdf819baa6badc6e89c65bb6c6428e01be41d40d..155aad57e1a6bcce20cbce2e0c8d92c776ead103 100644 (file)
@@ -93,18 +93,30 @@ void GlobalData::newRead() {
                        
                        //free memory
                        if (gGroupmap != NULL) { delete gGroupmap; gGroupmap = NULL; }
+
                        if (gListVector != NULL) { delete gListVector; gListVector = NULL;}
+
                        if (gSparseMatrix != NULL) { delete gSparseMatrix; gSparseMatrix = NULL; }
+
                        if (ginput != NULL) { delete ginput; ginput = NULL;}
+
                        if (gorder != NULL) { delete gorder; gorder = NULL; }
+
                        if (glist != NULL) { delete glist; glist = NULL;}
+
                        if (gSharedList != NULL) { delete gSharedList; gSharedList = NULL; }
+
                        if (sabund != NULL) { delete sabund; sabund = NULL;}
+
                        if (rabund != NULL) { delete rabund; rabund = NULL; }
+
                        if (gMatrix != NULL) { delete gMatrix; gMatrix = NULL;}
+
                        if (gTreemap != NULL) { delete gTreemap; gTreemap = NULL; }
+
                        if (gSequenceDB != NULL) { delete gSequenceDB; gSequenceDB = NULL;}
 
+
                        gTree.clear();
                        Treenames.clear();
                        labels.clear(); lines.clear(); Groups.clear();
index 0ee34f9432deedc6cfe9a914efc84f4b3cf8c91f..e21b14dce5afaf3744b1338416b1af3630a6830c 100644 (file)
@@ -39,8 +39,8 @@ HeatMapCommand::HeatMapCommand(string option){
                        }
                        
                        //make sure the user has already run the read.otu command
-                       if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
-                                mothurOut("You must read a list, or a list and a group, or a shared before you can use the heatmap.bin command."); mothurOutEndLine(); abort = true; 
+                       if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "") && (globaldata->getSharedFile() == "")) {
+                                mothurOut("You must read a list, rabund, sabund, or a list and a group, or a shared before you can use the heatmap.bin command."); mothurOutEndLine(); abort = true; 
                        }
 
                        //check for optional parameter and set defaults
@@ -132,7 +132,7 @@ int HeatMapCommand::execute(){
        try {
        
                if (abort == true) { return 0; }
-       
+
                int count = 1;  
                string lastLabel;
        
@@ -144,14 +144,16 @@ int HeatMapCommand::execute(){
                        input = globaldata->ginput;
                        lookup = input->getSharedRAbundVectors();
                        lastLabel = lookup[0]->getLabel();
-               }else if (format == "list") {
+       
+               }else if ((format == "list") || (format == "rabund") || (format == "sabund")) {
                        //you are using just a list file and have only one group
                        read = new ReadOTUFile(globaldata->inputFileName);      
                        read->read(&*globaldata); 
-                       
+               
                        rabund = globaldata->rabund;
                        lastLabel = rabund->getLabel();
-                       input = globaldata->ginput;             
+                       input = globaldata->ginput;     
+
                }
                
                //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
@@ -159,7 +161,7 @@ int HeatMapCommand::execute(){
                set<string> userLabels = labels;
                set<int> userLines = lines;
 
-               if (format != "list") { 
+               if ((format != "list") && (format != "rabund") && (format != "sabund")) {       
                
                        //as long as you are not at the end of the file or done wih the lines you want
                        while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
@@ -223,7 +225,7 @@ int HeatMapCommand::execute(){
                        globaldata->Groups.clear();  
                        
                }else{
-               
+       
                        while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
 
                                if(allLines == 1 || lines.count(count) == 1 || labels.count(rabund->getLabel()) == 1){                  
@@ -282,6 +284,7 @@ int HeatMapCommand::execute(){
                
                }
                
+               globaldata->rabund = NULL;
                delete input; globaldata->ginput = NULL;
                return 0;
        }
index cbf44ed11a96a03c251fcc3025b185c2020c2830..bf783a35d5e06e12fa4fcf2c3ff58ba7d9618778 100644 (file)
@@ -63,7 +63,7 @@ ListVector* InputData::getListVector(){
                if(fileHandle){
                        if(format == "list") {
                                list = new ListVector(fileHandle);
-                       }
+                       }else{ list = NULL;  }
                                        
                        gobble(fileHandle);
                        return list;
@@ -101,7 +101,7 @@ ListVector* InputData::getListVector(string label){
                                        else {  delete list;    }
                                        gobble(in);
                                }
-                       }
+                       }else{ list = NULL;  }
                        
                        in.close();
                        return list;
@@ -124,7 +124,7 @@ SharedListVector* InputData::getSharedListVector(){
                if(fileHandle){
                        if (format == "shared")  {
                                SharedList = new SharedListVector(fileHandle);
-                       }
+                       }else{ SharedList = NULL;  }
                                        
                        gobble(fileHandle);
                        return SharedList;
@@ -162,7 +162,7 @@ SharedListVector* InputData::getSharedListVector(string label){
                                        gobble(in);
                                }
 
-                       }
+                       }else{ SharedList = NULL;  }
                                
                        in.close();
                        return SharedList;
@@ -186,7 +186,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){
                if(fileHandle){
                        if (format == "sharedfile")  {
                                SharedOrder = new SharedOrderVector(fileHandle);
-                       }
+                       }else{ SharedOrder = NULL;  }
                                
                        gobble(fileHandle);
                        return SharedOrder;
@@ -225,7 +225,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){
                                        gobble(in);
                                }
 
-                       }
+                       }else{ SharedOrder = NULL;  }
                                
                        in.close();
                        return SharedOrder;
@@ -262,11 +262,12 @@ OrderVector* InputData::getOrderVector(){
                        else if(format == "sabund"){
                                input = new SAbundVector(fileHandle);
                        }
-                                       
+                       
                        gobble(fileHandle);
-                       output = new OrderVector();
-                       *output = (input->getOrderVector());
                        
+                       output = new OrderVector();     
+                       *output = (input->getOrderVector());
+               
                        return output;
                }
                else{
index 39ac13f786ad3c6e94d4b1a8252f126a23200522..74c34e18be897ecb2c7966e5a481a5fff81d76df 100644 (file)
@@ -593,8 +593,8 @@ void Pintail::createProcessesSpots() {
 
                for (int i = lines[0]->start; i < lines[0]->end; i++) {
                                it = trimmed[i].begin();
-                               map<int, int> win = decalc->findWindows(querySeqs[i], it->first, it->second, windowSizes[i], increment);
-                               windows[i] = win;
+                               vector<int> win = decalc->findWindows(querySeqs[i], it->first, it->second, windowSizes[i], increment);
+                               windowsForeachQuery[i] = win;
                }
 
 #endif         
@@ -852,7 +852,7 @@ void Pintail::createProcesses() {
 #else
                        mothurOut("Calculating observed distance... "); cout.flush();
                        for (int i = lines[0]->start; i < lines[0]->end; i++) {
-                               vector<float> obsi = decalc->calcObserved(querySeqs[i], bestfit[i], windows[i], windowSizes[i]);
+                               vector<float> obsi = decalc->calcObserved(querySeqs[i], bestfit[i], windowsForeachQuery[i], windowSizes[i]);
                                obsDistance[i] = obsi;
                        }
                        mothurOut("Done."); mothurOutEndLine();
@@ -861,7 +861,7 @@ void Pintail::createProcesses() {
                        
                        mothurOut("Finding variability... "); cout.flush();
                        for (int i = lines[0]->start; i < lines[0]->end; i++) {
-                               vector<float> q = decalc->findQav(windows[i], windowSizes[i], probabilityProfile, h[i]);
+                               vector<float> q = decalc->findQav(windowsForeachQuery[i], windowSizes[i], probabilityProfile);
                                Qav[i] = q;
                        }
                        mothurOut("Done."); mothurOutEndLine();
index 7d6247001c645b4b312d0e6599d0c4996fffa44b..e01063dad484f2328a714b0cbf8cff15c445b169 100644 (file)
@@ -289,15 +289,16 @@ SAbundVector RAbundVector::getSAbundVector() {
 OrderVector RAbundVector::getOrderVector(map<string,int>* nameMap = NULL) {
        try {
                OrderVector ov;
-       
+
                for(int i=0;i<data.size();i++){
                        for(int j=0;j<data[i];j++){
                                ov.push_back(i);
                        }
                }
                random_shuffle(ov.begin(), ov.end());
-
                ov.setLabel(label);     
+               ov.getNumBins();
+
                return ov;
        }
        catch(exception& e) {
index d16dab9477d4c02ce89ad42de0be4c46228588b4..1f64919825bbd8692043b4e8d16feaaf5e727e12 100644 (file)
@@ -35,20 +35,25 @@ void ReadOTUFile::read(GlobalData* globaldata){
                //memory leak prevention
                //if (globaldata->ginput != NULL) { delete globaldata->ginput;  }
                globaldata->ginput = input;     //saving to be used by collector and rarefact commands.
-               
+       
                if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary.
+
+//cout << input << '\t' << globaldata << endl;
                        order = input->getOrderVector();
                        //memory leak prevention
+
                        //if (globaldata->gorder != NULL) { delete globaldata->gorder;  }
                        globaldata->gorder = order;     //saving to be used by collect and rarefact commands.
                        sabund = inputSabund->getSAbundVector(); 
                        //if (globaldata->sabund != NULL) { delete globaldata->sabund;  }
                        globaldata->sabund = sabund; //saving to be used by summary command.
                        delete inputSabund;
+
                        rabund = inputRabund->getRAbundVector(); 
                        //if (globaldata->rabund != NULL) { delete globaldata->rabund;  }
                        globaldata->rabund = rabund; //saving to be used by heatmap.bin command.
                        delete inputRabund;
+
                        list = inputList->getListVector();
                        //if (globaldata->gListVector != NULL) { delete globaldata->gListVector;  }
                        globaldata->gListVector = list;
index 5e909e620d237ed063d9a64bd191f707ddea1daa..25fee86518bc6e2177b11824aa7989168c38772f 100644 (file)
@@ -116,6 +116,7 @@ int ReadNewickTree::read() {
 
                                //make new tree
                                T = new Tree(); 
+
                                numNodes = T->getNumNodes();
                                numLeaves = T->getNumLeaves();
                                
index a49d41a9485d22b6d302164f01913d37f42802aa..1b9edb0e98e20f7752fb9b8aab3584c1c05bccc0 100644 (file)
@@ -154,6 +154,7 @@ void RemoveSeqsCommand::readName(){
        try {
        
                string outputFileName = getRootName(namefile) + "pick" + getExtension(namefile);
+
                ofstream out;
                openOutputFile(outputFileName, out);
 
@@ -167,29 +168,29 @@ void RemoveSeqsCommand::readName(){
 
                        in >> firstCol;                         
                        in >> secondCol;                        
-                       
+
                        vector<string> parsedNames;
                        //parse second column saving each name
                        while (secondCol.find_first_of(',') != -1) { 
                                name = secondCol.substr(0,secondCol.find_first_of(','));
                                secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
                                parsedNames.push_back(name);
+
                        }
                        
                        //get name after last ,
                        parsedNames.push_back(secondCol);
-                       
-                       vector<string> validSecond;
+
+                       vector<string> validSecond;  validSecond.clear();
                        for (int i = 0; i < parsedNames.size(); i++) {
                                if (names.count(parsedNames[i]) == 0) {
                                        validSecond.push_back(parsedNames[i]);
-                               }else { names.erase(parsedNames[i]); }
+                               }
                        }
-
                        
                        //if the name in the first column is in the set then print it and any other names in second column also in set
                        if (names.count(firstCol) == 0) {
-                               
+                       
                                wroteSomething = true;
                                
                                out << firstCol << '\t';
@@ -200,8 +201,7 @@ void RemoveSeqsCommand::readName(){
                        
                        //make first name in set you come to first column and then add the remaining names to second column
                        }else {
-                               names.erase(firstCol);  
-                                       
+                               
                                //you want part of this row
                                if (validSecond.size() != 0) {
                                
@@ -278,7 +278,7 @@ void RemoveSeqsCommand::readGroup(){
 //alignreport file has a column header line then all other lines contain 16 columns.  we just want the first column since that contains the name
 void RemoveSeqsCommand::readAlign(){
        try {
-               string outputFileName = getRootName(alignfile) + "pick" + getExtension(alignfile);
+               string outputFileName = getRootName(getRootName(alignfile)) + "pick.align.report";
                ofstream out;
                openOutputFile(outputFileName, out);
 
index 26ba2211906fa025e3807aedf8c13ef3d913e413..9afb401014faaf097a1a30c2b1802d82ae8e659f 100644 (file)
@@ -156,9 +156,9 @@ void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
                        out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
                        thislookup[i]->print(out);
                        
+                       RAbundVector rav = thislookup[i]->getRAbundVector();
                        openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()]));
-                       (*filehandles[thislookup[i]->getGroup()]) << thislookup[i]->getLabel()  << '\t' << thislookup[i]->getGroup()  << '\t';
-                       thislookup[i]->print(*(filehandles[thislookup[i]->getGroup()]));
+                       rav.print(*(filehandles[thislookup[i]->getGroup()]));
                        (*(filehandles[thislookup[i]->getGroup()])).close();
                }
  
index 0a69e4c37849171e01544da40f2c09bbd86d40b0..cb20accf9f93819a45d8492ca9176cd8537b8a0c 100644 (file)
@@ -379,12 +379,15 @@ vector<SharedRAbundVector*> SharedRAbundVector::getSharedRAbundVectors(){
 
 RAbundVector SharedRAbundVector::getRAbundVector() {
        try {
-               RAbundVector rav(data.size());
+               RAbundVector rav;
                
                for (int i = 0; i < data.size(); i++) {
-                       rav.set(i, data[i].abundance);
+                       if(data[i].abundance != 0) {
+                               rav.push_back(data[i].abundance);
+                       }
                }
-       
+               
+               rav.setLabel(label);
                return rav;
        }
        catch(exception& e) {
index ce3de379d05d5eca8c991d2e93e64060377a2304..487db5c5f84805edcd232607472129ea98a86a4f 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -16,7 +16,7 @@ Tree::Tree() {
                globaldata = GlobalData::getInstance();
                
                if (globaldata->runParse == true) {  parseTreeFile();  globaldata->runParse = false;  }
-               
+//for(int i = 0; i <   globaldata->Treenames.size(); i++) { cout << i << '\t' << globaldata->Treenames[i] << endl;  }  
                numLeaves = globaldata->Treenames.size();
                numNodes = 2*numLeaves - 1;
                
@@ -529,7 +529,7 @@ void Tree::printTree() {
 }
 
 /*****************************************************************/
-
+//this code is a mess and should be rethought...-slw
 void Tree::parseTreeFile() {
        
        //only takes names from the first tree and assumes that all trees use the same names.
@@ -539,6 +539,7 @@ void Tree::parseTreeFile() {
                openInputFile(filename, filehandle);
                int c, comment;
                comment = 0;
+               int done = 1;
                
                //ifyou are not a nexus file 
                if((c = filehandle.peek()) != '#') {  
@@ -555,7 +556,8 @@ void Tree::parseTreeFile() {
                                        filehandle.get();
                                }
 
-                               readTreeString(filehandle); 
+                               done = readTreeString(filehandle); 
+                               if (done == 0) { break; }
                        }
                //ifyou are a nexus file
                }else if((c = filehandle.peek()) == '#') {
@@ -570,17 +572,20 @@ void Tree::parseTreeFile() {
                                        comment = 0;
                                }
                                filehandle >> holder; 
-       
-                               //ifthere is no translate then you must read tree string otherwise use translate to get names
-                               if(holder == "tree" && comment != 1){   
+
+                               //if there is no translate then you must read tree string otherwise use translate to get names
+                               if((holder == "tree") && (comment != 1)){       
                                        //pass over the "tree rep.6878900 = "
                                        while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF)) {;}
 
                                        if(c == EOF) { break; }
                                        filehandle.putback(c);  //put back first ( of tree.
-                                       readTreeString(filehandle);     
+                                       done = readTreeString(filehandle);
+       
                                        break;
                                }
+                       
+                               if (done == 0) { break;  }
                        }
                        
                        //use nexus translation rather than parsing tree to save time
@@ -610,10 +615,10 @@ void Tree::parseTreeFile() {
 /*******************************************************/
 
 /*******************************************************/
-void Tree::readTreeString(ifstream& filehandle)        {
+int Tree::readTreeString(ifstream& filehandle) {
        try {
                int c;
-               string name;// k;
+               string name;  //, k
                
                while((c = filehandle.peek()) != ';') { 
 //k = c;
@@ -624,7 +629,8 @@ void Tree::readTreeString(ifstream& filehandle)     {
                                while((c!=',') && (c != -1) && (c!= ':') && (c!=';')){ c=filehandle.get(); }
                                filehandle.putback(c);
                        }
-                       if(c == ';') { break; }
+                       if(c == ';') { return 0; }
+                       if(c == -1) { return 0; }
                        //if you are a name
                        if((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
                                name = "";
@@ -648,19 +654,22 @@ void Tree::readTreeString(ifstream& filehandle)   {
                        if(c  == ':') { //read until you reach the end of the branch length
                                while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
                                        c = filehandle.get();
-                                       //k = c;
+       //k = c;
        //cout << " in branch while " << k << endl;
                                }
                                filehandle.putback(c);
                        }
-                       
+               
                        c = filehandle.get();
-                       if(c == ';') { break; }
+//k = c;
+       //cout << " here after get " << k << endl;
+                       if(c == ';') { return 0; }
                        if(c == ')') { filehandle.putback(c); }
-       //              k = c;
+       //k = c;
 //cout << k << endl;
 
                }
+               return 0;
        }
        catch(exception& e) {
                errorOut(e, "Tree", "readTreeString");
diff --git a/tree.h b/tree.h
index a5259552d8fa09f18d1e81b1776ef94f84724748..c90f51a451461ceca068f743ecefe8fd3e7cba5f 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -59,7 +59,7 @@ private:
                                                        //this is required in case user has sequences in the names file that are
                                                        //not included in the tree. 
                                                        //only takes names from the first tree in the tree file and assumes that all trees use the same names.
-       void readTreeString(ifstream&);
+       int readTreeString(ifstream&);
 };
 
 #endif