]> git.donarmstrong.com Git - mothur.git/blobdiff - phylosummary.cpp
moved utilities out of mothur.h and into mothurOut class.
[mothur.git] / phylosummary.cpp
index 5612d7bbf3eded6f86bcdce40c45048ee8edcb25..39bfdf3dfecb1cd4aaecb2763043d0c8cbb00d29 100644 (file)
@@ -48,12 +48,12 @@ void PhyloSummary::summarize(string userTfile){
        try {
                
                ifstream in;
-               openInputFile(userTfile, in);
+               m->openInputFile(userTfile, in);
                
                //read in users taxonomy file and add sequences to tree
                string name, tax;
                while(!in.eof()){
-                       in >> name >> tax; gobble(in);
+                       in >> name >> tax; m->gobble(in);
                        
                        addSeqToTree(name, tax);
                        
@@ -172,6 +172,9 @@ void PhyloSummary::print(ofstream& out){
                //print labels
                out << "taxlevel\t rankID\t taxon\t daughterlevels\t total\t";
                if (groupmap != NULL) {
+                       //so the labels match the counts below, since the map sorts them automatically...
+                       //sort(groupmap->namesOfGroups.begin(), groupmap->namesOfGroups.end());
+                       
                        for (int i = 0; i < groupmap->namesOfGroups.size(); i++) {
                                out << groupmap->namesOfGroups[i] << '\t';
                        }
@@ -179,14 +182,22 @@ void PhyloSummary::print(ofstream& out){
                
                out << endl;
                
+               int totalChildrenInTree = 0;
+               
+               map<string,int>::iterator it;
+               for(it=tree[0].children.begin();it!=tree[0].children.end();it++){   
+                       if (tree[it->second].total != 0)  {   totalChildrenInTree++; }
+               }
+               
                //print root
-               out << tree[0].level << "\t" << tree[0].rank << "\t" << tree[0].name << "\t" << tree[0].children.size() << "\t" << tree[0].total << "\t";
+               out << tree[0].level << "\t" << tree[0].rank << "\t" << tree[0].name << "\t" << totalChildrenInTree << "\t" << tree[0].total << "\t";
                
                map<string, int>::iterator itGroup;
                if (groupmap != NULL) {
-                       for (itGroup = tree[0].groupCount.begin(); itGroup != tree[0].groupCount.end(); itGroup++) {
-                               out << itGroup->second << '\t';
-                       }
+                       //for (itGroup = tree[0].groupCount.begin(); itGroup != tree[0].groupCount.end(); itGroup++) {
+                       //      out << itGroup->second << '\t';
+                       //}
+                       for (int i = 0; i < groupmap->namesOfGroups.size(); i++) {  out << tree[0].groupCount[groupmap->namesOfGroups[i]] << '\t'; } 
                }
                out << endl;
                
@@ -208,13 +219,22 @@ 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)  {
-                               out << tree[it->second].level << "\t" << tree[it->second].rank << "\t" << tree[it->second].name << "\t" << tree[it->second].children.size() << "\t" << tree[it->second].total << "\t";
+                       
+                               int totalChildrenInTree = 0;
+               
+                               map<string,int>::iterator 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<string, int>::iterator itGroup;
                                if (groupmap != NULL) {
-                                       for (itGroup = tree[it->second].groupCount.begin(); itGroup != tree[it->second].groupCount.end(); itGroup++) {
-                                               out << itGroup->second << '\t';
-                                       }
+                                       //for (itGroup = tree[it->second].groupCount.begin(); itGroup != tree[it->second].groupCount.end(); itGroup++) {
+                                       //      out << itGroup->second << '\t';
+                                       //}
+                                       for (int i = 0; i < groupmap->namesOfGroups.size(); i++) {  out << tree[it->second].groupCount[groupmap->namesOfGroups[i]] << '\t'; } 
                                }
                                out << endl;
                        }
@@ -230,11 +250,17 @@ void PhyloSummary::print(int i, ofstream& out){
 /**************************************************************************************************/
 void PhyloSummary::readTreeStruct(ifstream& in){
        try {
+       
+               //read version
+               string line = m->getline(in); m->gobble(in);
+               
                int num;
                
-               in >> num; gobble(in);
+               in >> num; m->gobble(in);
                
                tree.resize(num);
+               
+               in >> maxLevel; m->gobble(in);
        
                //read the tree file
                for (int i = 0; i < tree.size(); i++) {
@@ -258,9 +284,9 @@ void PhyloSummary::readTreeStruct(ifstream& in){
                        
                        tree[i].total = 0;
                        
-                       gobble(in);
+                       m->gobble(in);
                        
-                       if (tree[i].level > maxLevel) {  maxLevel = tree[i].level;  }
+                       //if (tree[i].level > maxLevel) {  maxLevel = tree[i].level;  }
                }
 
        }