code: def log10_binomial(k, n, p):
      """Calculates numerically-stable value of log10(binomial(k, n, p)).
  
      Returns the log10 of the binomial density for k successes in n trials where
      each success has a probability of occurring of p.
  
      In real-space, we would calculate:
  
         result = (n choose k) * (1-p)^(n-k) * p^k
  
      This function computes the log10 of result, which is:
  
         log10(result) = log10(n choose k) + (n-k) * log10(1-p) + k * log10(p)
  
      This is equivalent to invoking the R function:
        dbinom(x=k, size=n, prob=p, log=TRUE)
  
      See https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Binomial.html
      for more details on the binomial.
  
      Args:
        k: int >= 0. Number of successes.
        n: int >= k. Number of trials.
        p: 0.0 <= float <= 1.0. Probability of success.
  
      Returns:
        log10 probability of seeing k successes in n trials with p.
      """
      r = math.lgamma(n + 1) - (
          math.lgamma(k + 1) + math.lgamma(n - k + 1)
      )
      if k > 0:
          r += k * math.log(p)
      if n > k:
          r += (n - k) * math.log1p(-p)
      return r / LOG_E_OF_10
  
file_path: deepvariant/third_party/nucleus/util/genomics_math.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import numpy
  from third_party.nucleus.util.python import math
label_desc: Use image node_id 3 for calling a global function with example usage: log10_binomial(k, n, p) and returns: unknown