X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sracommand.cpp;fp=sracommand.cpp;h=c291ddda5369fcb1a87a3420867934e55acc61aa;hb=ac03f1f6c27b5bfdf2cfb6d45c3667c3e0281f51;hp=0000000000000000000000000000000000000000;hpb=fe08eacea5a2d34cd4bd27e8451fd2872102a80a;p=mothur.git diff --git a/sracommand.cpp b/sracommand.cpp new file mode 100644 index 0000000..c291ddd --- /dev/null +++ b/sracommand.cpp @@ -0,0 +1,175 @@ +// +// sracommand.cpp +// Mothur +// +// Created by SarahsWork on 10/28/13. +// Copyright (c) 2013 Schloss Lab. All rights reserved. +// + +#include "sracommand.h" + +//********************************************************************************************************************** +vector SRACommand::setParameters(){ + try { + CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none","sra",false,false); parameters.push_back(psff); + CommandParameter pfastqfile("fastqfile", "InputTypes", "", "", "none", "none", "none","sra",false,false); parameters.push_back(pfastqfile); + //choose only one multiple options + CommandParameter pplatform("platform", "Multiple", "454-???-???", "454", "", "", "","",false,false); parameters.push_back(pplatform); + //every command must have inputdir and outputdir. This allows mothur users to redirect input and output files. + 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); } + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SRACommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string SRACommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The sra command creates a sequence read archive from sff or fastq files.\n"; + helpString += "The sra command parameters are: sff, fastqfiles, oligos, platform....\n"; + helpString += "The sffiles parameter is used to provide a file containing a \n"; + helpString += "The new command should be in the following format: \n"; + helpString += "new(...)\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "SRACommand", "getHelpString"); + exit(1); + } +} +//********************************************************************************************************************** +string SRACommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "sra") { pattern = "[filename],sra"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SRACommand", "getOutputPattern"); + exit(1); + } +} +//********************************************************************************************************************** +SRACommand::SRACommand(){ + try { + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["sra"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "SRACommand", "SRACommand"); + exit(1); + } +} +//********************************************************************************************************************** +SRACommand::SRACommand(string option) { + try { + abort = false; calledHelp = false; + + //allow user to run help + if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} + + else { + //valid paramters for this command + vector myArray = setParameters(); + + OptionParser parser(option); + map parameters = parser.getParameters(); + + ValidParameters validParameter; + map::iterator it; + //check to make sure all parameters are valid for command + for (it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } + } + + + //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 = ""; } + else { + + string path; + it = parameters.find("sfffiles"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["sfffiles"] = inputDir + it->second; } + } + + it = parameters.find("fastqfiles"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["fastqfiles"] = inputDir + it->second; } + } + } + + //check for parameters + fastqfiles = validParameter.validFile(parameters, "fastqfiles", true); + if (fastqfiles == "not open") { fastqfiles = ""; abort = true; } + else if (fastqfiles == "not found") { fastqfiles = ""; } + + sfffiles = validParameter.validFile(parameters, "sfffiles", true); + if (sfffiles == "not open") { sfffiles = ""; abort = true; } + else if (sfffiles == "not found") { sfffiles = ""; } + + if ((fastqfiles == "") && (sfffiles == "")) { + m->mothurOut("No valid current files. You must provide a sfffiles or fastqfiles file before you can use the sra command."); m->mothurOutEndLine(); abort = true; + } + + //use only one Mutliple type + platform = validParameter.validFile(parameters, "platform", false); + if (platform == "not found") { platform = "454"; } + + if ((platform == "454") || (platform == "????") || (platform == "????") || (platform == "????")) { } + else { m->mothurOut("Not a valid platform option. Valid platform options are 454, ...."); m->mothurOutEndLine(); abort = true; } + + + } + + } + catch(exception& e) { + m->errorOut(e, "SRACommand", "SRACommand"); + exit(1); + } +} +//********************************************************************************************************************** + +int SRACommand::execute(){ + try { + + if (abort == true) { if (calledHelp) { return 0; } return 2; } + + + + //output files created by command + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } + m->mothurOutEndLine(); + return 0; + + } + catch(exception& e) { + m->errorOut(e, "SRACommand", "SRACommand"); + exit(1); + } +} +//********************************************************************************************************************** + +