Skip to content

Commit

Permalink
fix (gtf): check added when converting a genomic location to gene coo…
Browse files Browse the repository at this point in the history
…rdinate to ensure they overlap
  • Loading branch information
zhuchcn committed Mar 4, 2025
1 parent 1ae3680 commit 78e971d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Fixed callVariant that peptide annotation not created correctly with SEC

## Changed

- A check added when converting a genomic location to gene coordinate to ensure they overlap.

## [1.4.6-rc1] - 2025-02-24

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions moPepGen/gtf/GenomicAnnotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ def coordinate_gene_to_transcript(self, index:int, gene:str,
def coordinate_genomic_to_gene(self, index:int, gene:str) -> int:
""" Get the gene coordinate from genomic coordinate. """
gene_location = self.genes[gene].location
if not gene_location.start <= index < gene_location.end:
loc = f"{self.genes[gene].chrom}:{gene_location.start}-{gene_location.end}"
raise ValueError(
f"The position does not overlap with the gene. index: {index}, "
f"gene: {gene}, {loc}"
)
if gene_location.strand == 1:
return index - gene_location.start
if gene_location.strand == -1:
Expand Down
2 changes: 1 addition & 1 deletion test/files/circRNA/CIRCexplorer3_circularRNA_known.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
chr22 0 464 circular_RNA/1 0 + 0 0 0,0,0 2 323,82 0,323 1 circRNA RIBC2 ENST00000614167.2 1,2 chr22:0-130787|chr22:131505-160911 1 1 1
chr22 4980 5177 circular_RNA/1 0 - 4980 4980 0,0,0 2 78,42 0,98 1 circRNA LZTR1 ENST00000642151.1 1,2 chr22:427119-435769|chr22:437511-472574 1 1 1
chr22 4980 5120 circular_RNA/1 0 - 4980 4980 0,0,0 2 78,42 0,98 1 circRNA LZTR1 ENST00000642151.1 1,2 chr22:427119-435769|chr22:437511-472574 1 1 1
chr22 5058 5078 circular_RNA/2 0 - 5058 5058 0,0,0 1 20 0 2 ciRNA LZTR1 ENST00000642151.1 1 chr22:868685-870710|chr22:884086-888846 1 1 1
2 changes: 1 addition & 1 deletion test/files/circRNA/CIRCexplorer_circularRNA_known.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
chr22 0 464 circular_RNA/1 0 + 0 0 0,0,0 2 323,82 0,323 1 circRNA RIBC2 ENST00000614167.2 1,2 chr22:0-130787|chr22:131505-160911
chr22 4980 5177 circular_RNA/1 0 - 4980 4980 0,0,0 2 78,42 0,98 1 circRNA LZTR1 ENST00000642151.1 1,2 chr22:427119-435769|chr22:437511-472574
chr22 4980 5120 circular_RNA/1 0 - 4980 4980 0,0,0 2 78,42 0,98 1 circRNA LZTR1 ENST00000642151.1 1,2 chr22:427119-435769|chr22:437511-472574
chr22 5058 5078 circular_RNA/2 0 - 5058 5058 0,0,0 1 20 0 2 ciRNA LZTR1 ENST00000642151.1 1 chr22:868685-870710|chr22:884086-888846
7 changes: 7 additions & 0 deletions test/unit/test_gtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@ def test_coordinate_convert(self):
x = anno.coordinate_gene_to_transcript(19, gene_id, tx_id)
self.assertEqual(x, 10)

anno = create_genomic_annotation(ANNOTATION_DATA)
gene_id = ANNOTATION_ATTRS[0]['gene_id']
tx_id = ANNOTATION_DATA['genes'][0]['transcripts'][0]
with self.assertRaises(ValueError):
## This gene is 0-40, so 50 is out of the gene.
anno.coordinate_gene_to_transcript(50, gene_id, tx_id)

def test_coordinate_convert_tx_exon_start(self):
""" Convert coodinate from transcript to genomic when the index is the
start of an exon"""
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_vep_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def test_vep_to_variant_record_case11(self):

vep_record = VEPParser.VEPRecord(
uploaded_variation='rs55971985',
location='chr1:38-50',
location='chr1:38-40',
allele='-',
gene='ENSG0001',
feature='ENST0001.1',
Expand Down Expand Up @@ -437,7 +437,7 @@ def test_vep_to_variant_record_case15(self):

vep_record = VEPParser.VEPRecord(
uploaded_variation='rs55971985',
location='chr1:2-7',
location='chr1:6-7',
allele='-',
gene='ENSG0001',
feature='ENST0001.1',
Expand Down

0 comments on commit 78e971d

Please sign in to comment.