예제 #1
0
    def _calc_reference_confidence(self, n_ref, n_total):
        """Performs the calculation described in reference_confidence()."""
        if n_ref < 0:
            raise ValueError('n_ref={} must be >= 0'.format(n_ref))
        if n_total < n_ref:
            raise ValueError('n_total={} must be >= n_ref={}'.format(
                n_total, n_ref))
        if self.options.ploidy != 2:
            raise ValueError('ploidy={} but we only support ploidy=2'.format(
                self.options.ploidy))

        if n_total == 0:
            # No coverage case - all likelihoods are log10 of 1/3, 1/3, 1/3.
            log10_probs = genomics_math.normalize_log10_probs(
                [-1.0, -1.0, -1.0])
        else:
            n_alts = n_total - n_ref
            log10_p_ref = genomics_math.log10_binomial(n_alts, n_total,
                                                       self.options.p_error)
            log10_p_het = genomics_math.log10_binomial(
                n_ref, n_total, 1.0 / self.options.ploidy)
            log10_p_hom_alt = genomics_math.log10_binomial(
                n_ref, n_total, self.options.p_error)
            log10_probs = genomics_math.normalize_log10_probs(
                [log10_p_ref, log10_p_het, log10_p_hom_alt])

        gq = genomics_math.log10_ptrue_to_phred(log10_probs[0],
                                                self.options.max_gq)
        gq = int(min(np.floor(gq), self.options.max_gq))
        return gq, log10_probs
예제 #2
0
  def _calc_reference_confidence(self, n_ref, n_total):
    """Performs the calculation described in reference_confidence()."""
    if n_ref < 0:
      raise ValueError('n_ref={} must be >= 0'.format(n_ref))
    if n_total < n_ref:
      raise ValueError('n_total={} must be >= n_ref={}'.format(n_total, n_ref))
    if self.options.ploidy != 2:
      raise ValueError('ploidy={} but we only support ploidy=2'.format(
          self.options.ploidy))

    if n_total == 0:
      # No coverage case - all likelihoods are log10 of 1/3, 1/3, 1/3.
      log10_probs = genomics_math.normalize_log10_probs([-1.0, -1.0, -1.0])
    else:
      n_alts = n_total - n_ref
      log10_p_ref = genomics_math.log10_binomial(n_alts, n_total,
                                                 self.options.p_error)
      log10_p_het = genomics_math.log10_binomial(n_ref, n_total,
                                                 1.0 / self.options.ploidy)
      log10_p_hom_alt = genomics_math.log10_binomial(n_ref, n_total,
                                                     self.options.p_error)
      log10_probs = genomics_math.normalize_log10_probs(
          [log10_p_ref, log10_p_het, log10_p_hom_alt])

    gq = genomics_math.log10_ptrue_to_phred(log10_probs[0], self.options.max_gq)
    gq = int(min(np.floor(gq), self.options.max_gq))
    return gq, log10_probs
예제 #3
0
 def test_log10_ptrue_to_phred(self, prob, value_if_not_finite, expected):
   actual = genomics_math.log10_ptrue_to_phred(prob, value_if_not_finite)
   self.assertAlmostEqual(actual, expected, places=6)
예제 #4
0
 def test_log10_ptrue_to_phred(self, prob, value_if_not_finite, expected):
   actual = genomics_math.log10_ptrue_to_phred(prob, value_if_not_finite)
   self.assertAlmostEqual(actual, expected, places=6)