]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed bugs for 1.8
authorwestcott <westcott>
Tue, 2 Feb 2010 14:33:49 +0000 (14:33 +0000)
committerwestcott <westcott>
Tue, 2 Feb 2010 14:33:49 +0000 (14:33 +0000)
Mothur.xcodeproj/project.pbxproj
formatphylip.cpp
hcluster.cpp
mothur.cpp
mothur.h
preclustercommand.cpp
preclustercommand.h
secondarystructurecommand.cpp
secondarystructurecommand.h
setdircommand.cpp

index e697db8d1b3e6c4718f1f24320b59bdb6c7d0d67..21dbf8dfbb074de24a0b70e523bd95e56d414695 100644 (file)
                A78782AA10A1B1CB0086103D /* alignmentdb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = alignmentdb.cpp; sourceTree = SOURCE_ROOT; };
                A787844310A1EBDD0086103D /* knn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = knn.h; sourceTree = SOURCE_ROOT; };
                A787844410A1EBDD0086103D /* knn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = knn.cpp; sourceTree = SOURCE_ROOT; };
-               A794200F11107897003AECCD /* distancedb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = distancedb.cpp; sourceTree = "<group>"; };
-               A794201011107897003AECCD /* distancedb.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = distancedb.hpp; sourceTree = "<group>"; };
+               A794200F11107897003AECCD /* distancedb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = distancedb.cpp; sourceTree = SOURCE_ROOT; };
+               A794201011107897003AECCD /* distancedb.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = distancedb.hpp; sourceTree = SOURCE_ROOT; };
                A7B04491106CC3E60046FC83 /* chimeraslayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimeraslayer.h; sourceTree = SOURCE_ROOT; };
                A7B04492106CC3E60046FC83 /* chimeraslayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimeraslayer.cpp; sourceTree = SOURCE_ROOT; };
                A7B0450C106CEEC90046FC83 /* slayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = slayer.h; sourceTree = SOURCE_ROOT; };
index 4a7878a54a19fb6a63ad32c00d359c7b490e5216..d7211cf8c0a2b1b0ef08c8696e348358404ae369 100644 (file)
@@ -165,16 +165,16 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                int index = nseqs;
                                map<int, float> rowMap;
                                map<int, float>::iterator itRow;
-
+                               rowPos.resize(nseqs, -1);
                 
                                for(int i=0;i<nseqs;i++){
                                        fileHandle >> name;                
-                                                                               
+                                                                       
                                        list->set(i, name);
                                        
                                        for(int j=0;j<nseqs;j++){
                                                fileHandle >> distance;
-                                               
+                                       
                                                if (distance == -1) { distance = 1000000; }
                                                
                                                if((distance < cutoff) && (j != i)){
@@ -184,6 +184,8 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){
                                                reading->update(index);
                                        }
                                        
+                                       gobble(fileHandle);
+                       
                                        //save position in file of each new row
                                        rowPos[i] = out.tellp();
 
index db937851dfae88802dd27ee9dcb65d8beeb60d0f..ee6040bb8802b36a6728a8abcd7dee7c7e3f2001 100644 (file)
@@ -622,9 +622,10 @@ void HCluster::combineFile() {
                mergedMin.clear();
                        
                //rename tempfile to distfile
-               remove(distfile.c_str());
-               rename(tempDistFile.c_str(), distfile.c_str());
-               
+               int renameOK = remove(distfile.c_str());
+               int ok = rename(tempDistFile.c_str(), distfile.c_str());
+//cout << "remove = "<< renameOK << " rename = " << ok << endl;        
+
                //merge clustered rows averaging the distances
                map<int, float>::iterator itMerge;
                map<int, float>::iterator it2Merge;
index bd7ab728c76d311ffe0dc7dcc052a026cfa6e741..b71057a24550aaad2b07bc1d7794a6710191409e 100644 (file)
@@ -44,9 +44,9 @@ int main(int argc, char *argv[]){
 
                
                //header
-               mothurOut("mothur v.1.7.2");
+               mothurOut("mothur v.1.8");
                mothurOutEndLine();             
-               mothurOut("Last updated: 12/04/2009");
+               mothurOut("Last updated: 2/02/2010");
                mothurOutEndLine();     
                mothurOutEndLine();             
                mothurOut("by");
index fdaa06362db6ecda7054fe4ff9b21442487c19d4..74d71caed4df23c2472b7b9b8c229e315721a424 100644 (file)
--- a/mothur.h
+++ b/mothur.h
@@ -639,7 +639,7 @@ inline int renameFile(string oldName, string newName){
        system(command.c_str());
 #else
        remove(newName.c_str());
-       renameOk = rename(oldName.c_str(), newName.c_str());
+       int renameOk = rename(oldName.c_str(), newName.c_str());
 #endif
        return 0;
 }
index 1697ff7a0d57534b81e9b1f135cf494ae55c2d34..d97ffc7934484c3b7ba29a3674418c672b77133a 100644 (file)
@@ -74,7 +74,7 @@ PreClusterCommand::PreClusterCommand(string option){
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not found") { namefile =  "";  }
                        else if (namefile == "not open") { abort = true; }      
-//                     else {  readNameFile();  }
+                       else {  readNameFile();  }
                        
                        string temp     = validParameter.validFile(parameters, "diffs", false);                         if(temp == "not found"){        temp = "1"; }
                        convert(temp, diffs); 
@@ -116,7 +116,7 @@ int PreClusterCommand::execute(){
                if (abort == true) { return 0; }
                
                //reads fasta file and return number of seqs
-               int numSeqs = readNamesFASTA(); //fills alignSeqs and makes all seqs active
+               int numSeqs = readFASTA(); //fills alignSeqs and makes all seqs active
        
                if (numSeqs == 0) { mothurOut("Error reading fasta file...please correct."); mothurOutEndLine(); return 0;  }
                if (diffs > length) { mothurOut("Error: diffs is greater than your sequence length."); mothurOutEndLine(); return 0;  }
@@ -179,7 +179,7 @@ int PreClusterCommand::execute(){
                exit(1);
        }
 }
-/**************************************************************************************************/
+/**************************************************************************************************
 int PreClusterCommand::readFASTA(){
        try {
 //             ifstream inFasta;
@@ -216,44 +216,55 @@ int PreClusterCommand::readFASTA(){
 }
 /**************************************************************************************************/
 //this seems to require the names and fasta file to be in the same order???
-int PreClusterCommand::readNamesFASTA(){
+int PreClusterCommand::readFASTA(){
        try {
-               ifstream inNames;
+               //ifstream inNames;
                ifstream inFasta;
                
-               openInputFile(namefile, inNames);
+               //openInputFile(namefile, inNames);
                openInputFile(fastafile, inFasta);
                
-               string firstCol, secondCol, nameString;
+               //string firstCol, secondCol, nameString;
                length = 0;
                
-               while (inFasta && inNames) {
+               while (!inFasta.eof()) {
        
-                       inNames >> firstCol >> secondCol;
-                       nameString = secondCol;
+                       //inNames >> firstCol >> secondCol;
+                       //nameString = secondCol;
                        
-                       gobble(inNames);
-                       int size = 1;
-                       while (secondCol.find_first_of(',') != -1) { 
-                               size++;
-                               secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
-                       }
+                       //gobble(inNames);
+                       //int size = 1;
+                       //while (secondCol.find_first_of(',') != -1) { 
+                       //      size++;
+                       //      secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
+                       //}
                        
                        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);
-                               alignSeqs.push_back(tempNode);
-                               if (seq.getAligned().length() > length) {  length = alignSeqs[0].seq.getAligned().length();  }
-                       }                       
+                       
+                       if (seq.getName() != "") {  //can get "" if commented line is at end of fasta file
+                               if (namefile != "") {
+                                       itSize = sizes.find(seq.getName());
+                                       
+                                       if (itSize == sizes.end()) { mothurOut(seq.getName() + " is not in your names file, please correct."); mothurOutEndLine(); exit(1); }
+                                       else{
+                                               seqPNode tempNode(itSize->second, seq, names[seq.getName()]);
+                                               alignSeqs.push_back(tempNode);
+                                               if (seq.getAligned().length() > length) {  length = alignSeqs[0].seq.getAligned().length();  }
+                                       }       
+                               }else { //no names file, you are identical to yourself 
+                                       seqPNode tempNode(1, seq, seq.getName());
+                                       alignSeqs.push_back(tempNode);
+                                       if (seq.getAligned().length() > length) {  length = alignSeqs[0].seq.getAligned().length();  }
+                               }
+                       }
                }
                inFasta.close();
-               inNames.close();
+               //inNames.close();
                return alignSeqs.size();
        }
        
        catch(exception& e) {
-               errorOut(e, "PreClusterCommand", "readNamesFASTA");
+               errorOut(e, "PreClusterCommand", "readFASTA");
                exit(1);
        }
 }
@@ -305,6 +316,30 @@ void PreClusterCommand::printData(string newfasta, string newname){
                exit(1);
        }
 }
+/**************************************************************************************************/
+void PreClusterCommand::readNameFile(){
+       try {
+               ifstream in;
+               openInputFile(namefile, in);
+               string firstCol, secondCol;
+                               
+               while (!in.eof()) {
+                       in >> firstCol >> secondCol; gobble(in);
+                       names[firstCol] = secondCol;
+                       int size = 1;
+                       while (secondCol.find_first_of(',') != -1) { 
+                               size++;
+                               secondCol = secondCol.substr(secondCol.find_first_of(',')+1, secondCol.length());
+                       }
+                       sizes[firstCol] = size;
+               }
+               in.close();
+       }
+       catch(exception& e) {
+               errorOut(e, "PreClusterCommand", "readNameFile");
+               exit(1);
+       }
+}
 
 /**************************************************************************************************/
 
index 3a1157d1979935e990f45e1f3202d4fe74525574..643a36783594cf6d0716e2e4b79fedf3413a6861 100644 (file)
@@ -40,12 +40,14 @@ private:
        bool abort;
        string fastafile, namefile, outputDir;
        vector<seqPNode> alignSeqs; //maps the number of identical seqs to a sequence
-//     map<string, string> names; //represents the names file first column maps to second column
-//     map<string, int> sizes;  //this map a seq name to the number of identical seqs in the names file
+       map<string, string> names; //represents the names file first column maps to second column
+       map<string, int> sizes;  //this map a seq name to the number of identical seqs in the names file
+       map<string, int>::iterator itSize; 
 //     map<string, bool> active; //maps sequence name to whether it has already been merged or not.
        
        int readFASTA();
-       int readNamesFASTA();
+       void readNameFile();
+       //int readNamesFASTA();
        int calcMisMatches(string, string);
        void printData(string, string); //fasta filename, names file name
 };
index e2302d38bf02f5c58daae759713deb28a1a75b6b..8acd696406c288303128a3c36aef3e6d816f2fbe 100644 (file)
@@ -15,6 +15,7 @@
 AlignCheckCommand::AlignCheckCommand(string option){
        try {
                abort = false;
+               haderror = 0;
                
                //allow user to run help
                if(option == "help") { help(); abort = true; }
@@ -124,6 +125,8 @@ int AlignCheckCommand::execute(){
                        if (seq.getName() != "") {
                                statData data = getStats(seq.getAligned());
                                
+                               if (haderror == 1) { break; }
+                               
                                out << seq.getName() << '\t' << data.pound << '\t' << data.dash << '\t' << data.plus << '\t' << data.equal << '\t';
                                out << data.loop << '\t' << data.tilde << '\t' << data.total << endl;
                        }
@@ -184,8 +187,11 @@ statData AlignCheckCommand::getStats(string sequence){
                statData data;
                sequence = "*" + sequence; // need to pad the sequence so we can index it by 1
                
-               int seqLength = sequence.length();
-               for(int i=1;i<seqLength;i++){
+               int length = sequence.length();
+               
+               if (length != seqLength) { mothurOut("your sequences are " + toString(length) + " long, but your map file only contains " + toString(seqLength) + " entries. please correct."); mothurOutEndLine(); haderror = 1; return data;  }
+               
+               for(int i=1;i<length;i++){
                        if(structMap[i] != 0){
                                if(sequence[i] == 'A'){
                                        if(sequence[structMap[i]] == 'T')               {       data.tilde++;   }
index dffb4cbd980ff504307465ae64a0f6645fe5e6a5..2e6191ca67f47f92f38bb8c030a8ad3e32920af6 100644 (file)
@@ -41,7 +41,7 @@ class AlignCheckCommand : public Command {
                vector<int> structMap;
                string mapfile, fastafile, outputDir;
                bool abort;
-               int seqLength;
+               int seqLength, haderror;
                
                void readMap();
                statData getStats(string sequence);
index a23b61dbcaf4c6f78705a96df5d80f3d4843cfa8..5a2c0022bf68ef4756d71ad6278b171bbce0f602 100644 (file)
@@ -99,6 +99,7 @@ int SetDirectoryCommand::execute(){
                        if(!out) {
                                mothurOut(output + " directory does not exist or is not writable."); mothurOutEndLine(); 
                        }else{
+                               out.close();
                                remove(outTemp.c_str());
                                mothurOut("Changing output directory to " + output); mothurOutEndLine();  
                                commandFactory->setOutputDirectory(output);
@@ -124,6 +125,7 @@ int SetDirectoryCommand::execute(){
                        if(!in) {
                                mothurOut(input + " directory does not exist or is not writable."); mothurOutEndLine(); 
                        }else{
+                               in.close();
                                remove(inTemp.c_str());
                                mothurOut("Changing input directory to " + input); mothurOutEndLine();  
                                commandFactory->setInputDirectory(input);