]> git.donarmstrong.com Git - mothur.git/blobdiff - phylotree.cpp
a few modifications for 1.9
[mothur.git] / phylotree.cpp
index a07cfde3b20aefe619b6c4638383c31655f82745..3cdd6acb2a33c38daf4af882253ad2c34acc39a6 100644 (file)
@@ -13,6 +13,7 @@
 
 PhyloTree::PhyloTree(){
        try {
+               m = MothurOut::getInstance();
                numNodes = 1;
                numSeqs = 0;
                tree.push_back(TaxNode("Root"));
@@ -20,7 +21,7 @@ PhyloTree::PhyloTree(){
                maxLevel = 0;
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "PhyloTree");
+               m->errorOut(e, "PhyloTree", "PhyloTree");
                exit(1);
        }
 }
@@ -28,6 +29,7 @@ PhyloTree::PhyloTree(){
 
 PhyloTree::PhyloTree(string tfile){
        try {
+               m = MothurOut::getInstance();
                numNodes = 1;
                numSeqs = 0;
                tree.push_back(TaxNode("Root"));
@@ -49,7 +51,7 @@ PhyloTree::PhyloTree(string tfile){
                assignHeirarchyIDs(0);
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "PhyloTree");
+               m->errorOut(e, "PhyloTree", "PhyloTree");
                exit(1);
        }
 }
@@ -60,20 +62,22 @@ string PhyloTree::getNextTaxon(string& heirarchy){
        try {
                string currentLevel = "";
                if(heirarchy != ""){
-                       currentLevel=heirarchy.substr(0,heirarchy.find_first_of(';'));
-                       heirarchy=heirarchy.substr(heirarchy.find_first_of(';')+1);
+                       int pos = heirarchy.find_first_of(';');
+                       currentLevel=heirarchy.substr(0,pos);
+                       if (pos != (heirarchy.length()-1)) {  heirarchy=heirarchy.substr(pos+1);  }
+                       else { heirarchy = ""; }
                }
                return currentLevel;
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "getNextTaxon");
+               m->errorOut(e, "PhyloTree", "getNextTaxon");
                exit(1);
        }
 }
 
 /**************************************************************************************************/
 
-void PhyloTree::addSeqToTree(string seqName, string seqTaxonomy){
+int PhyloTree::addSeqToTree(string seqName, string seqTaxonomy){
        try {
                numSeqs++;
                
@@ -89,6 +93,8 @@ void PhyloTree::addSeqToTree(string seqName, string seqTaxonomy){
                        
                        level++;
                        
+                       if (m->control_pressed) { return 0; }
+                       
                        //somehow the parent is getting one too many accnos
                        //use print to reassign the taxa id
                        taxon = getNextTaxon(seqTaxonomy);
@@ -123,7 +129,7 @@ void PhyloTree::addSeqToTree(string seqName, string seqTaxonomy){
 
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "addSeqToTree");
+               m->errorOut(e, "PhyloTree", "addSeqToTree");
                exit(1);
        }
 }
@@ -138,7 +144,7 @@ vector<int> PhyloTree::getGenusNodes()      {
                return genusIndex;
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "getGenusNodes");
+               m->errorOut(e, "PhyloTree", "getGenusNodes");
                exit(1);
        }
 }
@@ -153,7 +159,7 @@ void PhyloTree::assignHeirarchyIDs(int index){
                        tree[it->second].heirarchyID = tree[index].heirarchyID + '.' + toString(counter);
                        counter++;
                        tree[it->second].level = tree[index].level + 1;
-                       
+                                               
                        //save maxLevel for binning the unclassified seqs
                        if (tree[it->second].level > maxLevel) { maxLevel = tree[it->second].level; } 
                        
@@ -161,7 +167,7 @@ void PhyloTree::assignHeirarchyIDs(int index){
                }
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "assignHeirarchyIDs");
+               m->errorOut(e, "PhyloTree", "assignHeirarchyIDs");
                exit(1);
        }
 }
@@ -215,7 +221,7 @@ void PhyloTree::binUnclassified(){
                
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "binUnclassified");
+               m->errorOut(e, "PhyloTree", "binUnclassified");
                exit(1);
        }
 }
@@ -234,7 +240,7 @@ string PhyloTree::getFullTaxonomy(string seqName) {
                return tax;
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "getFullTaxonomy");
+               m->errorOut(e, "PhyloTree", "getFullTaxonomy");
                exit(1);
        }
 }
@@ -246,7 +252,7 @@ void PhyloTree::print(ofstream& out){
                print(0, out);
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "print");
+               m->errorOut(e, "PhyloTree", "print");
                exit(1);
        }
 }
@@ -264,7 +270,7 @@ void PhyloTree::print(int i, ofstream& out){
                
        }
        catch(exception& e) {
-               errorOut(e, "PhyloTree", "print");
+               m->errorOut(e, "PhyloTree", "print");
                exit(1);
        }
 }