diff --git a/DESCRIPTION b/DESCRIPTION index a9b8ad0e1..b7fb60b5f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. diff --git a/NAMESPACE b/NAMESPACE index fe2ae1e47..8700c46f3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index 6f016a5b5..fa8f7e1b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 8c1352635..581f35427 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -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", @@ -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", @@ -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", @@ -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 @@ -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, diff --git a/R/integration.R b/R/integration.R index bb4c37c5a..00b7e5e58 100644 --- a/R/integration.R +++ b/R/integration.R @@ -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 @@ -1910,6 +1911,8 @@ LocalStruct <- function( #' reference UMAP using \code{\link{ProjectUMAP}}} #' } #' +#' @importFrom rlang invoke +#' #' @export #' @concept integration #' @@ -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, @@ -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, @@ -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 ) ) @@ -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( diff --git a/man/ProjectUMAP.Rd b/man/ProjectUMAP.Rd index 080f1da4f..0e40dc4e4 100644 --- a/man/ProjectUMAP.Rd +++ b/man/ProjectUMAP.Rd @@ -14,7 +14,7 @@ ProjectUMAP(query, ...) query.dims = NULL, reference, reference.dims = NULL, - k.param = 20, + k.param = 30, nn.method = "annoy", n.trees = 50, annoy.metric = "cosine", @@ -31,7 +31,7 @@ ProjectUMAP(query, ...) query.dims = NULL, reference, reference.dims = NULL, - k.param = 20, + k.param = 30, nn.method = "annoy", n.trees = 50, annoy.metric = "cosine", @@ -50,7 +50,7 @@ ProjectUMAP(query, ...) reference, reference.reduction, reference.dims = NULL, - k.param = 20, + k.param = 30, nn.method = "annoy", n.trees = 50, annoy.metric = "cosine",