Skip to content

Fix SCTransform umi.assay incorrect source assay labels#10330

Open
YoukaiFromAccounting wants to merge 4 commits intomainfrom
fix-sctransform-modelassay
Open

Fix SCTransform umi.assay incorrect source assay labels#10330
YoukaiFromAccounting wants to merge 4 commits intomainfrom
fix-sctransform-modelassay

Conversation

@YoukaiFromAccounting
Copy link
Contributor

Fixes: #10323

Previously, SCTransform.Seurat() was hard-coded to only updated the umi.assay field for the first entry in SCTModel.list:

slot(object = slot(object = assay.data, name = "SCTModel.list")[[1]], name = "umi.assay") <- assay

For objects with multiple SCT models, such as those created from multiple samples or layers, the remaining models did not have their source assay updated correctly, which would remain at the default "RNA" source assay. This would cause issues with downstream functions such as PrepSCTFindMarkers.

This simple change updates umi.assay for every model in SCTModel.list, so all SCT models consistently record the assay used to run SCTransform(). With these changes, individual SCT models should now correctly have their source assay assigned following SCTransform().

Reproducible example:

data("pbmc_small")

# Create fake Seurat object with two samples
rna_counts <- LayerData(pbmc_small, assay = "RNA", layer = "counts")
obj <- CreateSeuratObject(counts = rna_counts)
obj$sample <- rep(c("sample1", "sample2"), length.out = ncol(obj))

# Create new "decontX" assay
obj[["decontX"]] <- CreateAssayObject(counts = rna_counts)
obj[["decontX"]] <- split(obj[["decontX"]], f = obj$sample)

# Run SCTransform
obj <- SCTransform(
  object = obj,
  assay = "decontX",
  ncells = ncol(obj),
  variable.features.n = 20,
  return.only.var.genes = FALSE,
  conserve.memory = FALSE
)

# Inspect resulting SCT assay
# With these changes, there should be two SCT models model1 and model1.1, both with the
# decontX source assay (rather than an incorrect RNA source assay)
SCTResults(obj, slot = "umi.assay")

Copilot AI review requested due to automatic review settings March 13, 2026 21:43
Copy link
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

This PR fixes incorrect umi.assay provenance recorded in SCTModel.list after running SCTransform.Seurat() on non-RNA assays when multiple SCT models are present, preventing downstream failures/misbehavior (e.g., in PrepSCTFindMarkers).

Changes:

  • Update SCTransform.Seurat() to set umi.assay for every model in SCTModel.list, not just the first.
  • Reassign the updated model list back into the resulting SCT assay so all models consistently track the source assay.

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

Comment on lines +4292 to +4299
# Extract all SCT models stored in assay
sct_models <- slot(object = assay.data, name = "SCTModel.list")

# Update umi.assay field for every SCT model
for (i in seq_along(sct_models)) {
slot(object = sct_models[[i]], name = "umi.assay") <- assay
}
slot(object = assay.data, name = "SCTModel.list") <- sct_models
@anashen anashen self-requested a review March 18, 2026 17:36
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.

BUG: When using custom assay data from a merged object, SCTransform either does not use the right data or mislabels the resulting umi.assay slot

2 participants