From: westcott Date: Thu, 28 Jan 2010 18:11:16 +0000 (+0000) Subject: fixed some bugs found while testing 1.8 X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=6777912b79eb6d011163da47f3ada09d1a9293c1 fixed some bugs found while testing 1.8 --- diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index 4f44880..bfd3e98 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -452,7 +452,7 @@ void BootSharedCommand::process(SharedOrderVector* order) { //set global data to calc trees globaldata->gTree = trees[k]; - string filename = getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[k]->getName() + ".boot" + order->getLabel(); + string filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[k]->getName() + ".boot" + order->getLabel(); consensus = new ConcensusCommand(filename); consensus->execute(); delete consensus; diff --git a/collectcommand.cpp b/collectcommand.cpp index a31883c..473d2db 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -136,17 +136,17 @@ int CollectCommand::execute(){ if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } - + for (int p = 0; p < inputFileNames.size(); p++) { - + if (outputDir == "") { outputDir += hasPath(inputFileNames[p]); } string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])); globaldata->inputFileName = inputFileNames[p]; - + if (inputFileNames.size() > 1) { mothurOutEndLine(); mothurOut("Processing group " + groups[p]); mothurOutEndLine(); mothurOutEndLine(); } - + validCalculator = new ValidCalculators(); for (int i=0; iread(&*globaldata); - + order = globaldata->gorder; string lastLabel = order->getLabel(); input = globaldata->ginput; diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index a8d5069..2f12282 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -223,10 +223,10 @@ int CollectSharedCommand::execute(){ //if the users entered no valid calculators don't execute command if (cDisplays.size() == 0) { return 0; } for(int i=0;isetAll(all); } - + read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); - + input = globaldata->ginput; order = input->getSharedOrderVector(); string lastLabel = order->getLabel(); diff --git a/commandfactory.cpp b/commandfactory.cpp index 5eb4ff5..c787d07 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -134,7 +134,7 @@ CommandFactory::CommandFactory(){ commands["phylotype"] = "phylotype"; commands["mgcluster"] = "mgcluster"; commands["pre.cluster"] = "pre.cluster"; - commands["pca"] = "pca"; + commands["pcoa"] = "pcoa"; commands["otu.hierarchy"] = "otu.hierarchy"; commands["set.dir"] = "set.dir"; } @@ -217,7 +217,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else if(commandName == "phylotype") { command = new PhylotypeCommand(optionString); } else if(commandName == "mgcluster") { command = new MGClusterCommand(optionString); } else if(commandName == "pre.cluster") { command = new PreClusterCommand(optionString); } - else if(commandName == "pca") { command = new PCACommand(optionString); } + else if(commandName == "pcoa") { command = new PCACommand(optionString); } else if(commandName == "otu.hierarchy") { command = new OtuHierarchyCommand(optionString); } else if(commandName == "set.dir") { command = new SetDirectoryCommand(optionString); } else { command = new NoCommand(optionString); } diff --git a/fileoutput.cpp b/fileoutput.cpp index cd3a1c7..0d78a2d 100644 --- a/fileoutput.cpp +++ b/fileoutput.cpp @@ -81,6 +81,8 @@ void ThreeColumnFile::resetFile(){ remove(inName.c_str()); renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { mothurOut("Unable to rename " + outName); mothurOutEndLine(); @@ -183,6 +185,8 @@ void ColumnFile::resetFile(){ remove(inName.c_str()); renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { mothurOut("Unable to rename " + outName); mothurOutEndLine(); @@ -265,9 +269,12 @@ void SharedThreeColumnFile::resetFile(){ outFile.close(); } counter = 1; + remove(inName.c_str()); renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { mothurOut("Unable to rename " + outName); mothurOutEndLine(); @@ -345,19 +352,22 @@ void OneColumnFile::resetFile(){ if(counter != 0){ outFile.close(); inFile.close(); - } - else{ + }else{ outFile.close(); } counter = 1; + remove(inName.c_str()); renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { mothurOut("Unable to rename " + outName); mothurOutEndLine(); perror(" : "); } + } catch(exception& e) { errorOut(e, "OneColumnFile", "resetFile"); @@ -445,9 +455,10 @@ void SharedOneColumnFile::resetFile(){ counter = 1; remove(inName.c_str()); - renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { mothurOut("Unable to rename " + outName); mothurOutEndLine(); diff --git a/fileoutput.h b/fileoutput.h index 0c7999d..17bd7a1 100644 --- a/fileoutput.h +++ b/fileoutput.h @@ -28,7 +28,7 @@ protected: class ThreeColumnFile : public FileOutput { public: - ThreeColumnFile(string n) : FileOutput(), inName(n), counter(0), outName(getPathName(n) + ".temp") { }; + ThreeColumnFile(string n) : FileOutput(), inName(n), counter(0), outName(n + ".temp") { }; ~ThreeColumnFile(); void initFile(string); void output(int, vector); @@ -52,7 +52,7 @@ class OneColumnFile : public FileOutput { public: - OneColumnFile(string n) : inName(n), counter(0), outName(getPathName(n) + ".temp") {}; + OneColumnFile(string n) : inName(n), counter(0), outName(n + ".temp") {}; ~OneColumnFile(); void output(int, vector); void initFile(string); @@ -76,7 +76,7 @@ class SharedOneColumnFile : public FileOutput { public: - SharedOneColumnFile(string n) : inName(n), counter(0), outName(getPathName(n) + ".temp") {}; + SharedOneColumnFile(string n) : inName(n), counter(0), outName(n + ".temp") {}; ~SharedOneColumnFile(); void output(int, vector); void initFile(string); @@ -101,7 +101,7 @@ private: class SharedThreeColumnFile : public FileOutput { public: - SharedThreeColumnFile(string n, string groups) : FileOutput(), groupLabel(groups), inName(n), counter(0), numGroup(1), outName(getPathName(n) + ".temp") { }; + SharedThreeColumnFile(string n, string groups) : FileOutput(), groupLabel(groups), inName(n), counter(0), numGroup(1), outName(n + ".temp") { }; ~SharedThreeColumnFile(); void initFile(string); void output(int, vector); @@ -125,7 +125,7 @@ private: class ColumnFile : public FileOutput { public: - ColumnFile(string n, string i) : FileOutput(), iters(i), inName(n), counter(0), outName(getPathName(n) + ".temp") {}; + ColumnFile(string n, string i) : FileOutput(), iters(i), inName(n), counter(0), outName(n + ".temp") {}; ~ColumnFile(); //to make compatible with parent class diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 6b9cee9..935812b 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -391,7 +391,7 @@ int GetOTURepCommand::execute(){ //close and remove formatted matrix file if (large) { inRow.close(); - //remove(distFile.c_str()); + remove(distFile.c_str()); } globaldata->gListVector = NULL; diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index 7af1ac6..0497589 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -189,7 +189,7 @@ int GetSharedOTUCommand::execute(){ openInputFile(fastafile, inFasta); while(!inFasta.eof()) { - Sequence seq(inFasta); + Sequence seq(inFasta); gobble(inFasta); if (seq.getName() != "") { seqs.push_back(seq); } } inFasta.close(); @@ -404,7 +404,7 @@ void GetSharedOTUCommand::process(ListVector* shared) { } outFasta << seqs[k].getAligned() << endl; - }else { mothurOut(seqs[k].getName() + " is not in your fasta file. Please correct."); mothurOutEndLine(); } + } } outFasta.close(); diff --git a/hcluster.h b/hcluster.h index da7769d..7fc8177 100644 --- a/hcluster.h +++ b/hcluster.h @@ -17,16 +17,6 @@ class RAbundVector; class ListVector; -/***********************************************************************/ -struct linkNode { - int links; - float dist; - - linkNode() {}; - linkNode(int l, float a) : links(l), dist(a) {}; - ~linkNode() {}; -}; - /***********************************************************************/ class HCluster { diff --git a/mothur.h b/mothur.h index 8065dd4..fdaa063 100644 --- a/mothur.h +++ b/mothur.h @@ -433,8 +433,8 @@ inline string getPathName(string longName){ string rootPathName = longName; - if(longName.find_last_of('/') != longName.npos){ - int pos = longName.find_last_of('/')+1; + if(longName.find_last_of("/\\") != longName.npos){ + int pos = longName.find_last_of("/\\")+1; rootPathName = longName.substr(0, pos); } @@ -591,19 +591,15 @@ inline int openInputFile(string fileName, ifstream& fileHandle, string m){ //get full path name string completeFileName = getFullPathName(fileName); - //string completeFileName = fileName; fileHandle.open(completeFileName.c_str()); if(!fileHandle) { - mothurOut("Error: Could not open " + completeFileName); mothurOutEndLine(); return 1; - } - else { + }else { //check for blank file gobble(fileHandle); return 0; - } - + } } /***********************************************************************/ @@ -625,6 +621,28 @@ inline int openInputFile(string fileName, ifstream& fileHandle){ } } +/***********************************************************************/ + +inline int renameFile(string oldName, string newName){ + + ifstream inTest; + int exist = openInputFile(newName, inTest, ""); + +#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) + if (exist == 0) { //you could open it so you want to delete it + inTest.close(); + string command = "rm " + newName; + system(command.c_str()); + } + + string command = "mv " + oldName + " " + newName; + system(command.c_str()); +#else + remove(newName.c_str()); + renameOk = rename(oldName.c_str(), newName.c_str()); +#endif + return 0; +} /***********************************************************************/ diff --git a/preclustercommand.cpp b/preclustercommand.cpp index d638bd2..1697ff7 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -215,7 +215,7 @@ int PreClusterCommand::readFASTA(){ } } /**************************************************************************************************/ - +//this seems to require the names and fasta file to be in the same order??? int PreClusterCommand::readNamesFASTA(){ try { ifstream inNames; @@ -238,7 +238,8 @@ int PreClusterCommand::readNamesFASTA(){ size++; secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length()); } - Sequence seq(inFasta); + + Sequence seq(inFasta); gobble(inFasta); if (seq.getName() != firstCol) { mothurOut(seq.getName() + " is not in your names file, please correct."); mothurOutEndLine(); exit(1); } else{ seqPNode tempNode(size, seq, nameString); diff --git a/readotucommand.cpp b/readotucommand.cpp index e55e980..89013e6 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -225,13 +225,8 @@ int ReadOtuCommand::execute(){ globaldata->setListFile(""); globaldata->setGroupFile(""); globaldata->setSharedFile(""); - }else{ - - //change format to shared to speed up commands - globaldata->setFormat("sharedfile"); - globaldata->setListFile(""); - globaldata->setGroupFile(""); } + delete shared; } return 0; diff --git a/sharedcommand.cpp b/sharedcommand.cpp index efc45c1..1fe2300 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -65,7 +65,7 @@ int SharedCommand::execute(){ //lookup.clear(); string errorOff = "no error"; //errorOff = ""; -cout << globaldata->inputFileName << endl; + //read in listfile read = new ReadOTUFile(globaldata->inputFileName); read->read(&*globaldata); @@ -101,7 +101,7 @@ cout << globaldata->inputFileName << endl; groups += globaldata->Groups[i] + "."; } - string newGroupFile = getRootName(globaldata->inputFileName) + groups + "groups"; + string newGroupFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + groups + "groups"; ofstream outGroups; openOutputFile(newGroupFile, outGroups); @@ -199,7 +199,13 @@ cout << globaldata->inputFileName << endl; delete it3->second; } + + //change format to shared to speed up commands + globaldata->setFormat("sharedfile"); + globaldata->setListFile(""); + globaldata->setGroupFile(""); globaldata->setSharedFile(filename); + return 0; } @@ -274,7 +280,7 @@ void SharedCommand::eliminateZeroOTUS(vector& thislookup) { void SharedCommand::createMisMatchFile() { try { ofstream outMisMatch; - string outputMisMatchName = getRootName(globaldata->inputFileName); + string outputMisMatchName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)); //you have sequences in your list file that are not in your group file if (SharedList->getNumSeqs() > groupMap->getNumSeqs()) { diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index 4dc07a7..70b1b4a 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -105,7 +105,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option){ temp = validParameter.validFile(parameters, "qfile", true); if (temp == "not found") { qFileName = ""; } - else if(temp == "not open") { abort = 0; } + else if(temp == "not open") { abort = true; } else { qFileName = temp; } temp = validParameter.validFile(parameters, "qthreshold", false); if (temp == "not found") { temp = "0"; } @@ -183,7 +183,10 @@ int TrimSeqsCommand::execute(){ try{ if (abort == true) { return 0; } - + + numFPrimers = 0; //this needs to be initialized + numRPrimers = 0; + ifstream inFASTA; openInputFile(fastaFile, inFASTA); @@ -207,9 +210,10 @@ int TrimSeqsCommand::execute(){ if(qFileName != "") { openInputFile(qFileName, qFile); } bool success; - + while(!inFASTA.eof()){ Sequence currSeq(inFASTA); + string origSeq = currSeq.getUnaligned(); if (origSeq != "") { int group; @@ -223,21 +227,22 @@ int TrimSeqsCommand::execute(){ } if(!success) { trashCode += 'q'; } } - + if(barcodes.size() != 0){ success = stripBarcode(currSeq, group); if(!success){ trashCode += 'b'; } } - + if(numFPrimers != 0){ success = stripForward(currSeq); if(!success){ trashCode += 'f'; } } - + if(numRPrimers != 0){ success = stripReverse(currSeq); if(!success){ trashCode += 'r'; } } + if(minLength > 0 || maxLength > 0){ success = cullLength(currSeq); if(!success){ trashCode += 'l'; } @@ -299,8 +304,7 @@ int TrimSeqsCommand::execute(){ outGroups.close(); inFASTA.close(); } - - + return 0; } catch(exception& e) {