From 5e8fcd2454ba4bd2e11983afd682b8aa6f7bb5c2 Mon Sep 17 00:00:00 2001 From: pschloss Date: Wed, 18 Feb 2009 15:56:06 +0000 Subject: [PATCH] fixed bug in read.tree --- Mothur.xcodeproj/project.pbxproj | 3 ++- readtree.cpp | 25 ++++++++++++++----------- readtree.h | 1 + unifracweightedcommand.cpp | 4 ++-- utilities.hpp | 2 +- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index c3c2a72..93e0e58 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -692,7 +692,7 @@ GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_FIX_AND_CONTINUE = YES; GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 0; + GCC_OPTIMIZATION_LEVEL = 3; GCC_PREPROCESSOR_DEFINITIONS = ( "_GLIBCXX_DEBUG=1", "_GLIBCXX_DEBUG_PEDANTIC=1", @@ -708,6 +708,7 @@ buildSettings = { DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_MODEL_TUNING = G5; + GCC_OPTIMIZATION_LEVEL = 3; INSTALL_PATH = /usr/local/bin; PRODUCT_NAME = mothur; }; diff --git a/readtree.cpp b/readtree.cpp index 77277e7..1910c4a 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -27,9 +27,10 @@ ReadTree::ReadTree() { /***********************************************************************/ int ReadTree::readSpecialChar(istream& f, char c, string name) { try { - char d; - while(isspace(d=f.get())) {;} + gobble(f); + char d = f.get(); + if(d == EOF){ cerr << "Error: Input file ends prematurely, expecting a " << name << "\n"; exit(1); @@ -39,10 +40,8 @@ int ReadTree::readSpecialChar(istream& f, char c, string name) { exit(1); } if(d == ')' && f.peek() == '\n'){ - while(isspace(d=f.get())) {;} - f.putback(d); + gobble(f); } - return d; } catch(exception& e) { @@ -58,8 +57,10 @@ int ReadTree::readSpecialChar(istream& f, char c, string name) { int ReadTree::readNodeChar(istream& f) { try { - char d; - while(isspace(d=f.get())) {;} +// while(isspace(d=f.get())) {;} + gobble(f); + char d = f.get(); + if(d == EOF){ cerr << "Error: Input file ends prematurely, expecting a left parenthesis\n"; exit(1); @@ -86,7 +87,7 @@ float ReadTree::readBranchLength(istream& f) { cerr << "Error: Missing branch length in input tree.\n"; exit(1); } - + gobble(f); return b; } catch(exception& e) { @@ -126,6 +127,7 @@ void ReadNewickTree::read() { readTreeString(); //save trees for later commands globaldata->gTree.push_back(T); + gobble(filehandle); } //if you are a nexus file }else if ((c = filehandle.peek()) == '#') { @@ -230,6 +232,7 @@ void ReadNewickTree::readTreeString() { if(ch == '('){ n = numLeaves; //number of leaves / sequences, we want node 1 to start where the leaves left off + lc = readNewickInt(filehandle, n, T); if(filehandle.peek()==','){ @@ -253,8 +256,8 @@ void ReadNewickTree::readTreeString() { filehandle.get(name, MAX_LINE,'\n'); SKIPLINE(filehandle, ch); - n = T->getIndex(name); + if(n!=0){ cerr << "Internal error: The only taxon is not taxon 0.\n"; exit(1); @@ -263,7 +266,7 @@ void ReadNewickTree::readTreeString() { } while((ch=filehandle.get())!=';'){;} - if(rooted != 1){ + if(rooted != 1){ T->tree[n].setChildren(lc,rc); T->tree[n].setBranchLength(0); T->tree[n].setParent(-1); @@ -291,7 +294,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { if(c == '('){ int lc = readNewickInt(f, n, T); readSpecialChar(f,',',"comma"); - + int rc = readNewickInt(f, n, T); if(f.peek()==')'){ readSpecialChar(f,')',"right parenthesis"); diff --git a/readtree.h b/readtree.h index 02b6129..653a853 100644 --- a/readtree.h +++ b/readtree.h @@ -14,6 +14,7 @@ using namespace std; #include #include #include "globaldata.hpp" +#include "utilities.hpp" #include "tree.h" #define MAX_LINE 513 diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index 4a8325a..3b3abf8 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -122,7 +122,7 @@ int UnifracWeightedCommand::execute() { //copy T[i]'s info. randT->getCopy(T[i]); - //get pscores for random trees + //get scores for random trees for (int j = 0; j < iters; j++) { //create a random tree with same topology as T[i], but different labels randT->assembleRandomUnifracTree(); @@ -178,7 +178,7 @@ int UnifracWeightedCommand::execute() { float ucumul = 0.0000; float rcumul = 0.0000; //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print. - for (it = validScores[b].begin(); it != validScores[b].end(); it++) { + for (it = validScores[b].end(); it == validScores[b].begin(); it--) { it2 = uscoreFreq[b].find(it->first); //user data has that score if (it2 != uscoreFreq[b].end()) { uscoreFreq[b][it->first] /= T.size(); ucumul+= it2->second; } diff --git a/utilities.hpp b/utilities.hpp index 0c67561..bf7df2d 100644 --- a/utilities.hpp +++ b/utilities.hpp @@ -58,7 +58,7 @@ string toString(const T&x, int i){ /***********************************************************************/ -inline void gobble(ifstream& f){ +inline void gobble(istream& f){ char d; while(isspace(d=f.get())) {;} -- 2.39.2