]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed some bugs found while testing 1.8
authorwestcott <westcott>
Thu, 28 Jan 2010 18:11:16 +0000 (18:11 +0000)
committerwestcott <westcott>
Thu, 28 Jan 2010 18:11:16 +0000 (18:11 +0000)
14 files changed:
bootstrapsharedcommand.cpp
collectcommand.cpp
collectsharedcommand.cpp
commandfactory.cpp
fileoutput.cpp
fileoutput.h
getoturepcommand.cpp
getsharedotucommand.cpp
hcluster.h
mothur.h
preclustercommand.cpp
readotucommand.cpp
sharedcommand.cpp
trimseqscommand.cpp

index 4f4488085a8754b731ca6c742ee43f7b0dc690c4..bfd3e984f28208d37e49f22403ad59647af38e7f 100644 (file)
@@ -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;
index a31883cf3c65aabf3955d12191b91b9ad9fe050c..473d2db8b473bbef240793c419e6c8beece29ddf 100644 (file)
@@ -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; i<Estimators.size(); i++) {
@@ -195,13 +195,12 @@ int CollectCommand::execute(){
                                }
                        }
                
-                       
                        //if the users entered no valid calculators don't execute command
                        if (cDisplays.size() == 0) { return 0; }
                        
                        read = new ReadOTUFile(inputFileNames[p]);      
                        read->read(&*globaldata); 
-                               
+               
                        order = globaldata->gorder;
                        string lastLabel = order->getLabel();
                        input = globaldata->ginput;
index a8d5069d7d123277b58df1cfdf1d0ff8b773c4e6..2f12282d7c4ca3379e9fe9b9848acd6ed5bd2df6 100644 (file)
@@ -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;i<cDisplays.size();i++){    cDisplays[i]->setAll(all);      }       
-               
+       
                read = new ReadOTUFile(globaldata->inputFileName);      
                read->read(&*globaldata); 
-                       
+               
                input = globaldata->ginput;
                order = input->getSharedOrderVector();
                string lastLabel = order->getLabel();
index 5eb4ff5df0eaf4999808925e658e61c1eedccf31..c787d07e066ae08db298efb849966dcf0782113d 100644 (file)
@@ -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);                                  }
index cd3a1c74084de46dd7f5c7805d3425f0d0dd3ecb..0d78a2db778b22ec0313d56781de192d56f64693 100644 (file)
@@ -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();
index 0c7999d2c901cc3c3c28357837e467dabb4a990a..17bd7a1d7d23dd6a86ae2ea2ec5e5c16e9665171 100644 (file)
@@ -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<double>);
@@ -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<double>);
        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<double>);
        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<double>);
@@ -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
index 6b9cee90c40f8f2848a076596d9ed3c88665ffb0..935812b1cdc07a1e86b8bde1e7179f1fd8db8d13 100644 (file)
@@ -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;
index 7af1ac67349843c59a282338387dc127239a1bcb..049758943550859e7df4a933ea427421be450e85 100644 (file)
@@ -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();
index da7769d8813e656cd5e63fc3ec15b10c210e062b..7fc8177c56d50303771e1a60c9fdd0f4e84d957b 100644 (file)
 class RAbundVector;
 class ListVector;
 
-/***********************************************************************/
-struct linkNode {
-       int     links;
-       float dist;
-       
-       linkNode() {};
-       linkNode(int l, float a) : links(l), dist(a) {};
-       ~linkNode() {};
-};
-
 /***********************************************************************/
 class HCluster {
        
index 8065dd4cc74284f11dbca4808eb2c8893a74b7c8..fdaa06362db6ecda7054fe4ff9b21442487c19d4 100644 (file)
--- 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;
+}
 
 /***********************************************************************/
 
index d638bd2240a46ab20a7b5253e15be5a056a41aa4..1697ff7a0d57534b81e9b1f135cf494ae55c2d34 100644 (file)
@@ -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);
index e55e9805af42cf37728fad27cc4f8b60f36fc882..89013e68bfd0235678ac6664838e3259596956f3 100644 (file)
@@ -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;
index efc45c191482cc191fa204e526758a81af4bf910..1fe2300387a96e81500a0b41c76190df02aba935 100644 (file)
@@ -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<SharedRAbundVector*>& 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()) { 
index 4dc07a7afa207f80b026077b7abfbbb27bb498c2..70b1b4ae8a0c931ff3f84a56d4dd68fa1edd537a 100644 (file)
@@ -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) {