X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=reversecommand.cpp;h=cde88b71203ac3c5fe364c2d7a7bd112bc8da8f8;hb=49d2b7459c5027557564b21e9487dadafbbbdc96;hp=17924c9669b6b5338d15824b2920410fcf305af4;hpb=e150b0b0664caec517485ee6d69dcdade6dcae77;p=mothur.git diff --git a/reversecommand.cpp b/reversecommand.cpp index 17924c9..cde88b7 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -43,7 +43,27 @@ string ReverseSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ReverseSeqsCommand::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 = "rc" + m->getExtension(inputName); } + else if (type == "qfile") { outputFileName = "rc" + m->getExtension(inputName); } + 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, "ReverseSeqsCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** ReverseSeqsCommand::ReverseSeqsCommand(){ try { @@ -113,11 +133,13 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { fastaFileName = validParameter.validFile(parameters, "fasta", true); if (fastaFileName == "not open") { abort = true; } else if (fastaFileName == "not found") { fastaFileName = "";}// m->mothurOut("fasta is a required parameter for the reverse.seqs command."); m->mothurOutEndLine(); abort = true; } + else { m->setFastaFile(fastaFileName); } qualFileName = validParameter.validFile(parameters, "qfile", true); if (qualFileName == "not open") { abort = true; } else if (qualFileName == "not found") { qualFileName = ""; }//m->mothurOut("fasta is a required parameter for the reverse.seqs command."); m->mothurOutEndLine(); abort = true; } - + else { m->setQualFile(qualFileName); } + if((fastaFileName == "") && (qualFileName == "")){ fastaFileName = m->getFastaFile(); if (fastaFileName != "") { m->mothurOut("Using " + fastaFileName + " as input file for the fasta parameter."); m->mothurOutEndLine(); } @@ -160,11 +182,11 @@ int ReverseSeqsCommand::execute(){ ofstream outFASTA; string tempOutputDir = outputDir; if (outputDir == "") { tempOutputDir += m->hasPath(fastaFileName); } //if user entered a file with a path then preserve it - fastaReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileName)) + "rc" + m->getExtension(fastaFileName); + fastaReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileName)) + getOutputFileNameTag("fasta", fastaFileName); m->openOutputFile(fastaReverseFileName, outFASTA); while(!inFASTA.eof()){ - if (m->control_pressed) { inFASTA.close(); outFASTA.close(); remove(fastaReverseFileName.c_str()); return 0; } + if (m->control_pressed) { inFASTA.close(); outFASTA.close(); m->mothurRemove(fastaReverseFileName); return 0; } Sequence currSeq(inFASTA); m->gobble(inFASTA); if (currSeq.getName() != "") { @@ -188,11 +210,11 @@ int ReverseSeqsCommand::execute(){ ofstream outQual; string tempOutputDir = outputDir; if (outputDir == "") { tempOutputDir += m->hasPath(qualFileName); } //if user entered a file with a path then preserve it - string qualReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(qualFileName)) + "rc" + m->getExtension(qualFileName); - m->openOutputFile(qualReverseFileName, outQual); + string qualReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(qualFileName)) + getOutputFileNameTag("qfile", qualFileName); + m->openOutputFile(qualReverseFileName, outQual); while(!inQual.eof()){ - if (m->control_pressed) { inQual.close(); outQual.close(); remove(qualReverseFileName.c_str()); return 0; } + if (m->control_pressed) { inQual.close(); outQual.close(); m->mothurRemove(qualReverseFileName); return 0; } currQual = QualityScores(inQual); m->gobble(inQual); currQual.flipQScores(); currQual.printQScores(outQual); @@ -202,7 +224,7 @@ int ReverseSeqsCommand::execute(){ outputNames.push_back(qualReverseFileName); outputTypes["qfile"].push_back(qualReverseFileName); } - if (m->control_pressed) { remove(qualReverseFileName.c_str()); remove(fastaReverseFileName.c_str()); return 0; } + if (m->control_pressed) { m->mothurRemove(qualReverseFileName); m->mothurRemove(fastaReverseFileName); return 0; } //set fasta file as new current fastafile string current = "";