X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=chopseqscommand.cpp;h=05037f6817a5a554a029a7d635460d048bf73203;hb=529ec122f7cac4af987e121d150b878d7c7a0d5d;hp=fc4327f210d04241b5c1e7a6056759525998c738;hpb=220dc345e493cddc569521111ce32ac4d965ab7f;p=mothur.git diff --git a/chopseqscommand.cpp b/chopseqscommand.cpp index fc4327f..05037f6 100644 --- a/chopseqscommand.cpp +++ b/chopseqscommand.cpp @@ -51,7 +51,27 @@ string ChopSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ChopSeqsCommand::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 = "chop.fasta"; } + else if (type == "accnos") { outputFileName = "chop.accnos"; } + 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, "ChopSeqsCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** ChopSeqsCommand::ChopSeqsCommand(){ try { @@ -121,7 +141,7 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(fastafile); } string temp = validParameter.validFile(parameters, "numbases", false); if (temp == "not found") { temp = "0"; } - convert(temp, numbases); + m->mothurConvert(temp, numbases); temp = validParameter.validFile(parameters, "countgaps", false); if (temp == "not found") { temp = "f"; } countGaps = m->isTrue(temp); @@ -147,8 +167,8 @@ int ChopSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.fasta"; - string outputFileNameAccnos = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta"); + string outputFileNameAccnos = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("accnos"); ofstream out; m->openOutputFile(outputFileName, out); @@ -165,7 +185,7 @@ int ChopSeqsCommand::execute(){ Sequence seq(in); - if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); outAcc.close(); remove(outputFileName.c_str()); remove(outputFileNameAccnos.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); outAcc.close(); m->mothurRemove(outputFileName); m->mothurRemove(outputFileNameAccnos); return 0; } if (seq.getName() != "") { string newSeqString = getChopped(seq); @@ -188,7 +208,7 @@ int ChopSeqsCommand::execute(){ m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); if (wroteAccnos) { m->mothurOut(outputFileNameAccnos); m->mothurOutEndLine(); outputNames.push_back(outputFileNameAccnos); outputTypes["accnos"].push_back(outputFileNameAccnos); } - else { remove(outputFileNameAccnos.c_str()); } + else { m->mothurRemove(outputFileNameAccnos); } m->mothurOutEndLine(); @@ -233,7 +253,7 @@ string ChopSeqsCommand::getChopped(Sequence seq) { for (int i = 0; i < temp.length(); i++) { //eliminate N's - if (toupper(temp[i]) == 'N') { temp[i] == '.'; } + if (toupper(temp[i]) == 'N') { temp[i] = '.'; } numBasesCounted++; @@ -241,7 +261,7 @@ string ChopSeqsCommand::getChopped(Sequence seq) { } if (stopSpot == 0) { temp = ""; } - else { temp = temp.substr(0, stopSpot); } + else { temp = temp.substr(0, stopSpot+1); } }else { if (!Short) { temp = ""; } //sequence too short @@ -255,7 +275,7 @@ string ChopSeqsCommand::getChopped(Sequence seq) { for (int i = (temp.length()-1); i >= 0; i--) { //eliminate N's - if (toupper(temp[i]) == 'N') { temp[i] == '.'; } + if (toupper(temp[i]) == 'N') { temp[i] = '.'; } numBasesCounted++; @@ -283,7 +303,7 @@ string ChopSeqsCommand::getChopped(Sequence seq) { for (int i = 0; i < temp.length(); i++) { //eliminate N's if (toupper(temp[i]) == 'N') { - temp[i] == '.'; + temp[i] = '.'; tempLength--; if (tempLength < numbases) { stopSpot = 0; break; } } @@ -294,7 +314,7 @@ string ChopSeqsCommand::getChopped(Sequence seq) { } if (stopSpot == 0) { temp = ""; } - else { temp = temp.substr(0, stopSpot); } + else { temp = temp.substr(0, stopSpot+1); } }else { if (!Short) { temp = ""; } //sequence too short @@ -309,7 +329,7 @@ string ChopSeqsCommand::getChopped(Sequence seq) { for (int i = (temp.length()-1); i >= 0; i--) { //eliminate N's if (toupper(temp[i]) == 'N') { - temp[i] == '.'; + temp[i] = '.'; tempLength--; if (tempLength < numbases) { stopSpot = 0; break; } } @@ -320,7 +340,7 @@ string ChopSeqsCommand::getChopped(Sequence seq) { } if (stopSpot == 0) { temp = ""; } - else { temp = temp.substr(stopSpot+1); } + else { temp = temp.substr(stopSpot); } }else { if (!Short) { temp = ""; } //sequence too short }