2 // getmimarkspackagecommand.cpp
5 // Created by Sarah Westcott on 3/25/14.
6 // Copyright (c) 2014 Schloss Lab. All rights reserved.
9 #include "getmimarkspackagecommand.h"
11 //**********************************************************************************************************************
12 vector<string> GetMIMarksPackageCommand::setParameters(){
14 //files that have dependancies
15 CommandParameter pgroup("group", "InputTypes", "", "", "groupOligos", "none", "none","",false,false); parameters.push_back(pgroup);
16 CommandParameter poligos("oligos", "InputTypes", "", "", "groupOligos", "none", "none","",false,false); parameters.push_back(poligos);
17 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
18 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
20 vector<string> myArray;
21 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
25 m->errorOut(e, "GetMIMarksPackageCommand", "setParameters");
29 //**********************************************************************************************************************
30 string GetMIMarksPackageCommand::getHelpString(){
32 string helpString = "";
33 helpString += "The get.mimarkspackage command creates a mimarks package form with your groups. The required fields are flagged with * characters.\n";
34 helpString += "Further documentation on the different packages and required formats can be found here, http://www.mothur.org/wiki/MIMarks_Data_Packages.\n";
35 helpString += "The get.mimarkspackage command parameters are: oligos, group and package. oligos or group is required.\n";
36 helpString += "The oligos parameter is used to provide your oligos file so mothur can extract your group names.\n";
37 helpString += "The group parameter is used to provide your group file so mothur can extract your group names.\n";
38 helpString += "The package parameter is used to select the mimarks package you would like to use. Default=???\n";
39 helpString += "The get.mimarkspackage command should be in the following format: get.mimarkspackage(oligos=yourOligosFile, package=yourPackage)\n";
40 helpString += "get.mimarkspackage(oligos=GQY1XT001.oligos, package=???)\n";
44 m->errorOut(e, "GetMIMarksPackageCommand", "getHelpString");
48 //**********************************************************************************************************************
49 string GetMIMarksPackageCommand::getOutputPattern(string type) {
53 if (type == "tsv") { pattern = "[filename],tsv"; }
54 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
59 m->errorOut(e, "GetMIMarksPackageCommand", "getOutputPattern");
63 //**********************************************************************************************************************
64 GetMIMarksPackageCommand::GetMIMarksPackageCommand(){
66 abort = true; calledHelp = true;
68 vector<string> tempOutNames;
69 outputTypes["tsv"] = tempOutNames;
72 m->errorOut(e, "GetMIMarksPackageCommand", "GetMIMarksPackageCommand");
76 //**********************************************************************************************************************
77 GetMIMarksPackageCommand::GetMIMarksPackageCommand(string option) {
80 abort = false; calledHelp = false;
82 //allow user to run help
83 if(option == "help") { help(); abort = true; calledHelp = true; }
84 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
87 //valid paramters for this command
88 vector<string> myArray = setParameters();
90 OptionParser parser(option);
91 map<string,string> parameters = parser.getParameters();
93 ValidParameters validParameter;
94 map<string,string>::iterator it;
95 //check to make sure all parameters are valid for command
96 for (it = parameters.begin(); it != parameters.end(); it++) {
97 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
100 vector<string> tempOutNames;
101 outputTypes["tsv"] = tempOutNames;
103 //if the user changes the input directory command factory will send this info to us in the output parameter
104 string inputDir = validParameter.validFile(parameters, "inputdir", false);
105 if (inputDir == "not found"){ inputDir = ""; }
109 it = parameters.find("oligos");
110 //user has given a template file
111 if(it != parameters.end()){
112 path = m->hasPath(it->second);
113 //if the user has not given a path then, add inputdir. else leave path alone.
114 if (path == "") { parameters["oligos"] = inputDir + it->second; }
117 it = parameters.find("group");
118 //user has given a template file
119 if(it != parameters.end()){
120 path = m->hasPath(it->second);
121 //if the user has not given a path then, add inputdir. else leave path alone.
122 if (path == "") { parameters["group"] = inputDir + it->second; }
127 groupfile = validParameter.validFile(parameters, "group", true);
128 if (groupfile == "not open") { groupfile = ""; abort = true; }
129 else if (groupfile == "not found") { groupfile = ""; }
130 else { m->setGroupFile(groupfile); }
132 oligosfile = validParameter.validFile(parameters, "oligos", true);
133 if (oligosfile == "not found") { oligosfile = ""; }
134 else if(oligosfile == "not open") { abort = true; }
135 else { m->setOligosFile(oligosfile); }
137 if ((groupfile != "") && (oligosfile != "")) {
138 m->mothurOut("[ERROR]: You may not use a group file and an oligos file, only one."); m->mothurOutEndLine(); abort = true;
141 if ((groupfile == "") && (oligosfile == "")) {
142 oligosfile = m->getOligosFile();
143 if (oligosfile != "") { m->mothurOut("Using " + oligosfile + " as input file for the oligos parameter."); m->mothurOutEndLine(); }
145 groupfile = m->getGroupFile();
146 if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); }
148 m->mothurOut("[ERROR]: You must provide groupfile or oligos file for the get.mimarkspackage command."); m->mothurOutEndLine(); abort = true;
153 package = validParameter.validFile(parameters, "package", false); if (package == "not found") { package = "package"; }
154 //if (!checkCasesPackage(package)) { abort = true; } //error message in function
156 //turn _ to spaces mothur's work around
157 for (int i = 0; i < package.length(); i++) { if (package[i] == '_') { package[i] = ' '; } }
163 catch(exception& e) {
164 m->errorOut(e, "GetMIMarksPackageCommand", "GetMIMarksPackageCommand");
168 //**********************************************************************************************************************
170 int GetMIMarksPackageCommand::execute(){
173 if (abort == true) { if (calledHelp) { return 0; } return 2; }
179 //output files created by command
180 m->mothurOutEndLine();
181 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
182 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
183 m->mothurOutEndLine();
187 catch(exception& e) {
188 m->errorOut(e, "GetMIMarksPackageCommand", "GetMIMarksPackageCommand");
192 //**********************************************************************************************************************