]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed bug in read.tree
authorwestcott <westcott>
Mon, 9 Mar 2009 18:55:33 +0000 (18:55 +0000)
committerwestcott <westcott>
Mon, 9 Mar 2009 18:55:33 +0000 (18:55 +0000)
Mothur.xcodeproj/project.pbxproj
fullmatrix.cpp
fullmatrix.h
libshuffcommand.cpp [new file with mode: 0644]
libshuffcommand.h [new file with mode: 0644]
readtree.cpp
unifracunweightedcommand.cpp
unifracweightedcommand.cpp
unweighted.cpp

index a403f35250d8e910f63798ac2ae26e46798b810c..e9446df8c629b83c5c065f84b2a768414fe372e8 100644 (file)
@@ -14,6 +14,7 @@
                3746107E0F4064D100460C57 /* weighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3746107D0F4064D100460C57 /* weighted.cpp */; };
                374610830F40652400460C57 /* unweighted.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374610820F40652400460C57 /* unweighted.cpp */; };
                3746109D0F40657600460C57 /* unifracunweightedcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */; };
+               374CD63F0F65832000D90B4A /* libshuffcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 374CD63E0F65832000D90B4A /* libshuffcommand.cpp */; };
                3782163D0F616079008E1F6D /* fullmatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3782163C0F616079008E1F6D /* fullmatrix.cpp */; };
                379293C30F2DE73400B9034A /* treemap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 379293C20F2DE73400B9034A /* treemap.cpp */; };
                379294700F2E191800B9034A /* parsimonycommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3792946F0F2E191800B9034A /* parsimonycommand.cpp */; };
                374610820F40652400460C57 /* unweighted.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unweighted.cpp; sourceTree = "<group>"; };
                3746109B0F40657600460C57 /* unifracunweightedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unifracunweightedcommand.h; sourceTree = "<group>"; };
                3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unifracunweightedcommand.cpp; sourceTree = "<group>"; };
+               374CD63D0F65832000D90B4A /* libshuffcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libshuffcommand.h; sourceTree = "<group>"; };
+               374CD63E0F65832000D90B4A /* libshuffcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = libshuffcommand.cpp; sourceTree = "<group>"; };
                3782163B0F616079008E1F6D /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = "<group>"; };
                3782163C0F616079008E1F6D /* fullmatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fullmatrix.cpp; sourceTree = "<group>"; };
                379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = "<group>"; };
                                A70B53A80F4CD7AD0064797E /* getlinecommand.cpp */,
                                37D927E40F21331F001D4494 /* helpcommand.h */,
                                37D927E30F21331F001D4494 /* helpcommand.cpp */,
+                               374CD63D0F65832000D90B4A /* libshuffcommand.h */,
+                               374CD63E0F65832000D90B4A /* libshuffcommand.cpp */,
                                37D927F30F21331F001D4494 /* nocommand.h */,
                                37D927F20F21331F001D4494 /* nocommand.cpp */,
                                37D927FA0F21331F001D4494 /* parselistcommand.h */,
                                A70B53AB0F4CD7AD0064797E /* getlabelcommand.cpp in Sources */,
                                A70B53AC0F4CD7AD0064797E /* getlinecommand.cpp in Sources */,
                                3782163D0F616079008E1F6D /* fullmatrix.cpp in Sources */,
+                               374CD63F0F65832000D90B4A /* libshuffcommand.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 6ea2318d740003f8cf46ec7e63815c175e1893ca..66c67b7da0999281af64e9836c9a0f94aff3a698 100644 (file)
@@ -16,6 +16,7 @@ FullMatrix::FullMatrix(ifstream& filehandle) {
                globaldata = GlobalData::getInstance();
                groupmap = globaldata->gGroupmap;
                
+               float minSoFar = 0.0;
                string name, group;
                filehandle >> numSeqs >> name;
                
@@ -39,9 +40,18 @@ FullMatrix::FullMatrix(ifstream& filehandle) {
                        if(isalnum(d)){ 
                                square = true;
                                filehandle.putback(d);
-                               for(int i=0;i<numSeqs;i++){
+                               
+                               if (numSeqs >= 2) {
+                                       //save first distance that is not distance to itself as minimum
+                                       filehandle >> matrix[0][0] >> minSoFar;
+                                       matrix[0][1] = minSoFar;
+                               }
+                               
+                               for(int i=2;i<numSeqs;i++){
                                        filehandle >> matrix[0][i];
+                                       if (matrix[0][i] < minSoFar) { minSoFar = matrix[0][i]; }
                                }
+                               index[0].minDist = minSoFar;
                                break;
                        }
                        
@@ -77,7 +87,8 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
                reading = new Progress("Reading matrix:    ", numSeqs * numSeqs);
                
                int count = 0;
-               float distance;
+               float distance, minSoFar;
+               minSoFar = 0.0;
                string group, name;
                
                for(int i=1;i<numSeqs;i++){
@@ -87,15 +98,23 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
                        index[i].groupname = group;
                        index[i].seqName = name;
                        
+                       filehandle >> minSoFar;
+                       matrix[i][0] = minSoFar;
+                       
                        if(group == "not found") {      cout << "Error: Sequence '" << name << "' was not found in the group file, please correct." << endl; exit(1); }
                                
-                       for(int j=0;j<numSeqs;j++){
+                       for(int j=1;j<numSeqs;j++){
                                filehandle >> distance;
+                               
+                               if ((distance < minSoFar) && (i != j)) { minSoFar = distance; }
                                        
                                matrix[i][j] = distance;
                                count++;
                                reading->update(count);
                        }
+                       
+                       //save minimum value for each row
+                       index[i].minDist = minSoFar;
                }
                reading->finish();
                delete reading;
@@ -117,7 +136,9 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) {
                reading = new Progress("Reading matrix:    ", numSeqs * (numSeqs - 1) / 2);
                
                int count = 0;
-               float distance;
+               float distance, minSoFar;
+               minSoFar = 0.0;
+
                string group, name;
                
                for(int i=1;i<numSeqs;i++){
@@ -126,16 +147,24 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) {
                        group = groupmap->getGroup(name);
                        index[i].groupname = group;
                        index[i].seqName = name;
+                       
+                       filehandle >> minSoFar;
+                       matrix[i][0] = minSoFar;
        
                        if(group == "not found") {      cout << "Error: Sequence '" << name << "' was not found in the group file, please correct." << endl;  exit(1); }
                                
-                       for(int j=0;j<i;j++){
+                       for(int j=1;j<i;j++){
                                filehandle >> distance;
+                               
+                               if (distance < minSoFar)  { minSoFar = distance; }
                                        
                                matrix[i][j] = distance;  matrix[j][i] = distance;
                                count++;
                                reading->update(count);
                        }
+                       
+                       //save minimum value for each row
+                       index[i].minDist = minSoFar;
                }
                reading->finish();
                delete reading;
index 0ab1d7175dce3b9bdef4758b83dffc26ace8079b..0bd5c873ea4da00bc48d8a3395844f80151bd630 100644 (file)
@@ -17,8 +17,9 @@
 using namespace std;
 
 struct Names {
-       string  groupname;
+       string          groupname;
        string          seqName;
+       float           minDist;
 };
 
 
diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp
new file mode 100644 (file)
index 0000000..1abbc05
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  libshuffcommand.cpp
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 3/9/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "libshuffcommand.h"
+
+//**********************************************************************************************************************
+
+
+LibShuffCommand::LibShuffCommand(){
+       try {
+               //globaldata = GlobalData::getInstance();
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function LibShuffCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the LibShuffCommand class function LibShuffCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+                       
+}
+
+//**********************************************************************************************************************
+
+LibShuffCommand::~LibShuffCommand(){
+       
+}
+
+//**********************************************************************************************************************
+
+int LibShuffCommand::execute(){
+       try {
+               return 0;
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the LibShuffCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
+
+//**********************************************************************************************************************
diff --git a/libshuffcommand.h b/libshuffcommand.h
new file mode 100644 (file)
index 0000000..490f23e
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef LIBSHUFFCOMMAND_H
+#define LIBSHUFFCOMMAND_H
+
+/*
+ *  libshuffcommand.h
+ *  Mothur
+ *
+ *  Created by Sarah Westcott on 3/9/09.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
+ *
+ */
+
+#include "command.hpp"
+
+using namespace std;
+
+class GlobalData;
+
+class LibShuffCommand : public Command {
+       
+       public:
+               LibShuffCommand();      
+               ~LibShuffCommand();
+               int execute();  
+       
+       private:
+               GlobalData* globaldata;
+               
+};
+
+#endif
index c33617fca57a483da46f179e384497661e205878..029164452c49d2247bd97262369a649cfbd3d190 100644 (file)
@@ -32,12 +32,12 @@ int ReadTree::readSpecialChar(istream& f, char c, string name) {
                char d = f.get();
        
                if(d == EOF){
-                       cerr << "Error: Input file ends prematurely, expecting a " << name << "\n";  return -1;
-                       //exit(1);
+                       cerr << "Error: Input file ends prematurely, expecting a " << name << "\n";
+                       exit(1);
                }
                if(d != c){
-                       cerr << "Error: Expected " << name << " in input file.  Found " << d << ".\n";  return -1;
-                       //exit(1);
+                       cerr << "Error: Expected " << name << " in input file.  Found " << d << ".\n";
+                       exit(1);
                }
                if(d == ')' && f.peek() == '\n'){
                        gobble(f);
@@ -62,8 +62,8 @@ int ReadTree::readNodeChar(istream& f) {
                char d = f.get();
 
                if(d == EOF){
-                       cerr << "Error: Input file ends prematurely, expecting a left parenthesis\n";  return -1;
-                       //exit(1);
+                       cerr << "Error: Input file ends prematurely, expecting a left parenthesis\n";
+                       exit(1);
                }
                return d;
        }
@@ -84,8 +84,8 @@ float ReadTree::readBranchLength(istream& f) {
                float b;
        
                if(!(f >> b)){
-                       cerr << "Error: Missing branch length in input tree.\n";  return -1;
-                       //exit(1);
+                       cerr << "Error: Missing branch length in input tree.\n";
+                       exit(1);
                }
                gobble(f);
                return b;
@@ -226,7 +226,7 @@ int ReadNewickTree::readTreeString() {
        try {
                
                int n = 0;
-               int lc, rc, error
+               int lc, rc; 
                
                int rooted = 0;
        
@@ -239,8 +239,7 @@ int ReadNewickTree::readTreeString() {
                        if (lc == -1) { return -1; } //reports an error in reading
                
                        if(filehandle.peek()==','){                                                     
-                               error = readSpecialChar(filehandle,',',"comma");
-                               if (error == -1) { readOk = -1; return -1; }
+                               readSpecialChar(filehandle,',',"comma");
                        }
                        // ';' means end of tree.                                                                                               
                        else if((ch=filehandle.peek())==';' || ch=='['){                
@@ -250,8 +249,7 @@ int ReadNewickTree::readTreeString() {
                                rc = readNewickInt(filehandle, n, T);
                                if (rc == -1) { return -1; } //reports an error in reading
                                if(filehandle.peek() == ')'){                                   
-                                       error = readSpecialChar(filehandle,')',"right parenthesis");
-                                       if (error == -1) { readOk = -1; return -1; }
+                                       readSpecialChar(filehandle,')',"right parenthesis");
                                }                                                                                       
                        }                                                                                               
                }
@@ -297,31 +295,25 @@ int ReadNewickTree::readTreeString() {
 
 int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) {
        try {
-               int error;
-               
                int c = readNodeChar(f);
-               if (c == -1) { readOk = -1; return -1; }
     
                if(c == '('){
                        int lc = readNewickInt(f, n, T);
                        if (lc == -1) { return -1; } //reports an error in reading
-                       error = readSpecialChar(f,',',"comma");
-                       if (error == -1) { readOk = -1; return -1; }
+                       readSpecialChar(f,',',"comma");
 
                        int rc = readNewickInt(f, n, T);
                        if (rc == -1) { return -1; }  //reports an error in reading     
                        if(f.peek()==')'){      
-                               error = readSpecialChar(f,')',"right parenthesis");     
-                               if (error == -1) { readOk = -1; return -1; }                            
+                               readSpecialChar(f,')',"right parenthesis");     
                        }                       
                
                        if(f.peek() == ':'){                                                                          
-                               error = readSpecialChar(f,':',"colon"); 
-                               if (error == -1) { readOk = -1; return -1; }                                            
+                               readSpecialChar(f,':',"colon"); 
+                                                                               
                                if(n >= numNodes){      cerr << "Error: Too many nodes in input tree\n";  readOk = -1; return -1; }
-                               error = readBranchLength(f);
-                               if (error == -1) { readOk = -1; return -1; }
-                               T->tree[n].setBranchLength(error);
+                               
+                               T->tree[n].setBranchLength(readBranchLength(f));
                        }else{T->tree[n].setBranchLength(0.0); }                                                
                
                        T->tree[n].setChildren(lc,rc);
@@ -378,9 +370,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) {
                
                        if(blen == 1){  
                                f.get();
-                               error = readBranchLength(f);    
-                               if (error == -1) { readOk = -1; return -1; }    
-                               T->tree[n1].setBranchLength(error);
+                               T->tree[n1].setBranchLength(readBranchLength(f));
                        }else{
                                T->tree[n1].setBranchLength(0.0);
                        }
index b5e592622868b93738d66e0b6a4639e1797c69f0..cf1cbce05dfce301409d3b80d861f0fb9dc0a0bd 100644 (file)
@@ -65,6 +65,7 @@ int UnifracUnweightedCommand::execute() {
                        for(int k = 0; k < numComp; k++) {
                                //saves users score
                                utreeScores[k].push_back(userData[k]);
+
                        }
                        
                        //get unweighted scores for random trees
index 2652f8f6de6cc1198e81112c2d7e3d88d417fad3..69b32aa11a84f2c435651e52dec92f400a868a8b 100644 (file)
@@ -51,7 +51,7 @@ int UnifracWeightedCommand::execute() {
                        uScores.resize(numComp);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
                        weightedFile = globaldata->getTreeFile()  + toString(i+1) + ".weighted";
                        weightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".weighted";
-                                                       
+
                        userData = weighted->getValues(T[i]);  //userData[0] = weightedscore
                        
                        //save users score
index 47ddd6b55263249fe2b5cca4dd11fd4365979f24..405dfd2b3feaf4c1a5327526936a7baaaa4aba0a 100644 (file)
@@ -368,7 +368,9 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) {
        
                        data[count] = UW;
                }
-
+               
+               delete copyTree;
+               
                return data;
        
        }