]> git.donarmstrong.com Git - mothur.git/blobdiff - tree.cpp
changes to blastdb to make filenames given to blast unique, changes to split.abund...
[mothur.git] / tree.cpp
index eca53d5527bbdda6dbc97ddc0c9f4e7766e15d25..400a72ae388a88c5b94aa2b8a717471f600b33ed 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -70,10 +70,11 @@ void Tree::addNamesToCounts() {
                                
                //go through each leaf and update its pcounts and pgroups
                for (int i = 0; i < numLeaves; i++) {
+
                        string name = tree[i].getName();
-                       
+               
                        map<string, string>::iterator itNames = globaldata->names.find(name);
-                       
+               
                        if (itNames == globaldata->names.end()) { m->mothurOut(name + " is not in your name file, please correct."); m->mothurOutEndLine(); exit(1);  }
                        else {
                                vector<string> dupNames;
@@ -131,8 +132,7 @@ void Tree::addNamesToCounts() {
                                tree[i].setGroup(nodeGroups);
                                
                        }//end else
-               }//end for
-                               
+               }//end for                                      
        }
        catch(exception& e) {
                m->errorOut(e, "Tree", "addNamesToCounts");
@@ -166,7 +166,7 @@ void Tree::setIndex(string searchName, int index) {
        }
 }
 /*****************************************************************/
-void Tree::assembleTree() {
+int Tree::assembleTree() {
        try {
        
                //if user has given a names file we want to include that info in the pgroups and pcount info.
@@ -174,9 +174,13 @@ void Tree::assembleTree() {
                
                //build the pGroups in non leaf nodes to be used in the parsimony calcs.
                for (int i = numLeaves; i < numNodes; i++) {
+                       if (m->control_pressed) { return 1; }
+
                        tree[i].pGroups = (mergeGroups(i));
                        tree[i].pcount = (mergeGcounts(i));
                }
+               
+               return 0;
        }
        catch(exception& e) {
                m->errorOut(e, "Tree", "assembleTree");
@@ -709,6 +713,10 @@ void Tree::parseTreeFile() {
                        }
                }
                filehandle.close();
+               
+               //for (int i = 0; i < globaldata->Treenames.size(); i++) {
+//cout << globaldata->Treenames[i] << endl; }
+//cout << globaldata->Treenames.size() << endl;
        }
        catch(exception& e) {
                m->errorOut(e, "Tree", "parseTreeFile");
@@ -728,39 +736,20 @@ int Tree::readTreeString(ifstream& filehandle)    {
 //cout << " at beginning of while " <<  k << endl;                     
                        if(c == ')')  {    
                                //to pass over labels in trees
-                               c=filehandle.get();
-                               while((c!=',') && (c != -1) && (c!= ':') && (c!=';')){ c=filehandle.get(); }
-                               filehandle.putback(c);
+                               string label = readLabel(filehandle);
                        }
+                       
                        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 = "";
-                               c = filehandle.get();
-                       //k = c;
-//cout << k << endl;
-                               while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {                       
-                                       name += c;
-                                       c = filehandle.get();
-                       //k = c;
-//cout << " in name while " << k << endl;
-                               }
-                               
-//cout << "name = " << name << endl;
+                               name = readName(filehandle);
                                globaldata->Treenames.push_back(name);
-                               filehandle.putback(c);
-//k = c;
-//cout << " after putback" <<  k << endl;
                        } 
                        
                        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;
-       //cout << " in branch while " << k << endl;
-                               }
-                               filehandle.putback(c);
+                               string bl = readBranchLength(filehandle);
                        }
                
                        c = filehandle.get();
@@ -781,6 +770,68 @@ int Tree::readTreeString(ifstream& filehandle)     {
 }      
 
 /*******************************************************/
+string Tree::readLabel(ifstream& filehandle)   {
+       try {
+               
+               string label = "";
+               
+               //to pass over labels in trees
+               int c=filehandle.get();
+               while((c!=',') && (c != -1) && (c!= ':') && (c!=';')){ label += c; c=filehandle.get(); }
+               filehandle.putback(c);
+               
+               return label;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "Tree", "readLabel");
+               exit(1);
+       }
+}      
+/*******************************************************/
+string Tree::readName(ifstream& filehandle)    {
+       try {
+               
+               string name = "";
+               int c = filehandle.get();
+               
+               while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {                       
+                       name += c;
+                       c = filehandle.get();
+               }
+                               
+//cout << "name = " << name << endl;
+               filehandle.putback(c);
+               
+               return name;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "Tree", "readName");
+               exit(1);
+       }
+}      
+/*******************************************************/
+string Tree::readBranchLength(ifstream& filehandle)    {
+       try {
+               
+               string br = "";
+               int c;
+               while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
+                       br += c;
+                       c = filehandle.get();
+               }
+               filehandle.putback(c);
+               
+               return br;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "Tree", "readBranchLength");
+               exit(1);
+       }
+}      
 
 /*******************************************************/
+/*******************************************************/