Skip to content

Add elbow-form layout for plot_tRNA_structure()#28

Open
jayhesselberth wants to merge 3 commits into
develfrom
worktree-elbow-layout
Open

Add elbow-form layout for plot_tRNA_structure()#28
jayhesselberth wants to merge 3 commits into
develfrom
worktree-elbow-layout

Conversation

@jayhesselberth
Copy link
Copy Markdown
Member

Summary

  • Adds layout = c("cloverleaf", "elbow") to plot_tRNA_structure() and structure_trnas(). Default is "cloverleaf" — fully backwards compatible.
  • Bundles 29 elbow-form SVG + JSON files for E. coli standard 3-arm tRNAs under inst/extdata/structures/Escherichia_coli/elbow/.
  • New offline generator data-raw/structures/generate_elbow.py derives geometry from canonical Sprinzl labels (so a single coordinate table covers all standard tRNAs across organisms), reads each cloverleaf JSON's sequence, and writes elbow SVG + JSON in the same schema as cloverleaf — so all overlay machinery (modifications, outlines, linkages, position markers, end labels) works unchanged.

The elbow form stacks the acceptor stem and T-arm coaxially at the top, with the D-arm extending horizontally and the anticodon arm hanging vertically — matching the L-shape depiction common in structural biology figures.

Variable-arm tRNAs (Leu, Ser, SeC, Tyr) are deferred to v2; the generator skips them with a clear log message and the R-side path errors cleanly when callers request elbow layout for an unbundled tRNA.

Test plan

  • devtools::test() — all 47 new + existing tests pass (8 pre-existing skips for rsvg/tidygraph/ggraph)
  • pkgdown::check_pkgdown() clean
  • Visual check: tRNA-Phe-GAA, tRNA-Asp-GTC, tRNA-Val-TAC, tRNA-Lys-TTT, tRNA-Ile-GAT (with 20a D-loop insertion) all render with correct elbow geometry
  • Sprinzl sanity: pos 34 lands at the bottom of AC-loop, pos 1 at the 5' end of the top stack
  • Modification overlay smoke test on elbow layout — <circle> annotations are placed correctly
  • Backwards compatibility: omitting layout renders identical cloverleaf output

🤖 Generated with Claude Code

Adds a `layout = c("cloverleaf", "elbow")` argument to
`plot_tRNA_structure()` and `structure_trnas()`. The elbow form stacks
the acceptor stem and T-arm coaxially at the top, with the D-arm
extending horizontally and the anticodon arm hanging vertically —
matching the L-shape depiction common in structural biology figures.

Geometry is derived from canonical Sprinzl labels via
`inst/extdata/sprinzl/ecoliK12_global_coords.tsv.gz`, so a single
coordinate table works across all standard tRNAs. The new generator
`data-raw/structures/generate_elbow.py` reads each cloverleaf JSON's
sequence, looks up Sprinzl labels, and writes elbow SVG + JSON in the
same schema as cloverleaf — overlay code (modifications, outlines,
linkages, position markers, end labels) works unchanged.

v1 ships 29 E. coli standard 3-arm tRNAs. Variable-arm tRNAs
(Leu, Ser, SeC, Tyr) are deferred to v2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 10, 2026

jayhesselberth and others added 2 commits May 10, 2026 10:17
Initial elbow layout drew the D-arm horizontally with D-loop at the far
left. The reference figure (Matsumoto 2026 JBC fig 2A) shows the L-shape
with D-arm and AC-arm both VERTICAL — sitting side-by-side as parallel
helices below the horizontal acceptor+T stack:

* D-arm on the LEFT, 4 bp going DOWN, D-loop curling at bottom-left
* AC-arm on the RIGHT, 5 bp going DOWN, AC-loop at the bottom
* pos 26 hinge bridges D-arm top-right to AC-arm top-left
* variable region curves from AC-arm top-right up to T-stem 5'

Updates the geometry constants and the D-arm + D-loop placement code in
generate_elbow.py and regenerates all 29 bundled E. coli elbow SVG/JSON
pairs. Visual check on Phe, Asp, and Val now matches the reference.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The first elbow layout had loop residues only 4-5 SVG units apart and the
variable region as tight as 2.5 units — too tight for the radius-4.3
modification circles and stroke outlines drawn by plot_tRNA_structure().

Fixes:
* Loop radii now solved analytically so chord between adjacent residues
  equals the backbone spacing S: R = S / (2 sin(π/(2N))) for N residues
  on a 180° arc. Previous formula (N-1)*S/π underestimated R by ~17%.
* Variable region (44..48) now sampled by ARC LENGTH along the bezier
  rather than by uniform t, so neighbors are evenly spaced instead of
  bunching at the apex.
* Wider canvas (240×170 vs 215×132) and deeper D-arm/AC-arm (D_TOP_Y
  pushed down by 14 units) give the variable-region path enough room.
* Acceptor stem widened (ACC_X1 220 vs 195) for more horizontal room.

Result: minimum neighbor distance is now 7.55 (matching the cloverleaf
median of 7.56), so modification circles fit without overlapping
neighboring letters.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant