def test_haploid_allele_indices_for_genotype_likelihood_index(self): for aix in six.moves.xrange(20): allele_indices = (aix,) ix = variant_utils.genotype_likelihood_index(allele_indices) actual = variant_utils.allele_indices_for_genotype_likelihood_index( ix, ploidy=1) self.assertEqual(actual, aix)
def recall_variant(log_priors, variant): """Update the genotype calls in variant given the new genotype priors.""" for call in variant.calls: if len(log_priors) != len(call.genotype_likelihood): continue posteriors = [ x + y for x, y in zip(log_priors, call.genotype_likelihood) ] sorted_posts = sorted(posteriors) highest_post = sorted_posts[-1] margin = 0 if FLAGS.posterior_margin > 0.0 and len(log_priors) > 1: margin = math.pow(10.0, highest_post) - math.pow( 10.0, sorted_posts[-2]) ploidy = variantcall_utils.ploidy(call) if margin < FLAGS.posterior_margin: call.genotype[:] = [-1] * ploidy else: best_genotype = posteriors.index(highest_post) call.genotype[:] = ( variant_utils.allele_indices_for_genotype_likelihood_index( best_genotype, ploidy=ploidy))
def test_diploid_allele_indices_for_genotype_likelihood_index(self): for aix in range(20): for bix in range(20): allele_indices = (aix, bix) expected = tuple(sorted(allele_indices)) ix = variant_utils.genotype_likelihood_index(allele_indices) actual = variant_utils.allele_indices_for_genotype_likelihood_index( ix, ploidy=2) self.assertEqual(actual, expected)
def test_unsupported_allele_indices_for_genotype_likelihood_index( self, ploidy): with self.assertRaisesRegexp(NotImplementedError, 'only supported for haploid and diploid'): variant_utils.allele_indices_for_genotype_likelihood_index(0, ploidy)