]> git.donarmstrong.com Git - mothur.git/blob - sracommand.cpp
added binary file operations to mothurout class. added comment to sequence class...
[mothur.git] / sracommand.cpp
1 //
2 //  sracommand.cpp
3 //  Mothur
4 //
5 //  Created by SarahsWork on 10/28/13.
6 //  Copyright (c) 2013 Schloss Lab. All rights reserved.
7 //
8
9 #include "sracommand.h"
10
11 //**********************************************************************************************************************
12 vector<string> SRACommand::setParameters(){
13         try {
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);
21                 
22                 vector<string> myArray;
23                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
24                 return myArray;
25         }
26         catch(exception& e) {
27                 m->errorOut(e, "SRACommand", "setParameters");
28                 exit(1);
29         }
30 }
31 //**********************************************************************************************************************
32 string SRACommand::getHelpString(){
33         try {
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";
40                 return helpString;
41         }
42         catch(exception& e) {
43                 m->errorOut(e, "SRACommand", "getHelpString");
44                 exit(1);
45         }
46 }
47 //**********************************************************************************************************************
48 string SRACommand::getOutputPattern(string type) {
49     try {
50         string pattern = "";
51         
52         if (type == "sra") {  pattern = "[filename],sra"; }
53         else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
54         
55         return pattern;
56     }
57     catch(exception& e) {
58         m->errorOut(e, "SRACommand", "getOutputPattern");
59         exit(1);
60     }
61 }
62 //**********************************************************************************************************************
63 SRACommand::SRACommand(){
64         try {
65                 abort = true; calledHelp = true;
66                 setParameters();
67         vector<string> tempOutNames;
68                 outputTypes["sra"] = tempOutNames; 
69         }
70         catch(exception& e) {
71                 m->errorOut(e, "SRACommand", "SRACommand");
72                 exit(1);
73         }
74 }
75 //**********************************************************************************************************************
76 SRACommand::SRACommand(string option)  {
77         try {
78                 abort = false; calledHelp = false;
79                 
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;}
83                 
84                 else {
85                         //valid paramters for this command
86                         vector<string> myArray = setParameters();
87                         
88                         OptionParser parser(option);
89                         map<string,string> parameters = parser.getParameters();
90                         
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;  }
96                         }
97                         
98                         
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 = "";          }
102                         else {
103             
104                 string path;
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;         }
111                                 }
112                                 
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;               }
119                                 }
120             }
121             
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 = ""; }
126                         
127                         sfffiles = validParameter.validFile(parameters, "sfffiles", true);
128                         if (sfffiles == "not open") {  sfffiles = "";  abort = true; }
129                         else if (sfffiles == "not found") { sfffiles = ""; }
130                         
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;
133             }
134                                     
135             //use only one Mutliple type
136                         platform = validParameter.validFile(parameters, "platform", false);
137                         if (platform == "not found") { platform = "454"; }
138                         
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; }
141             
142                                 
143                 }
144                 
145         }
146         catch(exception& e) {
147                 m->errorOut(e, "SRACommand", "SRACommand");
148                 exit(1);
149         }
150 }
151 //**********************************************************************************************************************
152
153 int SRACommand::execute(){
154         try {
155                 
156                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
157         
158
159                 
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();
165         return 0;
166                 
167     }
168         catch(exception& e) {
169                 m->errorOut(e, "SRACommand", "SRACommand");
170                 exit(1);
171         }
172 }
173 //**********************************************************************************************************************
174
175