Skip to content

Fix anno norm bug#126

Open
maxkarlsson wants to merge 6 commits intomainfrom
fix-anno-norm-bug
Open

Fix anno norm bug#126
maxkarlsson wants to merge 6 commits intomainfrom
fix-anno-norm-bug

Conversation

@maxkarlsson
Copy link
Copy Markdown
Contributor

@maxkarlsson maxkarlsson commented Apr 2, 2026

Description

  • Fixed bug in .seeded_nmf_annotaton where normalization of the internal temporary Seurat object would propagate to the output.

PNA-2475

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue).

How Has This Been Tested?

Added regression tests to control for bug.

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a bug in NMF-based cell annotation where normalizing an internal temporary Seurat object could unintentionally modify the returned query object’s normalization/data layers.

Changes:

  • Refactors .seeded_nmf_annotaton to normalize a minimal temporary query Seurat object built from counts, rather than normalizing the input query object directly.
  • Adds a regression test asserting that query counts and data layers are preserved after NMF annotation.
  • Documents the fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
R/annotate.R Avoids mutating the input query object during normalization for NMF by normalizing a separate temporary object.
tests/testthat/test-AnnotateCells.R Adds regression coverage to ensure AnnotateCells(..., method="nmf") preserves existing normalization.
CHANGELOG.md Notes the normalization-propagation fix in the Unreleased section.

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

Comment on lines +352 to +357
query_counts <- SeuratObject::LayerData(object, assay = query_assay, layer = "counts")
query_for_nm <- SeuratObject::CreateSeuratObject(
counts = query_counts,
assay = query_assay,
meta.data = data.frame(row.names = colnames(query_counts))
)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

query_counts <- LayerData(object, assay = query_assay, layer = "counts") assumes a single counts layer exists. For Seurat v5 Assay5/PNAAssay5 objects (common after merge()), count layers are typically counts.1, counts.2, ... and code elsewhere in the repo calls JoinLayers() before accessing layer = "counts". Please make this robust for multi-layer assays (e.g., join layers on a temporary copy of the assay/object, or explicitly combine all counts.* layers) so AnnotateCells(..., method = "nmf") works with assay version v5 merged objects without mutating the input object.

Copilot uses AI. Check for mistakes.
maxkarlsson and others added 3 commits April 2, 2026 15:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@ludvigla ludvigla left a comment

Choose a reason for hiding this comment

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

Nice find!

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