Skip to content

Commit

Permalink
#46 - get_tx_info should properly handle alt_ac and alt_aln_method
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw committed Jul 5, 2023
1 parent 2e98c5e commit 04bebe4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cdot/hgvs/dataproviders/json_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lazy import lazy
from hgvs.dataproviders.interface import Interface
from hgvs.dataproviders.seqfetcher import SeqFetcher
from hgvs.exceptions import HGVSDataNotAvailableError
from intervaltree import IntervalTree
from typing import List

Expand Down Expand Up @@ -181,15 +182,19 @@ def _get_transcript_info(transcript):
def get_tx_info(self, tx_ac, alt_ac, alt_aln_method):
self._check_alt_aln_method(alt_aln_method)

transcript = self._get_transcript(tx_ac)
if not transcript:
return None

tx_info = self._get_transcript_info(transcript)
tx_info["tx_ac"] = tx_ac
tx_info["alt_ac"] = alt_ac
tx_info["alt_aln_method"] = self.NCBI_ALN_METHOD
return tx_info
if transcript := self._get_transcript(tx_ac):
for build_data in transcript["genome_builds"].values():
print(f"BUILD DATA: {build_data}")
if alt_ac == build_data["contig"]:
tx_info = self._get_transcript_info(transcript)
tx_info["tx_ac"] = tx_ac
tx_info["alt_ac"] = alt_ac
tx_info["alt_aln_method"] = self.NCBI_ALN_METHOD
return tx_info

raise HGVSDataNotAvailableError(
f"No tx_info for (tx_ac={tx_ac},alt_ac={alt_ac},alt_aln_method={alt_aln_method})"
)

def get_tx_mapping_options(self, tx_ac):
mapping_options = []
Expand Down
12 changes: 12 additions & 0 deletions tests/test_json_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import hgvs
from hgvs.assemblymapper import AssemblyMapper
from hgvs.exceptions import HGVSDataNotAvailableError

from cdot.hgvs.dataproviders.json_data_provider import JSONDataProvider

Expand Down Expand Up @@ -86,6 +87,17 @@ def test_get_gene_info(self):
}
self.assertEqual(gene_info, expected)

def test_get_tx_info(self):
# We only have data for GRCh37 but none for 38

# Make sure 37 works
tx_info = self.json_data_provider.get_tx_info("NM_001637.3", "NC_000007.13", "splign")
print(tx_info)

# Make sure 38 fails
with self.assertRaises(HGVSDataNotAvailableError):
tx_info = self.json_data_provider.get_tx_info("NM_001637.3", "NC_000007.14", "splign")


if __name__ == '__main__':
unittest.main()

0 comments on commit 04bebe4

Please sign in to comment.