globaldata = GlobalData::getInstance();
if (globaldata->runParse == true) { parseTreeFile(); globaldata->runParse = false; }
-
+//for(int i = 0; i < globaldata->Treenames.size(); i++) { cout << i << '\t' << globaldata->Treenames[i] << endl; }
numLeaves = globaldata->Treenames.size();
numNodes = 2*numLeaves - 1;
// this is true if right child had a greater parsimony for a certain group
if(maxPars > 1){
//erase all the groups that are only 1 because you found something with 2.
- for(it=parsimony.begin();it!=parsimony.end();it++){
+ for(it=parsimony.begin();it!=parsimony.end();){
if(it->second == 1){
- parsimony.erase(it->first);
-// it--;
- }
+ parsimony.erase(it++);
+ }else { it++; }
}
//set one remaining groups to 1
//so with our above example p[white] = 2 would be left and it would become p[white] = 1
int rc = tree[i].getRChild();
//loop through nodes groups removing the ones the user doesn't want
- for (it = tree[lc].pGroups.begin(); it != tree[lc].pGroups.end(); it++) {
- if (inUsersGroups(it->first, g) != true) { tree[lc].pGroups.erase(it->first); }
+ for(it=tree[lc].pGroups.begin();it!=tree[lc].pGroups.end();){
+ if (inUsersGroups(it->first, g) != true) {
+ tree[lc].pGroups.erase(it++);
+ }else { it++; }
}
-
+
//loop through nodes groups removing the ones the user doesn't want
- for (it = tree[rc].pGroups.begin(); it != tree[rc].pGroups.end(); it++) {
- if (inUsersGroups(it->first, g) != true) { tree[rc].pGroups.erase(it->first); }
+ for(it=tree[rc].pGroups.begin();it!=tree[rc].pGroups.end();){
+ if (inUsersGroups(it->first, g) != true) {
+ tree[rc].pGroups.erase(it++);
+ }else { it++; }
}
//set parsimony groups to left child
// this is true if right child had a greater parsimony for a certain group
if(maxPars > 1){
//erase all the groups that are only 1 because you found something with 2.
- for(it=parsimony.begin();it!=parsimony.end();it++){
+ for(it=parsimony.begin();it!=parsimony.end();){
if(it->second == 1){
- parsimony.erase(it->first);
- }
+ parsimony.erase(it++);
+ }else { it++; }
}
+
for(it=parsimony.begin();it!=parsimony.end();it++){
parsimony[it->first] = 1;
}
escape = 1;
}
}
-
+
tree[i].setChildren(rnd_index1,rnd_index2);
tree[i].setParent(-1);
tree[rnd_index1].setParent(i);
}
/*****************************************************************/
-
+//this code is a mess and should be rethought...-slw
void Tree::parseTreeFile() {
//only takes names from the first tree and assumes that all trees use the same names.
openInputFile(filename, filehandle);
int c, comment;
comment = 0;
+ int done = 1;
//ifyou are not a nexus file
if((c = filehandle.peek()) != '#') {
filehandle.get();
}
- readTreeString(filehandle);
+ done = readTreeString(filehandle);
+ if (done == 0) { break; }
}
//ifyou are a nexus file
}else if((c = filehandle.peek()) == '#') {
comment = 0;
}
filehandle >> holder;
-
- //ifthere is no translate then you must read tree string otherwise use translate to get names
- if(holder == "tree" && comment != 1){
+
+ //if there is no translate then you must read tree string otherwise use translate to get names
+ if((holder == "tree") && (comment != 1)){
//pass over the "tree rep.6878900 = "
while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF)) {;}
if(c == EOF) { break; }
filehandle.putback(c); //put back first ( of tree.
- readTreeString(filehandle);
+ done = readTreeString(filehandle);
+
break;
}
+
+ if (done == 0) { break; }
}
//use nexus translation rather than parsing tree to save time
/*******************************************************/
/*******************************************************/
-void Tree::readTreeString(ifstream& filehandle) {
+int Tree::readTreeString(ifstream& filehandle) {
try {
int c;
- string name;// k;
+ string name; //, k
while((c = filehandle.peek()) != ';') {
//k = c;
while((c!=',') && (c != -1) && (c!= ':') && (c!=';')){ c=filehandle.get(); }
filehandle.putback(c);
}
- if(c == ';') { break; }
+ if(c == ';') { return 0; }
+ if(c == -1) { return 0; }
//if you are a name
if((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
name = "";
if(c == ':') { //read until you reach the end of the branch length
while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
c = filehandle.get();
- //k = c;
+ //k = c;
//cout << " in branch while " << k << endl;
}
filehandle.putback(c);
}
-
+
c = filehandle.get();
- if(c == ';') { break; }
+//k = c;
+ //cout << " here after get " << k << endl;
+ if(c == ';') { return 0; }
if(c == ')') { filehandle.putback(c); }
- // k = c;
+ //k = c;
//cout << k << endl;
}
+ return 0;
}
catch(exception& e) {
errorOut(e, "Tree", "readTreeString");