feat(metamorpheus): Prepopulate modification ID as a dropdown for PTM conversion#184
feat(metamorpheus): Prepopulate modification ID as a dropdown for PTM conversion#184swaraj-neu merged 4 commits intodevelfrom
Conversation
…populate the modification ID dropdown
📝 WalkthroughWalkthroughReads first 100 rows of uploaded Metamorpheus files when Changes
Sequence DiagramsequenceDiagram
participant User
participant UI as Shiny UI
participant Server as Shiny Server
participant Utils as Utils
participant FS as File System
User->>UI: set filetype="meta", BIO="PTM", choose file
UI->>Server: input change triggers observer
Server->>FS: read first 100 rows (data.table::fread)
FS-->>Server: preview dataframe / error
alt read success
Server->>Utils: .extract_mod_ids_from_preview(preview_df)
Utils-->>Server: mod ID list
Server->>UI: render selectizeInput (IDs + "__other__") or textInput
User->>UI: pick ID or choose "__other__" and enter custom
UI->>Server: inputs selected/custom
Server->>Utils: .resolve_mod_id(selected, custom)
Utils-->>Server: escaped mod_id
Server->>Server: embed escaped mod_id in generated code / processing
else read failure
Server->>UI: show warning notification, render fallback input
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/testthat/test-utils.R (1)
1599-1630: Add one extractor-path regression case.These cases cover
.resolve_mod_id(), but the new dropdown population path still has no test. AFull.Sequencefixture with two bracketed annotations would protect the preview parser from returning combined spans.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/testthat/test-utils.R` around lines 1599 - 1630, Add a regression test to exercises the extractor/dropdown population path (not just .resolve_mod_id): create a Full.Sequence fixture containing two separate bracketed annotations (e.g. "[A][B]"), call the same preview/extractor logic used to build the dropdown (the preview parser path) and assert it returns two distinct bracketed spans (not a merged span) and that selecting each yields the expected escaped string via .resolve_mod_id; this ensures the preview parser and dropdown population handle multiple bracketed annotations correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@R/module-loadpage-server.R`:
- Around line 53-92: The observer currently calls data.table::fread for every
uploaded file; restrict this so previews are only attempted for the Metamorpheus
PTM flow: check input$BIO and/or input$filetype before calling fread.
Concretely, inside the observe that uses main_data_file(), add a guard like
req(input$BIO == "PTM") or if (!(input$filetype %in% c(...ptm filetypes...))) {
preview_data(NULL); return() } so fread is only invoked when the PTM branch
applies; keep using preview_data(preview) and the existing error handler
unchanged. Ensure you reference main_data_file(), preview_data(), and the
observe block when making the change.
In `@R/utils.R`:
- Around line 15-16: The current extraction uses gregexpr with a lazy quantifier
which can collapse consecutive bracketed items; update the gregexpr pattern used
when building all_mods from sequences (the call paired with regmatches that
produces unique_mods) to use a bracket-aware pattern that matches an opening '['
then any number of characters that are not ']' and then a closing ']' (i.e.,
avoid ".*?" lazy quantifiers), leaving the regmatches/unlist/sort(unique(...))
pipeline intact so unique_mods is produced as before.
---
Nitpick comments:
In `@tests/testthat/test-utils.R`:
- Around line 1599-1630: Add a regression test to exercises the
extractor/dropdown population path (not just .resolve_mod_id): create a
Full.Sequence fixture containing two separate bracketed annotations (e.g.
"[A][B]"), call the same preview/extractor logic used to build the dropdown (the
preview parser path) and assert it returns two distinct bracketed spans (not a
merged span) and that selecting each yields the expected escaped string via
.resolve_mod_id; this ensures the preview parser and dropdown population handle
multiple bracketed annotations correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9d65ff4f-e41c-474b-a18b-8d623a3c7b1b
📒 Files selected for processing (4)
R/module-loadpage-server.RR/module-loadpage-ui.RR/utils.Rtests/testthat/test-utils.R
…led invalid modification ID case - Moved server function into UI and avoided using conditional panels
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@R/module-loadpage-ui.R`:
- Around line 413-424: The UI currently auto-selects the first modification by
setting selected = choices[1] for the selectizeInput ns("mod_id_meta_select"),
which bypasses the "no selection" validation in R/utils.R:.resolve_mod_id();
change the selectizeInput to not preselect anything (set selected = NULL or
character(0)) and add a placeholder (via options = list(placeholder = "Select
modification or Other")) so users must explicitly choose and .resolve_mod_id()
can detect no-selection.
In `@R/utils.R`:
- Around line 31-35: The code incorrectly assumes both brackets are escaped by
only checking grepl("\\\\\\[", val), so partially escaped IDs like "\\[Phospho]"
slip through; update the branch in R/utils.R that handles 'custom' and 'val' to
verify escaping for both '[' and ']' (e.g., check both grepl("\\\\\\[", val) and
grepl("\\\\\\]", val)) or always run gsub("(\\[|\\])", "\\\\\\1", val) to
normalize both independently before returning; ensure you reference and modify
the existing use of grepl and gsub on 'val' so both brackets are consistently
escaped.
- Around line 985-987: getDataCode currently calls
.resolve_mod_id(input$mod_id_meta_select, input$mod_id_meta_custom) directly
which can throw when no mod is selected; wrap that call in a tryCatch (mirroring
getData's behavior) inside getDataCode so failures are caught, set a safe
fallback (e.g., NA or empty string) for code_mod_id and ensure the generated
code includes a validation-friendly comment or variable (so downstream
validation can show a message instead of crashing). Update references to
.resolve_mod_id and getDataCode to use the tryCatch wrapper and preserve
original behavior when resolution succeeds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c8b52118-0064-4cf3-bef7-8afb84c255e2
📒 Files selected for processing (5)
R/module-loadpage-server.RR/module-loadpage-ui.RR/utils.Rtests/testthat/test-module-loadpage-ui.Rtests/testthat/test-utils.R
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/testthat/test-module-loadpage-ui.R
Refactor Loadpage UI & Server to Read First 100 Rows Upon Upload and populate the modification ID dropdown
Motivation and Context
The Loadpage module required manual entry of Metamorpheus PTM modification-ID patterns, which is error-prone and reduces usability. This PR improves UX by reading the first 100 rows of an uploaded Metamorpheus ("meta") file when BIO == "PTM", extracting bracket-enclosed modification IDs from the sequence column, and prepopulating a modification-ID selector. If preview fails or no IDs are found, the UI falls back to a manual text input.
Detailed Changes
R/module-loadpage-server.R
R/module-loadpage-ui.R
R/utils.R
Other wiring
Unit Tests Added or Modified
tests/testthat/test-utils.R
tests/testthat/test-module-loadpage-ui.R
Coding Guidelines