]> git.donarmstrong.com Git - mothur.git/commitdiff
finished get.relabund command
authorwestcott <westcott>
Tue, 22 Jun 2010 17:32:48 +0000 (17:32 +0000)
committerwestcott <westcott>
Tue, 22 Jun 2010 17:32:48 +0000 (17:32 +0000)
commandfactory.cpp
getrelabundcommand.cpp
getrelabundcommand.h
phylotree.cpp
phylotree.h
sharedcommand.cpp

index 0612c6c51977327cbbd8f100f7c1b13d6b18c7da..2b19f72e1761544c5ec5eb7b676d5bd8ad30e4a6 100644 (file)
@@ -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;
index 8293c9b31485bad93f1bb8875f2e53fc28a1d746..4d155f2f0fda2b4462450ad5e2789e70a12b13d7 100644 (file)
@@ -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");
index aa123a4f24e73c8b9a1dc94449e2acccbfc003cb..9725a31ab546f0829ec4ca0bf370e6792fdfeadf 100644 (file)
@@ -31,12 +31,13 @@ private:
        InputData* input;
        vector<SharedRAbundVector*> lookup;
        
-       bool abort, allLines;
+       bool abort, allLines, pickedGroups;
        set<string> labels; //holds labels to be used
        string groups, label, outputDir, scale;
        vector<string> Groups;
        
-       int getRelAbundance(vector<SharedRAbundVector*>, ofstream&);
+       int getRelAbundance(vector<SharedRAbundVector*>&, ofstream&);
+       int eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup);
 
 };
 
index 53492cafe6f17fbc2b167c8393dda6c24c72ea55..d6c740ae791b494ea64951a03405b38535593152 100644 (file)
@@ -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");
index 50bbb1dd86f3148e10110e3f10407ce754a30766..7aae8f1adedcf5f1db6b94d1bbe76a968a8e3100 100644 (file)
@@ -54,7 +54,7 @@ public:
        bool ErrorCheck(vector<string>);
        
 private:
-       string getNextTaxon(string&);
+       string getNextTaxon(string&, string);
        void print(ofstream&, vector<TaxNode>&); //used to create static reference taxonomy file
        void fillOutTree(int, vector<TaxNode>&); //used to create static reference taxonomy file
        void binUnclassified(string);
index 213fd49588bbf8a9278bc04c14d474bd11ccb278..91bb8e19604d3d9446016c4b9eaf82f566172c0a 100644 (file)
@@ -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<SharedRAbundVector*> 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;