]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed bug with creation of .tree.sum file
authorwestcott <westcott>
Thu, 5 Aug 2010 10:52:19 +0000 (10:52 +0000)
committerwestcott <westcott>
Thu, 5 Aug 2010 10:52:19 +0000 (10:52 +0000)
bayesian.cpp
classify.cpp
phylosummary.cpp
phylotree.cpp

index e5ab89e6216426e2cd9ca1c8a7eca16db203cd00..ae96a220ae2646c59a45a36152ed2d0b099c0c64 100644 (file)
@@ -20,6 +20,7 @@ Classify(), kmerSize(ksize), confidenceThreshold(cutoff), iters(i)  {
                string tfileroot = tfile.substr(0,tfile.find_last_of(".")+1);
                string tempfileroot = getRootName(getSimpleName(tempFile));
                string phyloTreeName = tfileroot + "tree.train";
+               string phyloTreeSumName = tfileroot + "tree.sum";
                string probFileName = tfileroot + tempfileroot + char('0'+ kmerSize) + "mer.prob";
                string probFileName2 = tfileroot + tempfileroot + char('0'+ kmerSize) + "mer.numNonZero";
                
@@ -29,10 +30,11 @@ Classify(), kmerSize(ksize), confidenceThreshold(cutoff), iters(i)  {
                ifstream phyloTreeTest(phyloTreeName.c_str());
                ifstream probFileTest2(probFileName2.c_str());
                ifstream probFileTest(probFileName.c_str());
+               ifstream probFileTest3(phyloTreeSumName.c_str());
                
                int start = time(NULL);
                
-               if(probFileTest && probFileTest2 && phyloTreeTest){     
+               if(probFileTest && probFileTest2 && phyloTreeTest && probFileTest3){    
                        m->mothurOut("Reading template taxonomy...     "); cout.flush();
                        
                        phyloTree = new PhyloTree(phyloTreeTest, phyloTreeName);
index 9a2de1fa46d78e99f8909abd729fb6f24e00bdf0..6bf2cb57ee2833d91ba0520f8e1e67a5c05ec348 100644 (file)
@@ -254,7 +254,7 @@ int Classify::readTaxonomy(string file) {
                phyloTree->assignHeirarchyIDs(0);
                
                phyloTree->setUp(file);
-               
+       
                m->mothurOut("DONE.");
                m->mothurOutEndLine();  cout.flush();
                
index 33396975f506626ff275a8c37fa6c0f83a3ead18..08cedeb26cbc134c2527b67abb0a5289c4013206 100644 (file)
@@ -255,6 +255,8 @@ void PhyloSummary::readTreeStruct(ifstream& in){
                in >> num; gobble(in);
                
                tree.resize(num);
+               
+               in >> maxLevel; gobble(in);
        
                //read the tree file
                for (int i = 0; i < tree.size(); i++) {
@@ -280,7 +282,7 @@ void PhyloSummary::readTreeStruct(ifstream& in){
                        
                        gobble(in);
                        
-                       if (tree[i].level > maxLevel) {  maxLevel = tree[i].level;  }
+                       //if (tree[i].level > maxLevel) {  maxLevel = tree[i].level;  }
                }
 
        }
index 6b32e27201b5103e077261117f21fe30b69eb31c..e2b0805656064d0930de37933a1e599301573881 100644 (file)
@@ -178,14 +178,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 +346,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) {
@@ -381,9 +376,9 @@ void PhyloTree::binUnclassified(string file){
                                leafNodes[i] = i;
                        }
                }
-       //cout << "maxLevel = " << maxLevel << endl;    
-               int copyNodes = copy.size();
                
+               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++) {
@@ -432,25 +427,24 @@ void PhyloTree::binUnclassified(string file){
 /**************************************************************************************************/
 void PhyloTree::fillOutTree(int index, vector<TaxNode>& copy) {
        try {
+       
                map<string,int>::iterator it;
                
-               if (copy[index].level < maxLevel) {
-                       it = copy[index].children.find("unclassified");
-                       if (it == copy[index].children.end()) { //no unclassified at this level
-                               string taxon = "unclassified";
-                               copy.push_back(TaxNode(taxon));
-                               copy[index].children[taxon] = copy.size()-1;
-                               copy[copy.size()-1].parent = index;
-                               copy[copy.size()-1].level = copy[index].level + 1;
-                       }
+               it = copy[index].children.find("unclassified");
+               if (it == copy[index].children.end()) { //no unclassified at this level
+                       string taxon = "unclassified";
+                       copy.push_back(TaxNode(taxon));
+                       copy[index].children[taxon] = copy.size()-1;
+                       copy[copy.size()-1].parent = index;
+                       copy[copy.size()-1].level = copy[index].level + 1;
+               }
                
-                       
-                       for(it=copy[index].children.begin();it!=copy[index].children.end();it++){ //check your children
+               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");
@@ -482,6 +476,8 @@ void PhyloTree::print(ofstream& out, vector<TaxNode>& copy){
        try {
                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';