Skip to content

Fix reverse-strand annotation translation for genes embedded in larger nodes - #208

Open
bobvh wants to merge 2 commits into
mainfrom
fix-reverse-strand-translation
Open

Fix reverse-strand annotation translation for genes embedded in larger nodes#208
bobvh wants to merge 2 commits into
mainfrom
fix-reverse-strand-translation

Conversation

@bobvh

@bobvh bobvh commented Jul 7, 2026

Copy link
Copy Markdown
Member

There was a bug in translating a gene to protein when the gene annotation is on the reverse strand and does not run all the way to the end of a node (i.e. having its reversed start codon start at the rightmost end of the node). This fixes that by properly making the reverse workflow the mirror image of the forward process.

extract_from_entry only walks left to right: it enters at the annotation's left
coordinate, walks to PATH_END, and lets translate_from reverse-complement and
flip the result. For a reverse-strand CDS that does not end at the contig's
right edge (the common single-contig case, e.g. pUC19 bla), the flip started
translation from the contig's right end, rev-comping trailing context onto the
front of the protein and halting at the first stop codon, collapsing a
286-residue gene to a few unrelated residues.

Add extract_to_anchor, the reverse-strand mirror: it anchors at the
annotation's right coordinate, walks left toward PATH_START, and trims the
anchor node's right edge. translate_from then flips the subgraph so translation
begins at the anchor and runs to its own stop codon, symmetric to the forward
path. translate_annotation selects the extractor by strand; translate_from_path
and forward strand are unchanged.

Rework reverse_strand_annotation_translation_handles_variant to anchor at the
gene's right (prefix) node and add
reverse_strand_trailing_context_is_not_translated, covering a reverse CDS with
trailing same-node context.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MPTVMiok2j48CqzSGR9CXd
@bobvh
bobvh force-pushed the fix-reverse-strand-translation branch from 1f20b7c to 1af0030 Compare July 7, 2026 07:18
@bobvh
bobvh requested a review from dkhofer July 7, 2026 15:11
@dkhofer

dkhofer commented Jul 8, 2026

Copy link
Copy Markdown
Member

This is fine, but an alternate solution would be to get the graph in memory, then reverse it (including the sequences referred to by nodes), and then you could run the same code for the forward strand on the reversed graph. That may be a bit more involved, but I feel like it could be a useful general solution to handling reverse strand things.

If you need to get this merged urgently, I can approve, but I'm curious how well reversing the graph would work

@bobvh

bobvh commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

Hmm. We do have the graph in memory already, so it wouldn't complicate things too much to load it as rev comp instead. We'd need to be real sure that we don't introduce off by one errors at the region parsing stage, but that's testable. I'll keep this open for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants