From: westcott Date: Thu, 5 Aug 2010 10:52:19 +0000 (+0000) Subject: fixed bug with creation of .tree.sum file X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=2df35fdeea85f574630d75b11fb5b08c39aec31a fixed bug with creation of .tree.sum file --- diff --git a/bayesian.cpp b/bayesian.cpp index e5ab89e..ae96a22 100644 --- a/bayesian.cpp +++ b/bayesian.cpp @@ -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); diff --git a/classify.cpp b/classify.cpp index 9a2de1f..6bf2cb5 100644 --- a/classify.cpp +++ b/classify.cpp @@ -254,7 +254,7 @@ int Classify::readTaxonomy(string file) { phyloTree->assignHeirarchyIDs(0); phyloTree->setUp(file); - + m->mothurOut("DONE."); m->mothurOutEndLine(); cout.flush(); diff --git a/phylosummary.cpp b/phylosummary.cpp index 3339697..08cedeb 100644 --- a/phylosummary.cpp +++ b/phylosummary.cpp @@ -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; } } } diff --git a/phylotree.cpp b/phylotree.cpp index 6b32e27..e2b0805 100644 --- a/phylotree.cpp +++ b/phylotree.cpp @@ -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::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& copy) { try { + map::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& 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';