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

Robust fallback mechanism #69

Merged
merged 3 commits into from
Jan 29, 2024
Merged
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
25 changes: 11 additions & 14 deletions R/scvelo.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
#' containing the velocity vectors for each cell.
#' }
#' The output will always have number of columns equal to the number of cells supplied in \code{x},
#' though the number of rows will depend on whether any subsetting (if \code{subset.row} is supplied)
#' though the number of rows will depend on whether any subsetting (if \code{subset.row} is supplied)
#' or feature selection (if \code{use.theirs=TRUE}) was performed.
#'
#' @examples
Expand All @@ -123,8 +123,8 @@
#' out <- scvelo(list(X=spliced, spliced=spliced, unspliced=unspliced))
#'
#' # make scvelo use 10 rather than the default 30 neighbors to compute moments for velocity estimation:
#' out <- scvelo(list(X=spliced, spliced=spliced, unspliced=unspliced),
#' scvelo.params=list(moments=list(n_neighbors=10L)))
#' out <- scvelo(list(X=spliced, spliced=spliced, unspliced=unspliced),
#' scvelo.params=list(moments=list(n_neighbors=10L)))
#'
#' @references
#' Bergen, V., Lange, M., Peidli, S. et al. Generalizing RNA velocity to transient cell states through dynamical modeling. Nat Biotechnol 38, 1408–1414 (2020). \url{https://doi.org/10.1038/s41587-020-0591-3}
Expand Down Expand Up @@ -175,28 +175,25 @@ NULL
X=X, spliced=spliced, unspliced=unspliced,
use.theirs=use.theirs, mode=mode,
scvelo.params=scvelo.params,
dimred=dimred)
dimred=dimred, testload = c("scvelo", "anndata"))

output
}

#' @importFrom reticulate import
#' @importFrom DelayedArray is_sparse t
#' @importFrom zellkonverter AnnData2SCE
.run_scvelo <- function(X, spliced, unspliced, use.theirs=FALSE, mode='dynamical', scvelo.params=list(), dimred=NULL) {
X <- t(.make_np_friendly(X))
spliced <- t(.make_np_friendly(spliced))
unspliced <- t(.make_np_friendly(unspliced))
X <- t(velociraptor:::.make_np_friendly(X))
spliced <- t(velociraptor:::.make_np_friendly(spliced))
unspliced <- t(velociraptor:::.make_np_friendly(unspliced))

and <- import("anndata")
scv <- import("scvelo")
and <- reticulate::import("anndata")
scv <- reticulate::import("scvelo")
adata <- and$AnnData(X, layers=list(spliced=spliced, unspliced=unspliced))
adata$obs_names <- rownames(spliced)
adata$var_names <- colnames(spliced)

## A supplied dimred will be used even if use.theirs=TRUE
if (!is.null(dimred)) {
dimred <- .make_np_friendly(dimred)
dimred <- velociraptor:::.make_np_friendly(dimred)
adata$obsm <- list(X_pca = dimred)
}

Expand All @@ -223,7 +220,7 @@ NULL

do.call(scv$tl$velocity_confidence, c(list(data=adata), scvelo.params$velocity_confidence))

AnnData2SCE(adata)
zellkonverter::AnnData2SCE(adata)
}

#' @export
Expand Down
Loading