2 // sffmultiplecommand.cpp
5 // Created by Sarah Westcott on 8/14/12.
6 // Copyright (c) 2012 Schloss Lab. All rights reserved.
9 #include "sffmultiplecommand.h"
12 //**********************************************************************************************************************
13 vector<string> SffMultipleCommand::setParameters(){
15 CommandParameter pfile("file", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfile);
18 CommandParameter ptrim("trim", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(ptrim);
21 CommandParameter pmaxhomop("maxhomop", "Number", "", "9", "", "", "",false,false); parameters.push_back(pmaxhomop);
22 CommandParameter pmaxflows("maxflows", "Number", "", "450", "", "", "",false,false); parameters.push_back(pmaxflows);
23 CommandParameter pminflows("minflows", "Number", "", "450", "", "", "",false,false); parameters.push_back(pminflows);
24 CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs);
25 CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pbdiffs);
26 CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pldiffs);
27 CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(psdiffs);
28 CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ptdiffs);
29 CommandParameter psignal("signal", "Number", "", "0.50", "", "", "",false,false); parameters.push_back(psignal);
30 CommandParameter pnoise("noise", "Number", "", "0.70", "", "", "",false,false); parameters.push_back(pnoise);
31 CommandParameter pallfiles("allfiles", "Boolean", "", "t", "", "", "",false,false); parameters.push_back(pallfiles);
32 CommandParameter porder("order", "String", "", "", "", "", "",false,false); parameters.push_back(porder);
34 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
35 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
36 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
38 vector<string> myArray;
39 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
43 m->errorOut(e, "SffMultipleCommand", "setParameters");
47 //**********************************************************************************************************************
48 string SffMultipleCommand::getHelpString(){
50 string helpString = "";
51 helpString += "The sff.multiple command reads a file containing sff filenames and optional oligos filenames. It runs the files through sffinfo, trim.flows, shhh.flows and trim.seqs combining the results.\n";
52 helpString += "The sff.multiple command parameters are file, trim, maxhomop, maxflows, minflows, pdiffs, bdiffs, ldiffs, sdiffs, tdiffs, signal, noise, allfiles, order. file is required. \n";
53 helpString += "The file parameter allows you to enter the a file containing the list of sff files and optional oligos files.\n";
54 helpString += "The trim parameter allows you to indicate if you would like a sequences and quality scores generated by sffinfo trimmed to the clipQualLeft and clipQualRight values. Default=True. \n";
55 helpString += "Example sff.multiple(file=mySffOligosFile.txt, trim=F).\n";
56 helpString += "Note: No spaces between parameter labels (i.e. file), '=' and parameters (i.e.mySffOligosFile.txt).\n";
60 m->errorOut(e, "SffMultipleCommand", "getHelpString");
64 //**********************************************************************************************************************
65 string SffMultipleCommand::getOutputFileNameTag(string type, string inputName=""){
67 string outputFileName = "";
68 map<string, vector<string> >::iterator it;
70 //is this a type this command creates
71 it = outputTypes.find(type);
72 if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
74 //if (type == "fasta") { outputFileName = "fasta"; }
75 //else if (type == "flow") { outputFileName = "flow"; }
76 // else if (type == "sfftxt") { outputFileName = "sff.txt"; }
77 //else if (type == "qfile") { outputFileName = "qual"; }
79 m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;
82 return outputFileName;
85 m->errorOut(e, "SffMultipleCommand", "getOutputFileNameTag");
91 //**********************************************************************************************************************
92 SffMultipleCommand::SffMultipleCommand(){
94 abort = true; calledHelp = true;
96 vector<string> tempOutNames;
97 outputTypes["fasta"] = tempOutNames;
98 outputTypes["flow"] = tempOutNames;
99 outputTypes["qfile"] = tempOutNames;
101 catch(exception& e) {
102 m->errorOut(e, "SffMultipleCommand", "SffMultipleCommand");
106 //**********************************************************************************************************************
108 SffMultipleCommand::SffMultipleCommand(string option) {
110 abort = false; calledHelp = false;
112 //allow user to run help
113 if(option == "help") { help(); abort = true; calledHelp = true; }
114 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
117 //valid paramters for this command
118 vector<string> myArray = setParameters();
120 OptionParser parser(option);
121 map<string, string> parameters = parser.getParameters();
123 ValidParameters validParameter;
124 map<string,string>::iterator it;
126 //check to make sure all parameters are valid for command
127 for (it = parameters.begin(); it != parameters.end(); it++) {
128 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
131 //initialize outputTypes
132 vector<string> tempOutNames;
133 outputTypes["fasta"] = tempOutNames;
134 outputTypes["flow"] = tempOutNames;
135 outputTypes["qfile"] = tempOutNames;
137 //if the user changes the output directory command factory will send this info to us in the output parameter
138 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
140 //if the user changes the input directory command factory will send this info to us in the output parameter
141 string inputDir = validParameter.validFile(parameters, "inputdir", false);
142 if (inputDir == "not found"){ inputDir = ""; }
145 it = parameters.find("file");
146 //user has given a template file
147 if(it != parameters.end()){
148 path = m->hasPath(it->second);
149 //if the user has not given a path then, add inputdir. else leave path alone.
150 if (path == "") { parameters["file"] = inputDir + it->second; }
154 filename = validParameter.validFile(parameters, "file", true);
155 if (filename == "not open") { filename = ""; abort = true; }
156 else if (filename == "not found") { filename = ""; }
159 temp = validParameter.validFile(parameters, "trim", false); if (temp == "not found"){ temp = "T"; }
160 trim = m->isTrue(temp);
163 catch(exception& e) {
164 m->errorOut(e, "SffMultipleCommand", "SffMultipleCommand");
168 //**********************************************************************************************************************
169 int SffMultipleCommand::execute(){
171 if (abort == true) { if (calledHelp) { return 0; } return 2; }
173 vector<string> sffFiles, oligosFiles;
174 readFile(sffFiles, oligosFiles);
176 if (m->control_pressed) { return 0; }
179 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
181 //set fasta file as new current fastafile
183 itTypes = outputTypes.find("fasta");
184 if (itTypes != outputTypes.end()) {
185 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
188 itTypes = outputTypes.find("qfile");
189 if (itTypes != outputTypes.end()) {
190 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
193 itTypes = outputTypes.find("flow");
194 if (itTypes != outputTypes.end()) {
195 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFlowFile(current); }
198 //report output filenames
199 m->mothurOutEndLine();
200 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
201 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
202 m->mothurOutEndLine();
206 catch(exception& e) {
207 m->errorOut(e, "SffMultipleCommand", "execute");
211 //**********************************************************************************************************************
212 int SffMultipleCommand::readFile(vector<string>& sffFiles, vector<string>& oligosFiles){
216 m->openInputFile(filename, in);
221 if (m->control_pressed) { break; }
225 //ignore file pairing
226 if(sff[0] == '#'){ while (!in.eof()) { char c = in.get(); if (c == 10 || c == 13){ break; } } m->gobble(in); }
227 else { //check for oligos file
230 // get rest of line in case there is a oligos filename
233 if (c == 10 || c == 13){ break; }
234 else if (c == 32 || c == 9){;} //space or tab
235 else { oligos += c; }
240 sffFiles.push_back(sff);
241 oligosFiles.push_back(oligos); //will push a blank if there is not an oligos for this sff file
247 catch(exception& e) {
248 m->errorOut(e, "SffMultipleCommand", "readFile");
252 //**********************************************************************************************************************