Class ParamUtils
java.lang.Object
org.broadinstitute.hellbender.utils.param.ParamUtils
This class should eventually be merged into Utils, which is in hellbender, and then this class should be deleted.
Double.NaN will generally cause a check to fail. Note that any comparison with a NaN yields false.
Created by lichtens on 8/25/15.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic double
Checks that the input is within range and returns the same value or throws anIllegalArgumentException
static int
Checks that the input int value is within range and returns the same value or throws anIllegalArgumentException
static long
Checks that the input is within range and returns the same value or throws anIllegalArgumentException
static long
Checks that the input is within range and returns the same value or throws anIllegalArgumentException
static double
Validates the value of a parameter.static int
Validates the value of a parameter.static double
Checks that the input is not infinity nor NaN or throws anIllegalArgumentException
static double
isNegativeOrZero
(double val, String message) Checks that the input is positive or zero and returns the same value or throws anIllegalArgumentException
static double
isPositive
(double val, String message) Checks that the input is greater than zero and returns the same value or throws anIllegalArgumentException
static int
isPositive
(int val, String message) Checks that the inputint
value is greater than zero and returns the same value or throws anIllegalArgumentException
static long
isPositive
(long val, String message) Checks that the input is greater than zero and returns the same value or throws anIllegalArgumentException
static double
isPositiveOrZero
(double val, String message) Checks that the input is positive or zero and returns the same value or throws anIllegalArgumentException
static int
isPositiveOrZero
(int val, String message) Checks that the input is positive or zero and returns the same value or throws anIllegalArgumentException
static long
isPositiveOrZero
(long val, String message) Checks that the input is positive or zero and returns the same value or throws anIllegalArgumentException
static void
isValidArrayOffsetAndRangeLength
(int from, int length, int arrayLength, String definition) Checks that a range in an array specified using the first element index/offset and the length of the range is valid.static double
log2
(double val) log the value in base 2static double
logb
(double val, double base) log the value in base bstatic double[]
readValuesFromFile
(File inputFile) Reads a double array from the given filename.static void
writeStringListToFile
(Iterable<String> stringIterator, File outputFile) Writes a list of strings to the given filename.static void
writeValuesToFile
(double[] data, File outputFile) Writes a double array to the given filename.
-
Field Details
-
INV_LOG_2
public static final double INV_LOG_2
-
-
Method Details
-
inRange
Checks that the input is within range and returns the same value or throws anIllegalArgumentException
Note that min can be greater than max, but that will guarantee that an exception is thrown.
- Parameters:
val
- value to checkmin
- minimum value for valmax
- maximum value for valmessage
- the text message that would be pass to the exception thrown wheno == null
.- Returns:
- the same value
- Throws:
IllegalArgumentException
-
inRange
Checks that the input is within range and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmin
- minimum value for valmax
- maximum value for valmessage
- the text message that would be pass to the exception thrown when val gt min or val lt max.- Returns:
- the same value
- Throws:
IllegalArgumentException
-
inRange
Checks that the input is within range and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmin
- minimum value for val (inclusive)max
- maximum value for val (inclusive)message
- the text message that would be pass to the exception thrown when val gt min or val lt max.- Returns:
- the same value
- Throws:
IllegalArgumentException
-
inRange
Checks that the input int value is within range and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmin
- minimum value for val (inclusive)max
- maximum value for val (inclusive)message
- the text message that would be pass to the exception thrown when val gt min or val lt max.- Returns:
- the same input int value
- Throws:
IllegalArgumentException
-
isPositiveOrZero
Checks that the input is positive or zero and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmessage
- the text message that would be pass to the exception thrown- Returns:
- the same value
- Throws:
IllegalArgumentException
-
isNegativeOrZero
Checks that the input is positive or zero and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmessage
- the text message that would be pass to the exception thrown- Returns:
- the same value
- Throws:
IllegalArgumentException
-
isPositiveOrZero
Checks that the input is positive or zero and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmessage
- the text message that would be pass to the exception thrown- Returns:
- the same value
- Throws:
IllegalArgumentException
-
isPositiveOrZero
Checks that the input is positive or zero and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmessage
- the text message that would be pass to the exception thrown- Returns:
- the same value
- Throws:
IllegalArgumentException
-
isPositive
Checks that the input is greater than zero and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmessage
- the text message that would be pass to the exception thrown- Returns:
- the same value
- Throws:
IllegalArgumentException
-
isPositive
Checks that the inputint
value is greater than zero and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmessage
- the text message that would be pass to the exception thrown- Returns:
- the same value.
- Throws:
IllegalArgumentException
- if the input value is 0 or less.
-
isPositive
Checks that the input is greater than zero and returns the same value or throws anIllegalArgumentException
- Parameters:
val
- value to checkmessage
- the text message that would be pass to the exception thrown- Returns:
- the same value
- Throws:
IllegalArgumentException
-
isFinite
Checks that the input is not infinity nor NaN or throws anIllegalArgumentException
- Parameters:
val
- value to checkmessage
- the text message that would be pass to the exception thrown- Returns:
- the same value
- Throws:
IllegalArgumentException
-
logb
public static double logb(double val, double base) log the value in base b- Parameters:
val
- -- The value to be logged.base
- -- The base of the logging- Returns:
- the logged value. If val is zero, returns Double.NEGATIVE_INFINITY. If base is zero, returns -0.0. If any input is negative, returns Double.NaN.
-
log2
public static double log2(double val) log the value in base 2- Parameters:
val
- -- The value to be logged.- Returns:
- the logged value. If val is zero, returns Double.NEGATIVE_INFINITY. If val is negative, returns Double.NaN.
-
writeStringListToFile
Writes a list of strings to the given filename. The file will be overwritten if it exists.- Parameters:
stringIterator
- Strings that will be written (one to a line)outputFile
- File to write
-
writeValuesToFile
Writes a double array to the given filename. The file will be overwritten if it exists.- Parameters:
data
- doubles that will be written (one to a line)outputFile
- File to write
-
readValuesFromFile
Reads a double array from the given filename.- Parameters:
inputFile
- doubles that will be read (one to a line)
-
inRange
public static double inRange(org.apache.commons.lang.math.DoubleRange validRange, double value, String definition) Validates the value of a parameter.An invalid value will result in an
IllegalArgumentException
.Notice that
nan
are always considered invalid whereas negative or infinity values will depends on the declared input range extreme values.- Parameters:
validRange
- the valid range for the parameter value.value
- the parameter value itself.definition
- a human friendly description of the parameter to be used in an explanatory exception.- Returns:
- the input value.
- Throws:
IllegalArgumentException
- if the value provided is in-valid.
-
inRange
public static int inRange(org.apache.commons.lang.math.IntRange validRange, int value, String definition) Validates the value of a parameter.An invalid value will result in an
IllegalArgumentException
.- Parameters:
validRange
- the valid range for the parameter value.value
- the parameter value itself.definition
- a human friendly description of the parameter to be used in an explanatory exception.- Returns:
- the input value.
- Throws:
IllegalArgumentException
- if the value provided is in-valid.
-
isValidArrayOffsetAndRangeLength
public static void isValidArrayOffsetAndRangeLength(int from, int length, int arrayLength, String definition) Checks that a range in an array specified using the first element index/offset and the length of the range is valid.- Parameters:
from
- the first position of th range.length
- the length of the range.arrayLength
- the target array length, thus indexes from 0 to arrayLength - 1.definition
- the description of the parameter.
-