From: westcott Date: Mon, 15 Jun 2009 19:13:51 +0000 (+0000) Subject: fixing minor bugs X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=753dc84cf289b1d5dc0ca5b0c043640927aa951a fixing minor bugs --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 8b890ae..25e6296 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -748,8 +748,6 @@ 37D928A90F2133E5001D4494 /* commands */ = { isa = PBXGroup; children = ( - 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */, - 7E5A17AD0FE57292003C6A03 /* mergefilecommand.h */, 37D927CD0F21331F001D4494 /* command.hpp */, 378DC5CD0FBDE1C8003B8607 /* aligncommand.h */, 378DC5CE0FBDE1C8003B8607 /* aligncommand.cpp */, @@ -793,6 +791,8 @@ 375873F30F7D648F0040F377 /* libshuffcommand.cpp */, 21E859D60FC4632E005E1A48 /* matrixoutputcommand.h */, 21E859D70FC4632E005E1A48 /* matrixoutputcommand.cpp */, + 7E5A17AD0FE57292003C6A03 /* mergefilecommand.h */, + 7E5A17AE0FE57292003C6A03 /* mergefilecommand.cpp */, 375873F70F7D649C0040F377 /* nocommands.h */, 375873F60F7D649C0040F377 /* nocommands.cpp */, 37D927FA0F21331F001D4494 /* parselistcommand.h */, diff --git a/clustercommand.cpp b/clustercommand.cpp index 706ff67..4db95b4 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -62,10 +62,10 @@ ClusterCommand::ClusterCommand(string option){ if (abort == false) { //get matrix, list and rabund for execute - if(globaldata->gSparseMatrix != NULL) { matrix = new SparseMatrix(*globaldata->gSparseMatrix); } + if(globaldata->gSparseMatrix != NULL) { matrix = globaldata->gSparseMatrix; } if(globaldata->gListVector != NULL){ - list = new ListVector(*globaldata->gListVector); + list = globaldata->gListVector; rabund = new RAbundVector(list->getRAbundVector()); } @@ -121,8 +121,6 @@ void ClusterCommand::help(){ ClusterCommand::~ClusterCommand(){ delete cluster; - delete matrix; - delete list; delete rabund; } diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 36b0dc1..6127c2d 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -44,6 +44,7 @@ CollectSharedCommand::CollectSharedCommand(string option){ lines.clear(); labels.clear(); Estimators.clear(); + Groups.clear(); //allow user to run help if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; } @@ -106,8 +107,8 @@ CollectSharedCommand::CollectSharedCommand(string option){ if (groups == "not found") { groups = ""; } else { splitAtDash(groups, Groups); - globaldata->Groups = Groups; } + globaldata->Groups = Groups; string temp; temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; } @@ -242,16 +243,16 @@ int CollectSharedCommand::execute(){ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; - set userLabels = globaldata->labels; - set userLines = globaldata->lines; + set userLabels = labels; + set userLines = lines; //set users groups util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect"); util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex); - while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) { + while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) { - if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){ + if(allLines == 1 || lines.count(count) == 1 || labels.count(order->getLabel()) == 1){ //create collectors curve cCurve = new Collect(order, cDisplays); diff --git a/engine.cpp b/engine.cpp index b037137..df65678 100644 --- a/engine.cpp +++ b/engine.cpp @@ -169,6 +169,7 @@ bool BatchEngine::getInput(){ }else { cout << "Invalid." << endl; } } + gobble(inputBatchFile); } return 1; } diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 7918899..35e6924 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -91,7 +91,7 @@ GetOTURepCommand::GetOTURepCommand(string option){ if (abort == false) { - if(globaldata->gSparseMatrix != NULL) { matrix = new SparseMatrix(*globaldata->gSparseMatrix); } + if(globaldata->gSparseMatrix != NULL) { matrix = globaldata->gSparseMatrix; } //globaldata->gListVector bin 0 = first name read in distance matrix, globaldata->gListVector bin 1 = second name read in distance matrix if(globaldata->gListVector != NULL) { diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index 766f7da..d4e893b 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -128,7 +128,7 @@ void HeatMapCommand::help(){ //********************************************************************************************************************** HeatMapCommand::~HeatMapCommand(){ - delete input; + delete read; delete heatmap; } @@ -276,6 +276,7 @@ int HeatMapCommand::execute(){ } + delete input; return 0; } catch(exception& e) { diff --git a/inputdata.cpp b/inputdata.cpp index 05eaaca..b237bb4 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -24,7 +24,7 @@ InputData::InputData(string fName, string f) : format(f){ InputData::~InputData(){ - + fileHandle.close(); // delete output; } diff --git a/parselistcommand.cpp b/parselistcommand.cpp index c0622f2..5de3b72 100644 --- a/parselistcommand.cpp +++ b/parselistcommand.cpp @@ -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 @@ -100,10 +97,6 @@ int ParseListCommand::execute(){ set processedLabels; set userLabels = globaldata->labels; set userLines = globaldata->lines; - - //read in group map info. - groupMap = new GroupMap(globaldata->getGroupFile()); - groupMap->readMap(); //create new list vectors to fill with parsed data for (int i=0; igetNumGroups(); i++) { @@ -163,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) { diff --git a/parselistcommand.h b/parselistcommand.h index 9f88bc6..b3a2f9c 100644 --- a/parselistcommand.h +++ b/parselistcommand.h @@ -44,6 +44,7 @@ private: SharedListVector* list; map listGroups; //maps group name to sequences from that group in a specific OTU map::iterator it; + map::iterator it2; map::iterator it3; void parse(int, SharedListVector*); void process(SharedListVector*); diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index d0179be..fdc9678 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -16,12 +16,14 @@ RareFactSharedCommand::RareFactSharedCommand(string option){ try { globaldata = GlobalData::getInstance(); + abort = false; allLines = 1; lines.clear(); labels.clear(); Estimators.clear(); - + Groups.clear(); + //allow user to run help if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; } @@ -83,8 +85,8 @@ RareFactSharedCommand::RareFactSharedCommand(string option){ if (groups == "not found") { groups = ""; } else { splitAtDash(groups, Groups); - globaldata->Groups = Groups; } + globaldata->Groups = Groups; string temp; temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; } @@ -176,7 +178,7 @@ int RareFactSharedCommand::execute(){ input = globaldata->ginput; lookup = input->getSharedRAbundVectors(); vector lastLookup = lookup; - + if (lookup.size() < 2) { cout << "I cannot run the command without at least 2 valid groups."; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } diff --git a/readotu.cpp b/readotu.cpp index 09a6c4c..286a2be 100644 --- a/readotu.cpp +++ b/readotu.cpp @@ -31,21 +31,24 @@ void ReadOTUFile::read(GlobalData* globaldata){ }else {//there is an orderfile input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat()); } - +//cout << "made it here" << endl; //memory leak prevention //if (globaldata->ginput != NULL) { delete globaldata->ginput; } globaldata->ginput = input; //saving to be used by collector and rarefact commands. - +//cout << "after input" << endl; if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary. 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. rabund = inputRabund->getRAbundVector(); + //if (globaldata->rabund != NULL) { delete globaldata->rabund; } globaldata->rabund = rabund; //saving to be used by heatmap.bin command. list = inputList->getListVector(); + //if (globaldata->gListVector != NULL) { delete globaldata->gListVector; } globaldata->gListVector = list; }else if (globaldata->getFormat() == "shared") { diff --git a/readotucommand.cpp b/readotucommand.cpp index 7c3e199..ba7eae4 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -106,7 +106,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ if (abort == false) { //gets whichever one of the above is set filename = globaldata->inputFileName; - read = new ReadOTUFile(filename); + //read = new ReadOTUFile(filename); } } @@ -155,7 +155,8 @@ void ReadOtuCommand::help(){ //********************************************************************************************************************** ReadOtuCommand::~ReadOtuCommand(){ - if (abort == false) { delete read; } + if (abort == false) { //delete read; + } } //********************************************************************************************************************** @@ -165,17 +166,20 @@ int ReadOtuCommand::execute(){ if (abort == true) { return 0; } - read->read(&*globaldata); + //read->read(&*globaldata); if (globaldata->getFormat() == "shared") { groupMap->readMap(); //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } - globaldata->gGroupmap = groupMap; - shared = new SharedCommand(); - shared->execute(); - + globaldata->gGroupmap = groupMap; + parselist = new ParseListCommand(); parselist->execute(); + delete parselist; + + shared = new SharedCommand(); + shared->execute(); + delete shared; //change format to shared to speed up commands globaldata->setFormat("sharedfile"); diff --git a/readotucommand.h b/readotucommand.h index c38d0a5..e07dadc 100644 --- a/readotucommand.h +++ b/readotucommand.h @@ -40,7 +40,7 @@ public: private: GlobalData* globaldata; - ReadOTUFile* read; + //ReadOTUFile* read; InputData* input; Command* shared; Command* parselist; diff --git a/shared.cpp b/shared.cpp index 73f283a..36dbbb1 100644 --- a/shared.cpp +++ b/shared.cpp @@ -21,6 +21,7 @@ void Shared::getSharedVectors(SharedListVector* list) { int i,j; label = list->getLabel(); + for (it = sharedGroups.begin(); it != sharedGroups.end(); it++) { delete it->second; } sharedGroups.clear(); //removes old info. //initalize sharedGroups diff --git a/shared.h b/shared.h index 06d558d..c80ef66 100644 --- a/shared.h +++ b/shared.h @@ -24,6 +24,7 @@ class Shared { private: GlobalData* globaldata; + map::iterator it; void parse(int, SharedListVector*); vector< map > sharedRAbund; //contains all the info needed to create the .shared file not sure if we will need }; diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 22dc2e9..dd90064 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -36,15 +36,19 @@ SharedCommand::SharedCommand(){ int SharedCommand::execute(){ try { globaldata = GlobalData::getInstance(); + //lookup.clear(); int count = 1; string errorOff = "no error"; //read in listfile read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); + input = globaldata->ginput; SharedList = globaldata->gSharedList; SharedListVector* lastList = SharedList; + //lookup = SharedList->getSharedRAbundVector(); + //vector lastLookup = lookup; //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -55,9 +59,9 @@ int SharedCommand::execute(){ while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) { - + if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){ - + shared->getSharedVectors(SharedList); //fills sharedGroups with new info and updates sharedVector printSharedData(); //prints info to the .shared file @@ -76,8 +80,11 @@ int SharedCommand::execute(){ if (count != 1) { delete lastList; } lastList = SharedList; - SharedList = input->getSharedListVector(); //get new list vector to process + + //if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } } + //lastLookup = lookup; + //if (SharedList != NULL) { lookup = SharedList->getSharedRAbundVector(); } } //output error messages about any remaining user labels @@ -101,6 +108,7 @@ int SharedCommand::execute(){ delete lastList; delete shared; + out.close(); return 0; } @@ -117,6 +125,12 @@ int SharedCommand::execute(){ //********************************************************************************************************************** void SharedCommand::printSharedData() { try { + + ///for (int i = 0; i < thislookup.size(); i++) { + // out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; +//cout << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << endl; + // thislookup[i]->print(out); + // } //prints out horizontally for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) { out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname diff --git a/sharedcommand.h b/sharedcommand.h index 08314b5..e5be50a 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -40,6 +40,7 @@ private: InputData* input; Shared* shared; map::iterator it; + //vector lookup; ofstream out; string filename; diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 33d3692..4774180 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -16,11 +16,11 @@ /***********************************************************************/ -SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){} +SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance();} /***********************************************************************/ -SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){} +SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance();} /***********************************************************************/ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { @@ -272,6 +272,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { rav.setLabel(label); rav.setGroup(groupName); + return rav; } @@ -292,6 +293,8 @@ vector SharedListVector::getSharedRAbundVector() { vector lookup; util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); + + delete util; for (int i = 0; i < globaldata->Groups.size(); i++) { SharedRAbundVector* temp = new SharedRAbundVector(); diff --git a/sharedlistvector.h b/sharedlistvector.h index 8cfb7e0..2c8d01b 100644 --- a/sharedlistvector.h +++ b/sharedlistvector.h @@ -33,7 +33,7 @@ public: SharedListVector(); SharedListVector(int); SharedListVector(ifstream&); - SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){}; + SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){globaldata = GlobalData::getInstance();}; ~SharedListVector(){}; int getNumBins() { return numBins; } diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 135763e..f60562a 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -15,11 +15,12 @@ /***********************************************************************/ -SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {} +SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {globaldata = GlobalData::getInstance();} /***********************************************************************/ SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) { + globaldata = GlobalData::getInstance(); individual newGuy; //initialize data for (int i=0; i< n; i++) { diff --git a/sharedutilities.cpp b/sharedutilities.cpp index 703241b..de627c6 100644 --- a/sharedutilities.cpp +++ b/sharedutilities.cpp @@ -66,7 +66,6 @@ void SharedUtil::getSharedVectorswithReplacement(vector Groups, vector Groups, vector& userGroups, vector& allGroups) { try { -//cout << "groups size" << userGroups.size() << endl; if (userGroups.size() != 0) { if (userGroups[0] != "all") { //check that groups are valid diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index a32b202..7c1275f 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -64,10 +64,8 @@ SummarySharedCommand::SummarySharedCommand(string option){ //make sure the user has already run the read.otu command if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the summary.shared command." << endl; abort = true; } - else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the summary.shared command." << endl; abort = true; } + cout << "You must read a list and a group, or a shared before you can use the summary.shared command." << endl; abort = true; } - //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -163,11 +161,9 @@ SummarySharedCommand::SummarySharedCommand(string option){ outputFileName = ((getRootName(globaldata->inputFileName)) + "shared.summary"); openOutputFile(outputFileName, outputFileHandle); -// format = globaldata->getFormat(); mult = false; } } - } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the SummarySharedCommand class Function SummarySharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -208,7 +204,6 @@ void SummarySharedCommand::help(){ //********************************************************************************************************************** SummarySharedCommand::~SummarySharedCommand(){ - delete input; delete read; delete validCalculator; } @@ -337,6 +332,10 @@ int SummarySharedCommand::execute(){ //close files outputFileHandle.close(); if (mult == true) { outAll.close(); } + + for(int i=0;i