X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getotulabelscommand.cpp;h=0f042c0bcb9a4de9d8cebd4f1bd017d1c65c37fb;hb=deba0af0ccdcb6005ed5b2b82649b137c63fbdf7;hp=40ad69f771c0b7b58602666c22d0c4587486ebdf;hpb=e0b6040c7b6ad4ecdad4aa90b4326c0528379178;p=mothur.git diff --git a/getotulabelscommand.cpp b/getotulabelscommand.cpp index 40ad69f..0f042c0 100644 --- a/getotulabelscommand.cpp +++ b/getotulabelscommand.cpp @@ -11,12 +11,12 @@ //********************************************************************************************************************** vector 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); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,true, true); parameters.push_back(paccnos); + CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none","constaxonomy",false,false, true); parameters.push_back(pconstaxonomy); + CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none","otucorr",false,false, true); parameters.push_back(potucorr); + CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none","corraxes",false,false, true); 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 myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -33,9 +33,9 @@ string GetOtuLabelsCommand::getHelpString(){ 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 constaxonomy parameter is used to input the results of the classify.otu command.\n"; + helpString += "The otucorr parameter is used to input the results of the otu.association command.\n"; + helpString += "The corraxes parameter is used to 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; @@ -45,15 +45,33 @@ string GetOtuLabelsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string GetOtuLabelsCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "constaxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "otucorr") { pattern = "[filename],pick,[extension]"; } + else if (type == "corraxes") { pattern = "[filename],pick,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetOtuLabelsCommand", "getOutputPattern"); + exit(1); + } +} + //********************************************************************************************************************** GetOtuLabelsCommand::GetOtuLabelsCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; - outputTypes["contaxonomy"] = tempOutNames; - outputTypes["otu.corr"] = tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["constaxonomy"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "GetOtuLabelsCommand", "GetOtuLabelsCommand"); @@ -126,9 +144,9 @@ GetOtuLabelsCommand::GetOtuLabelsCommand(string option) { } vector tempOutNames; - outputTypes["contaxonomy"] = tempOutNames; - outputTypes["otu.corr"] = tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["constaxonomy"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; //check for parameters accnosfile = validParameter.validFile(parameters, "accnos", true); @@ -175,7 +193,7 @@ int GetOtuLabelsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //get labels you want to keep - readAccnos(); + labels = m->readAccnos(accnosfile); if (m->control_pressed) { return 0; } @@ -204,7 +222,11 @@ int GetOtuLabelsCommand::readClassifyOtu(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(constaxonomyfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + "pick.taxonomy"; + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)); + variables["[extension]"] = m->getExtension(constaxonomyfile); + string outputFileName = getOutputFileName("constaxonomy", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -255,7 +277,11 @@ int GetOtuLabelsCommand::readOtuAssociation(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(otucorrfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + "pick.corr"; + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)); + variables["[extension]"] = m->getExtension(otucorrfile); + string outputFileName = getOutputFileName("otucorr", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -289,7 +315,7 @@ int GetOtuLabelsCommand::readOtuAssociation(){ 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); + outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); m->mothurOut("Selected " + toString(selectedCount) + " lines from your otu.corr file."); m->mothurOutEndLine(); @@ -306,7 +332,11 @@ int GetOtuLabelsCommand::readCorrAxes(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(corraxesfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + "pick.axes"; + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)); + variables["[extension]"] = m->getExtension(corraxesfile); + string outputFileName = getOutputFileName("corraxes", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -340,7 +370,7 @@ int GetOtuLabelsCommand::readCorrAxes(){ 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); + outputNames.push_back(outputFileName); outputTypes["corraxes"].push_back(outputFileName); m->mothurOut("Selected " + toString(selectedCount) + " lines from your corr.axes file."); m->mothurOutEndLine(); @@ -352,30 +382,4 @@ int 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); - } -} //**********************************************************************************************************************