Skip to content

Commit

Permalink
Merge pull request #612 from satijalab/fix/ProjectUMAP_n_neighbors
Browse files Browse the repository at this point in the history
Fix ProjectUMAP num of neighbors error and warnings
  • Loading branch information
mojaveazure authored Dec 14, 2021
2 parents c720005 + b42f1a1 commit 9efc44d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: Seurat
Version: 4.0.5.9005
Version: 4.0.5.9006
Date: 2021-12-14
Title: Tools for Single Cell Genomics
Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) <doi:10.1038/nbt.3192>, Macosko E, Basu A, Satija R, et al (2015) <doi:10.1016/j.cell.2015.05.002>, Stuart T, Butler A, et al (2019) <doi:10.1016/j.cell.2019.05.031>, and Hao, Hao, et al (2020) <doi:10.1101/2020.10.12.335331> for more details.
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ importFrom(reticulate,py_module_available)
importFrom(reticulate,py_set_seed)
importFrom(rlang,"!!")
importFrom(rlang,as_label)
importFrom(rlang,invoke)
importFrom(scales,brewer_pal)
importFrom(scales,hue_pal)
importFrom(scales,rescale)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Set `do.center` to FALSE for `lsiproject` in `FindTransferAnchors`
- Fix error message in `ReadMtx()` ([#5158](https://github.com/satijalab/seurat/issues/5158))
- Add `label.color` parameter to `FeaturePlot` ([#5314](https://github.com/satijalab/seurat/pull/5314))
- Fix issues in `ProjectUMAP` ([#5257](https://github.com/satijalab/seurat/issues/5257), [#5104](https://github.com/satijalab/seurat/issues/5104), [#5373](https://github.com/satijalab/seurat/issues/5373))

# Seurat 4.0.5 (2020-10-04)
## Changes
Expand Down
14 changes: 10 additions & 4 deletions R/dimensional_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ ProjectUMAP.default <- function(
query.dims = NULL,
reference,
reference.dims = NULL,
k.param = 20,
k.param = 30,
nn.method = "annoy",
n.trees = 50,
annoy.metric = "cosine",
Expand Down Expand Up @@ -389,7 +389,7 @@ ProjectUMAP.DimReduc <- function(
query.dims = NULL,
reference,
reference.dims = NULL,
k.param = 20,
k.param = 30,
nn.method = "annoy",
n.trees = 50,
annoy.metric = "cosine",
Expand Down Expand Up @@ -439,7 +439,7 @@ ProjectUMAP.Seurat <- function(
reference,
reference.reduction,
reference.dims = NULL,
k.param = 20,
k.param = 30,
nn.method = "annoy",
n.trees = 50,
annoy.metric = "cosine",
Expand Down Expand Up @@ -479,6 +479,7 @@ ProjectUMAP.Seurat <- function(
neighbor.name = neighbor.name,
reduction.model = reference[[reduction.model]],
reduction.key = reduction.key,
assay = DefaultAssay(query),
...
)
query[[reduction.name]] <- proj.umap$proj.umap
Expand Down Expand Up @@ -1385,7 +1386,12 @@ RunUMAP.default <- function(
)
}
if (is.list(x = object)) {
uwot::umap_transform(
if (ncol(object$idx) != model$n_neighbors) {
warning("Number of neighbors between query and reference ",
"is not equal to the number of neighbros within reference")
model$n_neighbors <- ncol(object$idx)
}
umap_transform(
X = NULL,
nn_method = object,
model = model,
Expand Down
27 changes: 16 additions & 11 deletions R/integration.R
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,7 @@ IntegrateEmbeddings.TransferAnchorSet <- function(
}
slot(object = anchorset, name = "object.list") <- object.list
new.reduction.name.safe <- gsub(pattern = "_", replacement = "", x = new.reduction.name)
new.reduction.name.safe <- gsub(pattern = "[.]", replacement = "", x = new.reduction.name)
slot(object = anchorset, name = "reference.objects") <- 1
anchors <- as.data.frame(x = anchors)
anchors$dataset1 <- 1
Expand Down Expand Up @@ -1910,6 +1911,8 @@ LocalStruct <- function(
#' reference UMAP using \code{\link{ProjectUMAP}}}
#' }
#'
#' @importFrom rlang invoke
#'
#' @export
#' @concept integration
#'
Expand Down Expand Up @@ -2002,9 +2005,9 @@ MapQuery <- function(
slot(object = query, name = "tools")$TransferData <- NULL
reuse.weights.matrix <- FALSE
if (!is.null(x = refdata)) {
query <- do.call(
what = TransferData,
args = c(list(
query <- invoke(
.fn = TransferData,
.args = c(list(
anchorset = anchorset,
reference = reference,
query = query,
Expand All @@ -2019,9 +2022,9 @@ MapQuery <- function(
}
}
if (anchor.reduction != "cca"){
query <- do.call(
what = IntegrateEmbeddings,
args = c(list(
query <- invoke(
.fn = IntegrateEmbeddings,
.args = c(list(
anchorset = anchorset,
reference = reference,
query = query,
Expand All @@ -2040,16 +2043,18 @@ MapQuery <- function(
message("Query and reference dimensions are not equal, proceeding with reference dimensions.")
query.dims <- reference.dims
}
query <- do.call(
what = ProjectUMAP,
args = c(list(
ref_nn.num <- Misc(object = reference[[reduction.model]], slot = "model")$n_neighbors
query <- invoke(
.fn = ProjectUMAP,
.args = c(list(
query = query,
query.reduction = new.reduction.name,
query.dims = query.dims,
reference = reference,
reference.dims = reference.dims,
reference.reduction = reference.reduction,
reduction.model = reduction.model
reduction.model = reduction.model,
k.param = ref_nn.num
), projectumap.args
)
)
Expand Down Expand Up @@ -3968,7 +3973,7 @@ MapQueryData <- function(
X = query.datasets,
FUN = function(dataset1) {
if (verbose) {
message("Integrating dataset ", dataset1, " with reference dataset")
message("\nIntegrating dataset ", dataset1, " with reference dataset")
}
filtered.anchors <- anchors[anchors$dataset1 %in% reference.datasets & anchors$dataset2 == dataset1, ]
integrated <- RunIntegration(
Expand Down
6 changes: 3 additions & 3 deletions man/ProjectUMAP.Rd

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

0 comments on commit 9efc44d

Please sign in to comment.