@@ -944,10 +944,10 @@ async def _genomic_to_tx_segment(
944944 )
945945 # gene is not required to liftover coordinates if tx_ac and genomic_ac are given, but we should set the associated gene
946946 if not gene :
947- _gene , err_msg = await self ._get_tx_ac_gene ( transcript )
948- if err_msg :
949- return GenomicTxSeg ( errors = [ err_msg ])
950- gene = _gene
947+ async with self .uta_db . repository () as uta :
948+ gene = await uta . get_gene_from_tx_ac ( transcript )
949+ if not gene :
950+ return GenomicTxSeg ( errors = [ f"No gene(s) found given { transcript } " ])
951951
952952 tx_exons = await self ._get_all_exon_coords (
953953 tx_ac = transcript , genomic_ac = genomic_ac
@@ -967,9 +967,10 @@ async def _genomic_to_tx_segment(
967967
968968 # Validate that the breakpoint occurs within 150 bp of the first and last exon for the selected transcript.
969969 # A breakpoint beyond this range is likely erroneous.
970- coordinate_check = await self ._validate_genomic_breakpoint (
971- pos = genomic_pos , genomic_ac = genomic_ac , tx_ac = transcript
972- )
970+ async with self .uta_db .repository () as uta :
971+ coordinate_check = await uta .validate_genomic_breakpoint (
972+ pos = genomic_pos , genomic_ac = genomic_ac , tx_ac = transcript
973+ )
973974 if not coordinate_check :
974975 msg = (
975976 f"{ genomic_pos } on { genomic_ac } occurs more than 150 bp outside the "
@@ -1053,69 +1054,6 @@ async def _get_grch38_pos(
10531054 )
10541055 return liftover_data [1 ] if liftover_data else None
10551056
1056- async def _validate_genomic_breakpoint (
1057- self ,
1058- pos : int ,
1059- genomic_ac : str ,
1060- tx_ac : str ,
1061- ) -> bool :
1062- """Validate that a genomic coordinate falls within the first and last exon
1063- for a transcript on a given accession
1064-
1065- :param pos: Genomic position on ``genomic_ac``
1066- :param genomic_ac: RefSeq genomic accession, e.g. ``"NC_000007.14"``
1067- :param transcript: A transcript accession
1068- :return: ``True`` if the coordinate falls within 150bp of the first and last exon
1069- for the transcript, ``False`` if not. Breakpoints past this threshold
1070- are likely erroneous.
1071- """
1072- query = """
1073- WITH tx_boundaries AS (
1074- SELECT
1075- MIN(alt_start_i) AS min_start,
1076- MAX(alt_end_i) AS max_end
1077- FROM tx_exon_aln_mv
1078- WHERE tx_ac = %(tx_ac)s
1079- AND alt_ac = %(genomic_ac)s
1080- )
1081- SELECT * FROM tx_boundaries
1082- WHERE %(pos)s between (tx_boundaries.min_start - 150) and (tx_boundaries.max_end + 150);
1083- """
1084- async with self .uta_db .repository () as uta :
1085- cursor = await uta .execute_query (
1086- query , {"tx_ac" : tx_ac , "genomic_ac" : genomic_ac , "pos" : pos }
1087- )
1088- result = await cursor .fetchone ()
1089- return bool (result )
1090-
1091- async def _get_tx_ac_gene (
1092- self ,
1093- tx_ac : str ,
1094- ) -> tuple [str | None , str | None ]:
1095- """Get gene given a transcript.
1096-
1097- If multiple genes are found for a given ``tx_ac``, only one
1098- gene will be returned.
1099-
1100- :param tx_ac: RefSeq transcript, e.g. ``"NM_004333.6"``
1101- :return: HGNC gene symbol associated to transcript and
1102- warning
1103- """
1104- query = """
1105- SELECT DISTINCT hgnc
1106- FROM tx_exon_aln_mv
1107- WHERE tx_ac = %(tx_ac)s
1108- ORDER BY hgnc
1109- LIMIT 1;
1110- """
1111- async with self .uta_db .repository () as uta :
1112- cursor = await uta .execute_query (query , {"tx_ac" : tx_ac })
1113- result = await cursor .fetchone ()
1114- if not result :
1115- return None , f"No gene(s) found given { tx_ac } "
1116-
1117- return result [0 ], None
1118-
11191057 @staticmethod
11201058 def _is_exonic_breakpoint (pos : int , tx_genomic_coords : list [_ExonCoord ]) -> bool :
11211059 """Check if a breakpoint occurs on an exon
0 commit comments