]> git.donarmstrong.com Git - mothur.git/blobdiff - phylotree.cpp
added oldfasta and column parameter to dist.seqs so you can append distances to an...
[mothur.git] / phylotree.cpp
index d085f6c52ce3c733c7666d1c7df28e95a0575647..2ea219350c1f8bf8099b7cfc40d28ddcdfc9d872 100644 (file)
@@ -54,6 +54,9 @@ PhyloTree::PhyloTree(ifstream& in, string filename){
                        istringstream iss (tempBuf,istringstream::in);
                        delete buffer;
                        
+                       //read version
+                       getline(iss); gobble(iss);
+                       
                        iss >> numNodes; gobble(iss);
                        
                        tree.resize(numNodes);
@@ -78,6 +81,9 @@ PhyloTree::PhyloTree(ifstream& in, string filename){
                        MPI_File_close(&inMPI);
                        
                #else
+                       //read version
+                       string line = getline(in); gobble(in);
+                       
                        in >> numNodes; gobble(in);
                        
                        tree.resize(numNodes);
@@ -178,14 +184,14 @@ PhyloTree::PhyloTree(string tfile){
                        //read in users taxonomy file and add sequences to tree
                        while(!in.eof()){
                                in >> name >> tax; gobble(in);
-                               
+                       
                                addSeqToTree(name, tax);
                        }
                        in.close();
                #endif
-               
+       
                assignHeirarchyIDs(0);
-               
+       
                //create file for summary if needed
                setUp(tfile);
        }
@@ -346,12 +352,7 @@ void PhyloTree::setUp(string tfile){
                        if (pid == 0) {  binUnclassified(taxFileNameTest);  }
                
                #else
-                       //create file needed for summary if it doesn't exist
-                       ifstream FileTest(taxFileNameTest.c_str());
-                       
-                       if (!FileTest) { 
-                               binUnclassified(taxFileNameTest); 
-                       }
+                       binUnclassified(taxFileNameTest); 
                #endif
        }
        catch(exception& e) {
@@ -370,11 +371,11 @@ void PhyloTree::binUnclassified(string file){
                map<string, int>::iterator childPointer;
                
                vector<TaxNode> copy = tree;
-                               
+                       
                //fill out tree
                fillOutTree(0, copy);
-               
-               //get leaf nodes that may need externsion
+       
+               //get leaf nodes that may need extension
                for (int i = 0; i < copy.size(); i++) {  
 
                        if (copy[i].children.size() == 0) {
@@ -383,7 +384,7 @@ void PhyloTree::binUnclassified(string file){
                }
                
                int copyNodes = copy.size();
-               
+       
                //go through the seqs and if a sequence finest taxon is not the same level as the most finely defined taxon then classify it as unclassified where necessary
                map<int, int>::iterator itLeaf;
                for (itLeaf = leafNodes.begin(); itLeaf != leafNodes.end(); itLeaf++) {
@@ -394,7 +395,7 @@ void PhyloTree::binUnclassified(string file){
                        int currentNode = itLeaf->second;
                        
                        //this sequence is unclassified at some levels
-                       while(level <= maxLevel){
+                       while(level < maxLevel){
                
                                level++;
                        
@@ -432,6 +433,7 @@ void PhyloTree::binUnclassified(string file){
 /**************************************************************************************************/
 void PhyloTree::fillOutTree(int index, vector<TaxNode>& copy) {
        try {
+       
                map<string,int>::iterator it;
                
                it = copy[index].children.find("unclassified");
@@ -443,12 +445,12 @@ void PhyloTree::fillOutTree(int index, vector<TaxNode>& copy) {
                        copy[copy.size()-1].level = copy[index].level + 1;
                }
                
-               if (tree[index].level <= maxLevel) {
+               if (tree[index].level < maxLevel) {
                        for(it=tree[index].children.begin();it!=tree[index].children.end();it++){ //check your children
                                fillOutTree(it->second, copy);
                        }
                }
-               
+
        }
        catch(exception& e) {
                m->errorOut(e, "PhyloTree", "fillOutTree");
@@ -478,8 +480,14 @@ string PhyloTree::getFullTaxonomy(string seqName) {
 
 void PhyloTree::print(ofstream& out, vector<TaxNode>& copy){
        try {
+       
+               //output mothur version
+               out << "#" << m->getVersion() << endl;
+               
                out << copy.size() << endl;
                
+               out << maxLevel << endl;
+               
                for (int i = 0; i < copy.size(); i++) {
        
                        out << copy[i].level << '\t'<< copy[i].name << '\t' << copy[i].children.size() << '\t';
@@ -513,6 +521,9 @@ void PhyloTree::printTreeNodes(string treefilename) {
                        ofstream outTree;
                        openOutputFile(treefilename, outTree);
                        
+                       //output mothur version
+                       outTree << "#" << m->getVersion() << endl;
+                       
                        //print treenodes
                        outTree << tree.size() << endl;
                        for (int i = 0; i < tree.size(); i++) {