Skip to content

fix the JoinLayers logic inside scVI.R#228

Merged
anashen merged 3 commits into
masterfrom
fix_scVI_with_SCT
Feb 17, 2026
Merged

fix the JoinLayers logic inside scVI.R#228
anashen merged 3 commits into
masterfrom
fix_scVI_with_SCT

Conversation

@longmanz
Copy link
Copy Markdown

This is a bug reported by multiple users (e.g., #209) and have been confirmed. This is caused by the fact that JoinLayers() does not support SCTAssay (SCTAssay is already a single matrix, so no need to join), so when performing scVI integration with SCT-corrected assay, users will run into error.

To reproduce this error, one can run

library(Seurat)
library(SeuratData)
library(SeuratWrappers)

#  SeuratData::InstallData("pbmcsca")
obj <- SeuratData::LoadData("pbmcsca")
obj <- UpdateSeuratObject(obj)

obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method)
obj <- SCTransform(object = obj)
obj <- RunPCA(obj)

obj <- IntegrateLayers(
    object = obj, method = scVIIntegration,
    orig.reduction = "pca", new.reduction = "integrated.scvi",
    assay = "SCT", conda_env = "/Users/uqljian5/opt/anaconda3/envs/scvi", verbose = FALSE
)

This PR proposes a fix which was originally from https://github.com/satijalab/project-management/issues/131. Basically, now when SCTAssay is used for scVI integration, the function will perform a check on the object type, and skip the JoinLayers() if it is SCTAssay.

Copy link
Copy Markdown

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 scVI integration when using SCTransform by avoiding JoinLayers() on SCTAssay objects (which don’t implement JoinLayers() and are already represented as a single matrix), and by splitting batch labels via SCT model identifiers instead of layers.

Changes:

  • Skip JoinLayers() when the input is an SCTAssay, preventing the reported JoinLayers.SCTAssay dispatch error.
  • Refactor batch construction logic by separating SCT-specific batch detection into a new .FindSCTBatches() helper.
  • Update internal roxygen describing how batches are computed (StdAssay-by-layer vs SCT-by-model).
Comments suppressed due to low confidence (1)

R/scVI.R:208

  • There are multiple trailing blank lines at the end of the file after .FindSCTBatches(). Please remove the extra empty lines to keep file formatting consistent with the rest of the R sources in this repo.

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

Comment thread R/scVI.R
Comment thread R/scVI.R
Comment thread R/scVI.R Outdated
Comment thread R/scVI.R
Copy link
Copy Markdown
Member

@anashen anashen left a comment

Choose a reason for hiding this comment

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

Thanks @longmanz for the reproducible example & fix! Tested + made some minor edits to function documentation.

@anashen anashen merged commit ffaf74e into master Feb 17, 2026
0 of 2 checks passed
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