Beispiel #1
0
PhyloSummary::PhyloSummary(string refTfile, GroupMap* g, bool r, int p){
	try {
		m = MothurOut::getInstance();
		maxLevel = 0;
		ignore = false;
        numSeqs = 0;
        relabund = r;
        printlevel = p;
		
		groupmap = g;
        ct = NULL;
				
		//check for necessary files
		string taxFileNameTest = m->getFullPathName((refTfile.substr(0,refTfile.find_last_of(".")+1) + "tree.sum"));
		ifstream FileTest(taxFileNameTest.c_str());
		
		if (!FileTest) { 
			m->mothurOut("Error: can't find " + taxFileNameTest + "."); m->mothurOutEndLine(); exit(1);
		}else{
			readTreeStruct(FileTest);
		}
		
		tree[0].rank = "0";
		assignRank(0);

	}
	catch(exception& e) {
		m->errorOut(e, "PhyloSummary", "PhyloSummary");
		exit(1);
	}
}
Beispiel #2
0
PhyloSummary::PhyloSummary(string refTfile, CountTable* c){
	try {
		m = MothurOut::getInstance();
		maxLevel = 0;
		ignore = false;
        numSeqs = 0;
		
		ct = c;
        groupmap = NULL;
        
		//check for necessary files
        if (refTfile == "saved") { ReferenceDB* rdb = ReferenceDB::getInstance(); refTfile = rdb->getSavedTaxonomy(); }
		string taxFileNameTest = m->getFullPathName((refTfile.substr(0,refTfile.find_last_of(".")+1) + "tree.sum"));
		ifstream FileTest(taxFileNameTest.c_str());
		
		if (!FileTest) { 
			m->mothurOut("Error: can't find " + taxFileNameTest + "."); m->mothurOutEndLine(); exit(1);
		}else{
			readTreeStruct(FileTest);
		}
		
		tree[0].rank = "0";
		assignRank(0);
        
	}
	catch(exception& e) {
		m->errorOut(e, "PhyloSummary", "PhyloSummary");
		exit(1);
	}
}
Beispiel #3
0
void PhyloSummary::print(ofstream& out, bool relabund){
	try {
		
		if (ignore) { assignRank(0); }
	
		int totalChildrenInTree = 0;
		map<string, int>::iterator itGroup;
		
		map<string,int>::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<string> 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<string> 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<string> mGroups = groupmap->getNamesOfGroups();
			for (int i = 0; i < mGroups.size(); i++) {  out << "1.0000" << '\t'; }
        }else if ( ct != NULL) {
            vector<string> 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);
	}
}
Beispiel #4
0
void PhyloSummary::assignRank(int index){
	try {
		map<string,int>::iterator it;
		int counter = 1;
        
		for(it=tree[index].children.begin();it!=tree[index].children.end();it++){
			tree[it->second].rank = tree[index].rank + '.' + toString(counter);
			counter++;
			assignRank(it->second);
		}
	}
	catch(exception& e) {
		m->errorOut(e, "PhyloSummary", "assignRank");
		exit(1);
	}
}
Beispiel #5
0
void PhyloSummary::print(ofstream& out, string output){
	try {
		
		if (ignore)     {  assignRank(0); }
        vector<string> mGroups;
        
        //print labels
        if (output == "detail") {   out << "taxlevel\trankID\ttaxon\tdaughterlevels\ttotal";  }
        else                    {   out << "taxonomy\ttotal";  }
        
        if (printlevel == -1) { printlevel = maxLevel; }
        else if (printlevel > maxLevel) { m->mothurOut("[WARNING]: Your printlevel is greater than your maxlevel, adjusting your printlevel to " + toString(maxLevel) + "\n"); printlevel = maxLevel; }
        
		if (groupmap != NULL) {
			//so the labels match the counts below, since the map sorts them automatically...
			//sort(groupmap->namesOfGroups.begin(), groupmap->namesOfGroups.end());
            mGroups = groupmap->getNamesOfGroups();
			for (int i = 0; i < mGroups.size(); i++) {
				out << '\t' << mGroups[i];
			}
		}else if (ct != NULL) {
            if (ct->hasGroupInfo()) {
                mGroups = ct->getNamesOfGroups();
                for (int i = 0; i < mGroups.size(); i++) {
                    out << '\t' << mGroups[i];
                }
            }
        }
		out << endl;
		
		int totalChildrenInTree = 0;
		map<string, int>::iterator itGroup;
		map<string,int>::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) {
					for (int i = 0; i < mGroups.size(); i++) { tree[0].groupCount[mGroups[i]] += tree[it->second].groupCount[mGroups[i]]; } 
				}else if ( ct != NULL) {
                    if (ct->hasGroupInfo()) { for (int i = 0; i < mGroups.size(); i++) { tree[0].groupCount[mGroups[i]] += tree[it->second].groupCount[mGroups[i]]; } }
                }
			}
		}
		
        
        
            //print root
            if (relabund) {
                out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
                
                if (output == "detail") {
                    out << tree[0].level << "\t" << tree[0].rank << "\t" << tree[0].name << "\t" << totalChildrenInTree << "\t" << (tree[0].total/(double) tree[0].total);
                }else{
                    out << tree[0].name << "\t" << (tree[0].total/(double) tree[0].total);
                }
                
                
                if (groupmap != NULL) {
                    for (int i = 0; i < mGroups.size(); i++) {
                        double thisNum = tree[0].groupCount[mGroups[i]];
                        thisNum /= (double) groupmap->getNumSeqs(mGroups[i]);
                        out  << '\t' << thisNum;
                    }
                }else if ( ct != NULL) {
                    if (ct->hasGroupInfo()) {
                        for (int i = 0; i < mGroups.size(); i++) {
                            double thisNum = tree[0].groupCount[mGroups[i]];
                            thisNum /= (double) ct->getGroupCount(mGroups[i]);
                            out  << '\t' << thisNum;
                        }
                    }
                }
                out << endl;
               
                
            }else {
                if (output == "detail") {
                    out << tree[0].level << "\t" << tree[0].rank << "\t" << tree[0].name << "\t" << totalChildrenInTree << "\t" << tree[0].total;
                }else{
                    out << tree[0].name << '\t' << tree[0].total;
                }
                
                if (groupmap != NULL) {
                    for (int i = 0; i < mGroups.size(); i++) {  out  << '\t'<< tree[0].groupCount[mGroups[i]]; }
                }else if ( ct != NULL) {
                    if (ct->hasGroupInfo()) { for (int i = 0; i < mGroups.size(); i++) {  out  << '\t' << tree[0].groupCount[mGroups[i]]; } }
                }
                out << endl;
                
            }
        
        
		//print rest
		print(0, out, output);
		
	}
	catch(exception& e) {
		m->errorOut(e, "PhyloSummary", "print");
		exit(1);
	}
}
Beispiel #6
0
void PhyloSummary::print(ofstream& out){
	try {
		
		if (ignore) { assignRank(0); }
        vector<string> mGroups;
		//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());
            mGroups = groupmap->getNamesOfGroups();
			for (int i = 0; i < mGroups.size(); i++) {
				out << mGroups[i] << '\t';
			}
		}else if (ct != NULL) {
            if (ct->hasGroupInfo()) {
                mGroups = ct->getNamesOfGroups();
                for (int i = 0; i < mGroups.size(); i++) {
                    out << mGroups[i] << '\t';
                }
            }
        }
		
		out << endl;
		
		int totalChildrenInTree = 0;
		map<string, int>::iterator itGroup;
		
		map<string,int>::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) {
					for (int i = 0; i < mGroups.size(); i++) { tree[0].groupCount[mGroups[i]] += tree[it->second].groupCount[mGroups[i]]; } 
				}else if ( ct != NULL) {
                    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].level << "\t" << tree[0].rank << "\t" << tree[0].name << "\t" << totalChildrenInTree << "\t" << tree[0].total << "\t";
		
		
		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'; } }
        }
		out << endl;
		
		//print rest
		print(0, out);
		
	}
	catch(exception& e) {
		m->errorOut(e, "PhyloSummary", "print");
		exit(1);
	}
}