X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=deuniqueseqscommand.cpp;h=918079cfe45aa2fbe6f14b155a6edd494e555c1d;hb=f509429e06e545bde69c97cacc0eb436775bd329;hp=fb02764e93cc8ca2494773aebeccab857e58f378;hpb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;p=mothur.git diff --git a/deuniqueseqscommand.cpp b/deuniqueseqscommand.cpp index fb02764..918079c 100644 --- a/deuniqueseqscommand.cpp +++ b/deuniqueseqscommand.cpp @@ -36,7 +36,7 @@ string DeUniqueSeqsCommand::getHelpString(){ helpString += "The deunique.seqs command should be in the following format: \n"; helpString += "deunique.seqs(fasta=yourFastaFile, name=yourNameFile) \n"; helpString += "Example deunique.seqs(fasta=abrecovery.unique.fasta, name=abrecovery.names).\n"; - helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; return helpString; } catch(exception& e) { @@ -45,6 +45,26 @@ string DeUniqueSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** +string DeUniqueSeqsCommand::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 = "redundant.fasta"; } + 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, "DeUniqueSeqsCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** DeUniqueSeqsCommand::DeUniqueSeqsCommand(){ try { abort = true; calledHelp = true; @@ -64,6 +84,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 +134,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 +148,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); } } } @@ -147,21 +168,21 @@ int DeUniqueSeqsCommand::execute() { 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); + outFastaFile = outputDir + outFastaFile.substr(0, pos) + getOutputFileNameTag("fasta"); }else{ - outFastaFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "redundant" + m->getExtension(fastaFile); + outFastaFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + getOutputFileNameTag("fasta"); } 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 +216,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();