5 // Created by SarahsWork on 10/28/13.
6 // Copyright (c) 2013 Schloss Lab. All rights reserved.
9 #include "sracommand.h"
11 //**********************************************************************************************************************
12 vector<string> SRACommand::setParameters(){
14 CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none","sra",false,false); parameters.push_back(psff);
15 CommandParameter pfastqfile("fastqfile", "InputTypes", "", "", "none", "none", "none","sra",false,false); parameters.push_back(pfastqfile);
16 //choose only one multiple options
17 CommandParameter pplatform("platform", "Multiple", "454-???-???", "454", "", "", "","",false,false); parameters.push_back(pplatform);
18 //every command must have inputdir and outputdir. This allows mothur users to redirect input and output files.
19 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
20 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
22 vector<string> myArray;
23 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
27 m->errorOut(e, "SRACommand", "setParameters");
31 //**********************************************************************************************************************
32 string SRACommand::getHelpString(){
34 string helpString = "";
35 helpString += "The sra command creates a sequence read archive from sff or fastq files.\n";
36 helpString += "The sra command parameters are: sff, fastqfiles, oligos, platform....\n";
37 helpString += "The sffiles parameter is used to provide a file containing a \n";
38 helpString += "The new command should be in the following format: \n";
39 helpString += "new(...)\n";
43 m->errorOut(e, "SRACommand", "getHelpString");
47 //**********************************************************************************************************************
48 string SRACommand::getOutputPattern(string type) {
52 if (type == "sra") { pattern = "[filename],sra"; }
53 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
58 m->errorOut(e, "SRACommand", "getOutputPattern");
62 //**********************************************************************************************************************
63 SRACommand::SRACommand(){
65 abort = true; calledHelp = true;
67 vector<string> tempOutNames;
68 outputTypes["sra"] = tempOutNames;
71 m->errorOut(e, "SRACommand", "SRACommand");
75 //**********************************************************************************************************************
76 SRACommand::SRACommand(string option) {
78 abort = false; calledHelp = false;
80 //allow user to run help
81 if(option == "help") { help(); abort = true; calledHelp = true; }
82 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
85 //valid paramters for this command
86 vector<string> myArray = setParameters();
88 OptionParser parser(option);
89 map<string,string> parameters = parser.getParameters();
91 ValidParameters validParameter;
92 map<string,string>::iterator it;
93 //check to make sure all parameters are valid for command
94 for (it = parameters.begin(); it != parameters.end(); it++) {
95 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
99 //if the user changes the input directory command factory will send this info to us in the output parameter
100 string inputDir = validParameter.validFile(parameters, "inputdir", false);
101 if (inputDir == "not found"){ inputDir = ""; }
105 it = parameters.find("sfffiles");
106 //user has given a template file
107 if(it != parameters.end()){
108 path = m->hasPath(it->second);
109 //if the user has not given a path then, add inputdir. else leave path alone.
110 if (path == "") { parameters["sfffiles"] = inputDir + it->second; }
113 it = parameters.find("fastqfiles");
114 //user has given a template file
115 if(it != parameters.end()){
116 path = m->hasPath(it->second);
117 //if the user has not given a path then, add inputdir. else leave path alone.
118 if (path == "") { parameters["fastqfiles"] = inputDir + it->second; }
122 //check for parameters
123 fastqfiles = validParameter.validFile(parameters, "fastqfiles", true);
124 if (fastqfiles == "not open") { fastqfiles = ""; abort = true; }
125 else if (fastqfiles == "not found") { fastqfiles = ""; }
127 sfffiles = validParameter.validFile(parameters, "sfffiles", true);
128 if (sfffiles == "not open") { sfffiles = ""; abort = true; }
129 else if (sfffiles == "not found") { sfffiles = ""; }
131 if ((fastqfiles == "") && (sfffiles == "")) {
132 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;
135 //use only one Mutliple type
136 platform = validParameter.validFile(parameters, "platform", false);
137 if (platform == "not found") { platform = "454"; }
139 if ((platform == "454") || (platform == "????") || (platform == "????") || (platform == "????")) { }
140 else { m->mothurOut("Not a valid platform option. Valid platform options are 454, ...."); m->mothurOutEndLine(); abort = true; }
146 catch(exception& e) {
147 m->errorOut(e, "SRACommand", "SRACommand");
151 //**********************************************************************************************************************
153 int SRACommand::execute(){
156 if (abort == true) { if (calledHelp) { return 0; } return 2; }
160 //output files created by command
161 m->mothurOutEndLine();
162 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
163 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
164 m->mothurOutEndLine();
168 catch(exception& e) {
169 m->errorOut(e, "SRACommand", "SRACommand");
173 //**********************************************************************************************************************