X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=deuniqueseqscommand.cpp;h=f72a7c9c7e1264265d4d28e1072e087cf501c288;hp=24438824a0ba70225f9ae435065d4c55fa631084;hb=615301e57c25e241356a9c2380648d117709458d;hpb=1d898dc6edaf9e9f287fab53bf1f21fb29757a17 diff --git a/deuniqueseqscommand.cpp b/deuniqueseqscommand.cpp index 2443882..f72a7c9 100644 --- a/deuniqueseqscommand.cpp +++ b/deuniqueseqscommand.cpp @@ -13,10 +13,10 @@ //********************************************************************************************************************** vector DeUniqueSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pname); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pname); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -45,6 +45,21 @@ string DeUniqueSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** +string DeUniqueSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "fasta") { pattern = "[filename],redundant.fasta"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "DeUniqueSeqsCommand", "getOutputPattern"); + exit(1); + } +} +//********************************************************************************************************************** DeUniqueSeqsCommand::DeUniqueSeqsCommand(){ try { abort = true; calledHelp = true; @@ -64,6 +79,7 @@ DeUniqueSeqsCommand::DeUniqueSeqsCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { vector myArray = setParameters(); @@ -113,7 +129,7 @@ DeUniqueSeqsCommand::DeUniqueSeqsCommand(string option) { fastaFile = m->getFastaFile(); if (fastaFile != "") { m->mothurOut("Using " + fastaFile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setFastaFile(fastaFile); } //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ @@ -127,7 +143,7 @@ DeUniqueSeqsCommand::DeUniqueSeqsCommand(string option) { nameFile = m->getNameFile(); if (nameFile != "") { m->mothurOut("Using " + nameFile + " as input file for the name parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current namefile and the name parameter is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setNameFile(nameFile); } } } @@ -146,22 +162,22 @@ int DeUniqueSeqsCommand::execute() { ofstream out; string outFastaFile = m->getRootName(m->getSimpleName(fastaFile)); int pos = outFastaFile.find("unique"); - if (pos != string::npos) { - outFastaFile = outputDir + outFastaFile.substr(0, pos) + "redundant" + m->getExtension(fastaFile); - }else{ - outFastaFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "redundant" + m->getExtension(fastaFile); - } + if (pos != string::npos) { outFastaFile = outputDir + outFastaFile.substr(0, pos); } + else { outFastaFile = outputDir + outFastaFile; } + map variables; + variables["[filename]"] = outFastaFile; + outFastaFile = getOutputFileName("fasta", variables); m->openOutputFile(outFastaFile, out); readNamesFile(); - if (m->control_pressed) { out.close(); outputTypes.clear(); remove(outFastaFile.c_str()); return 0; } + if (m->control_pressed) { out.close(); outputTypes.clear(); m->mothurRemove(outFastaFile); return 0; } ifstream in; m->openInputFile(fastaFile, in); while (!in.eof()) { - if (m->control_pressed) { in.close(); out.close(); outputTypes.clear(); remove(outFastaFile.c_str()); return 0; } + if (m->control_pressed) { in.close(); out.close(); outputTypes.clear(); m->mothurRemove(outFastaFile); return 0; } Sequence seq(in); m->gobble(in); @@ -195,7 +211,7 @@ int DeUniqueSeqsCommand::execute() { } } - if (m->control_pressed) { outputTypes.clear(); remove(outFastaFile.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(outFastaFile); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine();