From: westcott Date: Tue, 22 Jun 2010 17:32:48 +0000 (+0000) Subject: finished get.relabund command X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=762b3e4c83e1e8e8392c1199b6482d36ee89e50f finished get.relabund command --- diff --git a/commandfactory.cpp b/commandfactory.cpp index 0612c6c..2b19f72 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -81,6 +81,7 @@ #include "clustersplitcommand.h" #include "classifyotucommand.h" #include "degapseqscommand.h" +#include "getrelabundcommand.h" /*******************************************************/ @@ -168,6 +169,7 @@ CommandFactory::CommandFactory(){ commands["split.abund"] = "split.abund"; commands["classify.otu"] = "classify.otu"; commands["degap.seqs"] = "degap.seqs"; + commands["get.relabund"] = "get.relabund"; commands["classify.seqs"] = "MPIEnabled"; commands["dist.seqs"] = "MPIEnabled"; commands["filter.seqs"] = "MPIEnabled"; @@ -294,6 +296,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else if(commandName == "cluster.split") { command = new ClusterSplitCommand(optionString); } else if(commandName == "classify.otu") { command = new ClassifyOtuCommand(optionString); } else if(commandName == "degap.seqs") { command = new DegapSeqsCommand(optionString); } + else if(commandName == "get.relabund") { command = new GetRelAbundCommand(optionString); } else { command = new NoCommand(optionString); } return command; diff --git a/getrelabundcommand.cpp b/getrelabundcommand.cpp index 8293c9b..4d155f2 100644 --- a/getrelabundcommand.cpp +++ b/getrelabundcommand.cpp @@ -94,7 +94,7 @@ void GetRelAbundCommand::help(){ m->mothurOut("The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"); m->mothurOut("The scale parameter allows you to select what scale you would like to use. Choices are totalgroup, totalotu, averagegroup, averageotu, default is totalgroup.\n"); m->mothurOut("The get.relabund command should be in the following format: get.relabund(groups=yourGroups, label=yourLabels).\n"); - m->mothurOut("Example get.relabund(groups=A-B-C, scale=log10).\n"); + m->mothurOut("Example get.relabund(groups=A-B-C, scale=averagegroup).\n"); m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); m->mothurOut("The get.relabund command outputs a .relabund file.\n"); m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); diff --git a/getrelabundcommand.h b/getrelabundcommand.h index aa123a4..9725a31 100644 --- a/getrelabundcommand.h +++ b/getrelabundcommand.h @@ -31,12 +31,13 @@ private: InputData* input; vector lookup; - bool abort, allLines; + bool abort, allLines, pickedGroups; set labels; //holds labels to be used string groups, label, outputDir, scale; vector Groups; - int getRelAbundance(vector, ofstream&); + int getRelAbundance(vector&, ofstream&); + int eliminateZeroOTUS(vector& thislookup); }; diff --git a/phylotree.cpp b/phylotree.cpp index 53492ca..d6c740a 100644 --- a/phylotree.cpp +++ b/phylotree.cpp @@ -197,14 +197,22 @@ PhyloTree::PhyloTree(string tfile){ /**************************************************************************************************/ -string PhyloTree::getNextTaxon(string& heirarchy){ +string PhyloTree::getNextTaxon(string& heirarchy, string seqname){ try { string currentLevel = ""; if(heirarchy != ""){ int pos = heirarchy.find_first_of(';'); - currentLevel=heirarchy.substr(0,pos); - if (pos != (heirarchy.length()-1)) { heirarchy=heirarchy.substr(pos+1); } - else { heirarchy = ""; } + + if (pos == -1) { //you can't find another ; + currentLevel = heirarchy; + heirarchy = ""; + m->mothurOut(seqname + " is missing a ;, please check for other errors."); m->mothurOutEndLine(); + }else{ + currentLevel=heirarchy.substr(0,pos); + if (pos != (heirarchy.length()-1)) { heirarchy=heirarchy.substr(pos+1); } + else { heirarchy = ""; } + } + } return currentLevel; } @@ -228,16 +236,16 @@ int PhyloTree::addSeqToTree(string seqName, string seqTaxonomy){ tree[0].accessions.push_back(seqName); string taxon;// = getNextTaxon(seqTaxonomy); - + while(seqTaxonomy != ""){ level++; - + if (m->control_pressed) { return 0; } //somehow the parent is getting one too many accnos //use print to reassign the taxa id - taxon = getNextTaxon(seqTaxonomy); + taxon = getNextTaxon(seqTaxonomy, seqName); if (taxon == "") { m->mothurOut(seqName + " has an error in the taxonomy. This may be due to a ;;"); m->mothurOutEndLine(); if (currentNode != 0) { uniqueTaxonomies[currentNode] = currentNode; } break; } @@ -254,21 +262,13 @@ int PhyloTree::addSeqToTree(string seqName, string seqTaxonomy){ tree[currentNode].children[taxon] = numNodes-1; tree[numNodes-1].parent = currentNode; - // int numChildren = tree[currentNode].children.size(); - // string heirarchyID = tree[currentNode].heirarchyID; - // tree[currentNode].accessions.push_back(seqName); - currentNode = tree[currentNode].children[taxon]; tree[currentNode].accessions.push_back(seqName); name2Taxonomy[seqName] = currentNode; - // tree[currentNode].level = level; - // tree[currentNode].childNumber = numChildren; - // tree[currentNode].heirarchyID = heirarchyID + '.' + toString(tree[currentNode].childNumber); } if (seqTaxonomy == "") { uniqueTaxonomies[currentNode] = currentNode; } } - } catch(exception& e) { m->errorOut(e, "PhyloTree", "addSeqToTree"); diff --git a/phylotree.h b/phylotree.h index 50bbb1d..7aae8f1 100644 --- a/phylotree.h +++ b/phylotree.h @@ -54,7 +54,7 @@ public: bool ErrorCheck(vector); private: - string getNextTaxon(string&); + string getNextTaxon(string&, string); void print(ofstream&, vector&); //used to create static reference taxonomy file void fillOutTree(int, vector&); //used to create static reference taxonomy file void binUnclassified(string); diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 213fd49..91bb8e1 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -8,7 +8,11 @@ */ #include "sharedcommand.h" - +//******************************************************************************************************************** +//sorts lowest to highest +inline bool compareSharedRabunds(SharedRAbundVector* left, SharedRAbundVector* right){ + return (left->getGroup() < right->getGroup()); +} //********************************************************************************************************************** SharedCommand::SharedCommand(string o) : outputDir(o) { @@ -143,6 +147,7 @@ int SharedCommand::execute(){ if(globaldata->allLines == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){ lookup = SharedList->getSharedRAbundVector(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); if (pickedGroups) { //check for otus with no seqs in them eliminateZeroOTUS(lookup); @@ -275,6 +280,8 @@ int SharedCommand::execute(){ void SharedCommand::printSharedData(vector thislookup) { try { + sort(thislookup.begin(), thislookup.end(), compareSharedRabunds); + //initialize bin values for (int i = 0; i < thislookup.size(); i++) { //cout << "in printData " << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << endl;