Skip to content

Commit

Permalink
Merge pull request #58 from TileDB-Inc/aaronwolen/fix-retrieval-of-da…
Browse files Browse the repository at this point in the history
…tasets-without-cell-identities

Improve handling of Seurat objects with empty cell identities
  • Loading branch information
aaronwolen authored May 20, 2022
2 parents 79995ed + 83e6151 commit bdf4fe2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Description: Store and retrieve single cell data using TileDB and the on-disk
format proposed in the Unified Single Cell Data Model and API. Users can
import from and export to in-memory formats used by popular toolchains like
Seurat and Bioconductor SingleCellExperiment.
Version: 0.1.1
Version: 0.1.2
Authors@R: c(
person(given = "Aaron",
family = "Wolen",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# tiledbsc 0.1.2

Improve handling of Seurat objects with empty cell identities (#58).

# tiledbsc 0.1.1

tiledbsc now uses the enhanced Group API's introduced in TileDB v2.8 and TileDB-R 0.12.0.
Expand Down
7 changes: 5 additions & 2 deletions R/SCDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ SCDataset <- R6::R6Class(
obs_df <- self$scgroups[[1]]$obs$to_dataframe()

# retain cell identities before restoring cell-level metadata
idents <- setNames(obs_df$active_ident, rownames(obs_df))
obs_df$active_ident <- NULL
idents <- obs_df$active_ident
if (!is.null(idents)) {
idents <- setNames(idents, rownames(obs_df))
obs_df$active_ident <- NULL
}

object <- SeuratObject::CreateSeuratObject(
counts = assays[[1]],
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test_SCDataset_Seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,19 @@ test_that("a dataset containing an assay with empty cells is fully retrieved", {
# Cannot add a different number of cells than already present
expect_silent(scdataset$to_seurat())
})

test_that("a dataset with empty cell identities is retrieved", {
uri <- withr::local_tempdir("empty-cell-identities")
assay_counts <- SeuratObject::CreateSeuratObject(
counts = GetAssayData(pbmc_small[["RNA"]])
)

# verify identities is unset
testthat::expect_length(nlevels(SeuratObject::Idents(assay_counts)), 1L)

scdataset <- SCDataset$new(uri, verbose = FALSE)
scdataset$from_seurat(assay_counts)

# Should not trigger error
expect_silent(scdataset$to_seurat())
})

0 comments on commit bdf4fe2

Please sign in to comment.