5 * Created by Sarah Westcott on 1/5/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "validparameter.h"
12 /***********************************************************************/
14 ValidParameters::ValidParameters() {
16 initParameterRanges();
19 cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function ValidParameters. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
23 cout << "An unknown error has occurred in the ValidParameters class function ValidParameters. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
28 /***********************************************************************/
30 ValidParameters::~ValidParameters() {}
32 /***********************************************************************/
33 bool ValidParameters::isValidParameter(string parameter, vector<string> cParams, string value) {
36 //vector<string> cParams = commandParameters[command];
37 int numParams = cParams.size();
38 for(int i = 0; i < numParams; i++) {
39 if(cParams.at(i).compare(parameter) == 0) {
45 cout << "'" << parameter << "' is not a valid parameter." << endl;
46 cout << "The valid parameters are: ";
47 for(int i = 0; i < numParams-1; i++)
48 cout << cParams.at(i) << ", ";
49 cout << "and " << cParams.at(numParams-1) << ".\n";
53 if(parameterRanges.count(parameter) != 1)
57 double piSentinel = 3.14159;
58 vector<string> range = parameterRanges[parameter];
60 vector<string> values;
61 splitAtDash(value, values);
63 for(int i = 0; i < values.size(); i++) {
65 valid = convertTest(value, pVal);
72 /********************************************************************************************************
74 *********************************************************************************************************/
76 if(parameter.compare("precision") == 0) {
77 double logNum = log10((double)pVal);
78 double diff = (double)((int)logNum - logNum);
80 cout << "The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n";
85 /************************************************************************************************************/
91 if(range.at(1).compare("NA") == 0)
94 a = atoi(range.at(1).c_str());
96 if(range.at(3).compare("NA") == 0)
99 b = atoi(range.at(3).c_str());
101 if(range.at(4).compare("between") == 0)
103 else if(range.at(4).compare("only") == 0)
106 cout << "The range can only be 'between' or 'only' the bounding numbers.\n";
110 if(range.at(0).compare(">") == 0)
112 else if(range.at(0).compare(">=") == 0 || range[3].compare("=>") == 0)
115 cout << "The parameter value can only be '>', '>=', or '=>' the lower bounding number.\n";
119 if(range.at(2).compare("<") == 0)
121 else if(range.at(2).compare("<=") == 0 || range[4].compare("=<") == 0)
124 cout << "The parameter value can only be '<', '<=', or '=<' the upper bounding number.\n";
134 if(a != piSentinel && b == piSentinel) {
140 else if(a == piSentinel && b != piSentinel) {
149 else if(d == 0 && e == 1)
151 else if(d == 1 && e == 0)
158 if(a != piSentinel && b == piSentinel)
160 else if(a == piSentinel && b != piSentinel)
163 valid = (pVal == a || pVal == b);
168 cout << "The '" << parameter << "' parameter needs to be ";
170 cout << "either '" << a << "' or '" << b << "'.\n";
172 if(a != piSentinel) {
176 cout << " '" << a << "'";
180 else if(a != piSentinel)
182 if(b != piSentinel) {
186 cout << " '" << b << "'.\n";
194 catch(exception& e) {
195 cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
199 cout << "An unknown error has occurred in the ValidParameters class function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
203 /*******************************************************/
205 /******************************************************/
207 string ValidParameters::validFile(map<string, string> container, string parameter, bool isFile) {
211 map<string, string>::iterator it;
213 it = container.find(parameter);
214 if(it != container.end()){ //no parameter given
216 ableToOpen = openInputFile(it->second, in);
217 if (ableToOpen == 1) { return "not open"; }
220 }else { return "not found"; }
225 catch(exception& e) {
226 cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function validFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
230 cout << "An unknown error has occurred in the ValidParameters class function validFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
235 /***********************************************************************/
237 /***********************************************************************/
238 void ValidParameters::initParameterRanges() {
242 /**************************************************************************************************************
243 {">=" or "=>" or ">" if the value should be greater than or equal to or just greater than the lower bound,
244 A number representing the lower bound ("NA" if there is no lower bound),
245 "<=" or "=<" or "<" if the value shoud be less than or equal to or just less than the upper bound,
246 A number representing the upper bound ("NA" if there is no lower bound),
247 "between" if between lower and upper bounds or "only" if exactly one of the bounds};
250 # (>, >=) lower bound, # (<, <=) upperbound, # should be (between, only) lower and upper bounds.
251 ***********************************************************************************************************/
253 string precisionArray[] = {">=","10", "<","NA", "between"};
254 parameterRanges["precision"] = addParameters(precisionArray, rangeSize);
256 string itersArray[] = {">=","10", "<","NA", "between"};
257 parameterRanges["iters"] = addParameters(itersArray, rangeSize);
259 string freqArray[] = {">=","1", "<","NA", "between"};
260 parameterRanges["freq"] = addParameters(freqArray, rangeSize);
262 //string lineArray[] = {">=","1", "<","NA", "between"};
263 //parameterRanges["line"] = addParameters(lineArray, rangeSize);
265 string abundArray[] = {">=","5", "<","NA", "between"};
266 parameterRanges["abund"] = addParameters(abundArray, rangeSize);
268 string softArray[] = {">=","0", "<=","100", "between"};
269 parameterRanges["soft"] = addParameters(softArray, rangeSize);
271 string sizeArray[] = {">=","1", "<","NA", "between"};
272 parameterRanges["size"] = addParameters(sizeArray, rangeSize);
274 catch(exception& e) {
275 cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
279 cout << "An unknown error has occurred in the ValidParameters class function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
284 /***********************************************************************/
286 /***********************************************************************/
287 vector<string> ValidParameters::addParameters(string parameters[], int size) {
289 vector<string> pVector (parameters, parameters+size);
292 catch(exception& e) {
293 cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
297 cout << "An unknown error has occurred in the ValidParameters class function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";