Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Updates
- `ReadPNA_Seurat` now only loads a subset of the available meta data columns to avoid bloating the `meta.data` slot. Users can enable loading of detailed meta data by setting `detailed_meta_data = TRUE`.

### Fixes
- Fixed a bug in `ProximityScores.Seurat` that would (on some systems) throw an error when setting the connection to the lazy table of proximity scores.
- Fixed bug in `AnnotateCells` (method "nmf") where cells with 0 value prediction scores crashed the function. Such cells are now labeled as "Unknown".
Expand Down
10 changes: 10 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ globalVariables(
)


#' Default columns to pull from cell metadata table __adata__obs in PXL files
#'
#' @noRd
CELL_META_COLS <- c(
"n_umi", "n_edges", "n_antibodies", "isotype_fraction",
"average_k_core", "reads_in_component",
"n_umi1", "n_umi2", "sample"
)


#' Check global option for verbosity
#'
#' By setting the global option \code{options(pixelatorR.verbose = FALSE)},
Expand Down
9 changes: 9 additions & 0 deletions R/load_data_pna.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ ReadPNA_counts <- function(
#' be loaded into the \code{PNAAssay}/\code{PNAAssay5}. If you only intend to analyze
#' abundance data or PNA graphs, you can set this parameter to \code{FALSE} to use less
#' memory. This parameter only have an effect if \code{return_pna_assay = TRUE}.
#' @param detailed_meta_data Logical specifying whether to load detailed meta data.
#' If \code{FALSE} (default), only a subset of the meta data columns will be loaded,
#' including those used for quality control. The additional columns are mostly useful
#' for troubleshooting.
#' @param ... Additional parameters passed to \code{\link[SeuratObject]{CreateSeuratObject}}
#' @inheritParams ReadPNA_counts
#' @inheritParams ReadPNA_proximity
Expand All @@ -75,6 +79,7 @@ ReadPNA_Seurat <- function(
return_pna_assay = TRUE,
load_proximity_scores = TRUE,
calc_log2_ratio = TRUE,
detailed_meta_data = FALSE,
verbose = TRUE,
...
) {
Expand All @@ -86,6 +91,7 @@ ReadPNA_Seurat <- function(
assert_single_value(return_pna_assay, type = "bool")
assert_single_value(load_proximity_scores, type = "bool")
assert_single_value(calc_log2_ratio, type = "bool")
assert_single_value(detailed_meta_data, type = "bool")
assert_single_value(verbose, type = "bool")

# Setup connection to PXL file
Expand Down Expand Up @@ -158,6 +164,9 @@ ReadPNA_Seurat <- function(

# Extract meta data
meta_data <- db$cell_meta()
if (!detailed_meta_data) {
meta_data <- meta_data %>% select(any_of(CELL_META_COLS))
}
Comment thread
ludvigla marked this conversation as resolved.

if (!all(rownames(meta_data) == colnames(seur_obj))) {
cli::cli_abort(
Expand Down
6 changes: 6 additions & 0 deletions man/ReadPNA_Seurat.Rd

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

3 changes: 2 additions & 1 deletion tests/testthat/test-MoleculeRankPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pxl_file_mpx <- minimal_mpx_pxl_file()
seur_obj_mpx <- ReadMPX_Seurat(pxl_file_mpx)
pxl_file_pna <- minimal_pna_pxl_file()
seur_obj_pna <- ReadPNA_Seurat(pxl_file_pna)
seur_obj_pna$sample_id <- c("S1", "S1", "S2", "S2", "S3")

test_that("MoleculeRankPlot works for Seurat objects", {
expect_no_error({
Expand All @@ -17,7 +18,7 @@ test_that("MoleculeRankPlot works for Seurat objects", {
})
expect_s3_class(moleculerank_plot, "ggplot")
expect_no_error({
moleculerank_plot <- MoleculeRankPlot(seur_obj_pna, group_by = "tau_type")
moleculerank_plot <- MoleculeRankPlot(seur_obj_pna, group_by = "sample_id")
})
})

Expand Down
8 changes: 6 additions & 2 deletions tests/testthat/test-ReadPNA_Seurat.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ for (assay_version in c("v3", "v5")) {

expect_no_error(suppressWarnings(seur_obj <- ReadPNA_Seurat(pxl_file, return_pna_assay = FALSE, verbose = FALSE)))
expect_s4_class(seur_obj[["PNA"]], ifelse(assay_version == "v3", "Assay", "Assay5"))

# Including detailed meta data
expect_no_error(suppressWarnings(seur_obj_detailed_meta <- ReadPNA_Seurat(pxl_file, detailed_meta_data = TRUE, verbose = FALSE)))
expect_true(ncol(seur_obj_detailed_meta[[]]) > ncol(seur_obj[[]]))
})

test_that("ReadPNA_Seurat fails with invalid input", {
Expand All @@ -32,7 +36,7 @@ for (assay_version in c("v3", "v5")) {

test_that("ReadPNA_Seurat fails when X collapses to a vector (1 cell)", {
# Inject an error by subsetting X to have only one cell
trace(ReadPNA_Seurat, tracer = quote(X <- X[, 1]), at = 13, print = FALSE)
trace(ReadPNA_Seurat, tracer = quote(X <- X[, 1, drop = FALSE]), at = 14, print = FALSE)
on.exit(untrace(ReadPNA_Seurat), add = TRUE)

expect_error(
Expand All @@ -43,7 +47,7 @@ for (assay_version in c("v3", "v5")) {

test_that("ReadPNA_Seurat fails when X is a 1-column matrix", {
# Inject an error by subsetting X to have only one cell, keeping it as a matrix
trace(ReadPNA_Seurat, tracer = quote(X <- X[, 1, drop = FALSE]), at = 13, print = FALSE)
trace(ReadPNA_Seurat, tracer = quote(X <- X[, 1, drop = FALSE]), at = 14, print = FALSE)
on.exit(untrace(ReadPNA_Seurat), add = TRUE)

expect_error(
Expand Down
Loading