From a611b4d2f1777b7b32f7a2f0266d36591dd461a1 Mon Sep 17 00:00:00 2001 From: Jeremy Arbesfeld Date: Thu, 12 Dec 2024 12:12:46 -0500 Subject: [PATCH] Add gene symbol check in translator methods --- src/fusor/translator.py | 18 ++++++++++++++++++ tests/test_translators.py | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/src/fusor/translator.py b/src/fusor/translator.py index ca13eb6..cdf825f 100644 --- a/src/fusor/translator.py +++ b/src/fusor/translator.py @@ -141,6 +141,21 @@ def _get_gene_element(self, genes: str, caller: Caller) -> GeneElement: ge = self.fusor.gene_element(gene=gene) return ge[0] if ge[0] else self._get_gene_element_unnormalized(gene) + def _fusion_symbol_check(self, gene_5prime: str, gene_3prime: str) -> bool: + """Check if the normalized gene symbols for the two fusion partners + are different. If not, this event is not a fusion + + :param gene_5prime: The 5' gene partner + :param gene_3prime: The 3' gene partner + :return ``True`` if the gene symbols are different, ``False`` if not + """ + if gene_5prime != gene_3prime: + return True + _logger.error( + "The supplied fusion is not valid as the two fusion partners are the same" + ) + return False + def _get_genomic_ac(self, chrom: str, build: Assembly) -> str: """Return a RefSeq genomic accession given a chromosome and a reference build @@ -190,6 +205,9 @@ async def from_jaffa( gene_5prime = gene_5prime_element.gene.label gene_3prime = gene_3prime_element.gene.label + if not self._fusion_symbol_check(gene_5prime, gene_3prime): + return None + tr_5prime = await self.fusor.transcript_segment_element( tx_to_genomic_coords=False, genomic_ac=self._get_genomic_ac(chrom1, rb), diff --git a/tests/test_translators.py b/tests/test_translators.py index 5eb8c0f..d5199d1 100644 --- a/tests/test_translators.py +++ b/tests/test_translators.py @@ -115,6 +115,15 @@ def test_gene_element_arriba(translator_instance): assert gene.gene.label == "MIR3672" +def test_valid_fusion_partners(translator_instance): + """Test that the fusion partners supplied to the translator are different""" + partners_check = translator_instance._fusion_symbol_check("BCR", "ABL1") + assert partners_check + + partners_check = translator_instance._fusion_symbol_check("BCR", "BCR") + assert not partners_check + + @pytest.mark.asyncio() async def test_jaffa( fusion_data_example, fusion_data_example_nonexonic, translator_instance