From: westcott Date: Fri, 8 Apr 2011 13:30:14 +0000 (+0000) Subject: fixing bugs while testing X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=10c8178dc5e3f96ef8e92a986f1eddd13e622173 fixing bugs while testing --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 9d88f25..5a384ce 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -1014,8 +1014,8 @@ A7E9B82412D37EC400DA6239 /* sharedutilities.h */, A7E9B82D12D37EC400DA6239 /* singlelinkage.cpp */, A7E9B83012D37EC400DA6239 /* slibshuff.cpp */, - A7E9B83112D37EC400DA6239 /* slibshuff.h */, A7E9B85112D37EC400DA6239 /* suffixdb.cpp */, + A7E9B83112D37EC400DA6239 /* slibshuff.h */, A7E9B85212D37EC400DA6239 /* suffixdb.hpp */, A7E9B85312D37EC400DA6239 /* suffixnodes.cpp */, A7E9B85412D37EC400DA6239 /* suffixnodes.hpp */, diff --git a/amovacommand.cpp b/amovacommand.cpp index af867de..f1e5f61 100644 --- a/amovacommand.cpp +++ b/amovacommand.cpp @@ -282,7 +282,7 @@ double AmovaCommand::runAMOVA(ofstream& AMOVAFile, map > gro m->mothurOut("df\t" + toString(dfAmong) + '\t' + toString(dfWithin) + '\t' + toString(dfTotal) + '\n'); AMOVAFile << "MS\t" << MSAmong << '\t' << MSWithin << endl << endl; - m->mothurOut("MS\t" + toString(MSAmong) + '\t' + toString(MSWithin) + "\n"); + m->mothurOut("MS\t" + toString(MSAmong) + '\t' + toString(MSWithin) + "\n\n"); AMOVAFile << "Fs:\t" << Fs << endl; m->mothurOut("Fs:\t" + toString(Fs) + '\n'); diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index 3f9378f..34965f6 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -281,10 +281,6 @@ int BinSeqCommand::execute(){ if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } - delete input; - delete fasta; - if (groupfile != "") { delete groupMap; } - m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } diff --git a/formatphylip.cpp b/formatphylip.cpp index 60a3b41..0390a80 100644 --- a/formatphylip.cpp +++ b/formatphylip.cpp @@ -24,7 +24,12 @@ int FormatPhylipMatrix::read(NameAssignment* nameMap){ string name; ofstream out; - fileHandle >> nseqs >> name; + string numTest; + fileHandle >> numTest >> name; + + if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ", quitting."); m->mothurOutEndLine(); exit(1); } + else { convert(numTest, nseqs); } + list = new ListVector(nseqs); list->set(0, name); diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index 236eef2..381a950 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -16,7 +16,6 @@ vector GetlabelCommand::setParameters(){ CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); - CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); @@ -44,7 +43,7 @@ GetlabelCommand::GetlabelCommand(){ string GetlabelCommand::getHelpString(){ try { string helpString = ""; - helpString += "The get.label command parameters are list, sabund, rabund and shared file. \n"; + helpString += "The get.label command parameters are list, sabund and rabund file. \n"; helpString += "The get.label command should be in the following format: \n"; helpString += "get.label()\n"; helpString += "Example get.label().\n"; @@ -83,13 +82,6 @@ GetlabelCommand::GetlabelCommand(string option) { if (inputDir == "not found"){ inputDir = ""; } else { string path; - it = parameters.find("shared"); - //user has given a template file - if(it != parameters.end()){ - path = m->hasPath(it->second); - //if the user has not given a path then, add inputdir. else leave path alone. - if (path == "") { parameters["shared"] = inputDir + it->second; } - } it = parameters.find("rabund"); //user has given a template file @@ -132,35 +124,26 @@ GetlabelCommand::GetlabelCommand(string option) { else if (rabundfile == "not found") { rabundfile = ""; } else { format = "rabund"; inputfile = rabundfile; } - sharedfile = validParameter.validFile(parameters, "shared", true); - if (sharedfile == "not open") { sharedfile = ""; abort = true; } - else if (sharedfile == "not found") { sharedfile = ""; } - else { format = "sharedfile"; inputfile = sharedfile; } - - if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { + if ((listfile == "") && (rabundfile == "") && (sabundfile == "")) { //is there are current file available for any of these? - //give priority to shared, then list, then rabund, then sabund + //give priority to list, then rabund, then sabund //if there is a current shared file, use it - sharedfile = m->getSharedFile(); - if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } else { - listfile = m->getListFile(); - if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + rabundfile = m->getRabundFile(); + if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } else { - rabundfile = m->getRabundFile(); - if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + sabundfile = m->getSabundFile(); + if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } else { - sabundfile = m->getSabundFile(); - if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } - else { - m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file before you can use the collect.single command."); m->mothurOutEndLine(); - abort = true; - } + m->mothurOut("No valid current files. You must provide a list, sabund or rabund file."); m->mothurOutEndLine(); + abort = true; } } } } - } } @@ -184,10 +167,10 @@ int GetlabelCommand::execute(){ if (m->control_pressed) { delete input; delete order; return 0; } - m->mothurOut(label); m->mothurOutEndLine(); - label = order->getLabel(); + m->mothurOut(label); m->mothurOutEndLine(); + delete order; order = input->getOrderVector(); } diff --git a/getlabelcommand.h b/getlabelcommand.h index 3aaa92d..606daf4 100644 --- a/getlabelcommand.h +++ b/getlabelcommand.h @@ -31,7 +31,7 @@ public: private: - string inputfile, listfile, rabundfile, sabundfile, sharedfile, format; + string inputfile, listfile, rabundfile, sabundfile, format; bool abort; vector outputNames; }; diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index 65eedaa..2f49a3b 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -194,8 +194,6 @@ int GetRAbundCommand::execute(){ if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } - - delete rabund; processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); @@ -214,8 +212,6 @@ int GetRAbundCommand::execute(){ if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } - delete rabund; - processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index ebfa839..8208684 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -186,7 +186,6 @@ int GetSAbundCommand::execute(){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); sabund->print(out); - delete sabund; if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete sabund; delete input; return 0; } @@ -202,7 +201,6 @@ int GetSAbundCommand::execute(){ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); sabund->print(out); - delete sabund; if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete sabund; delete input; return 0; } diff --git a/inputdata.cpp b/inputdata.cpp index ec23955..08bab60 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -292,7 +292,7 @@ OrderVector* InputData::getOrderVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - + m->gobble(fileHandle); output = new OrderVector(); @@ -394,7 +394,7 @@ OrderVector* InputData::getOrderVector(string label){ } } - + in.close(); output = new OrderVector(); @@ -622,8 +622,7 @@ SAbundVector* InputData::getSAbundVector(){ } else if(format == "sabund"){ input = new SAbundVector(fileHandle); - } - + } m->gobble(fileHandle); sabund = new SAbundVector(); @@ -762,7 +761,7 @@ RAbundVector* InputData::getRAbundVector(){ else if(format == "sabund"){ input = new SAbundVector(fileHandle); } - + m->gobble(fileHandle); rabund = new RAbundVector(); @@ -862,7 +861,8 @@ RAbundVector* InputData::getRAbundVector(string label){ } - } + } + in.close(); diff --git a/mothurout.cpp b/mothurout.cpp index 59e4fdc..7309c17 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -1731,6 +1731,23 @@ bool MothurOut::checkReleaseVersion(ifstream& file, string version) { } } /**************************************************************************************************/ +bool MothurOut::isContainingOnlyDigits(string input) { + try{ + + //are you a digit in ascii code + for (int i = 0;i < input.length(); i++){ + if( input[i]>47 && input[i]<58){} + else { return false; } + } + + return true; + } + catch(exception& e) { + errorOut(e, "MothurOut", "isContainingOnlyDigits"); + exit(1); + } +} +/**************************************************************************************************/ diff --git a/mothurout.h b/mothurout.h index 6654455..f20d5c1 100644 --- a/mothurout.h +++ b/mothurout.h @@ -75,6 +75,7 @@ class MothurOut { int getNumSeqs(ifstream&); int getNumNames(string); bool isTrue(string); + bool isContainingOnlyDigits(string); //string manipulation diff --git a/readcluster.cpp b/readcluster.cpp index 025d718..497fc80 100644 --- a/readcluster.cpp +++ b/readcluster.cpp @@ -60,8 +60,13 @@ int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ int square, nseqs; string name; vector matrixNames; - - in >> nseqs >> name; + + string numTest; + in >> numTest >> name; + + if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ", quitting."); m->mothurOutEndLine(); exit(1); } + else { convert(numTest, nseqs); } + rowToName[0] = name; matrixNames.push_back(name); diff --git a/readphylip.cpp b/readphylip.cpp index b13dc25..1c529b2 100644 --- a/readphylip.cpp +++ b/readphylip.cpp @@ -36,9 +36,13 @@ int ReadPhylipMatrix::read(NameAssignment* nameMap){ int square, nseqs; string name; vector matrixNames; - - fileHandle >> nseqs >> name; - + + string numTest; + fileHandle >> numTest >> name; + + if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ", quitting."); m->mothurOutEndLine(); exit(1); } + else { convert(numTest, nseqs); } + matrixNames.push_back(name); if(nameMap == NULL){ diff --git a/readphylipvector.cpp b/readphylipvector.cpp index c3ffcce..85f4777 100644 --- a/readphylipvector.cpp +++ b/readphylipvector.cpp @@ -34,7 +34,11 @@ vector ReadPhylipVector::read(vector< vector >& matrix) { int numSeqs; string name; - in >> numSeqs >> name; + string numTest; + in >> numTest >> name; + + if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ". I suspect you entered a column formatted file as a phylip file, quitting."); m->mothurOutEndLine(); exit(1); } + else { convert(numTest, numSeqs); } while((d=in.get()) != EOF){ diff --git a/validparameter.cpp b/validparameter.cpp index 4b263b4..7855dde 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -291,6 +291,18 @@ string ValidParameters::validFile(map& container, string paramet m->mothurOut("Unable to open " + container[parameter]); m->mothurOutEndLine(); return "not open"; } + + //check phylip file to make sure its really phylip and not column + if ((it->first == "phylip") && (ableToOpen != 1)) { + ifstream inPhylip; + m->openInputFile(it->second, inPhylip); + + string numTest, name; + inPhylip >> numTest >> name; + inPhylip.close(); + + if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ". I suspect you entered a column formatted file as a phylip file, aborting."); m->mothurOutEndLine(); return "not found"; } + } } }else { return "not found"; }