]> git.donarmstrong.com Git - mothur.git/blobdiff - phylotree.cpp
added countable class to read and store count file. added count parameter to make...
[mothur.git] / phylotree.cpp
index e430fb9e85622dcd1d425534857fe37dff600da9..3dde18680c625eb816230a8d13774ccfc47032cf 100644 (file)
@@ -20,6 +20,7 @@ PhyloTree::PhyloTree(){
                tree[0].heirarchyID = "0";
                maxLevel = 0;
                calcTotals = true;
+               addSeqToTree("unknown", "unknown;");
        }
        catch(exception& e) {
                m->errorOut(e, "PhyloTree", "PhyloTree");
@@ -127,7 +128,6 @@ PhyloTree::PhyloTree(string tfile){
                maxLevel = 0;
                calcTotals = true;
                string name, tax;
-
                
                #ifdef USE_MPI
                        int pid, num, processors;
@@ -178,20 +178,26 @@ PhyloTree::PhyloTree(string tfile){
                        MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
                
                #else
-                       ifstream in;
-                       m->openInputFile(tfile, in);
-                       
-                       //read in users taxonomy file and add sequences to tree
-                       while(!in.eof()){
-                               in >> name >> tax; m->gobble(in);
-                       
-                               addSeqToTree(name, tax);
-                       }
-                       in.close();
+            map<string, string> temp;
+            m->readTax(tfile, temp);
+        
+            for (map<string, string>::iterator itTemp = temp.begin(); itTemp != temp.end();) {
+                addSeqToTree(itTemp->first, itTemp->second);
+                temp.erase(itTemp++);
+            }
                #endif
        
                assignHeirarchyIDs(0);
-       
+        
+        
+        string unknownTax = "unknown;";
+        //added last taxon until you get desired level
+               for (int i = 1; i < maxLevel; i++) {
+                       unknownTax += "unclassfied;";
+               }
+        
+        addSeqToTree("unknown", unknownTax);
+        
                //create file for summary if needed
                setUp(tfile);
        }
@@ -232,7 +238,6 @@ string PhyloTree::getNextTaxon(string& heirarchy, string seqname){
 
 int PhyloTree::addSeqToTree(string seqName, string seqTaxonomy){
        try {
-                       
                numSeqs++;
                
                map<string, int>::iterator childPointer;
@@ -375,7 +380,7 @@ void PhyloTree::binUnclassified(string file){
                map<string, int>::iterator childPointer;
                
                vector<TaxNode> copy = tree;
-                       
+               
                //fill out tree
                fillOutTree(0, copy);
        
@@ -484,16 +489,16 @@ string PhyloTree::getFullTaxonomy(string seqName) {
 
 void PhyloTree::print(ofstream& out, vector<TaxNode>& copy){
        try {
-       
+               
                //output mothur version
                out << "#" << m->getVersion() << endl;
                
                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';
                        
                        map<string,int>::iterator it;
@@ -606,17 +611,20 @@ bool PhyloTree::ErrorCheck(vector<string> templateFileNames){
        try {
        
                bool okay = true;
+               templateFileNames.push_back("unknown");
                
                map<string, int>::iterator itFind;
                map<string, int> taxonomyFileNames = name2Taxonomy;
                
+        if (m->debug) { m->mothurOut("[DEBUG]: in error check. Numseqs in template = " + toString(templateFileNames.size()) + ". Numseqs in taxonomy = " + toString(taxonomyFileNames.size()) + ".\n"); }
+        
                for (int i = 0; i < templateFileNames.size(); i++) {
                        itFind = taxonomyFileNames.find(templateFileNames[i]);
                        
                        if (itFind != taxonomyFileNames.end()) { //found it so erase it
                                taxonomyFileNames.erase(itFind);
                        }else {
-                               m->mothurOut(templateFileNames[i] + " is in your template file and is not in your taxonomy file. Please correct."); m->mothurOutEndLine();
+                               m->mothurOut("'" +templateFileNames[i] + "' is in your template file and is not in your taxonomy file. Please correct."); m->mothurOutEndLine();
                                okay = false;
                        }