PhyloTree::PhyloTree(string tfile){ try { m = MothurOut::getInstance(); current = CurrentFile::getInstance(); numNodes = 1; numSeqs = 0; tree.push_back(TaxNode("Root")); tree[0].heirarchyID = "0"; tree[0].level = 0; maxLevel = 0; calcTotals = true; string name, tax; map<string, string> temp; util.readTax(tfile, temp, true); for (map<string, string>::iterator itTemp = temp.begin(); itTemp != temp.end();) { addSeqToTree(itTemp->first, itTemp->second); temp.erase(itTemp++); } string unknownTax = "unknown;"; //added last taxon until you get desired level for (int i = 1; i < maxLevel; i++) { unknownTax += "unknown_unclassfied;"; } addSeqToTree("unknown", unknownTax); assignHeirarchyIDs(0); //create file for summary if needed setUp(tfile); } catch(exception& e) { m->errorOut(e, "PhyloTree", "PhyloTree"); exit(1); } }
void PhyloTree::assignHeirarchyIDs(int index){ try { map<string,int>::iterator it; int counter = 1; for(it=tree[index].children.begin();it!=tree[index].children.end();it++){ if (m->debug) { m->mothurOut(toString(index) +'\t' + tree[it->second].name +'\n'); } 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; } assignHeirarchyIDs(it->second); } } catch(exception& e) { m->errorOut(e, "PhyloTree", "assignHeirarchyIDs"); exit(1); } }