Skip to content

Filter cell meta data in ReadPNA_Seurat - #145

Open
ludvigla wants to merge 5 commits into
mainfrom
pna-2926
Open

Filter cell meta data in ReadPNA_Seurat#145
ludvigla wants to merge 5 commits into
mainfrom
pna-2926

Conversation

@ludvigla

@ludvigla ludvigla commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR adds a meta data filter to ReadPNA_Seurat to keep the meta.data slot clean. Full meta data can be obtained by setting detailed_meta_data = TRUE.

The columns to keep are defined in the CELL_META_COLS variable. Currently, these are:

CELL_META_COLS <- c(
  "n_umi", "n_edges", "n_antibodies", "isotype_fraction",
  "average_k_core", "reads_in_component", "tau", "tau_type",
  "n_umi1", "n_umi2", "sample"
)

Fixes: PNA-3078

Type of change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • This change requires a documentation update.

How Has This Been Tested?

Added new test to tests/testthat/test-ReadPNA_Seurat.R

PR checklist:

  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have documented any significant changes to the code in CHANGELOG.md

Note

Medium Risk
Default Seurat metadata is slimmer and may omit columns downstream code assumed were present; behavior is opt-in restorable via detailed_meta_data = TRUE.

Overview
ReadPNA_Seurat now loads only a QC-focused subset of PXL cell metadata into meta.data by default, using the new internal CELL_META_COLS list (e.g. n_umi, n_edges, sample). Set detailed_meta_data = TRUE to restore the full __adata__obs table for troubleshooting.

This is a behavior change for workflows that expect extra columns (such as tau_type) without opting in—tests were updated accordingly (e.g. MoleculeRankPlot grouping uses a synthetic sample_id column). Changelog and roxygen/man docs document the new argument; coverage asserts that detailed mode yields more metadata columns than the default.

Reviewed by Cursor Bugbot for commit 58788c3. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in mechanism to retain full per-cell metadata when loading PNA PXL files into Seurat, while defaulting to a curated subset of QC-relevant columns to keep meta.data smaller/cleaner (Fixes: PNA-2926).

Changes:

  • Added detailed_meta_data argument to ReadPNA_Seurat(); when FALSE it filters meta.data to CELL_META_COLS.
  • Introduced CELL_META_COLS as a central definition of which cell metadata columns are retained by default.
  • Updated documentation, changelog, and added a test to cover the new behavior.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
R/load_data_pna.R Adds detailed_meta_data parameter, validates it, and filters cell metadata by default.
R/aaa.R Defines CELL_META_COLS constant used for default metadata filtering.
tests/testthat/test-ReadPNA_Seurat.R Adds a test asserting detailed metadata loads more columns than the default.
man/ReadPNA_Seurat.Rd Documents the new detailed_meta_data argument.
CHANGELOG.md Notes the new default metadata filtering behavior and how to opt into detailed metadata.
Files not reviewed (1)
  • man/ReadPNA_Seurat.Rd: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/load_data_pna.R

@maxkarlsson maxkarlsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should drop tau!

Comment thread R/aaa.R Outdated
Comment thread R/load_data_pna.R
@ludvigla
ludvigla requested a review from maxkarlsson June 22, 2026 18:02

@maxkarlsson maxkarlsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 58788c3. Configure here.

test_that("ReadPNA_Seurat fails when X collapses to a vector (1 cell)", {
# Inject an error by subsetting X to have only one cell
trace(ReadPNA_Seurat, tracer = quote(X <- X[, 1]), at = 13, print = FALSE)
trace(ReadPNA_Seurat, tracer = quote(X <- X[, 1, drop = FALSE]), at = 14, print = FALSE)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test accidentally duplicated, losing vector collapse coverage

Medium Severity

The first test ("fails when X collapses to a vector") was changed from quote(X <- X[, 1]) to quote(X <- X[, 1, drop = FALSE]), making it identical to the second test ("fails when X is a 1-column matrix"). The original test without drop = FALSE exercised the is.null(ncol(X)) branch of the guard; now both tests only exercise the ncol(X) == 1 branch. The vector-collapse code path is no longer covered.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 58788c3. Configure here.

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.

3 participants