Skip to content

Commit

Permalink
Fixed bug in tx2genome() stranded handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tleonardi committed Feb 21, 2019
1 parent b43a17c commit c968072
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bedparse/bedline.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ def tx2genome(self, coord, stranded=False):
if not isinstance(coord, int):
raise BEDexception("coord must be of type integer")

if stranded and not self.stranded:
raise BEDexception("The standed option only makes sense for stranded transcripts")

# If the bed record if not type 12 set exStarts
# and exLens to the whole transcript
if self.bedType < 12:
Expand All @@ -317,7 +320,7 @@ def tx2genome(self, coord, stranded=False):
exLens = [ int(i) for i in self.exLengths.split(',')if i!='' ]
nEx=self.nEx

if stranded:
if stranded and self.strand == "-":
coord = sum(exLens)-coord-1

# Throw an exception is the coordinate is invalid
Expand Down
8 changes: 8 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ class KnownValues(unittest.TestCase):
# Transcript
['chr1', 1000, 2000, 'Tx1', '0', '+', 1000, 1000, 0, 1, '1000,', '0,'],
# Tuple of tuples (txCoord, GenomeCoord)
((0, 1000), (500, 1500), (999, 1999)),
# Tuple of txCoord that should throw exception
(-10, -100, "a", 0.7, 2000, 10000)
),
(
# Transcript
['chr1', 1000, 2000, 'Tx1', '0', '-', 1000, 1000, 0, 1, '1000,', '0,'],
# Tuple of tuples (txCoord, GenomeCoord)
((0, 1999), (500, 1499), (999, 1000)),
# Tuple of txCoord that should throw exception
(-10, -100, "a", 0.7, 2000, 10000)
Expand Down

0 comments on commit c968072

Please sign in to comment.