X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=filterseqscommand.cpp;h=7a8fbc8cdfe6236601dbc0b369f6ef415a5c7c48;hb=6ede3bf5c0a9eedb23f24577a97da81ab3e1f7df;hp=93e18e82f374c9fa5bad6a90f6fc2ff56e20246a;hpb=43ed0accfbc2852849e104ff7eccdd2c42acd4ec;p=mothur.git diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index 93e18e8..7a8fbc8 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -57,6 +57,27 @@ string FilterSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** +string FilterSeqsCommand::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 == "fasta") { outputFileName = "filter.fasta"; } + else if (type == "filter") { outputFileName = "filter"; } + 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, "FilterSeqsCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** FilterSeqsCommand::FilterSeqsCommand(){ try { abort = true; calledHelp = true; @@ -125,7 +146,12 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { fasta = validParameter.validFile(parameters, "fasta", false); if (fasta == "not found") { fasta = m->getFastaFile(); - if (fasta != "") { fastafileNames.push_back(fasta); m->mothurOut("Using " + fasta + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + if (fasta != "") { + fastafileNames.push_back(fasta); + m->mothurOut("Using " + fasta + " as input file for the fasta parameter."); m->mothurOutEndLine(); + string simpleName = m->getSimpleName(fasta); + filterFileName += simpleName.substr(0, simpleName.find_first_of('.')); + } else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } } else { @@ -273,8 +299,8 @@ int FilterSeqsCommand::execute() { //prevent giantic file name string filterFile; - if (fastafileNames.size() > 3) { filterFile = outputDir + "merge.filter"; } - else { filterFile = outputDir + filterFileName + ".filter"; } + if (fastafileNames.size() > 3) { filterFile = outputDir + "merge." + getOutputFileNameTag("filter"); } + else { filterFile = outputDir + filterFileName + "." + getOutputFileNameTag("filter"); } m->openOutputFile(filterFile, outFilter); outFilter << filter << endl; @@ -337,7 +363,7 @@ int FilterSeqsCommand::filterSequences() { for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); - string filteredFasta = outputDir + m->getRootName(m->getSimpleName(fastafileNames[s])) + "filter.fasta"; + string filteredFasta = outputDir + m->getRootName(m->getSimpleName(fastafileNames[s])) + getOutputFileNameTag("fasta"); #ifdef USE_MPI int pid, numSeqsPerProcessor, num; int tag = 2001;