X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=phylosummary.cpp;h=a9d501e2190a9f68ed79edc8586b4dba2cb03342;hb=541bab1dac00688b4c3a8c4a95ab464412663c50;hp=9717087d72a55a6bc28ce2d77f02545a7eb5b612;hpb=006601d68abe8d0061f77e8d28323b160750e343;p=mothur.git diff --git a/phylosummary.cpp b/phylosummary.cpp index 9717087..a9d501e 100644 --- a/phylosummary.cpp +++ b/phylosummary.cpp @@ -454,7 +454,61 @@ void PhyloSummary::print(ofstream& out){ exit(1); } } +/**************************************************************************************************/ +void PhyloSummary::print(ofstream& out, bool relabund){ + try { + + if (ignore) { assignRank(0); } + + int totalChildrenInTree = 0; + map::iterator itGroup; + + map::iterator it; + for(it=tree[0].children.begin();it!=tree[0].children.end();it++){ + if (tree[it->second].total != 0) { + totalChildrenInTree++; + tree[0].total += tree[it->second].total; + + if (groupmap != NULL) { + vector mGroups = groupmap->getNamesOfGroups(); + for (int i = 0; i < mGroups.size(); i++) { tree[0].groupCount[mGroups[i]] += tree[it->second].groupCount[mGroups[i]]; } + }else if ( ct != NULL) { + vector mGroups = ct->getNamesOfGroups(); + if (ct->hasGroupInfo()) { for (int i = 0; i < mGroups.size(); i++) { tree[0].groupCount[mGroups[i]] += tree[it->second].groupCount[mGroups[i]]; } } + } + } + } + + //print root + out << tree[0].name << "\t" << "1.0000" << "\t"; //root relative abundance is 1, everyone classifies to root + + /* + if (groupmap != NULL) { + for (int i = 0; i < mGroups.size(); i++) { out << tree[0].groupCount[mGroups[i]] << '\t'; } + }else if ( ct != NULL) { + if (ct->hasGroupInfo()) { for (int i = 0; i < mGroups.size(); i++) { out << tree[0].groupCount[mGroups[i]] << '\t'; } } + }*/ + + if (groupmap != NULL) { + vector mGroups = groupmap->getNamesOfGroups(); + for (int i = 0; i < mGroups.size(); i++) { out << "1.0000" << '\t'; } + }else if ( ct != NULL) { + vector mGroups = ct->getNamesOfGroups(); + if (ct->hasGroupInfo()) { for (int i = 0; i < mGroups.size(); i++) { out << "1.0000" << '\t'; } } + } + + out << endl; + + //print rest + print(0, out, relabund); + + } + catch(exception& e) { + m->errorOut(e, "PhyloSummary", "print"); + exit(1); + } +} /**************************************************************************************************/ void PhyloSummary::print(int i, ofstream& out){ @@ -463,14 +517,14 @@ void PhyloSummary::print(int i, ofstream& out){ for(it=tree[i].children.begin();it!=tree[i].children.end();it++){ if (tree[it->second].total != 0) { - + int totalChildrenInTree = 0; - + map::iterator it2; - for(it2=tree[it->second].children.begin();it2!=tree[it->second].children.end();it2++){ + for(it2=tree[it->second].children.begin();it2!=tree[it->second].children.end();it2++){ if (tree[it2->second].total != 0) { totalChildrenInTree++; } } - + out << tree[it->second].level << "\t" << tree[it->second].rank << "\t" << tree[it->second].name << "\t" << totalChildrenInTree << "\t" << tree[it->second].total << "\t"; map::iterator itGroup; @@ -479,11 +533,11 @@ void PhyloSummary::print(int i, ofstream& out){ // out << itGroup->second << '\t'; //} vector mGroups = groupmap->getNamesOfGroups(); - for (int i = 0; i < mGroups.size(); i++) { out << tree[it->second].groupCount[mGroups[i]] << '\t'; } + for (int i = 0; i < mGroups.size(); i++) { out << tree[it->second].groupCount[mGroups[i]] << '\t'; } }else if (ct != NULL) { if (ct->hasGroupInfo()) { vector mGroups = ct->getNamesOfGroups(); - for (int i = 0; i < mGroups.size(); i++) { out << tree[it->second].groupCount[mGroups[i]] << '\t'; } + for (int i = 0; i < mGroups.size(); i++) { out << tree[it->second].groupCount[mGroups[i]] << '\t'; } } } out << endl; @@ -498,6 +552,64 @@ void PhyloSummary::print(int i, ofstream& out){ exit(1); } } + +/**************************************************************************************************/ + +void PhyloSummary::print(int i, ofstream& out, bool relabund){ + try { + map::iterator it; + for(it=tree[i].children.begin();it!=tree[i].children.end();it++){ + + if (tree[it->second].total != 0) { + + int totalChildrenInTree = 0; + + map::iterator it2; + for(it2=tree[it->second].children.begin();it2!=tree[it->second].children.end();it2++){ + if (tree[it2->second].total != 0) { totalChildrenInTree++; } + } + + string nodeName = ""; + int thisNode = it->second; + while (tree[thisNode].rank != "0") { //while you are not at top + if (m->control_pressed) { break; } + nodeName = tree[thisNode].name + "|" + nodeName; + thisNode = tree[thisNode].parent; + } + if (nodeName != "") { nodeName = nodeName.substr(0, nodeName.length()-1); } + + out << nodeName << "\t" << (tree[it->second].total / (float)tree[i].total) << "\t"; + + map::iterator itGroup; + if (groupmap != NULL) { + vector mGroups = groupmap->getNamesOfGroups(); + for (int j = 0; j < mGroups.size(); j++) { + if (tree[i].groupCount[mGroups[j]] == 0) { + out << 0 << '\t'; + }else { out << (tree[it->second].groupCount[mGroups[j]] / (float)tree[i].groupCount[mGroups[j]]) << '\t'; } + } + }else if (ct != NULL) { + if (ct->hasGroupInfo()) { + vector mGroups = ct->getNamesOfGroups(); + for (int j = 0; j < mGroups.size(); j++) { + if (tree[i].groupCount[mGroups[j]] == 0) { + out << 0 << '\t'; + }else { out << (tree[it->second].groupCount[mGroups[j]] / (float)tree[i].groupCount[mGroups[j]]) << '\t'; } + } + } + } + out << endl; + + } + + print(it->second, out, relabund); + } + } + catch(exception& e) { + m->errorOut(e, "PhyloSummary", "print"); + exit(1); + } +} /**************************************************************************************************/ void PhyloSummary::readTreeStruct(ifstream& in){ try {