def test_add_call_to_variant(self, probs, expected): raw_variant = variants_pb2.Variant( reference_name=expected.reference_name, reference_bases=expected.reference_bases, alternate_bases=expected.alternate_bases, start=expected.start, end=expected.end, calls=[variants_pb2.VariantCall(call_set_name=_DEFAULT_SAMPLE_NAME)]) variant = postprocess_variants.add_call_to_variant( variant=raw_variant, predictions=probs, sample_name=_DEFAULT_SAMPLE_NAME) self.assertEqual(variant.reference_bases, expected.reference_bases) self.assertEqual(variant.alternate_bases, expected.alternate_bases) self.assertEqual(variant.reference_name, expected.reference_name) self.assertEqual(variant.start, expected.start) self.assertEqual(variant.end, expected.end) self.assertAlmostEquals(variant.quality, expected.quality, places=6) self.assertEqual(variant.filter, expected.filter) self.assertEqual(len(variant.calls), 1) self.assertEqual(len(expected.calls), 1) self.assertEqual(variant.calls[0].genotype, expected.calls[0].genotype) self.assertEqual(variant.calls[0].info['GQ'], expected.calls[0].info['GQ']) for gl, expected_gl in zip(variant.calls[0].genotype_likelihood, expected.calls[0].genotype_likelihood): self.assertAlmostEquals(gl, expected_gl, places=6)
def test_add_call_to_variant(self, probs, expected): raw_variant = variants_pb2.Variant( reference_name=expected.reference_name, reference_bases=expected.reference_bases, alternate_bases=expected.alternate_bases, start=expected.start, end=expected.end, calls=[variants_pb2.VariantCall(call_set_name=_DEFAULT_SAMPLE_NAME)]) variant = postprocess_variants.add_call_to_variant( variant=raw_variant, predictions=probs, sample_name=_DEFAULT_SAMPLE_NAME) self.assertEqual(variant.reference_bases, expected.reference_bases) self.assertEqual(variant.alternate_bases, expected.alternate_bases) self.assertEqual(variant.reference_name, expected.reference_name) self.assertEqual(variant.start, expected.start) self.assertEqual(variant.end, expected.end) self.assertAlmostEquals(variant.quality, expected.quality, places=6) self.assertEqual(variant.filter, expected.filter) self.assertEqual(len(variant.calls), 1) self.assertEqual(len(expected.calls), 1) self.assertEqual(variant.calls[0].genotype, expected.calls[0].genotype) self.assertEqual(variant.calls[0].info['GQ'], expected.calls[0].info['GQ']) for gl, expected_gl in zip(variant.calls[0].genotype_likelihood, expected.calls[0].genotype_likelihood): self.assertAlmostEquals(gl, expected_gl, places=6)
def test_triallelic_genotype_in_add_call_to_variant( self, highest_prob_position, expected_best_genotype): """Ensures the order of GLs are interpreted correctly for triallelics.""" raw_variant = _create_variant_with_alleles(ref='CACA', alts=['C', 'A']) # Create a probability with 6 elements, one of them 0.995 (best genotype), # and the rest 0.001. probs = [0.001] * 6 assert 0 <= highest_prob_position <= len(probs) probs[highest_prob_position] = 0.995 variant = postprocess_variants.add_call_to_variant( variant=raw_variant, predictions=probs, sample_name=_DEFAULT_SAMPLE_NAME) self.assertEqual(variant.calls[0].genotype, expected_best_genotype)
def test_triallelic_genotype_in_add_call_to_variant( self, highest_prob_position, expected_best_genotype): """Ensures the order of GLs are interpreted correctly for triallelics.""" raw_variant = _create_variant_with_alleles(ref='CACA', alts=['C', 'A']) # Create a probability with 6 elements, one of them 0.995 (best genotype), # and the rest 0.001. probs = [0.001] * 6 assert 0 <= highest_prob_position <= len(probs) probs[highest_prob_position] = 0.995 variant = postprocess_variants.add_call_to_variant( variant=raw_variant, predictions=probs, sample_name=_DEFAULT_SAMPLE_NAME) self.assertEqual(variant.calls[0].genotype, expected_best_genotype)