5 * Created by Thomas Ryabin on 1/30/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "getlabelcommand.h"
13 //**********************************************************************************************************************
14 vector<string> GetlabelCommand::setParameters(){
16 CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist);
17 CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund);
18 CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund);
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, "GetlabelCommand", "setParameters");
31 //**********************************************************************************************************************
32 GetlabelCommand::GetlabelCommand(){
34 abort = true; calledHelp = true;
38 m->errorOut(e, "GetlabelCommand", "CollectCommand");
42 //**********************************************************************************************************************
43 string GetlabelCommand::getHelpString(){
45 string helpString = "";
46 helpString += "The get.label command parameters are list, sabund and rabund file. \n";
47 helpString += "The get.label command should be in the following format: \n";
48 helpString += "get.label()\n";
49 helpString += "Example get.label().\n";
53 m->errorOut(e, "GetlabelCommand", "getHelpString");
57 //**********************************************************************************************************************
59 GetlabelCommand::GetlabelCommand(string option) {
61 abort = false; calledHelp = false;
63 //allow user to run help
64 if(option == "help") { help(); abort = true; calledHelp = true; }
67 vector<string> myArray = setParameters();
69 OptionParser parser(option);
70 map<string,string> parameters = parser.getParameters();
71 map<string,string>::iterator it;
73 ValidParameters validParameter;
75 //check to make sure all parameters are valid for command
76 for (it = parameters.begin(); it != parameters.end(); it++) {
77 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
80 //if the user changes the input directory command factory will send this info to us in the output parameter
81 string inputDir = validParameter.validFile(parameters, "inputdir", false);
82 if (inputDir == "not found"){ inputDir = ""; }
86 it = parameters.find("rabund");
87 //user has given a template file
88 if(it != parameters.end()){
89 path = m->hasPath(it->second);
90 //if the user has not given a path then, add inputdir. else leave path alone.
91 if (path == "") { parameters["rabund"] = inputDir + it->second; }
94 it = parameters.find("sabund");
95 //user has given a template file
96 if(it != parameters.end()){
97 path = m->hasPath(it->second);
98 //if the user has not given a path then, add inputdir. else leave path alone.
99 if (path == "") { parameters["sabund"] = inputDir + it->second; }
102 it = parameters.find("list");
103 //user has given a template file
104 if(it != parameters.end()){
105 path = m->hasPath(it->second);
106 //if the user has not given a path then, add inputdir. else leave path alone.
107 if (path == "") { parameters["list"] = inputDir + it->second; }
111 //check for required parameters
112 listfile = validParameter.validFile(parameters, "list", true);
113 if (listfile == "not open") { listfile = ""; abort = true; }
114 else if (listfile == "not found") { listfile = ""; }
115 else { format = "list"; inputfile = listfile; }
117 sabundfile = validParameter.validFile(parameters, "sabund", true);
118 if (sabundfile == "not open") { sabundfile = ""; abort = true; }
119 else if (sabundfile == "not found") { sabundfile = ""; }
120 else { format = "sabund"; inputfile = sabundfile; }
122 rabundfile = validParameter.validFile(parameters, "rabund", true);
123 if (rabundfile == "not open") { rabundfile = ""; abort = true; }
124 else if (rabundfile == "not found") { rabundfile = ""; }
125 else { format = "rabund"; inputfile = rabundfile; }
127 if ((listfile == "") && (rabundfile == "") && (sabundfile == "")) {
128 //is there are current file available for any of these?
129 //give priority to list, then rabund, then sabund
130 //if there is a current shared file, use it
132 listfile = m->getListFile();
133 if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
135 rabundfile = m->getRabundFile();
136 if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); }
138 sabundfile = m->getSabundFile();
139 if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
141 m->mothurOut("No valid current files. You must provide a list, sabund or rabund file."); m->mothurOutEndLine();
150 catch(exception& e) {
151 m->errorOut(e, "GetlabelCommand", "GetlabelCommand");
155 //**********************************************************************************************************************
157 int GetlabelCommand::execute(){
160 if (abort == true) { if (calledHelp) { return 0; } return 2; }
162 InputData* input = new InputData(inputfile, format);
163 OrderVector* order = input->getOrderVector();
164 string label = order->getLabel();
166 while (order != NULL) {
168 if (m->control_pressed) { delete input; delete order; return 0; }
170 label = order->getLabel();
172 m->mothurOut(label); m->mothurOutEndLine();
175 order = input->getOrderVector();
183 catch(exception& e) {
184 m->errorOut(e, "GetlabelCommand", "execute");
188 //**********************************************************************************************************************