X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=removeotulabelscommand.cpp;fp=removeotulabelscommand.cpp;h=01d8529dded5e9c7e17bd02724158156566dece7;hb=49d2b7459c5027557564b21e9487dadafbbbdc96;hp=77305fb49babaa2640d6a69db0a25e0816ac6785;hpb=ee8403d4eb5760187d62b42a9cf4272de8fc0ec4;p=mothur.git diff --git a/removeotulabelscommand.cpp b/removeotulabelscommand.cpp index 77305fb..01d8529 100644 --- a/removeotulabelscommand.cpp +++ b/removeotulabelscommand.cpp @@ -46,14 +46,36 @@ string RemoveOtuLabelsCommand::getHelpString(){ } } //********************************************************************************************************************** +string RemoveOtuLabelsCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "constaxonomy") { outputFileName = "pick.taxonomy"; } + else if (type == "otucorr") { outputFileName = "pick.corr"; } + else if (type == "corraxes") { outputFileName = "pick.axes"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "RemoveOtuLabelsCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; outputTypes["contaxonomy"] = tempOutNames; - outputTypes["otu.corr"] = tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "RemoveOtuLabelsCommand", "RemoveOtuLabelsCommand"); @@ -127,8 +149,8 @@ RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(string option) { vector tempOutNames; outputTypes["contaxonomy"] = tempOutNames; - outputTypes["otu.corr"] = tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; //check for parameters accnosfile = validParameter.validFile(parameters, "accnos", true); @@ -175,7 +197,7 @@ int RemoveOtuLabelsCommand::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 +226,7 @@ int RemoveOtuLabelsCommand::readClassifyOtu(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(constaxonomyfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + "pick.taxonomy"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + getOutputFileNameTag("constaxonomy"); ofstream out; m->openOutputFile(outputFileName, out); @@ -253,7 +275,7 @@ int RemoveOtuLabelsCommand::readOtuAssociation(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(otucorrfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + "pick.corr"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + getOutputFileNameTag("otucorr"); ofstream out; m->openOutputFile(outputFileName, out); @@ -286,7 +308,7 @@ int RemoveOtuLabelsCommand::readOtuAssociation(){ 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); + outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); m->mothurOut("Removed " + toString(removedCount) + " lines from your otu.corr file."); m->mothurOutEndLine(); @@ -303,7 +325,7 @@ int RemoveOtuLabelsCommand::readCorrAxes(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(corraxesfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + "pick.axes"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + getOutputFileNameTag("corraxes"); ofstream out; m->openOutputFile(outputFileName, out); @@ -336,7 +358,7 @@ int RemoveOtuLabelsCommand::readCorrAxes(){ 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); + outputNames.push_back(outputFileName); outputTypes["corraxes"].push_back(outputFileName); m->mothurOut("Removed " + toString(removedCount) + " lines from your corr.axes file."); m->mothurOutEndLine(); @@ -348,32 +370,6 @@ int 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); - } -} //**********************************************************************************************************************