Skip to content

Updates to RunUMAP #9752

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ importFrom(utils,tail)
importFrom(utils,txtProgressBar)
importFrom(utils,write.table)
importFrom(uwot,umap)
importFrom(uwot,umap2)
importFrom(uwot,umap_transform)
importMethodsFrom(Matrix,t)
useDynLib(Seurat)
59 changes: 48 additions & 11 deletions R/dimensional_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ RunTSNE.Seurat <- function(
}

#' @importFrom reticulate py_module_available py_set_seed import
#' @importFrom uwot umap umap_transform
#' @importFrom uwot umap umap_transform umap2
#' @importFrom future nbrOfWorkers
#'
#' @rdname RunUMAP
Expand Down Expand Up @@ -1503,14 +1503,6 @@ RunUMAP.default <- function(
}
},
'uwot-predict' = {
if (metric == 'correlation') {
warning(
"UWOT does not implement the correlation metric, using cosine instead",
call. = FALSE,
immediate. = TRUE
)
metric <- 'cosine'
}
if (is.null(x = reduction.model) || !inherits(x = reduction.model, what = 'DimReduc')) {
stop(
"If running projection UMAP, please pass a DimReduc object with the model stored to reduction.model.",
Expand Down Expand Up @@ -1558,6 +1550,51 @@ RunUMAP.default <- function(
)
}
},
'uwot2' = {
if (is.list(x = object)) {
umap2(
X = NULL,
nn_method = object,
n_threads = nbrOfWorkers(),
n_components = as.integer(x = n.components),
metric = metric,
n_epochs = n.epochs,
learning_rate = learning.rate,
min_dist = min.dist,
spread = spread,
set_op_mix_ratio = set.op.mix.ratio,
local_connectivity = local.connectivity,
repulsion_strength = repulsion.strength,
negative_sample_rate = negative.sample.rate,
a = a,
b = b,
fast_sgd = uwot.sgd,
verbose = verbose,
ret_model = return.model
)
} else {
umap2(
X = object,
n_threads = nbrOfWorkers(),
n_neighbors = as.integer(x = n.neighbors),
n_components = as.integer(x = n.components),
metric = metric,
n_epochs = n.epochs,
learning_rate = learning.rate,
min_dist = min.dist,
spread = spread,
set_op_mix_ratio = set.op.mix.ratio,
local_connectivity = local.connectivity,
repulsion_strength = repulsion.strength,
negative_sample_rate = negative.sample.rate,
a = a,
b = b,
fast_sgd = uwot.sgd,
verbose = verbose,
ret_model = return.model
)
}
},
stop("Unknown umap method: ", umap.method, call. = FALSE)
)
if (return.model) {
Expand Down Expand Up @@ -1723,8 +1760,8 @@ RunUMAP.Neighbor <- function(
#' @param slot The slot used to pull data for when using \code{features}. data slot is by default.
#' @param umap.method UMAP implementation to run. Can be
#' \describe{
#' \item{\code{uwot}:}{Runs umap via the uwot R package}
#' \item{\code{uwot-learn}:}{Runs umap via the uwot R package and return the learned umap model}
#' \item{\code{uwot}:}{Runs umap via the uwot R package (\code{uwot::umap})}
#' \item{\code{uwot2}:}{Runs umap2 via the uwot R package (\code{uwot::umap2})}
#' \item{\code{umap-learn}:}{Run the Seurat wrapper of the python umap-learn package}
#' }
#' @param n.neighbors This determines the number of neighboring points used in
Expand Down
4 changes: 2 additions & 2 deletions man/RunUMAP.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.