+ 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;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ReadNewickTree", "read");
+ exit(1);
+ }
+}
+/**************************************************************************************************/
+//This function read the file through the translation of the sequences names and updates treemap.
+string ReadNewickTree::nexusTranslation(CountTable* ct) {
+ try {
+
+ holder = "";
+ int numSeqs = m->Treenames.size(); //must save this some when we clear old names we can still know how many sequences there were
+ int comment = 0;
+
+ // get past comments
+ while(holder != "translate" && holder != "Translate"){
+ if(holder == "[" || holder == "[!"){
+ comment = 1;
+ }
+ if(holder == "]"){
+ comment = 0;
+ }
+ filehandle >> holder;
+ if(holder == "tree" && comment != 1){return holder;}
+ }
+
+ string number, name;
+ for(int i=0;i<numSeqs;i++){
+
+ filehandle >> number;
+ filehandle >> name;
+ name.erase(name.end()-1); //erase the comma
+ ct->renameSeq(name, toString(number));
+ }
+
+ return name;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ReadNewickTree", "nexusTranslation");
+ exit(1);
+ }
+}
+
+/**************************************************************************************************/
+int ReadNewickTree::readTreeString(CountTable* ct) {
+ try {
+