X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=degapseqscommand.cpp;h=f1190c84ad58a73b66b3423cbf2d10cee907bb93;hb=df41d90a9611eab75d0516e2654ed8580f8df24c;hp=6a9c25eb74d240404b16f2677ec30b047781a159;hpb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6;p=mothur.git diff --git a/degapseqscommand.cpp b/degapseqscommand.cpp index 6a9c25e..f1190c8 100644 --- a/degapseqscommand.cpp +++ b/degapseqscommand.cpp @@ -10,8 +10,54 @@ #include "degapseqscommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector DegapSeqsCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +DegapSeqsCommand::DegapSeqsCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "DegapSeqsCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector DegapSeqsCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector DegapSeqsCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "getRequiredFiles"); + exit(1); + } +} //*************************************************************************************************************** - DegapSeqsCommand::DegapSeqsCommand(string option) { try { abort = false; @@ -35,6 +81,11 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + + //initialize outputTypes + vector tempOutNames; + outputTypes["fasta"] = 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,10 +112,25 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { if (m->getDefaultPath() != "") { //default path is set string tryPath = m->getDefaultPath() + m->getSimpleName(fastaFileNames[i]); m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ableToOpen = m->openInputFile(tryPath, in, "noerror"); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); fastaFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + fastaFileNames[i] = tryPath; + } + } + in.close(); if (ableToOpen == 1) { @@ -131,11 +197,13 @@ int DegapSeqsCommand::execute(){ m->openInputFile(fastaFileNames[s], inFASTA); ofstream outFASTA; - string degapFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ng.fasta"; + string tempOutputDir = outputDir; + if (outputDir == "") { tempOutputDir = m->hasPath(fastaFileNames[s]); } + string degapFile = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ng.fasta"; m->openOutputFile(degapFile, outFASTA); while(!inFASTA.eof()){ - if (m->control_pressed) { inFASTA.close(); outFASTA.close(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); inFASTA.close(); outFASTA.close(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } Sequence currSeq(inFASTA); m->gobble(inFASTA); if (currSeq.getName() != "") { @@ -146,9 +214,9 @@ int DegapSeqsCommand::execute(){ inFASTA.close(); outFASTA.close(); - outputNames.push_back(degapFile); + outputNames.push_back(degapFile); outputTypes["fasta"].push_back(degapFile); - if (m->control_pressed) { remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); remove(degapFile.c_str()); for (int j = 0; j < outputNames.size(); j++) { remove(outputNames[j].c_str()); } return 0; } } m->mothurOutEndLine();