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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions R/scVI.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NULL
#' scVI Integration
#' @param object A \code{StdAssay} or \code{STDAssay} instance containing
#' merged data
#' @param assay Assay name passed, to be logged in the DimRedc object
#' @param features Features to integrate
#' @param layers Layers to integrate
#' @param conda_env conda environment to run scVI
Expand Down Expand Up @@ -58,6 +59,7 @@ NULL
#' the integrated data
scVIIntegration <- function(
object,
assay = NULL,
features = NULL,
layers = "counts",
conda_env = NULL,
Expand All @@ -67,7 +69,7 @@ scVIIntegration <- function(
gene_likelihood = "nb",
max_epochs = NULL,
...) {

# import python methods from specified conda env
reticulate::use_condaenv(conda_env, required = TRUE)
sc <- reticulate::import("scanpy", convert = FALSE)
Expand All @@ -86,11 +88,14 @@ scVIIntegration <- function(

# build a meta.data-style data.frame indicating the batch for each cell
batches <- .FindBatches(object, layers = layers)
# scVI expects a single counts matrix so we'll join our layers together
# it also expects the raw counts matrix
# TODO: avoid hardcoding this - users can rename their layers arbitrarily
# so there's no gauruntee that the usual naming conventions will be followed
object <- JoinLayers(object = object, layers = "counts")

if (inherits(x = object, what = 'StdAssay')) {
# scVI expects a single counts matrix so we'll join our layers together
# it also expects the raw counts matrix
# TODO: avoid hardcoding this - users can rename their layers arbitrarily
# so there's no gauruntee that the usual naming conventions will be followed
object <- JoinLayers(object = object, layers = "counts")
}
# setup an `AnnData` python instance
adata <- sc$AnnData(
X = scipy$sparse$csr_matrix(
Expand Down Expand Up @@ -125,7 +130,8 @@ scVIIntegration <- function(
suppressWarnings(
latent.dr <- CreateDimReducObject(
embeddings = latent,
key = new.reduction
key = new.reduction,
assay = assay
)
)
# to make it easier to add the reduction into a `Seurat` instance
Expand Down