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;
};
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; }
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);
#include "makebiomcommand.h"
#include "getcoremicrobiomecommand.h"
#include "listotulabelscommand.h"
+#include "getotulabelscommand.h"
+#include "removeotulabelscommand.h"
#include "makecontigscommand.h"
/*******************************************************/
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";
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); }
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); }
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(); }
--- /dev/null
+//
+// 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);
+ }
+}
+//**********************************************************************************************************************
--- /dev/null
+#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
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;
}
//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()); }
--- /dev/null
+//
+// 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);
+ }
+}
+//**********************************************************************************************************************
+
+
+
--- /dev/null
+#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