Skip to content

plot_tRNA_structure() silently draws overlapping circles for duplicate positions #22

@jayhesselberth

Description

@jayhesselberth

Problem

When plot_tRNA_structure() receives a modifications tibble with duplicate positions (e.g., a position that is both a MODOMICS modification and part of a user-added "anticodon" group via bind_rows()), two semi-transparent filled circles are drawn at the same coordinates. The colors blend unpredictably due to fill-opacity = "0.6", and the legend shows both entries as if they are distinct.

There is no deduplication, warning, or error — the collision is silent.

Reproduction

The vignette pattern of combining MODOMICS modifications with a user-defined anticodon group triggers this when an anticodon position (e.g., Sprinzl 34) also has a MODOMICS modification:

mods <- get_modifications(clov)
anticodon <- tibble(pos = 34:36, mod1 = "anticodon")
combined <- bind_rows(mods, anticodon)

# Position 34 now appears twice — once as a MODOMICS mod, once as "anticodon"
plot_tRNA_structure(combined)

Affected code

add_mod_circles() in R/plot-structure.R:390-413 iterates all rows without checking for duplicate positions:

for (i in seq_len(nrow(modifications))) {
    mod_pos <- modifications$pos[i]
    # ...
    xml2::xml_add_child(
      mod_group,
      "circle",
      cx = as.character(nuc$x + nuc_x_offset),
      cy = as.character(nuc$y + nuc_y_offset),
      r = "4.3",
      fill = color,
      "fill-opacity" = "0.6",
      stroke = "none"
    )
}

Suggestion

Deduplicate by position before drawing circles (last entry wins, matching bind_rows() semantics), and emit a cli::cli_warn() listing the affected positions so users know their data had collisions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions