From: ryabin Date: Mon, 30 Mar 2009 20:18:37 +0000 (+0000) Subject: Fixed validParameter() method so line parameter can use dashes without breaking the... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=5d3f35ac36e3f55d3d031016340ec99420fd1b24 Fixed validParameter() method so line parameter can use dashes without breaking the covertTest() method. --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index e71f9ce..31fc481 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -115,6 +115,7 @@ EB6F015B0F6AC1670048081A /* sharedbdiversity.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB6F015A0F6AC1670048081A /* sharedbdiversity.cpp */; }; EB9303EB0F534D9400E8EF26 /* logsd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB9303EA0F534D9400E8EF26 /* logsd.cpp */; }; EB9303F90F53517300E8EF26 /* geom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EB9303F80F53517300E8EF26 /* geom.cpp */; }; + EBC564190F81479000A5AC46 /* sharedjackknife.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EBC564180F81479000A5AC46 /* sharedjackknife.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -358,6 +359,8 @@ EB9303EA0F534D9400E8EF26 /* logsd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = logsd.cpp; sourceTree = ""; }; EB9303F70F53517300E8EF26 /* geom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = geom.h; sourceTree = ""; }; EB9303F80F53517300E8EF26 /* geom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = geom.cpp; sourceTree = ""; }; + EBC564170F81479000A5AC46 /* sharedjackknife.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sharedjackknife.h; sourceTree = ""; }; + EBC564180F81479000A5AC46 /* sharedjackknife.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sharedjackknife.cpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -502,6 +505,8 @@ 37D928240F21331F001D4494 /* sharedchao1.cpp */, 37D928290F21331F001D4494 /* sharedjabund.h */, 37D928280F21331F001D4494 /* sharedjabund.cpp */, + EBC564170F81479000A5AC46 /* sharedjackknife.h */, + EBC564180F81479000A5AC46 /* sharedjackknife.cpp */, 37D9282B0F21331F001D4494 /* sharedjclass.h */, 37D9282A0F21331F001D4494 /* sharedjclass.cpp */, 37D9282D0F21331F001D4494 /* sharedjest.h */, @@ -811,6 +816,7 @@ 3758740C0F7D64FC0040F377 /* sharedmorisitahorn.cpp in Sources */, 3758740D0F7D64FC0040F377 /* sharedochiai.cpp in Sources */, 37519A6B0F80E6EB00FED5E8 /* sharedanderbergs.cpp in Sources */, + EBC564190F81479000A5AC46 /* sharedjackknife.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/validparameter.cpp b/validparameter.cpp index 51fefd8..11e7bf9 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -49,6 +49,10 @@ bool ValidParameters::isValidParameter(string parameter, string command, string if(!valid) { cout << "'" << parameter << "' is not a valid parameter for the " << command << " command.\n"; + cout << "The valid paramters for the " << command << " command are: "; + for(int i = 0; i < numParams-1; i++) + cout << cParams.at(i) << ", "; + cout << "and " << cParams.at(numParams-1) << ".\n"; return false; } @@ -58,153 +62,155 @@ bool ValidParameters::isValidParameter(string parameter, string command, string int pVal; double piSentinel = 3.14159; vector range = parameterRanges[parameter]; - - valid = convertTest(value, pVal); - - if(!valid) - return false; - + vector values; + splitAtDash(value, values); - /******************************************************************************************************** - Special Cases - *********************************************************************************************************/ - - if(parameter.compare("precision") == 0) + for(int i = 0; i < values.size(); i++) { - double logNum = log10((double)pVal); - double diff = (double)((int)logNum - logNum); - if(diff != 0) + value = values.at(i); + valid = convertTest(value, pVal); + + if(!valid) + return false; + + + + /******************************************************************************************************** + Special Cases + *********************************************************************************************************/ + + if(parameter.compare("precision") == 0) + { + double logNum = log10((double)pVal); + double diff = (double)((int)logNum - logNum); + if(diff != 0) + { + cout << "The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n"; + return false; + } + } + + /************************************************************************************************************/ + + + + double a,b,c,d,e; + + if(range.at(1).compare("NA") == 0) + a = piSentinel; + else + a = atoi(range.at(1).c_str()); + + if(range.at(3).compare("NA") == 0) + b = piSentinel; + else + b = atoi(range.at(3).c_str()); + + if(range.at(4).compare("between") == 0) + c = 0; + else if(range.at(4).compare("only") == 0) + c = 1; + else { - cout << "The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n"; + cout << "The range can only be 'between' or 'only' the bounding numbers.\n"; return false; } - } - - /************************************************************************************************************/ - - - - double a,b,c,d,e; - - if(range.at(1).compare("NA") == 0) - a = piSentinel; - else - a = atoi(range.at(1).c_str()); - if(range.at(3).compare("NA") == 0) - b = piSentinel; - else - b = atoi(range.at(3).c_str()); - - if(range.at(4).compare("between") == 0) - c = 0; - else if(range.at(4).compare("only") == 0) - c = 1; - else - { - cout << "The range can only be 'between' or 'only' the bounding numbers.\n"; - return false; - } - - if(range.at(0).compare(">") == 0) - d = 0; - else if(range.at(0).compare(">=") == 0 || range[3].compare("=>") == 0) - d = 1; - else - { - cout << "The parameter value can only be '>', '>=', or '=>' the lower bounding number.\n"; - return false; - } - - if(range.at(2).compare("<") == 0) - e = 0; - else if(range.at(2).compare("<=") == 0 || range[4].compare("=<") == 0) - e = 1; - else - { - cout << "The parameter value can only be '<', '<=', or '=<' the upper bounding number.\n"; - return false; - } - - bool a0 = pVal > a; - bool a1 = pVal >= a; - bool b0 = pVal < b; - bool b1 = pVal <= b; - - if(c != 1) - { - if(a == piSentinel && b == piSentinel) - return true; - if(a != piSentinel && b == piSentinel) + if(range.at(0).compare(">") == 0) + d = 0; + else if(range.at(0).compare(">=") == 0 || range[3].compare("=>") == 0) + d = 1; + else { - if(d == 0) - valid = a0; - else - valid = a1; + cout << "The parameter value can only be '>', '>=', or '=>' the lower bounding number.\n"; + return false; } - else if(a == piSentinel && b != piSentinel) + + if(range.at(2).compare("<") == 0) + e = 0; + else if(range.at(2).compare("<=") == 0 || range[4].compare("=<") == 0) + e = 1; + else { - if(e == 0) - valid = b0; + cout << "The parameter value can only be '<', '<=', or '=<' the upper bounding number.\n"; + return false; + } + + bool a0 = pVal > a; + bool a1 = pVal >= a; + bool b0 = pVal < b; + bool b1 = pVal <= b; + + if(c != 1) + { + if(a != piSentinel && b == piSentinel) + { + if(d == 0) + valid = a0; + else + valid = a1; + } + else if(a == piSentinel && b != piSentinel) + { + if(e == 0) + valid = b0; + else + valid = b1; + } else - valid = b1; + { + if(d == 0 && e == 0) + valid = (a0 && b0); + else if(d == 0 && e == 1) + valid = (a0 && b1); + else if(d == 1 && e == 0) + valid = (a1 && b0); + else + valid = (a1 && b1); + } } else { - if(d == 0 && e == 0) - valid = (a0 && b0); - else if(d == 0 && e == 1) - valid = (a0 && b1); - else if(d == 1 && e == 0) - valid = (a1 && b0); + if(a != piSentinel && b == piSentinel) + valid = (pVal == a); + else if(a == piSentinel && b != piSentinel) + valid = (pVal == b); else - valid = (a1 && b1); + valid = (pVal == a || pVal == b); } - } - else - { - if(a == piSentinel && b == piSentinel) - return true; - if(a != piSentinel && b == piSentinel) - valid = (pVal == a); - else if(a == piSentinel && b != piSentinel) - valid = (pVal == b); - else - valid = (pVal == a || pVal == b); - } - - if(valid) - return true; - - else - { - cout << "The '" << parameter << "' parameter needs to be "; - if(c == 1) - cout << "either '" << a << "' or '" << b << "'.\n"; - else + + + if(!valid) { - if(a != piSentinel) - { - cout << ">"; - if(d != 0) - cout << "="; - cout << " '" << a << "'"; - } - if(b == piSentinel) - cout << ".\n"; - else if(a != piSentinel) - cout << " and "; - if(b != piSentinel) + cout << "The '" << parameter << "' parameter needs to be "; + if(c == 1) + cout << "either '" << a << "' or '" << b << "'.\n"; + else { - cout << "<"; - if(e != 0) - cout << "="; - cout << " '" << b << ".\n"; + if(a != piSentinel) + { + cout << ">"; + if(d != 0) + cout << "="; + cout << " '" << a << "'"; + } + if(b == piSentinel) + cout << ".\n"; + else if(a != piSentinel) + cout << " and "; + if(b != piSentinel) + { + cout << "<"; + if(e != 0) + cout << "="; + cout << " '" << b << ".\n"; + } } + return false; } - return false; } + return true; } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the ValidParameters class Function isValidParameter. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";