int ReadNewickTree::read(CountTable* ct) { try { holder = ""; int c, error; int comment = 0; //if you are not a nexus file if ((c = filehandle.peek()) != '#') { while((c = filehandle.peek()) != EOF) { if (m->control_pressed) { filehandle.close(); return 0; } while ((c = filehandle.peek()) != EOF) { if (m->control_pressed) { filehandle.close(); return 0; } // get past comments if(c == '[') { comment = 1; } if(c == ']'){ comment = 0; } if((c == '(') && (comment != 1)){ break; } filehandle.get(); } //make new tree T = new Tree(ct); numNodes = T->getNumNodes(); numLeaves = T->getNumLeaves(); error = readTreeString(ct); //save trees for later commands Trees.push_back(T); m->gobble(filehandle); } //if you are a nexus file }else if ((c = filehandle.peek()) == '#') { //get right number of seqs from nexus file. Tree* temp = new Tree(ct); delete temp; nexusTranslation(ct); //reads file through the translation and updates treemap while((c = filehandle.peek()) != EOF) { if (m->control_pressed) { filehandle.close(); return 0; } // get past comments while ((c = filehandle.peek()) != EOF) { if (m->control_pressed) { filehandle.close(); return 0; } if(holder == "[" || holder == "[!"){ comment = 1; } if(holder == "]"){ comment = 0; } if((holder == "tree" || holder == "end;") && comment != 1){ holder = ""; comment = 0; break;} filehandle >> holder; } //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. //make new tree T = new Tree(ct); numNodes = T->getNumNodes(); numLeaves = T->getNumLeaves(); //read tree info error = readTreeString(ct); //save trees for later commands Trees.push_back(T); } } if (error != 0) { readOk = error; } filehandle.close(); return readOk; }
//this code is a mess and should be rethought...-slw int Tree::parseTreeFile() { //only takes names from the first tree and assumes that all trees use the same names. try { string filename = m->getTreeFile(); ifstream filehandle; m->openInputFile(filename, filehandle); int c, comment; comment = 0; int done = 1; //ifyou are not a nexus file if((c = filehandle.peek()) != '#') { while((c = filehandle.peek()) != ';') { if (m->control_pressed) { filehandle.close(); return 0; } while ((c = filehandle.peek()) != ';') { if (m->control_pressed) { filehandle.close(); return 0; } // get past comments if(c == '[') { comment = 1; } if(c == ']'){ comment = 0; } if((c == '(') && (comment != 1)){ break; } filehandle.get(); } done = readTreeString(filehandle); if (done == 0) { break; } } //ifyou are a nexus file }else if((c = filehandle.peek()) == '#') { string holder = ""; // get past comments while(holder != "translate" && holder != "Translate"){ if (m->control_pressed) { filehandle.close(); return 0; } if(holder == "[" || holder == "[!"){ comment = 1; } if(holder == "]"){ comment = 0; } filehandle >> holder; //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. done = readTreeString(filehandle); break; } if (done == 0) { break; } } //use nexus translation rather than parsing tree to save time if((holder == "translate") || (holder == "Translate")) { string number, name, h; h = ""; // so it enters the loop the first time while((h != ";") && (number != ";")) { if (m->control_pressed) { filehandle.close(); return 0; } filehandle >> number; filehandle >> name; //c = , until done with translation then c = ; h = name.substr(name.length()-1, name.length()); name.erase(name.end()-1); //erase the comma m->Treenames.push_back(number); } if(number == ";") { m->Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name } }