char d = f.get();
if(d == EOF){
- cerr << "Error: Input file ends prematurely, expecting a " << name << "\n";
- exit(1);
+ cerr << "Error: Input file ends prematurely, expecting a " << name << "\n"; return -1;
+ //exit(1);
}
if(d != c){
- cerr << "Error: Expected " << name << " in input file. Found " << d << ".\n";
- exit(1);
+ cerr << "Error: Expected " << name << " in input file. Found " << d << ".\n"; return -1;
+ //exit(1);
}
if(d == ')' && f.peek() == '\n'){
gobble(f);
char d = f.get();
if(d == EOF){
- cerr << "Error: Input file ends prematurely, expecting a left parenthesis\n";
- exit(1);
+ cerr << "Error: Input file ends prematurely, expecting a left parenthesis\n"; return -1;
+ //exit(1);
}
return d;
}
float b;
if(!(f >> b)){
- cerr << "Error: Missing branch length in input tree.\n";
- exit(1);
+ cerr << "Error: Missing branch length in input tree.\n"; return -1;
+ //exit(1);
}
gobble(f);
return b;
/***********************************************************************/
//This class reads a file in Newick form and stores it in a tree.
-void ReadNewickTree::read() {
+int ReadNewickTree::read() {
try {
- int c;
+ int c, error;
int comment = 0;
//if you are not a nexus file
numNodes = T->getNumNodes();
numLeaves = T->getNumLeaves();
- readTreeString();
+ error = readTreeString();
//save trees for later commands
globaldata->gTree.push_back(T);
numLeaves = T->getNumLeaves();
//read tree info
- readTreeString();
+ error = readTreeString();
//save trees for later commands
globaldata->gTree.push_back(T);
}
}
+ return readOk;
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the ReadNewickTree class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
}
/**************************************************************************************************/
-void ReadNewickTree::readTreeString() {
+int ReadNewickTree::readTreeString() {
try {
int n = 0;
- int lc, rc;
+ int lc, rc, error;
int rooted = 0;
n = numLeaves; //number of leaves / sequences, we want node 1 to start where the leaves left off
lc = readNewickInt(filehandle, n, T);
+ if (lc == -1) { return -1; } //reports an error in reading
if(filehandle.peek()==','){
- readSpecialChar(filehandle,',',"comma");
+ error = readSpecialChar(filehandle,',',"comma");
+ if (error == -1) { readOk = -1; return -1; }
}
// ';' means end of tree.
else if((ch=filehandle.peek())==';' || ch=='['){
}
if(rooted != 1){
rc = readNewickInt(filehandle, n, T);
+ if (rc == -1) { return -1; } //reports an error in reading
if(filehandle.peek() == ')'){
- readSpecialChar(filehandle,')',"right parenthesis");
+ error = readSpecialChar(filehandle,')',"right parenthesis");
+ if (error == -1) { readOk = -1; return -1; }
}
}
}
if(n!=0){
cerr << "Internal error: The only taxon is not taxon 0.\n";
- exit(1);
+ //exit(1);
+ readOk = -1; return -1;
}
lc = rc = -1;
}
if(lc!=-1){ T->tree[lc].setParent(n); }
if(rc!=-1){ T->tree[rc].setParent(n); }
}
+ return 0;
}
catch(exception& e) {
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);
- readSpecialChar(f,',',"comma");
+ if (lc == -1) { return -1; } //reports an error in reading
+ error = readSpecialChar(f,',',"comma");
+ if (error == -1) { readOk = -1; return -1; }
- int rc = readNewickInt(f, n, T);
+ int rc = readNewickInt(f, n, T);
+ if (rc == -1) { return -1; } //reports an error in reading
if(f.peek()==')'){
- readSpecialChar(f,')',"right parenthesis");
+ error = readSpecialChar(f,')',"right parenthesis");
+ if (error == -1) { readOk = -1; return -1; }
}
if(f.peek() == ':'){
- readSpecialChar(f,':',"colon");
- if(n >= numNodes){ cerr << "Error: Too many nodes in input tree\n"; exit(1); }
- T->tree[n].setBranchLength(readBranchLength(f));
+ error = readSpecialChar(f,':',"colon");
+ if (error == -1) { readOk = -1; return -1; }
+ 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);
}else{T->tree[n].setBranchLength(0.0); }
T->tree[n].setChildren(lc,rc);
//adds sequence names that are not in group file to the "xxx" group
if(n1 == -1) {
- cerr << "Name: " << name << " not found in your groupfile.. \n"; exit(1);
+ cerr << "Name: " << name << " not found in your groupfile. \n"; readOk = -1; return n1;
//globaldata->gTreemap->namesOfSeqs.push_back(name);
//globaldata->gTreemap->treemap[name].groupname = "xxx";
T->tree[n1].setChildren(-1,-1);
if(blen == 1){
- f.get();
- T->tree[n1].setBranchLength(readBranchLength(f));
+ f.get();
+ error = readBranchLength(f);
+ if (error == -1) { readOk = -1; return -1; }
+ T->tree[n1].setBranchLength(error);
}else{
T->tree[n1].setBranchLength(0.0);
}