]> git.donarmstrong.com Git - mothur.git/commitdiff
added get.otulabels and remove.otulabels commands per user request
authorSarah Westcott <mothur.westcott@gmail.com>
Mon, 21 May 2012 18:00:07 +0000 (14:00 -0400)
committerSarah Westcott <mothur.westcott@gmail.com>
Mon, 21 May 2012 18:00:07 +0000 (14:00 -0400)
Mothur.xcodeproj/project.pbxproj
classifyotucommand.cpp
commandfactory.cpp
getotulabelscommand.cpp [new file with mode: 0644]
getotulabelscommand.h [new file with mode: 0644]
listotulabelscommand.cpp
listotulabelscommand.h
removeotulabelscommand.cpp [new file with mode: 0644]
removeotulabelscommand.h [new file with mode: 0644]

index f40cb4b53045edaf45f23a3784a8d38d7b3c8eec..d98b28443921915890802e12777ab374aa31d402 100644 (file)
@@ -11,6 +11,8 @@
                219C1DE41559BCCF004209F9 /* getcoremicrobiomecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 219C1DE31559BCCD004209F9 /* getcoremicrobiomecommand.cpp */; };
                7E6BE10A12F710D8007ADDBE /* refchimeratest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E6BE10912F710D8007ADDBE /* refchimeratest.cpp */; };
                8DD76FB00486AB0100D96B5E /* mothur.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6A0FF2C0290799A04C91782 /* mothur.1 */; };
+               A70056E6156A93D000924A2D /* getotulabelscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70056E5156A93D000924A2D /* getotulabelscommand.cpp */; };
+               A70056EB156AB6E500924A2D /* removeotulabelscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70056EA156AB6E500924A2D /* removeotulabelscommand.cpp */; };
                A70332B712D3A13400761E33 /* makefile in Sources */ = {isa = PBXBuildFile; fileRef = A70332B512D3A13400761E33 /* makefile */; };
                A713EBAC12DC7613000092AC /* readphylipvector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A713EBAB12DC7613000092AC /* readphylipvector.cpp */; };
                A713EBED12DC7C5E000092AC /* nmdscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A713EBEC12DC7C5E000092AC /* nmdscommand.cpp */; };
                7E6BE10912F710D8007ADDBE /* refchimeratest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = refchimeratest.cpp; sourceTree = "<group>"; };
                7E78911B135F3E8600E725D2 /* eachgapdistignorens.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = eachgapdistignorens.h; sourceTree = "<group>"; };
                8DD76FB20486AB0100D96B5E /* mothur */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mothur; sourceTree = BUILT_PRODUCTS_DIR; };
+               A70056E5156A93D000924A2D /* getotulabelscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getotulabelscommand.cpp; sourceTree = "<group>"; };
+               A70056E8156A93E300924A2D /* getotulabelscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getotulabelscommand.h; sourceTree = "<group>"; };
+               A70056E9156AB6D400924A2D /* removeotulabelscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = removeotulabelscommand.h; sourceTree = "<group>"; };
+               A70056EA156AB6E500924A2D /* removeotulabelscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = removeotulabelscommand.cpp; sourceTree = "<group>"; };
                A70332B512D3A13400761E33 /* makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = makefile; sourceTree = "<group>"; };
                A713EBAA12DC7613000092AC /* readphylipvector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readphylipvector.h; sourceTree = "<group>"; };
                A713EBAB12DC7613000092AC /* readphylipvector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readphylipvector.cpp; sourceTree = "<group>"; };
                                A7E9B6F412D37EC400DA6239 /* getgroupscommand.cpp */,
                                A7E9B6F712D37EC400DA6239 /* getlabelcommand.h */,
                                A7E9B6F612D37EC400DA6239 /* getlabelcommand.cpp */,
+                               A70056E8156A93E300924A2D /* getotulabelscommand.h */,
+                               A70056E5156A93D000924A2D /* getotulabelscommand.cpp */,
                                A7E9B6F912D37EC400DA6239 /* getlineagecommand.h */,
                                A7E9B6F812D37EC400DA6239 /* getlineagecommand.cpp */,
                                A7E9B6FB12D37EC400DA6239 /* getlistcountcommand.h */,
                                A7E9B72B12D37EC400DA6239 /* indicatorcommand.cpp */,
                                A7E9B73C12D37EC400DA6239 /* libshuffcommand.h */,
                                A7E9B73B12D37EC400DA6239 /* libshuffcommand.cpp */,
-                               A7E9B73E12D37EC400DA6239 /* listseqscommand.h */,
-                               A7E9B73D12D37EC400DA6239 /* listseqscommand.cpp */,
                                A7A0671C156294810095C8C5 /* listotulabelscommand.h */,
                                A7A067191562946F0095C8C5 /* listotulabelscommand.cpp */,
+                               A7E9B73E12D37EC400DA6239 /* listseqscommand.h */,
+                               A7E9B73D12D37EC400DA6239 /* listseqscommand.cpp */,
                                A7FA10001302E096003860FE /* mantelcommand.h */,
                                A7FA10011302E096003860FE /* mantelcommand.cpp */,
                                A724D2B4153C8600000A826F /* makebiomcommand.h */,
                                A7E9B7C512D37EC400DA6239 /* removelineagecommand.cpp */,
                                A7E9B7C812D37EC400DA6239 /* removeotuscommand.h */,
                                A7E9B7C712D37EC400DA6239 /* removeotuscommand.cpp */,
+                               A70056E9156AB6D400924A2D /* removeotulabelscommand.h */,
+                               A70056EA156AB6E500924A2D /* removeotulabelscommand.cpp */,
                                A727864212E9E28C00F86ABA /* removerarecommand.h */,
                                A727864312E9E28C00F86ABA /* removerarecommand.cpp */,
                                A7E9B7CA12D37EC400DA6239 /* removeseqscommand.h */,
                                219C1DE41559BCCF004209F9 /* getcoremicrobiomecommand.cpp in Sources */,
                                A7A0671A1562946F0095C8C5 /* listotulabelscommand.cpp in Sources */,
                                A7A0671F1562AC3E0095C8C5 /* makecontigscommand.cpp in Sources */,
+                               A70056E6156A93D000924A2D /* getotulabelscommand.cpp in Sources */,
+                               A70056EB156AB6E500924A2D /* removeotulabelscommand.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index ec22de8b35762adf92e2a3b750198dcbb91f0396..ef41ee1bab8853f6741938005f775076b60723ab 100644 (file)
@@ -544,7 +544,9 @@ int ClassifyOtuCommand::process(ListVector* processList) {
                        taxaSum = new PhyloSummary(groupfile);
                }
                
+
                //for each bin in the list vector
+        string snumBins = toString(processList->getNumBins());
                for (int i = 0; i < processList->getNumBins(); i++) {
                        
                        if (m->control_pressed) { break; }
@@ -555,7 +557,15 @@ int ClassifyOtuCommand::process(ListVector* processList) {
                        if (m->control_pressed) { out.close();  return 0; }
                        
                        //output to new names file
-                       out << (i+1) << '\t' << size << '\t' << conTax << endl;
+            string binLabel = "Otu";
+            string sbinNumber = toString(i+1);
+            if (sbinNumber.length() < snumBins.length()) { 
+                int diff = snumBins.length() - sbinNumber.length();
+                for (int h = 0; h < diff; h++) { binLabel += "0"; }
+            }
+            binLabel += sbinNumber;
+
+                       out << binLabel << '\t' << size << '\t' << conTax << endl;
                        
                        string noConfidenceConTax = conTax;
                        m->removeConfidences(noConfidenceConTax);
index 1241a04e998537fe33446a1c9ba3d933e690e557..2822d0b9920a0f5cc5005cf01ce653b38b9ede6d 100644 (file)
 #include "makebiomcommand.h"
 #include "getcoremicrobiomecommand.h"
 #include "listotulabelscommand.h"
+#include "getotulabelscommand.h"
+#include "removeotulabelscommand.h"
 #include "makecontigscommand.h"
 
 /*******************************************************/
@@ -288,6 +290,8 @@ CommandFactory::CommandFactory(){
     commands["make.biom"]           = "make.biom";
     commands["get.coremicrobiome"]  = "get.coremicrobiome";
     commands["list.otulabels"]      = "list.otulabels";
+    commands["get.otulabels"]       = "get.otulabels";
+    commands["remove.otulabels"]    = "remove.otulabels";
     commands["make.contigs"]        = "make.contigs";
        commands["quit"]                                = "MPIEnabled"; 
 
@@ -501,6 +505,8 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
         else if(commandName == "make.biom")             {      command = new MakeBiomCommand(optionString);                }
         else if(commandName == "get.coremicrobiome")    {      command = new GetCoreMicroBiomeCommand(optionString);       }
         else if(commandName == "list.otulabels")        {      command = new ListOtuLabelsCommand(optionString);           }
+        else if(commandName == "get.otulabels")         {      command = new GetOtuLabelsCommand(optionString);            }
+        else if(commandName == "remove.otulabels")      {      command = new RemoveOtuLabelsCommand(optionString);         }
         else if(commandName == "make.contigs")          {      command = new MakeContigsCommand(optionString);             }
                else                                                                                    {       command = new NoCommand(optionString);                                          }
 
@@ -655,6 +661,8 @@ Command* CommandFactory::getCommand(string commandName, string optionString, str
         else if(commandName == "make.biom")             {      pipecommand = new MakeBiomCommand(optionString);                }
         else if(commandName == "get.coremicrobiome")    {      pipecommand = new GetCoreMicroBiomeCommand(optionString);       }
         else if(commandName == "list.otulabels")        {      pipecommand = new ListOtuLabelsCommand(optionString);           }
+        else if(commandName == "get.otulabels")         {      pipecommand = new GetOtuLabelsCommand(optionString);            }
+        else if(commandName == "remove.otulabels")      {      pipecommand = new RemoveOtuLabelsCommand(optionString);         }
         else if(commandName == "make.contigs")          {      pipecommand = new MakeContigsCommand(optionString);             }
                else                                                                                    {       pipecommand = new NoCommand(optionString);                                              }
 
@@ -795,6 +803,8 @@ Command* CommandFactory::getCommand(string commandName){
         else if(commandName == "make.biom")             {      shellcommand = new MakeBiomCommand();               }
         else if(commandName == "get.coremicrobiome")    {      shellcommand = new GetCoreMicroBiomeCommand();      }
         else if(commandName == "list.otulabels")        {      shellcommand = new ListOtuLabelsCommand();          }
+        else if(commandName == "get.otulabels")         {      shellcommand = new GetOtuLabelsCommand();           }
+        else if(commandName == "remove.otulabels")      {      shellcommand = new RemoveOtuLabelsCommand();        }
         else if(commandName == "make.contigs")          {      shellcommand = new MakeContigsCommand();            }
                else                                                                                    {       shellcommand = new NoCommand();                                         }
 
diff --git a/getotulabelscommand.cpp b/getotulabelscommand.cpp
new file mode 100644 (file)
index 0000000..40ad69f
--- /dev/null
@@ -0,0 +1,381 @@
+//
+//  getotulabelscommand.cpp
+//  Mothur
+//
+//  Created by Sarah Westcott on 5/21/12.
+//  Copyright (c) 2012 Schloss Lab. All rights reserved.
+//
+
+#include "getotulabelscommand.h"
+
+//**********************************************************************************************************************
+vector<string> GetOtuLabelsCommand::setParameters(){   
+       try {
+        CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos);
+        CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pconstaxonomy);
+               CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(potucorr);
+        CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pcorraxes);
+        CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               
+               vector<string> myArray;
+               for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "setParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+string GetOtuLabelsCommand::getHelpString(){   
+       try {
+               string helpString = "";
+               helpString += "The get.otulabels command can be used to select specific otus with the output from classify.otu, otu.association, or corr.axes.\n";
+               helpString += "The get.otulabels parameters are: constaxonomy, otucorr, corraxes, and accnos.\n";
+               helpString += "The constaxonomy parameter is input the results of the classify.otu command.\n";
+        helpString += "The otucorr parameter is input the results of the otu.association command.\n";
+        helpString += "The corraxes parameter is input the results of the corr.axes command.\n";
+               helpString += "The get.otulabels commmand should be in the following format: \n";
+               helpString += "get.otulabels(accnos=yourListOfOTULabels, corraxes=yourCorrAxesFile)\n";
+               return helpString;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "getHelpString");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+GetOtuLabelsCommand::GetOtuLabelsCommand(){    
+       try {
+               abort = true; calledHelp = true;
+               setParameters();
+        vector<string> tempOutNames;
+               outputTypes["contaxonomy"] = tempOutNames; 
+        outputTypes["otu.corr"] = tempOutNames;
+        outputTypes["corr.axes"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "GetOtuLabelsCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+GetOtuLabelsCommand::GetOtuLabelsCommand(string option)  {
+       try {
+               abort = false; calledHelp = false;   
+        
+               //allow user to run help
+               if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
+               
+               else {
+                       //valid paramters for this command
+                       vector<string> myArray = setParameters();
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       map<string,string>::iterator it;
+                       //check to make sure all parameters are valid for command
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                
+                //edit file types below to include only the types you added as parameters
+                
+                               string path;
+                it = parameters.find("constaxonomy");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["constaxonomy"] = inputDir + it->second;             }
+                               }
+                
+                it = parameters.find("accnos");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["accnos"] = inputDir + it->second;           }
+                               }
+                
+                it = parameters.find("corraxes");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["corraxes"] = inputDir + it->second;         }
+                               }
+                
+                it = parameters.find("otucorr");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["otucorr"] = inputDir + it->second;          }
+                               }
+            }
+            
+            vector<string> tempOutNames;
+            outputTypes["contaxonomy"] = tempOutNames; 
+            outputTypes["otu.corr"] = tempOutNames;
+            outputTypes["corr.axes"] = tempOutNames;
+            
+                       //check for parameters
+            accnosfile = validParameter.validFile(parameters, "accnos", true);
+                       if (accnosfile == "not open") { abort = true; }
+                       else if (accnosfile == "not found") {  
+                               accnosfile = m->getAccnosFile(); 
+                               if (accnosfile != "") {  m->mothurOut("Using " + accnosfile + " as input file for the accnos parameter."); m->mothurOutEndLine(); }
+                               else { 
+                                       m->mothurOut("You have no valid accnos file and accnos is required."); m->mothurOutEndLine(); 
+                                       abort = true;
+                               } 
+                       }else { m->setAccnosFile(accnosfile); } 
+                       
+                       constaxonomyfile = validParameter.validFile(parameters, "constaxonomy", true);
+                       if (constaxonomyfile == "not open") { constaxonomyfile = ""; abort = true; }
+                       else if (constaxonomyfile == "not found") {  constaxonomyfile = "";  }
+            
+            corraxesfile = validParameter.validFile(parameters, "corraxes", true);
+                       if (corraxesfile == "not open") { corraxesfile = ""; abort = true; }
+                       else if (corraxesfile == "not found") {  corraxesfile = "";  }
+            
+            otucorrfile = validParameter.validFile(parameters, "otucorr", true);
+                       if (otucorrfile == "not open") { otucorrfile = ""; abort = true; }
+                       else if (otucorrfile == "not found") {  otucorrfile = "";  }
+
+            
+            //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){   outputDir = "";        }
+            
+            if ((constaxonomyfile == "") && (corraxesfile == "") && (otucorrfile == ""))  { m->mothurOut("You must provide one of the following: constaxonomy, corraxes or otucorr."); m->mothurOutEndLine(); abort = true; }
+               }
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "GetOtuLabelsCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+int GetOtuLabelsCommand::execute(){
+       try {
+               
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+        
+        //get labels you want to keep
+               readAccnos();
+               
+               if (m->control_pressed) { return 0; }
+               
+               //read through the correct file and output lines you want to keep
+               if (constaxonomyfile != "")     {               readClassifyOtu();      }
+               if (corraxesfile != "")         {               readCorrAxes();         }
+               if (otucorrfile != "")          {               readOtuAssociation();   }
+        
+        if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); }  return 0; }
+        
+        //output files created by command
+               m->mothurOutEndLine();
+               m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+               for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
+               m->mothurOutEndLine();
+        
+        return 0;
+    }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "execute");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+int GetOtuLabelsCommand::readClassifyOtu(){
+       try {
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(constaxonomyfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + "pick.taxonomy";
+               ofstream out;
+               m->openOutputFile(outputFileName, out);
+               
+               ifstream in;
+               m->openInputFile(constaxonomyfile, in);
+               
+               bool wroteSomething = false;
+               int selectedCount = 0;
+               
+        //read headers
+        string headers = m->getline(in);
+        out << headers << endl;
+        
+        while (!in.eof()) {
+            
+            if (m->control_pressed) { break; }
+            
+            string otu = ""; string tax = "unknown";
+            int size = 0;
+            
+            in >> otu >> size >> tax; m->gobble(in);
+            
+            if (labels.count(otu) != 0) {
+                               wroteSomething = true;
+                               selectedCount++;
+                
+                out << otu << '\t' << size << '\t' << tax << endl;
+            }
+        }
+        in.close();
+        out.close();
+               
+               if (wroteSomething == false) { m->mothurOut("Your file does not contain any labels from the .accnos file."); m->mothurOutEndLine();  }
+               outputNames.push_back(outputFileName);  outputTypes["constaxonomy"].push_back(outputFileName);
+               
+               m->mothurOut("Selected " + toString(selectedCount) + " otus from your constaxonomy file."); m->mothurOutEndLine();
+               
+               return 0;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "readClassifyOtu");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+int GetOtuLabelsCommand::readOtuAssociation(){
+       try {
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(otucorrfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + "pick.corr";
+               ofstream out;
+               m->openOutputFile(outputFileName, out);
+               
+               ifstream in;
+               m->openInputFile(otucorrfile, in);
+               
+               bool wroteSomething = false;
+               int selectedCount = 0;
+               
+        //read headers
+        string headers = m->getline(in);
+        out << headers << endl;
+        
+        while (!in.eof()) {
+            
+            if (m->control_pressed) { break; }
+            
+            string otu1 = ""; 
+            string otu2 = ""; 
+            in >> otu1 >> otu2;
+            string line = m->getline(in); m->gobble(in);
+            
+            if ((labels.count(otu1) != 0) && (labels.count(otu2) != 0)){
+                               wroteSomething = true;
+                               selectedCount++;
+                
+                out << otu1 << '\t' << otu2 << '\t' << line << endl;
+            }
+        }
+        in.close();
+        out.close();
+               
+               if (wroteSomething == false) { m->mothurOut("Your file does not contain any labels from the .accnos file."); m->mothurOutEndLine();  }
+               outputNames.push_back(outputFileName);  outputTypes["otu.corr"].push_back(outputFileName);
+               
+               m->mothurOut("Selected " + toString(selectedCount) + " lines from your otu.corr file."); m->mothurOutEndLine();
+               
+               return 0;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "readOtuAssociation");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+int GetOtuLabelsCommand::readCorrAxes(){
+       try {
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(corraxesfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + "pick.axes";
+               ofstream out;
+               m->openOutputFile(outputFileName, out);
+               
+        
+               ifstream in;
+               m->openInputFile(corraxesfile, in);
+               
+               bool wroteSomething = false;
+               int selectedCount = 0;
+               
+        //read headers
+        string headers = m->getline(in);
+        out << headers << endl;
+        
+        while (!in.eof()) {
+            
+            if (m->control_pressed) { break; }
+            
+            string otu = ""; 
+            in >> otu;
+            string line = m->getline(in); m->gobble(in);
+            
+            if (labels.count(otu) != 0) {
+                               wroteSomething = true;
+                               selectedCount++;
+                
+                out << otu << '\t' << line << endl;
+            }
+        }
+        in.close();
+        out.close();
+               
+               if (wroteSomething == false) { m->mothurOut("Your file does not contain any labels from the .accnos file."); m->mothurOutEndLine();  }
+               outputNames.push_back(outputFileName);  outputTypes["corr.axes"].push_back(outputFileName);
+               
+               m->mothurOut("Selected " + toString(selectedCount) + " lines from your corr.axes file."); m->mothurOutEndLine();
+               
+               return 0;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "readCorrAxes");
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+int GetOtuLabelsCommand::readAccnos(){
+       try {
+               
+               ifstream in;
+               m->openInputFile(accnosfile, in);
+               string name;
+               
+               while(!in.eof()){
+                       in >> name;
+            
+                       labels.insert(name);
+                       
+                       m->gobble(in);
+               }
+               in.close();     
+               
+               return 0;
+        
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "readAccnos");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
diff --git a/getotulabelscommand.h b/getotulabelscommand.h
new file mode 100644 (file)
index 0000000..bad0f55
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef Mothur_getotulabelscommand_h
+#define Mothur_getotulabelscommand_h
+
+//
+//  getotulabelscommand.h
+//  Mothur
+//
+//  Created by Sarah Westcott on 5/21/12.
+//  Copyright (c) 2012 Schloss Lab. All rights reserved.
+//
+
+
+#include "command.hpp"
+
+/**************************************************************************************************/
+
+class GetOtuLabelsCommand : public Command {
+public:
+    GetOtuLabelsCommand(string);
+    GetOtuLabelsCommand();
+    ~GetOtuLabelsCommand(){}
+    
+    vector<string> setParameters();
+    string getCommandName()                    { return "get.otulabels";          }
+    string getCommandCategory()                { return "OTU-Based Approaches";        } 
+    string getHelpString();    
+    string getCitation() { return "http://www.mothur.org/wiki/Get.otulabels"; }
+    string getDescription()            { return "Can be used with output from classify.otu, otu.association, or corr.axes to select specific otus."; }
+    
+    int execute(); 
+    void help() { m->mothurOut(getHelpString()); }     
+    
+private:
+    bool abort;
+    string outputDir, accnosfile, constaxonomyfile, otucorrfile, corraxesfile;
+    vector<string> outputNames;
+    set<string> labels;
+    
+    int readClassifyOtu();
+    int readOtuAssociation();
+    int readCorrAxes();
+    int readAccnos();
+    
+};
+
+/**************************************************************************************************/
+
+
+
+
+
+
+#endif
index becfae3ff949f0a3f8bba42604459f8e4267dc65..93b1510d22bc04cc19fec975df447381285b7788 100644 (file)
@@ -33,11 +33,11 @@ vector<string> ListOtuLabelsCommand::setParameters(){
 string ListOtuLabelsCommand::getHelpString(){  
        try {
                string helpString = "";
-               helpString += "The list.labels lists otu labels from shared or relabund file. The results can be used by the get.labels to select specific otus with the output from classify.otu, otu.association, or corr.axes.\n";
-               helpString += "The list.labels parameters are: shared, relabund, label and groups.\n";
+               helpString += "The list.otulabels lists otu labels from shared or relabund file. The results can be used by the get.otulabels to select specific otus with the output from classify.otu, otu.association, or corr.axes.\n";
+               helpString += "The list.otulabels parameters are: shared, relabund, label and groups.\n";
                helpString += "The label parameter is used to analyze specific labels in your input.\n";
                helpString += "The groups parameter allows you to specify which of the groups you would like analyzed.\n";
-               helpString += "The list.labels commmand should be in the following format: \n";
+               helpString += "The list.otulabels commmand should be in the following format: \n";
                helpString += "list.otulabels(shared=yourSharedFile, groups=yourGroup1-yourGroup2)\n";
                return helpString;
        }
index ea41539adb021cdc56fd6175f7845f2ae70363e4..dbfd5d4f06cfc2c8453cfcc7cc2c556e17c882ee 100644 (file)
@@ -27,7 +27,7 @@ public:
     //commmand category choices: Sequence Processing, OTU-Based Approaches, Hypothesis Testing, Phylotype Analysis, General, Clustering and Hidden
     string getHelpString();    
     string getCitation() { return "http://www.mothur.org/wiki/List.otulabels"; }
-    string getDescription()            { return "lists otu labels from shared or relabund file. Can be used with output from classify.otu, otu.association, or corr.axes to select specific otus."; }
+    string getDescription()            { return "lists otu labels from shared or relabund file. Can be used by get.otulabels with output from classify.otu, otu.association, or corr.axes to select specific otus."; }
     
     int execute(); 
     void help() { m->mothurOut(getHelpString()); }     
diff --git a/removeotulabelscommand.cpp b/removeotulabelscommand.cpp
new file mode 100644 (file)
index 0000000..77305fb
--- /dev/null
@@ -0,0 +1,380 @@
+//
+//  removeotulabels.cpp
+//  Mothur
+//
+//  Created by Sarah Westcott on 5/21/12.
+//  Copyright (c) 2012 Schloss Lab. All rights reserved.
+//
+
+#include "removeotulabelscommand.h"
+
+//**********************************************************************************************************************
+vector<string> RemoveOtuLabelsCommand::setParameters(){        
+       try {
+        CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos);
+        CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pconstaxonomy);
+               CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(potucorr);
+        CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pcorraxes);
+        CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               
+               vector<string> myArray;
+               for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveOtuLabelsCommand", "setParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+string RemoveOtuLabelsCommand::getHelpString(){        
+       try {
+               string helpString = "";
+               helpString += "The remove.otulabels command can be used to remove specific otus with the output from classify.otu, otu.association, or corr.axes.\n";
+               helpString += "The remove.otulabels parameters are: constaxonomy, otucorr, corraxes, and accnos.\n";
+               helpString += "The constaxonomy parameter is input the results of the classify.otu command.\n";
+        helpString += "The otucorr parameter is input the results of the otu.association command.\n";
+        helpString += "The corraxes parameter is input the results of the corr.axes command.\n";
+               helpString += "The remove.otulabels commmand should be in the following format: \n";
+               helpString += "remove.otulabels(accnos=yourListOfOTULabels, corraxes=yourCorrAxesFile)\n";
+               return helpString;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveOtuLabelsCommand", "getHelpString");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(){      
+       try {
+               abort = true; calledHelp = true;
+               setParameters();
+        vector<string> tempOutNames;
+               outputTypes["contaxonomy"] = tempOutNames; 
+        outputTypes["otu.corr"] = tempOutNames;
+        outputTypes["corr.axes"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveOtuLabelsCommand", "RemoveOtuLabelsCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(string option)  {
+       try {
+               abort = false; calledHelp = false;   
+        
+               //allow user to run help
+               if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
+               
+               else {
+                       //valid paramters for this command
+                       vector<string> myArray = setParameters();
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       map<string,string>::iterator it;
+                       //check to make sure all parameters are valid for command
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                
+                //edit file types below to include only the types you added as parameters
+                
+                               string path;
+                it = parameters.find("constaxonomy");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["constaxonomy"] = inputDir + it->second;             }
+                               }
+                
+                it = parameters.find("accnos");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["accnos"] = inputDir + it->second;           }
+                               }
+                
+                it = parameters.find("corraxes");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["corraxes"] = inputDir + it->second;         }
+                               }
+                
+                it = parameters.find("otucorr");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["otucorr"] = inputDir + it->second;          }
+                               }
+            }
+            
+            vector<string> tempOutNames;
+            outputTypes["contaxonomy"] = tempOutNames; 
+            outputTypes["otu.corr"] = tempOutNames;
+            outputTypes["corr.axes"] = tempOutNames;
+            
+                       //check for parameters
+            accnosfile = validParameter.validFile(parameters, "accnos", true);
+                       if (accnosfile == "not open") { abort = true; }
+                       else if (accnosfile == "not found") {  
+                               accnosfile = m->getAccnosFile(); 
+                               if (accnosfile != "") {  m->mothurOut("Using " + accnosfile + " as input file for the accnos parameter."); m->mothurOutEndLine(); }
+                               else { 
+                                       m->mothurOut("You have no valid accnos file and accnos is required."); m->mothurOutEndLine(); 
+                                       abort = true;
+                               } 
+                       }else { m->setAccnosFile(accnosfile); } 
+                       
+                       constaxonomyfile = validParameter.validFile(parameters, "constaxonomy", true);
+                       if (constaxonomyfile == "not open") { constaxonomyfile = ""; abort = true; }
+                       else if (constaxonomyfile == "not found") {  constaxonomyfile = "";  }
+            
+            corraxesfile = validParameter.validFile(parameters, "corraxes", true);
+                       if (corraxesfile == "not open") { corraxesfile = ""; abort = true; }
+                       else if (corraxesfile == "not found") {  corraxesfile = "";  }
+            
+            otucorrfile = validParameter.validFile(parameters, "otucorr", true);
+                       if (otucorrfile == "not open") { otucorrfile = ""; abort = true; }
+                       else if (otucorrfile == "not found") {  otucorrfile = "";  }
+            
+            
+            //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){   outputDir = "";        }
+            
+            if ((constaxonomyfile == "") && (corraxesfile == "") && (otucorrfile == ""))  { m->mothurOut("You must provide one of the following: constaxonomy, corraxes or otucorr."); m->mothurOutEndLine(); abort = true; }
+               }
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveOtuLabelsCommand", "RemoveOtuLabelsCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+int RemoveOtuLabelsCommand::execute(){
+       try {
+               
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+        
+        //get labels you want to keep
+               readAccnos();
+               
+               if (m->control_pressed) { return 0; }
+               
+               //read through the correct file and output lines you want to keep
+               if (constaxonomyfile != "")     {               readClassifyOtu();      }
+               if (corraxesfile != "")         {               readCorrAxes();         }
+               if (otucorrfile != "")          {               readOtuAssociation();   }
+        
+        if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); }  return 0; }
+        
+        //output files created by command
+               m->mothurOutEndLine();
+               m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+               for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
+               m->mothurOutEndLine();
+        
+        return 0;
+    }
+       catch(exception& e) {
+               m->errorOut(e, "GetOtuLabelsCommand", "execute");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+int RemoveOtuLabelsCommand::readClassifyOtu(){
+       try {
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(constaxonomyfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + "pick.taxonomy";
+               ofstream out;
+               m->openOutputFile(outputFileName, out);
+               
+               ifstream in;
+               m->openInputFile(constaxonomyfile, in);
+               
+               bool wroteSomething = false;
+               int removedCount = 0;
+               
+        //read headers
+        string headers = m->getline(in);
+        out << headers << endl;
+        
+        while (!in.eof()) {
+            
+            if (m->control_pressed) { break; }
+            
+            string otu = ""; string tax = "unknown";
+            int size = 0;
+            
+            in >> otu >> size >> tax; m->gobble(in);
+            
+            if (labels.count(otu) == 0) {
+                               wroteSomething = true;
+                out << otu << '\t' << size << '\t' << tax << endl;
+            }else {  removedCount++;  }
+        }
+        in.close();
+        out.close();
+               
+               if (wroteSomething == false) { m->mothurOut("Your file only contains labels from the .accnos file."); m->mothurOutEndLine();  }
+               outputNames.push_back(outputFileName);  outputTypes["constaxonomy"].push_back(outputFileName);
+               
+               m->mothurOut("Removed " + toString(removedCount) + " otus from your constaxonomy file."); m->mothurOutEndLine();
+               
+               return 0;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveOtuLabelsCommand", "readClassifyOtu");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+int RemoveOtuLabelsCommand::readOtuAssociation(){
+       try {
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(otucorrfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + "pick.corr";
+               ofstream out;
+               m->openOutputFile(outputFileName, out);
+               
+               ifstream in;
+               m->openInputFile(otucorrfile, in);
+               
+               bool wroteSomething = false;
+               int removedCount = 0;
+               
+        //read headers
+        string headers = m->getline(in);
+        out << headers << endl;
+        
+        while (!in.eof()) {
+            
+            if (m->control_pressed) { break; }
+            
+            string otu1 = ""; 
+            string otu2 = ""; 
+            in >> otu1 >> otu2;
+            string line = m->getline(in); m->gobble(in);
+            
+            if ((labels.count(otu1) == 0) && (labels.count(otu2) == 0)){
+                               wroteSomething = true;
+                
+                out << otu1 << '\t' << otu2 << '\t' << line << endl;
+            }else { removedCount++; }
+        }
+        in.close();
+        out.close();
+               
+               if (wroteSomething == false) { m->mothurOut("Your file only contains labels from the .accnos file."); m->mothurOutEndLine();  }
+               outputNames.push_back(outputFileName);  outputTypes["otu.corr"].push_back(outputFileName);
+               
+               m->mothurOut("Removed " + toString(removedCount) + " lines from your otu.corr file."); m->mothurOutEndLine();
+               
+               return 0;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveOtuLabelsCommand", "readOtuAssociation");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+int RemoveOtuLabelsCommand::readCorrAxes(){
+       try {
+               string thisOutputDir = outputDir;
+               if (outputDir == "") {  thisOutputDir += m->hasPath(corraxesfile);  }
+               string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + "pick.axes";
+               ofstream out;
+               m->openOutputFile(outputFileName, out);
+               
+        
+               ifstream in;
+               m->openInputFile(corraxesfile, in);
+               
+               bool wroteSomething = false;
+               int removedCount = 0;
+               
+        //read headers
+        string headers = m->getline(in);
+        out << headers << endl;
+        
+        while (!in.eof()) {
+            
+            if (m->control_pressed) { break; }
+            
+            string otu = ""; 
+            in >> otu;
+            string line = m->getline(in); m->gobble(in);
+            
+            if (labels.count(otu) == 0) {
+                               wroteSomething = true;
+                
+                out << otu << '\t' << line << endl;
+            }else { removedCount++; }
+        }
+        in.close();
+        out.close();
+               
+               if (wroteSomething == false) { m->mothurOut("Your file only contains labels from the .accnos file."); m->mothurOutEndLine();  }
+               outputNames.push_back(outputFileName);  outputTypes["corr.axes"].push_back(outputFileName);
+               
+               m->mothurOut("Removed " + toString(removedCount) + " lines from your corr.axes file."); m->mothurOutEndLine();
+               
+               return 0;
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveOtuLabelsCommand", "readCorrAxes");
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+int RemoveOtuLabelsCommand::readAccnos(){
+       try {
+               
+               ifstream in;
+               m->openInputFile(accnosfile, in);
+               string name;
+               
+               while(!in.eof()){
+                       in >> name;
+            
+                       labels.insert(name);
+                       
+                       m->gobble(in);
+               }
+               in.close();     
+               
+               return 0;
+        
+       }
+       catch(exception& e) {
+               m->errorOut(e, "RemoveOtuLabelsCommand", "readAccnos");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+
+
diff --git a/removeotulabelscommand.h b/removeotulabelscommand.h
new file mode 100644 (file)
index 0000000..da2441d
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef Mothur_removeotulabelscommand_h
+#define Mothur_removeotulabelscommand_h
+
+
+//
+//  removeotulabelscommand.h
+//  Mothur
+//
+//  Created by Sarah Westcott on 5/21/12.
+//  Copyright (c) 2012 Schloss Lab. All rights reserved.
+//
+
+#include "command.hpp"
+
+/**************************************************************************************************/
+
+class RemoveOtuLabelsCommand : public Command {
+public:
+    RemoveOtuLabelsCommand(string);
+    RemoveOtuLabelsCommand();
+    ~RemoveOtuLabelsCommand(){}
+    
+    vector<string> setParameters();
+    string getCommandName()                    { return "remove.otulabels";          }
+    string getCommandCategory()                { return "OTU-Based Approaches";        } 
+    string getHelpString();    
+    string getCitation() { return "http://www.mothur.org/wiki/Get.otulabels"; }
+    string getDescription()            { return "Can be used with output from classify.otu, otu.association, or corr.axes to remove specific otus."; }
+    
+    int execute(); 
+    void help() { m->mothurOut(getHelpString()); }     
+    
+private:
+    bool abort;
+    string outputDir, accnosfile, constaxonomyfile, otucorrfile, corraxesfile;
+    vector<string> outputNames;
+    set<string> labels;
+    
+    int readClassifyOtu();
+    int readOtuAssociation();
+    int readCorrAxes();
+    int readAccnos();
+    
+};
+
+/**************************************************************************************************/
+
+
+
+
+
+
+
+
+#endif