Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
  def scaled_likelihoods(self):
    """Returns the scaled likelihood of each genotype."""
    if not all(bool(x) for x in self._genotype_likelihood_containers):
      raise ValueError(
          'All genotypes must have some probability mass: {}'.format(
              self._genotype_likelihood_containers))

    return genomics_math.normalize_log10_probs([
        genomics_math.log10sumexp(unscaled)
        for unscaled in self._genotype_likelihood_containers
    ])
Ejemplo n.º 4
0
 def test_normalize_log10_probs(self, log10_probs, expected):
   npt.assert_allclose(
       genomics_math.normalize_log10_probs(log10_probs), expected, atol=1e-6)
Ejemplo n.º 5
0
 def test_normalize_log10_probs(self, log10_probs, expected):
   npt.assert_allclose(
       genomics_math.normalize_log10_probs(log10_probs), expected, atol=1e-6)