feat: port create_lr_dataframe() into the package - #97
Merged
Conversation
Long-format reshape of the three matrices produced by calculate_lr_scores() / calculate_gene_set_score() / calculate_gene_set_specificity() — pivots them into a tidy data frame keyed by (interaction, source_cell_type, target_cell_type) with merged ligand/receptor gene names from the lrpairs reference. The function previously lived in the SpaceMarkers_Protocol repo's R/protocol-helpers.R; Orian asked that we promote it to the package proper since (a) it's the natural tidy view of the package's own LR-scoring outputs, (b) all the dependencies (reshape2, dplyr) are already in Imports, and (c) it's per-sample, not multi-sample orchestration. Two cleanups vs. the protocol-helpers version: - Drop the unconditional `lrscores[is.na(lrscores)] <- 0` line. That was the silent-zero footgun that masked the all-NaN LR matrix bug we hit during the protocol render. NAs now propagate to the score column; callers can filter or impute explicitly. - Doc/code mismatch on @return columns: original docstring listed 8 columns; function returned 9 (source_to_target was tacked on at the end). Updated docstring to list all 9. Also added a @note flagging the parsing constraint: cell-type names must not contain "_to_" or "_and_" (the function uses those as delimiters when reconstructing source/target from the joined-key string). Tests cover the round-trip on a small fixture plus an explicit NA-preservation check (the regression we just fixed).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Promotes `create_lr_dataframe()` from the protocol-helpers vendor file into the package proper, per Orian's request. It's the natural tidy view of `calculate_lr_scores` / `calculate_gene_set_score` / `calculate_gene_set_specificity` output — those are already in the package, so the consumer should be too.
Two cleanups vs. the original
Constraint flagged via `@note`
The function reconstructs `source_cell_type` / `target_cell_type` from a joined string key (`andto`), so cell-type names must not contain `to` or `and` substrings. Documented at the top of the manpage.
Tests
`devtools::test(filter = "create_lr_dataframe")` → 6 PASS, 0 FAIL.
🤖 Generated with Claude Code