Class ParamUtils

java.lang.Object
org.broadinstitute.hellbender.utils.param.ParamUtils

public class ParamUtils extends Object
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 Details

    • INV_LOG_2

      public static final double INV_LOG_2
  • Method Details

    • inRange

      public static double inRange(double val, double min, double max, String message)
      Checks that the input is within range and returns the same value or throws an IllegalArgumentException

      Note that min can be greater than max, but that will guarantee that an exception is thrown.

      Parameters:
      val - value to check
      min - minimum value for val
      max - maximum value for val
      message - the text message that would be pass to the exception thrown when o == null.
      Returns:
      the same value
      Throws:
      IllegalArgumentException
    • inRange

      public static long inRange(long val, double min, double max, String message)
      Checks that the input is within range and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      min - minimum value for val
      max - maximum value for val
      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

      public static long inRange(long val, long min, long max, String message)
      Checks that the input is within range and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      min - 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

      public static int inRange(int val, int min, int max, String message)
      Checks that the input int value is within range and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      min - 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

      public static double isPositiveOrZero(double val, String message)
      Checks that the input is positive or zero and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      message - the text message that would be pass to the exception thrown
      Returns:
      the same value
      Throws:
      IllegalArgumentException
    • isNegativeOrZero

      public static double isNegativeOrZero(double val, String message)
      Checks that the input is positive or zero and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      message - the text message that would be pass to the exception thrown
      Returns:
      the same value
      Throws:
      IllegalArgumentException
    • isPositiveOrZero

      public static long isPositiveOrZero(long val, String message)
      Checks that the input is positive or zero and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      message - the text message that would be pass to the exception thrown
      Returns:
      the same value
      Throws:
      IllegalArgumentException
    • isPositiveOrZero

      public static int isPositiveOrZero(int val, String message)
      Checks that the input is positive or zero and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      message - the text message that would be pass to the exception thrown
      Returns:
      the same value
      Throws:
      IllegalArgumentException
    • isPositive

      public static long isPositive(long val, String message)
      Checks that the input is greater than zero and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      message - the text message that would be pass to the exception thrown
      Returns:
      the same value
      Throws:
      IllegalArgumentException
    • isPositive

      public static int isPositive(int val, String message)
      Checks that the input int value is greater than zero and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      message - 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

      public static double isPositive(double val, String message)
      Checks that the input is greater than zero and returns the same value or throws an IllegalArgumentException
      Parameters:
      val - value to check
      message - the text message that would be pass to the exception thrown
      Returns:
      the same value
      Throws:
      IllegalArgumentException
    • isFinite

      public static double isFinite(double val, String message)
      Checks that the input is not infinity nor NaN or throws an IllegalArgumentException
      Parameters:
      val - value to check
      message - 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

      public static void writeStringListToFile(Iterable<String> stringIterator, File outputFile)
      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

      public static void writeValuesToFile(double[] data, File outputFile)
      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

      public static double[] readValuesFromFile(File inputFile)
      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.