X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=chopseqscommand.cpp;h=1ebb1f4b631f21d02596aa3e1e528d27cb3587df;hb=7c08fa69c0b89e7a08341af2aa724f206f182075;hp=b2810741ae7b2b6591a7f0aa8e3b52b143dcfe3d;hpb=15bc21bb4281af0f3ea7b29d9b9363f4635ef939;p=mothur.git diff --git a/chopseqscommand.cpp b/chopseqscommand.cpp index b281074..1ebb1f4 100644 --- a/chopseqscommand.cpp +++ b/chopseqscommand.cpp @@ -11,17 +11,64 @@ #include "sequence.hpp" //********************************************************************************************************************** - +vector ChopSeqsCommand::getValidParameters(){ + try { + string AlignArray[] = {"fasta","short","numbases","countgaps","keep","outputdir","inputdir"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +ChopSeqsCommand::ChopSeqsCommand(){ + try { + abort = true; calledHelp = true; + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChopSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","numbases"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ChopSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** ChopSeqsCommand::ChopSeqsCommand(string option) { try { - abort = false; + abort = false; calledHelp = false; //allow user to run help - if(option == "help") { help(); abort = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } else { //valid paramters for this command - string Array[] = {"fasta","numbases","countgaps","keep","outputdir","inputdir"}; + string Array[] = {"fasta","numbases","countgaps","keep","short","outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -35,6 +82,11 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -61,7 +113,10 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { convert(temp, numbases); temp = validParameter.validFile(parameters, "countgaps", false); if (temp == "not found") { temp = "f"; } - countGaps = m->isTrue(temp); + countGaps = m->isTrue(temp); + + temp = validParameter.validFile(parameters, "short", false); if (temp == "not found") { temp = "f"; } + Short = m->isTrue(temp); keep = validParameter.validFile(parameters, "keep", false); if (keep == "not found") { keep = "front"; } @@ -84,6 +139,8 @@ void ChopSeqsCommand::help(){ m->mothurOut("The numbases parameter allows you to specify the number of bases you want to keep.\n"); m->mothurOut("The keep parameter allows you to specify whether you want to keep the front or the back of your sequence, default=front.\n"); m->mothurOut("The countgaps parameter allows you to specify whether you want to count gaps as bases, default=false.\n"); + m->mothurOut("The short parameter allows you to specify you want to keep sequences that are too short to chop, default=false.\n"); + m->mothurOut("For example, if you ran chop.seqs with numbases=200 and short=t, if a sequence had 100 bases mothur would keep the sequence rather than eliminate it.\n"); m->mothurOut("Example chop.seqs(fasta=amazon.fasta, numbases=200, keep=front).\n"); m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); } @@ -98,7 +155,7 @@ void ChopSeqsCommand::help(){ int ChopSeqsCommand::execute(){ try { - if (abort == true) { return 0; } + 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"; @@ -118,7 +175,7 @@ int ChopSeqsCommand::execute(){ Sequence seq(in); - if (m->control_pressed) { 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(); remove(outputFileName.c_str()); remove(outputFileNameAccnos.c_str()); return 0; } if (seq.getName() != "") { string newSeqString = getChopped(seq); @@ -138,9 +195,9 @@ int ChopSeqsCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); - if (wroteAccnos) { m->mothurOut(outputFileNameAccnos); m->mothurOutEndLine(); } + if (wroteAccnos) { m->mothurOut(outputFileNameAccnos); m->mothurOutEndLine(); outputNames.push_back(outputFileNameAccnos); outputTypes["accnos"].push_back(outputFileNameAccnos); } else { remove(outputFileNameAccnos.c_str()); } m->mothurOutEndLine(); @@ -181,8 +238,9 @@ string ChopSeqsCommand::getChopped(Sequence seq) { if (stopSpot == 0) { temp = ""; } else { temp = temp.substr(0, stopSpot); } - }else { temp = ""; } //sequence too short - + }else { + if (!Short) { temp = ""; } //sequence too short + } }else { //you are keeping the back int tempLength = temp.length(); if (tempLength > numbases) { //you have enough bases to remove some @@ -201,8 +259,9 @@ string ChopSeqsCommand::getChopped(Sequence seq) { if (stopSpot == 0) { temp = ""; } else { temp = temp.substr(stopSpot+1); } + }else { + if (!Short) { temp = ""; } //sequence too short } - else { temp = ""; } //sequence too short } }else{ @@ -232,8 +291,9 @@ string ChopSeqsCommand::getChopped(Sequence seq) { if (stopSpot == 0) { temp = ""; } else { temp = temp.substr(0, stopSpot); } - }else { temp = ""; } //sequence too short - + }else { + if (!Short) { temp = ""; } //sequence too short + } }else { //you are keeping the back int tempLength = tempUnaligned.length(); if (tempLength > numbases) { //you have enough bases to remove some @@ -256,8 +316,9 @@ string ChopSeqsCommand::getChopped(Sequence seq) { if (stopSpot == 0) { temp = ""; } else { temp = temp.substr(stopSpot+1); } + }else { + if (!Short) { temp = ""; } //sequence too short } - else { temp = ""; } //sequence too short } }