X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readtree.cpp;h=c805edc9896bf15b4e7397305c13d8bfbce175d8;hb=cad05a21b084833b07808c1586e755be48fe7e1a;hp=3062f6677fa8527b4eb59a9ab979458465bfb777;hpb=aa9238c0a9e6e7aa0ed8b8b606b08ad4fd7dcfe3;p=mothur.git diff --git a/readtree.cpp b/readtree.cpp index 3062f66..c805edc 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -230,7 +230,7 @@ int ReadNewickTree::readTreeString() { lc = readNewickInt(filehandle, n, T); if (lc == -1) { m->mothurOut("error with lc"); m->mothurOutEndLine(); return -1; } //reports an error in reading - + if(filehandle.peek()==','){ readSpecialChar(filehandle,',',"comma"); } @@ -287,21 +287,62 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { if (m->control_pressed) { return -1; } int c = readNodeChar(f); - + string k; +k = c; + cout << "at beginning = " << k < childrenNodes; + while(f.peek() != ')'){ + int child = readNewickInt(f, n, T); + if (child == -1) { return -1; } //reports an error in reading + + childrenNodes.push_back(child); + + //after a child you either have , or ), check for both + if(f.peek()==')'){ break; } + else if (f.peek()==',') { readSpecialChar(f,',',"comma"); } + else { string k; + k = f.peek(); + cout << "in here k = " << k << '\t' << f.tellg() <mothurOut("Error in tree, please correct."); m->mothurOutEndLine(); return -1; } + + //then force into 2 node structure + for (int i = 1; i < childrenNodes.size(); i++) { + + int lc, rc; + if (i == 1) { lc = childrenNodes[i-1]; rc = childrenNodes[i]; } + else { lc = n; rc = childrenNodes[i]; } + cout << i << '\t' << lc << '\t' << rc << endl; + T->tree[n].setChildren(lc,rc); + T->tree[lc].setParent(n); + T->tree[rc].setParent(n); + + T->printTree(); cout << endl; + n++; + } + + //to account for extra ++ in looping + n--; + //int lc = readNewickInt(f, n, T); + //if (lc == -1) { return -1; } //reports an error in reading + + //readSpecialChar(f,',',"comma"); - int rc = readNewickInt(f, n, T); - if (rc == -1) { return -1; } //reports an error in reading + //int rc = readNewickInt(f, n, T); + //if (rc == -1) { return -1; } //reports an error in reading + if(f.peek()==')'){ readSpecialChar(f,')',"right parenthesis"); //to pass over labels in trees c=filehandle.get(); while((c!=',') && (c != -1) && (c!= ':') && (c!=';')){ c=filehandle.get(); } filehandle.putback(c); - } if(f.peek() == ':'){ @@ -313,12 +354,55 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { }else{ T->tree[n].setBranchLength(0.0); } + + //to account for multifurcating trees generated by fasttree, we are forcing them to be bifurcating + /*while(f.peek() == ','){ + string k; + k = f.peek(); + cout << "in here k = " << k << '\t' << f.tellg() <tree[n].setChildren(lc,rc); + T->tree[lc].setParent(n); + T->tree[rc].setParent(n); + + T->printTree(); cout << endl; + lc = n; + n++; + + readSpecialChar(f,',',"comma"); + + rc = readNewickInt(f, n, T); - T->tree[n].setChildren(lc,rc); - T->tree[lc].setParent(n); - T->tree[rc].setParent(n); + if (rc == -1) { return -1; } //reports an error in reading + + if(f.peek()==')'){ + readSpecialChar(f,')',"right parenthesis"); + //to pass over labels in trees + c=filehandle.get(); + while((c!=',') && (c != -1) && (c!= ':') && (c!=';')){ c=filehandle.get(); } + filehandle.putback(c); + + if(f.peek() == ':'){ + readSpecialChar(f,':',"colon"); + + if(n >= numNodes){ m->mothurOut("Error: Too many nodes in input tree\n"); readOk = -1; return -1; } + + T->tree[n].setBranchLength(readBranchLength(f)); + }else{ + T->tree[n].setBranchLength(0.0); + } + + break; + } + }*/ + //T->tree[n].setChildren(lc,rc); + //T->tree[lc].setParent(n); + //T->tree[rc].setParent(n); + //T->printTree(); cout << endl; + return n++; + }else{ f.putback(c); string name = ""; @@ -327,7 +411,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { name += d; d=f.get(); } - + cout << name << endl; int blen = 0; if(d == ':') { blen = 1; }