Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with running scVI integration over SCTransformed data #184

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GreenGilad
Copy link

As described at the bottom of this issue , when running IntegrateLaters over an SCT assay with the scVIIntegration method, we get the following error:

Error in UseMethod(generic = "JoinLayers", object = object) : 
  no applicable method for 'JoinLayers' applied to an object of class "c('SCTAssay', 'Assay', 'KeyMixin')"

This error happens when calling JoinLayers (line 93). The purpose of this line is to join the different (count) layers so to create a single counts matrix to pass to AnnData (line 98, calling LayerData). While the call to JoinLayers is indeed needed for a standard assay (and thus scVIIntegration works over RNA assay), it is not needed for an SCTAssay as calling LayerData with such an assay pulls the information from all nested SCTModels. The proposed solution is therefore to call JoinLayers only or standard assays:

if (inherits(x = object, what = 'StdAssay')) {
  object <- JoinLayers(object = object, layers = "counts")
}

One additional change regards the downstream use of the scVI integrated reduction object. When calling `FindClusters` over an `SCTransform` + `scVIIntegration` + `FindNeighbors` object, it states that there is no graph with the passed name (i.e. by default `"SCT_snn"`). That is because the newly created dimensionality reduction object has an `assay.used` of `"RNA"`. As such the saved graph name is then `"RNA_snn"`, while `FindClusters` is looking for `"SCT_snn"`. To fix that I've:
  • Added assay = NULL as an argument of the function (which is passed from IntegrateLayers as SCT (for SCT being the specified assay or the default one)
  • Added assay = assay in the CreateDimReducObject.

Code for testing:

library(Seurat)
library(SeuratWrappers)
library(dplyr)

# Testing that scVIIntegration over RNA assay still works
obj <- LoadSeuratRds("seurat.object.rds") # "Fresh" object with only a count matrix
obj[["RNA"]] <- split(obj[["RNA"]], obj$orig.ident)
obj <- NormalizeData(obj, verbose=F) %>% FindVariableFeatures(verbose=F) %>% ScaleData(verbose=F) %>% RunPCA(verbose = F)
obj <- IntegrateLayers(
  object = obj,
  method = scVIIntegration,
  conda_env = "conda/env/path",
  verbose = TRUE
)

# Testing that fix actually fixed the problem
obj <- LoadSeuratRds("seurat.object.rds") # "Fresh" object with only a count matrix
obj[["RNA"]] <- split(obj[["RNA"]], obj$orig.ident)
obj <- SCTransform(obj, verbose=F) %>% RunPCA(verbose = F)
obj <- IntegrateLayers(
  object = obj,
  method = scVIIntegration,
  new.reduction = "integrated.scVI",
  conda_env = "conda/env/path",
  verbose = TRUE
)

# Verify that downstream clustering over integrated embedding works
obj <- FindNeighbors(obj, reduction = "integrated.scVI", dims = 1:30, verbose=F) %>%
    FindClusters(resolution = 3, verbose=F) %>%
    RunUMAP(reduction = "integrated.scVI", dims = 1:30, reduction.name = "umap.scVI", verbose=F)

Gilad Green and others added 2 commits March 8, 2024 12:14
… object. When function is called as part of Seurat5 IntegrateLayers this parameter is passed with the DefaultAssay value or the user specific value
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.

1 participant