From ac1da2a793271cb67f2a2155c5558e1fabdd6aba Mon Sep 17 00:00:00 2001 From: westcott Date: Sat, 1 Aug 2009 21:28:33 +0000 Subject: [PATCH] bugs fixes while testing for 1.5 release --- bootstrapsharedcommand.cpp | 8 ++++---- getseqscommand.cpp | 4 +--- globaldata.cpp | 12 ++++++++++++ heatmapcommand.cpp | 19 +++++++++++-------- inputdata.cpp | 19 ++++++++++--------- pintail.cpp | 8 ++++---- rabundvector.cpp | 5 +++-- readotu.cpp | 7 ++++++- readtree.cpp | 1 + removeseqscommand.cpp | 18 +++++++++--------- sharedcommand.cpp | 4 ++-- sharedrabundvector.cpp | 9 ++++++--- tree.cpp | 37 +++++++++++++++++++++++-------------- tree.h | 2 +- 14 files changed, 93 insertions(+), 60 deletions(-) diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index db1fa9e..a3717fe 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -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(); } diff --git a/getseqscommand.cpp b/getseqscommand.cpp index 509241d..04b2545 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -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 { diff --git a/globaldata.cpp b/globaldata.cpp index cdf819b..155aad5 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -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(); diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index 0ee34f9..e21b14d 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -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 userLabels = labels; set 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; } diff --git a/inputdata.cpp b/inputdata.cpp index cbf44ed..bf783a3 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -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{ diff --git a/pintail.cpp b/pintail.cpp index 39ac13f..74c34e1 100644 --- a/pintail.cpp +++ b/pintail.cpp @@ -593,8 +593,8 @@ void Pintail::createProcessesSpots() { for (int i = lines[0]->start; i < lines[0]->end; i++) { it = trimmed[i].begin(); - map win = decalc->findWindows(querySeqs[i], it->first, it->second, windowSizes[i], increment); - windows[i] = win; + vector 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 obsi = decalc->calcObserved(querySeqs[i], bestfit[i], windows[i], windowSizes[i]); + vector 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 q = decalc->findQav(windows[i], windowSizes[i], probabilityProfile, h[i]); + vector q = decalc->findQav(windowsForeachQuery[i], windowSizes[i], probabilityProfile); Qav[i] = q; } mothurOut("Done."); mothurOutEndLine(); diff --git a/rabundvector.cpp b/rabundvector.cpp index 7d62470..e01063d 100644 --- a/rabundvector.cpp +++ b/rabundvector.cpp @@ -289,15 +289,16 @@ SAbundVector RAbundVector::getSAbundVector() { OrderVector RAbundVector::getOrderVector(map* nameMap = NULL) { try { OrderVector ov; - + for(int i=0;iginput != 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; diff --git a/readtree.cpp b/readtree.cpp index 5e909e6..25fee86 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -116,6 +116,7 @@ int ReadNewickTree::read() { //make new tree T = new Tree(); + numNodes = T->getNumNodes(); numLeaves = T->getNumLeaves(); diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index a49d41a..1b9edb0 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -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 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 validSecond; + + vector 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); diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 26ba221..9afb401 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -156,9 +156,9 @@ void SharedCommand::printSharedData(vector 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(); } diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 0a69e4c..cb20acc 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -379,12 +379,15 @@ vector 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) { diff --git a/tree.cpp b/tree.cpp index ce3de37..487db5c 100644 --- 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 a525955..c90f51a 100644 --- 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 -- 2.39.2