Skip to content

Commit

Permalink
Merge pull request from satijalab/fix/dims_to_integrate
Browse files Browse the repository at this point in the history
Stop dims.to.integrate from being overwritten
  • Loading branch information
dcollins15 authored Dec 20, 2024
2 parents 0c2b035 + 1ae5263 commit 1c87c96
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 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: 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) <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.
Authors@R: c(
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
5 changes: 3 additions & 2 deletions R/integration.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -6319,8 +6319,9 @@ 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)
dims.to.integrate <- 1:ncol(x = reductions)
}
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")) {
Expand Down
112 changes: 112 additions & 0 deletions tests/testthat/test_integration5.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,43 @@ 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 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", {
Expand Down Expand Up @@ -127,6 +164,44 @@ 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,
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)

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", {
Expand Down Expand Up @@ -159,6 +234,43 @@ 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,
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)

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", {
Expand Down

0 comments on commit 1c87c96

Please sign in to comment.