From bbb9ceef44037df7dde71bee95a11337d5be6e2b Mon Sep 17 00:00:00 2001 From: Izzy Grabski Date: Fri, 1 Nov 2024 11:17:58 -0400 Subject: [PATCH 1/8] only modify dims.to.integrate if it's incompatible with the reduction dimension --- R/integration.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/integration.R b/R/integration.R index 2264783f0..46387076c 100644 --- a/R/integration.R +++ b/R/integration.R @@ -6319,8 +6319,8 @@ ValidateParams_IntegrateEmbeddings_IntegrationAnchors <- function( warning("Max dims.to.integrate is larger than the number of dimensions in ", "the provided reduction. Setting dims.to.integrate to 1:", ncol(x = reductions), " and continuing.", immediate. = TRUE, call. = FALSE) + ModifyParam(param = 'dims.to.integrate', value = 1:ncol(x = reductions)) } - ModifyParam(param = 'dims.to.integrate', value = 1:ncol(x = reductions)) } if (!is.null(x = weight.reduction)) { if (inherits(x = weight.reduction, what = "character")) { From c9f8b5e9fec5c6d6e23ad021e9b9143195b605e9 Mon Sep 17 00:00:00 2001 From: Izzy Grabski Date: Fri, 1 Nov 2024 11:41:22 -0400 Subject: [PATCH 2/8] only use the reduction loadings specified by dims.to.integrate --- R/integration.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/integration.R b/R/integration.R index 46387076c..71173dbeb 100644 --- a/R/integration.R +++ b/R/integration.R @@ -1694,7 +1694,7 @@ IntegrateEmbeddings.IntegrationAnchorSet <- function( object = reference.integrated[[new.reduction.name.safe]] ))), assay = intdr.assay, - loadings = Loadings(object = reductions), + loadings = Loadings(object = reductions)[,dims.to.integrate], key = paste0(new.reduction.name.safe, "_") ) DefaultAssay(object = reference.integrated) <- int.assay From b132d0c64a9ea201da012ffd8114213797f11aba Mon Sep 17 00:00:00 2001 From: Izzy Grabski Date: Fri, 1 Nov 2024 11:52:30 -0400 Subject: [PATCH 3/8] otherwise dims.to.integrate will stay NULL if no value specified --- R/integration.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/integration.R b/R/integration.R index 71173dbeb..39899bede 100644 --- a/R/integration.R +++ b/R/integration.R @@ -6321,6 +6321,7 @@ ValidateParams_IntegrateEmbeddings_IntegrationAnchors <- function( ncol(x = reductions), " and continuing.", immediate. = TRUE, call. = FALSE) ModifyParam(param = 'dims.to.integrate', value = 1:ncol(x = reductions)) } + ModifyParam(param = 'dims.to.integrate', value = dims.to.integrate) } if (!is.null(x = weight.reduction)) { if (inherits(x = weight.reduction, what = "character")) { From 81cb30c587fb9e8b2beb07016408f2083cfc78bd Mon Sep 17 00:00:00 2001 From: Izzy Grabski Date: Fri, 1 Nov 2024 12:12:04 -0400 Subject: [PATCH 4/8] adding tests to make sure dims.to.integrate is not overwritten --- tests/testthat/test_integration5.R | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/testthat/test_integration5.R b/tests/testthat/test_integration5.R index f4f635790..374f731ac 100644 --- a/tests/testthat/test_integration5.R +++ b/tests/testthat/test_integration5.R @@ -95,6 +95,23 @@ test_that("IntegrateLayers works with CCAIntegration", { Embeddings(integrated[["integrated"]])[75, 45], 0.5442 ) + + integrated_sub <- suppressWarnings( + IntegrateLayers( + test.data.std, + method = CCAIntegration, + orig.reduction = "pca", + new.reduction = "integrated", + verbose = FALSE, + # since `k.weight` must be less than the number of samples in the + # smallest layer being integrated, it must be set to accommodate the + # small dataset used for testing + k.weight = 10, + dims.to.integrate = 1:10 + ) + ) + # check that dims.to.integrate is not being overwritten + expect_equal(ncol(integrated_sub[["integrated"]]), 10) }) test_that("IntegrateLayers works with RPCAIntegration", { @@ -127,6 +144,23 @@ test_that("IntegrateLayers works with RPCAIntegration", { Embeddings(integrated[["integrated"]])[75, 45], 0.5442 ) + + integrated_sub <- suppressWarnings( + IntegrateLayers( + test.data.std, + method = RPCAIntegration, + orig.reduction = "pca", + new.reduction = "integrated", + verbose = FALSE, + # since `k.weight` must be less than the number of samples in the + # smallest layer being integrated, it must be set to accommodate the + # small dataset used for testing + k.weight = 10, + dims.to.integrate = 1:10 + ) + ) + # check that dims.to.integrate is not being overwritten + expect_equal(ncol(integrated_sub[["integrated"]]), 10) }) test_that("IntegrateLayers works with JointPCAIntegration", { @@ -159,6 +193,23 @@ test_that("IntegrateLayers works with JointPCAIntegration", { Embeddings(integrated[["integrated"]])[75, 45], 0.5442 ) + + integrated_sub <- suppressWarnings( + IntegrateLayers( + test.data.std, + method = JointPCAIntegration, + orig.reduction = "pca", + new.reduction = "integrated", + verbose = FALSE, + # since `k.weight` must be less than the number of samples in the + # smallest layer being integrated, it must be set to accommodate the + # small dataset used for testing + k.weight = 10, + dims.to.integrate = 1:10 + ) + ) + # check that dims.to.integrate is not being overwritten + expect_equal(ncol(integrated_sub[["integrated"]]), 10) }) test_that("IntegrateLayers fails when expected", { From 0c7186d5216b359f1c03023d9574096429c8e4e7 Mon Sep 17 00:00:00 2001 From: David Collins Date: Thu, 19 Dec 2024 23:09:28 -0500 Subject: [PATCH 5/8] Expand on IntegrateLayers dims.to.integrate tests --- tests/testthat/test_integration5.R | 69 ++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test_integration5.R b/tests/testthat/test_integration5.R index 374f731ac..73552c198 100644 --- a/tests/testthat/test_integration5.R +++ b/tests/testthat/test_integration5.R @@ -95,7 +95,7 @@ test_that("IntegrateLayers works with CCAIntegration", { Embeddings(integrated[["integrated"]])[75, 45], 0.5442 ) - + integrated_sub <- suppressWarnings( IntegrateLayers( test.data.std, @@ -110,8 +110,28 @@ test_that("IntegrateLayers works with CCAIntegration", { dims.to.integrate = 1:10 ) ) - # check that dims.to.integrate is not being overwritten + # check that the integrated reduction has the specified number of + # `dims.to.integrate` expect_equal(ncol(integrated_sub[["integrated"]]), 10) + + integrated_overflow <- suppressWarnings( + IntegrateLayers( + test.data.std, + method = CCAIntegration, + orig.reduction = "pca", + new.reduction = "integrated", + verbose = FALSE, + # since `k.weight` must be less than the number of samples in the + # smallest layer being integrated, it must be set to accommodate the + # small dataset used for testing + k.weight = 10, + dims.to.integrate = 1:100 + ) + ) + # check that the integrated reduction is the same as you'd get if you + # didn't specify `dims.to.integrate` (i.e. the same size as the initial + # reduction) + expect_equal(Embeddings(integrated_overflow), Embeddings(integrated)) }) test_that("IntegrateLayers works with RPCAIntegration", { @@ -144,7 +164,9 @@ test_that("IntegrateLayers works with RPCAIntegration", { Embeddings(integrated[["integrated"]])[75, 45], 0.5442 ) - + + # check that the integrated reduction has the specified number of + # `dims.to.integrate` integrated_sub <- suppressWarnings( IntegrateLayers( test.data.std, @@ -161,6 +183,25 @@ test_that("IntegrateLayers works with RPCAIntegration", { ) # check that dims.to.integrate is not being overwritten expect_equal(ncol(integrated_sub[["integrated"]]), 10) + + integrated_overflow <- suppressWarnings( + IntegrateLayers( + test.data.std, + method = RPCAIntegration, + orig.reduction = "pca", + new.reduction = "integrated", + verbose = FALSE, + # since `k.weight` must be less than the number of samples in the + # smallest layer being integrated, it must be set to accommodate the + # small dataset used for testing + k.weight = 10, + dims.to.integrate = 1:100 + ) + ) + # check that the integrated reduction is the same as you'd get if you + # didn't specify `dims.to.integrate` (i.e. the same size as the initial + # reduction) + expect_equal(Embeddings(integrated_overflow), Embeddings(integrated)) }) test_that("IntegrateLayers works with JointPCAIntegration", { @@ -193,7 +234,8 @@ test_that("IntegrateLayers works with JointPCAIntegration", { Embeddings(integrated[["integrated"]])[75, 45], 0.5442 ) - + # check that the integrated reduction has the specified number of + # `dims.to.integrate` integrated_sub <- suppressWarnings( IntegrateLayers( test.data.std, @@ -210,6 +252,25 @@ test_that("IntegrateLayers works with JointPCAIntegration", { ) # check that dims.to.integrate is not being overwritten expect_equal(ncol(integrated_sub[["integrated"]]), 10) + + integrated_overflow <- suppressWarnings( + IntegrateLayers( + test.data.std, + method = JointPCAIntegration, + orig.reduction = "pca", + new.reduction = "integrated", + verbose = FALSE, + # since `k.weight` must be less than the number of samples in the + # smallest layer being integrated, it must be set to accommodate the + # small dataset used for testing + k.weight = 10, + dims.to.integrate = 1:100 + ) + ) + # check that the integrated reduction is the same as you'd get if you + # didn't specify `dims.to.integrate` (i.e. the same size as the initial + # reduction) + expect_equal(Embeddings(integrated_overflow), Embeddings(integrated)) }) test_that("IntegrateLayers fails when expected", { From d2a5c1dc4a16402328c0acef351b78c2e6e69eff Mon Sep 17 00:00:00 2001 From: David Collins Date: Thu, 19 Dec 2024 23:09:40 -0500 Subject: [PATCH 6/8] Ensure dims.to.integrate is updated if too large --- R/integration.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/integration.R b/R/integration.R index 39899bede..8ef4d47d1 100644 --- a/R/integration.R +++ b/R/integration.R @@ -6319,7 +6319,7 @@ ValidateParams_IntegrateEmbeddings_IntegrationAnchors <- function( warning("Max dims.to.integrate is larger than the number of dimensions in ", "the provided reduction. Setting dims.to.integrate to 1:", ncol(x = reductions), " and continuing.", immediate. = TRUE, call. = FALSE) - ModifyParam(param = 'dims.to.integrate', value = 1:ncol(x = reductions)) + dims.to.integrate <- 1:ncol(x = reductions) } ModifyParam(param = 'dims.to.integrate', value = dims.to.integrate) } From 62894809e7a415e500e74e4daeebbbd23702ed2a Mon Sep 17 00:00:00 2001 From: David Collins Date: Thu, 19 Dec 2024 23:13:59 -0500 Subject: [PATCH 7/8] Update changelog --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index e81712cd5..106d27ce6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # Unreleased ## Changes +- Fixed `IntegrateLayers` to respect the `dims.to.integrate` parameter. - Added `stroke.size` parameter to `DimPlot` ([#8180](https://github.com/satijalab/seurat/pull/8180)) - Updated `RunLeiden` to use the `leidenbase` package instead of `leiden`; deprecated the `method` parameter for `RunLeiden` and `FindClusters`; updated `RunLeiden` to reset `random.seed` to 1 if the value is 0 or less ([#6792](https://github.com/satijalab/seurat/pull/6792)) - Updated `RunUMAP` to support `umap-learn` version >= 0.5.0 ([#9559](https://github.com/satijalab/seurat/pull/9559)) From 1ae5263d430375e08b2696b949d7ab381c94b811 Mon Sep 17 00:00:00 2001 From: David Collins Date: Thu, 19 Dec 2024 23:15:24 -0500 Subject: [PATCH 8/8] Bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 907f1ea1f..eab97d73a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 5.1.0.9015 +Version: 5.1.0.9016 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. Authors@R: c(