Skip to content

Commit

Permalink
Fix for case no. 2 from David
Browse files Browse the repository at this point in the history
  • Loading branch information
lucventurini committed Oct 9, 2018
1 parent 155547a commit 5219d68
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Mikado/loci/locus.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,9 @@ def expand_transcript(transcript, new_start, new_end, fai, logger):
logger.debug("%s does not need to be expanded, exiting", transcript.id)
return transcript

# Make a backup copy of the transcript
backup = transcript.deepcopy()

# First get the ORFs
transcript.logger = logger
if transcript.combined_cds_length > 0:
Expand Down Expand Up @@ -923,4 +926,15 @@ def expand_transcript(transcript, new_start, new_end, fai, logger):
if upstream > 0 or downstream > 0:
transcript.attributes["padded"] = True
transcript.finalize()

# Now check that we have a valid expansion
if backup.is_coding and not transcript.is_coding:
# Something has gone wrong. Just return the original transcript.
logger.warning("Padding %s would lead to an invalid CDS. Aborting.")
return backup
elif ((backup.strand == "-" and backup.combined_cds_end < transcript.combined_cds_end) or
(backup.combined_cds_end > transcript.combined_cds_end)):
logger.warning("Padding %s would lead to an in-frame stop codon. Aborting.")
return backup

return transcript

0 comments on commit 5219d68

Please sign in to comment.