Skip to content

Commit

Permalink
Merge pull request #371 from monarch-initiative/370-add-check-for-ref…
Browse files Browse the repository at this point in the history
…-and-alt-alleles-for-variants-recorded-in-a-phenopacket

370 add check for ref and alt alleles for variants recorded in a phenopacket
  • Loading branch information
yaseminbridges authored Dec 4, 2024
2 parents 4472a94 + e06b1ea commit 99b441d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/pheval/prepare/prepare_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def prepare_corpus(
f"Removed {phenopacket_path.name} from the corpus due to missing variant fields."
)
continue
elif phenopacket_util.check_variant_alleles():
info_log.warning(
f"Removed {phenopacket_path.name} from the corpus due to identical "
"reference and alternate allele fields."
)
if gene_analysis:
if phenopacket_util.check_incomplete_gene_record():
info_log.warning(
Expand Down
13 changes: 13 additions & 0 deletions src/pheval/utils/phenopacket_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,19 @@ def check_incomplete_variant_record(self) -> bool:
return True
return False

def check_variant_alleles(self) -> bool:
"""
Check if any variant record in the phenopacket has identical reference and alternate alleles.
Returns:
bool: True if the reference and alternate alleles are identical, False otherwise.
"""
variants = self.diagnosed_variants()
for variant in variants:
if variant.ref == variant.alt:
return True
return False

def check_incomplete_gene_record(self) -> bool:
"""
Check if any gene record in the phenopacket has incomplete information.
Expand Down
11 changes: 11 additions & 0 deletions tests/test_phenopacket_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from copy import deepcopy
from pathlib import Path

from phenopackets import (
Expand Down Expand Up @@ -606,6 +607,16 @@ def test_check_incomplete_disease_record(self):
def test_check_incomplete_disease_record_missing_records(self):
self.assertTrue(self.structural_variant_phenopacket.check_incomplete_disease_record())

def test_check_variant_alleles(self):
self.assertFalse(self.phenopacket.check_variant_alleles())

def test_check_variant_alleles_duplicate(self):
phenopacket_copy = deepcopy(self.phenopacket)
phenopacket_copy.phenopacket_contents.interpretations[0].diagnosis.genomic_interpretations[
0
].variant_interpretation.variation_descriptor.vcf_record.alt = "C"
self.assertTrue(phenopacket_copy.check_variant_alleles())


class TestPhenopacketRebuilder(unittest.TestCase):
@classmethod
Expand Down

0 comments on commit 99b441d

Please sign in to comment.