From: westcott Date: Mon, 9 Mar 2009 18:55:33 +0000 (+0000) Subject: fixed bug in read.tree X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=8fd4a602269974e6548f4a387dddd6bd80a999ab fixed bug in read.tree --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index a403f35..e9446df 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -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 */; }; @@ -126,6 +127,8 @@ 374610820F40652400460C57 /* unweighted.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unweighted.cpp; sourceTree = ""; }; 3746109B0F40657600460C57 /* unifracunweightedcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unifracunweightedcommand.h; sourceTree = ""; }; 3746109C0F40657600460C57 /* unifracunweightedcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unifracunweightedcommand.cpp; sourceTree = ""; }; + 374CD63D0F65832000D90B4A /* libshuffcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libshuffcommand.h; sourceTree = ""; }; + 374CD63E0F65832000D90B4A /* libshuffcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = libshuffcommand.cpp; sourceTree = ""; }; 3782163B0F616079008E1F6D /* fullmatrix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fullmatrix.h; sourceTree = ""; }; 3782163C0F616079008E1F6D /* fullmatrix.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fullmatrix.cpp; sourceTree = ""; }; 379293C10F2DE73400B9034A /* treemap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = treemap.h; sourceTree = ""; }; @@ -474,6 +477,8 @@ A70B53A80F4CD7AD0064797E /* getlinecommand.cpp */, 37D927E40F21331F001D4494 /* helpcommand.h */, 37D927E30F21331F001D4494 /* helpcommand.cpp */, + 374CD63D0F65832000D90B4A /* libshuffcommand.h */, + 374CD63E0F65832000D90B4A /* libshuffcommand.cpp */, 37D927F30F21331F001D4494 /* nocommand.h */, 37D927F20F21331F001D4494 /* nocommand.cpp */, 37D927FA0F21331F001D4494 /* parselistcommand.h */, @@ -699,6 +704,7 @@ A70B53AB0F4CD7AD0064797E /* getlabelcommand.cpp in Sources */, A70B53AC0F4CD7AD0064797E /* getlinecommand.cpp in Sources */, 3782163D0F616079008E1F6D /* fullmatrix.cpp in Sources */, + 374CD63F0F65832000D90B4A /* libshuffcommand.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/fullmatrix.cpp b/fullmatrix.cpp index 6ea2318..66c67b7 100644 --- a/fullmatrix.cpp +++ b/fullmatrix.cpp @@ -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= 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> 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> 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> 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;igetGroup(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> 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; diff --git a/fullmatrix.h b/fullmatrix.h index 0ab1d71..0bd5c87 100644 --- a/fullmatrix.h +++ b/fullmatrix.h @@ -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 index 0000000..1abbc05 --- /dev/null +++ b/libshuffcommand.cpp @@ -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 index 0000000..490f23e --- /dev/null +++ b/libshuffcommand.h @@ -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 diff --git a/readtree.cpp b/readtree.cpp index c33617f..0291644 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -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); } diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index b5e5926..cf1cbce 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -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 diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index 2652f8f..69b32aa 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -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 diff --git a/unweighted.cpp b/unweighted.cpp index 47ddd6b..405dfd2 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -368,7 +368,9 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) { data[count] = UW; } - + + delete copyTree; + return data; }