diff --git a/.Rbuildignore b/.Rbuildignore
index afdb8fc..ba8262a 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -1,4 +1,5 @@
^\.Rbuildignore$
+^LICENSE\.md$
^\.git$
^\.Rproj\.user$
^\.Rprofile$
diff --git a/DESCRIPTION b/DESCRIPTION
index f38a927..9d6672a 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,12 +1,13 @@
Package: MarchR
Type: Package
Title: Multi-Assay Multi-Dataset Disk-Backed Analysis
-Version: 0.3.0
+Version: 1.0.0
Authors@R: c(
person("Eric", "Liu", , "erliu1@stanford.edu", role = c("aut", "cre")),
person("Immanuel", "Abdi", , "iabdi@stanford.edu", role = c("aut")),
- person("Stanford University", role=c("cph", "fnd")))
-Date: 2026-10-26
+ person("MarchR Contributors", role = "cph"),
+ person("Stanford University", role = "fnd"))
+Date: 2026-12-02
Description: Multi-Assay Multi-Dataset Disk-Backed Analysis.
License: MIT + file LICENSE
Encoding: UTF-8
@@ -19,6 +20,8 @@ Imports:
BiocGenerics,
circlize,
ComplexHeatmap,
+ digest,
+ dplyr,
ggplot2,
igraph,
magrittr,
@@ -64,7 +67,6 @@ Suggests:
S4Vectors,
knitr,
rmarkdown,
- dplyr,
GenomicRanges,
IRanges,
Rsamtools,
diff --git a/NAMESPACE b/NAMESPACE
index efe6df3..c72287b 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -295,6 +295,7 @@ export(insert_dataset)
export(load_project)
export(make_knn_pseudobulks)
export(normalize_log)
+export(normalize_tfidf)
export(palette_continuous)
export(palette_discrete)
export(peak_annotation_enrichment)
@@ -320,7 +321,6 @@ export(project)
export(project_bulk_atac)
export(project_dim_reduction)
export(project_doublets)
-export(project_test)
export(pseudobulk_fragments)
export(qc_fragments)
export(qc_matrix)
@@ -353,6 +353,7 @@ export(subset_assays)
export(subset_cells)
export(subset_project)
export(theme_archr)
+export(validate_assay_alignment)
export(validate_cell_alignment)
export(write_pseudobulk_bigwig)
export(write_pseudobulk_chrom_sizes)
@@ -361,7 +362,6 @@ export(write_pseudobulk_fragments)
export(write_pseudobulk_manifest)
export(write_pseudobulk_peaks)
export(write_sce2g_inputs)
-exportPattern("^[[:alpha:]]+")
import(BPCells)
importFrom(Matrix,t)
importFrom(Rcpp,evalCpp)
diff --git a/NEWS.md b/NEWS.md
index 39656c2..29c4596 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,17 +1,18 @@
-# MarchR (development version)
+# MarchR 1.0.0 (Initial Beta Release)
## New features
* `save_project(copy = FALSE)` saves a lightweight checkpoint that points at stored data instead of copying it. Cell or feature subsets, fragment operations and lazy tile matrices are saved as recipes, and `load_project()` reports when it loads one.
-* `add_tile_matrix(materialize = FALSE)` keeps the tile matrix lazy: nothing is written, and every read recomputes it from fragments.
-* Printing a project marks assays that are computed when read.
+* `add_tile_matrix(materialize = FALSE)` Keeps tile matrix lazy. Reads recomputed from fragments.
+* Printing a project marks assays that are computed when read (lazy).
## Behavior changes
* `add_gene_score_matrix()` stores gene scores under the project directory instead of reading a temporary file.
* `save_project(copy = FALSE)` keeps the project's working directory, never deletes data when saving over a checkpoint, and still copies data stored in R's temporary directory, including UMAP models and linkage matrices.
-* `load_project()` errors when data referenced by a checkpoint no longer matches what was saved.
+* `load_project()` rejects changed dimensions or reordered or renamed matrix rows, matrix columns, fragment cells, and chromosomes in newly saved checkpoints.
* `add_tile_matrix()` errors on arguments it does not use instead of ignoring them.
+* Export only documented functions. Internal helpers such as the `assert_*()` checks, test fixtures, and Rcpp wrappers are no longer exported.
* The hematopoiesis and multiome tutorials keep the project under `cache_dir` instead of R's temporary directory.
* `plot_embedding()` and `plot_doublet_scores()` gain `legend_labels = "value"`, which labels the continuous color bar in data units instead of quantiles.
diff --git a/R/MarchR.R b/R/MarchR.R
index 2cec13c..ca239df 100644
--- a/R/MarchR.R
+++ b/R/MarchR.R
@@ -6,5 +6,4 @@
#' @importFrom Rcpp evalCpp
#' @importFrom Matrix t
#' @importFrom patchwork wrap_plots
-#' @exportPattern "^[[:alpha:]]+"
"_PACKAGE"
diff --git a/R/RcppExports.R b/R/RcppExports.R
index 633c512..2a63b8d 100644
--- a/R/RcppExports.R
+++ b/R/RcppExports.R
@@ -1,10 +1,6 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
-rcpp_hello_world <- function() {
- .Call(`_MarchR_rcpp_hello_world`)
-}
-
steady_clock_seconds_rcpp <- function() {
.Call(`_MarchR_steady_clock_seconds_rcpp`)
}
diff --git a/R/assays.R b/R/assays.R
index ff0695a..bff03ee 100644
--- a/R/assays.R
+++ b/R/assays.R
@@ -216,6 +216,7 @@ align_assays <- function(proj, assays = NULL) {
#' @param assays (character) Vector of assay names to check.
#' @return (list) A list with assay names as keys and boolean values
#' indicating whether the assays are aligned.
+#' @export
validate_assay_alignment <- function(proj, assays = NULL) {
assert_for(proj, "MarchRProject")
assert_for(assays, c("NULL", "character"))
diff --git a/R/coaccessibility.R b/R/coaccessibility.R
index 8ece2a8..2db9a12 100644
--- a/R/coaccessibility.R
+++ b/R/coaccessibility.R
@@ -72,6 +72,7 @@ add_co_accessibility.MarchRProject <- function(
if (is.null(proj$peak_set) || nrow(proj$peak_set) == 0) {
rlang::abort("Project has no peak set. Run add_reproducible_peak_set() first.")
}
+ assert_has_package(c("GenomicRanges", "IRanges", "S4Vectors"))
embedding_name <- select_embedding_name(proj, embedding_name)
dataset_names <- select_dataset_names(proj, dataset_names)
@@ -191,6 +192,7 @@ get_co_accessibility.MarchRProject <- function(proj, cor_cutoff = 0.5,
df <- proj$co_accessibility
df <- df[df$correlation >= cor_cutoff, , drop = FALSE]
if (!return_loops) return(df)
+ assert_has_package(c("GenomicRanges", "IRanges"))
peaks <- proj$peak_set
summit <- as.integer((peaks$start + peaks$end) / 2L)
diff --git a/R/dimensionality_reduction.R b/R/dimensionality_reduction.R
index 64f6379..5c55038 100644
--- a/R/dimensionality_reduction.R
+++ b/R/dimensionality_reduction.R
@@ -17,7 +17,7 @@ DimReduction <- function(
feature_names = character(0),
...
) {
- assertthat::assert_that(class(fitted_params) == "list")
+ assertthat::assert_that(inherits(fitted_params, "list"))
assert_for(feature_names, "character")
structure(
list(
@@ -1124,11 +1124,6 @@ project.LSI <- function(x, mat, threads = NULL, drop_zero_cells = TRUE, ...) {
return(res)
}
-#' @export
-project_test <- function(mat, ...) {
- t(mat)
-}
-
#' Run Iterative LSI on a matrix.
#'
@@ -1954,8 +1949,11 @@ IterativeLSI.MarchRProject <- function(
#' @param n_dimensions (integer) Number of principal components to compute. Default is 50.
#' Will be automatically limited based on matrix dimensions after feature selection.
#' @param overwrite (logical) Whether to overwrite existing results. Default is FALSE.
-#' @param threads (integer) Threads for normalization, feature selection, and the SVD. Default
-#' `get_threads()`. `project()` runs single-threaded by default.
+#' @param threads (integer) Maximum threads for normalization, default feature selection,
+#' and the SVD. Default `get_threads()`. PCA reduces the thread count for these
+#' steps when BPCells would split a small matrix into chunks with too few entries.
+#' Custom feature selectors receive the requested thread count.
+#' `project()` runs single-threaded by default.
#' @param verbose (logical) Print progress messages. Default \code{getOption("MarchR.verbose", FALSE)}.
#' @param mat (IterableMatrix) For \code{project.PCA}: New matrix to project into PCA space.
#' @param ... Additional arguments passed to methods.
@@ -2067,14 +2065,22 @@ PCA.default <- function(
# Adjust n_features to not exceed the number of available features
n_features <- min(nrow(x), n_features)
- # Log normalization
- # Use MarchR's normalize_log function which implements Seurat-style normalization
-
- x_norm <- normalize_log(x, scale_factor = scale_factor, threads = threads)
+ # shortcut: BPCells makes four chunks per thread. Cap threads until it handles
+ # empty chunks and the variance of one-column chunks safely.
+ chunks_per_thread <- 4L
+ row_major <- is(x, "IterableMatrix") && storage_order(x) == "row"
+ split_size <- if (row_major) nrow(x) else ncol(x)
+ norm_threads <- min(threads, max(1L, split_size %/% chunks_per_thread))
+ # Column-major row variances are merged across chunks, so each needs two cells.
+ # Row-major chunks contain whole features and need just one feature per chunk.
+ variance_threads <- if (row_major) norm_threads else {
+ min(threads, max(1L, split_size %/% (2L * chunks_per_thread)))
+ }
+ x_norm <- normalize_log(x, scale_factor = scale_factor, threads = norm_threads)
# Variable gene selection
# Calculate statistics for normalization
- stats <- BPCells::matrix_stats(x_norm, row_stats = "variance")
+ stats <- BPCells::matrix_stats(x_norm, row_stats = "variance", threads = variance_threads)
mean_stats <- stats$row_stats['mean', ]
var_stats <- stats$row_stats['variance', ]
@@ -2084,7 +2090,7 @@ PCA.default <- function(
feature_selection_result <- feature_selection_method(
x_norm,
num_feats = n_features,
- threads = threads
+ threads = if (identical(feature_selection_method, select_features_variance)) variance_threads else threads
)
variable_features <- which(feature_selection_result$highly_variable)
} else {
@@ -2145,7 +2151,10 @@ PCA.default <- function(
)
}
- svd_result <- BPCells::svds(x_norm, k = n_dimensions, threads = threads)
+ # Feature selection can shrink the split axis of a row-major matrix.
+ split_size <- if (storage_order(x_norm) == "row") nrow(x_norm) else ncol(x_norm)
+ svd_threads <- min(threads, max(1L, split_size %/% chunks_per_thread))
+ svd_result <- BPCells::svds(x_norm, k = n_dimensions, threads = svd_threads)
if (verbose) .log_step(paste("Fit PCA on", .log_plural(ncol(x), "cell")), since = t0)
# Create PC embeddings (cells x PCs)
diff --git a/R/enrichment.R b/R/enrichment.R
index 2ebfc19..a03946f 100644
--- a/R/enrichment.R
+++ b/R/enrichment.R
@@ -653,6 +653,7 @@ custom_enrichment.MarchRProject <- function(
background <- match.arg(background)
matches <- get_matches(proj, peak_annotation)
+ assert_has_package(c("GenomicRanges", "IRanges", "S4Vectors"))
peak_gr <- .peak_set_to_granges(proj$peak_set)
hits <- GenomicRanges::findOverlaps(peak_gr, ranges, ignore.strand = TRUE)
fg_idx <- unique(S4Vectors::queryHits(hits))
diff --git a/R/feature_selection.R b/R/feature_selection.R
index 2f539a2..51deee0 100644
--- a/R/feature_selection.R
+++ b/R/feature_selection.R
@@ -109,9 +109,6 @@ select_features_variance.default <- function(
normalize_method = NULL,
threads = 1L
) {
- if (rlang::is_missing(mat)) {
- return(create_partial())
- }
prepared <- .prepare_feature_selection(mat, num_feats, threads, normalize_method)
mat <- prepared$mat
num_feats <- prepared$num_feats
@@ -165,9 +162,6 @@ select_features_dispersion.default <- function(
normalize_method = NULL,
threads = 1L
) {
- if (rlang::is_missing(mat)) {
- return(create_partial())
- }
prepared <- .prepare_feature_selection(mat, num_feats, threads, normalize_method)
mat <- prepared$mat
num_feats <- prepared$num_feats
@@ -217,9 +211,6 @@ select_features_mean.default <- function(
normalize_method = NULL,
threads = 1L
) {
- if (rlang::is_missing(mat)) {
- return(create_partial())
- }
prepared <- .prepare_feature_selection(mat, num_feats, threads, normalize_method)
mat <- prepared$mat
num_feats <- prepared$num_feats
@@ -285,9 +276,6 @@ select_features_binned_dispersion.default <- function(
assert_is_wholenumber(n_bins)
assert_len(n_bins, 1)
assert_greater_than_zero(n_bins)
- if (rlang::is_missing(mat)) {
- return(create_partial())
- }
prepared <- .prepare_feature_selection(mat, num_feats, threads)
mat <- prepared$mat
num_feats <- prepared$num_feats
@@ -390,9 +378,6 @@ select_features_top.default <- function(
assert_greater_than_zero(filter_top_features)
assert_is_wholenumber(filter_top_features)
}
- if (rlang::is_missing(mat)) {
- return(create_partial())
- }
assert_is_mat(mat)
# Support fractional num_feats (e.g. 0.5 = 50% of features)
diff --git a/R/footprinting.R b/R/footprinting.R
index 3597e5e..35558b3 100644
--- a/R/footprinting.R
+++ b/R/footprinting.R
@@ -360,6 +360,7 @@ get_footprints.MarchRProject <- function(
if (!is.null(peak_annotation)) {
positions <- get_positions(proj, peak_annotation)
}
+ assert_has_package(c("GenomicRanges", "S4Vectors", "SummarizedExperiment"))
if (!methods::is(positions, "GRangesList")) {
positions <- as(positions, "GRangesList")
}
diff --git a/R/fragments.R b/R/fragments.R
index 98723bf..2be1f5d 100644
--- a/R/fragments.R
+++ b/R/fragments.R
@@ -412,7 +412,7 @@ add_fragments.MarchRDataset <- function(
# Validate data
assert_for(frags, "IterableFragments")
assertthat::assert_that(
- (is(frags_name, "character")) && length(frags_name == 1)
+ (is(frags_name, "character")) && length(frags_name) == 1
)
# Add fragments to the dataset
proj$fragments[[frags_name]] <- frags
diff --git a/R/peak2gene.R b/R/peak2gene.R
index 470c6c6..ee8f217 100644
--- a/R/peak2gene.R
+++ b/R/peak2gene.R
@@ -165,6 +165,7 @@ add_peak2gene_links.MarchRProject <- function(
if (is.null(genes) || nrow(genes) == 0) {
rlang::abort("Project has no gene annotations. Run set_gene_annotations() first.")
}
+ assert_has_package(c("GenomicRanges", "IRanges", "S4Vectors"))
embedding_name <- select_embedding_name(proj, embedding_name)
dataset_names <- select_dataset_names(proj, dataset_names)
@@ -386,6 +387,7 @@ get_peak2gene_links.MarchRProject <- function(proj, cor_cutoff = 0.45, fdr_cutof
keep <- keep & df$FDR <= fdr_cutoff & df$VarQATAC > var_cutoff_atac & df$VarQRNA > var_cutoff_rna
df <- df[keep, , drop = FALSE]
if (!return_loops) return(df)
+ assert_has_package(c("GenomicRanges", "IRanges"))
peaks <- proj$peak_set
summit <- as.integer((peaks$start + peaks$end) / 2L)
diff --git a/R/peaks.R b/R/peaks.R
index e8df49d..1364027 100644
--- a/R/peaks.R
+++ b/R/peaks.R
@@ -1237,6 +1237,7 @@ add_peak_annotations.MarchRProject <- function(
))
}
+ assert_has_package(c("GenomicRanges", "IRanges", "S4Vectors"))
region_grl <- .coerce_to_grangeslist(regions)
peak_gr <- .peak_set_to_granges(proj$peak_set)
diff --git a/R/save_load.R b/R/save_load.R
index d83ba26..8a17970 100644
--- a/R/save_load.R
+++ b/R/save_load.R
@@ -25,13 +25,18 @@ new_ondisk_ref <- function(kind, path, relative, ...) {
.path_relative_to(path, root) %||% normalizePath(path, mustWork = FALSE)
}
-.ref_to <- function(kind, dir, root, ...) {
+.ref_names_hash <- function(obj, kind) {
+ keys <- if (kind == "matrix") dimnames(obj) else list(cellNames(obj), chrNames(obj))
+ digest::digest(keys, algo = "xxhash64", serializeVersion = 2L)
+}
+
+.ref_to <- function(kind, dir, root, obj, check_names = TRUE) {
rel <- .path_relative_to(dir, root)
- if (is.null(rel)) {
- new_ondisk_ref(kind, normalizePath(dir, mustWork = FALSE), FALSE, ...)
- } else {
- new_ondisk_ref(kind, rel, TRUE, ...)
- }
+ new_ondisk_ref(
+ kind, rel %||% normalizePath(dir, mustWork = FALSE), !is.null(rel),
+ dim = if (kind == "matrix") dim(obj),
+ names_hash = if (check_names) .ref_names_hash(obj, kind)
+ )
}
.session_temp_dir <- function() normalizePath(tempdir(), mustWork = FALSE)
@@ -160,11 +165,11 @@ new_ondisk_ref <- function(kind, path, relative, ...) {
} else if (kind == "matrix" && length(sel) > 0) {
new_ondisk_ref(
"matrix", NA_character_, NA,
- subset_of = .ref_to("matrix", dirs, root, dim = dim(leaf)),
+ subset_of = .ref_to("matrix", dirs, root, leaf),
rows = sel$rows, cols = sel$cols
)
} else {
- .ref_to(kind, dirs, root, dim = if (kind == "matrix") dim(obj))
+ .ref_to(kind, dirs, root, obj)
}
dirs <- normalizePath(dirs, mustWork = FALSE)
inside <- !vapply(lapply(dirs, .path_relative_to, root = root), is.null, logical(1))
@@ -200,7 +205,7 @@ new_ondisk_ref <- function(kind, path, relative, ...) {
rlib_message_verbosity = "quiet"
)
}
- ref <- .ref_to(kind, target_norm, root, dim = if (kind == "matrix") dim(handle))
+ ref <- .ref_to(kind, target_norm, root, handle, check_names = !copy)
list(ref = ref, handle = handle, kept = target_norm, external = character(0))
}
@@ -307,10 +312,13 @@ new_ondisk_ref <- function(kind, path, relative, ...) {
acc$missing <- c(acc$missing, dir)
return(ref)
}
- if (identical(ref$kind, "fragments")) return(open_fragments_dir(dir))
- mat <- open_matrix_dir(dir)
- if (!is.null(ref$dim) && !all(dim(mat) == ref$dim)) acc$changed <- c(acc$changed, dir)
- mat
+ obj <- if (ref$kind == "fragments") open_fragments_dir(dir) else open_matrix_dir(dir)
+ if ((!is.null(ref$dim) && !all(dim(obj) == ref$dim)) ||
+ (!is.null(ref$names_hash) && !identical(.ref_names_hash(obj, ref$kind), ref$names_hash))) {
+ acc$changed <- c(acc$changed, dir)
+ return(ref)
+ }
+ obj
}
# Reopen every ref in `x`; record missing dirs in `acc$missing` and mismatches in `acc$changed`.
@@ -507,10 +515,14 @@ new_ondisk_ref <- function(kind, path, relative, ...) {
#' @return (invisibly) The input \code{MarchRProject}. With \code{copy = TRUE}, its \code{dir} is
#' set to \code{path} and its matrices and fragments read from the copies.
#' @details
-#' A checkpoint (\code{copy = FALSE}) reads stored data where it lives, so rerunning a step that
-#' overwrites that data changes what the checkpoint loads; \code{load_project()} errors if the
-#' dimensions or cell names no longer match. Data it cannot reference, such as data in R's
-#' temporary directory, is written into \code{path}.
+#' A checkpoint (\code{copy = FALSE}) reads stored data where it lives. For newly saved
+#' checkpoints, \code{load_project()} checks matrix dimensions and the names and order of
+#' matrix rows and columns, fragment cells, and chromosomes. Rewrites that preserve these
+#' can still change the data the checkpoint reads. Data it cannot reference, such as data in
+#' R's temporary directory, is written into \code{path}.
+#'
+#' An interrupted or failed save with \code{overwrite = TRUE} can leave the previous
+#' save partially updated. Save to a new directory to preserve the previous save.
#' @export
save_project <- function(project, ...) UseMethod("save_project")
diff --git a/R/selections.R b/R/selections.R
index 7980097..efc78c7 100644
--- a/R/selections.R
+++ b/R/selections.R
@@ -6,6 +6,9 @@
#' @param proj (MarchRDataset, MarchRProject) The project/dataset to subset.
#' @param cell_subset (character vector; logical vector; numeric vector) A subset of cells to keep in the matrices. Requires that
#' the matrices are cell aligned if provided.
+#' For a project with `by_dataset = FALSE`, a logical vector must contain one
+#' non-missing value per cell, and numeric indices must be positive whole numbers
+#' within the total number of cells.
#' @param subset_fragments (logical) If TRUE, subset fragments to only include the cells in `cell_subset`.
#' @param values_only (logical) If TRUE, return the matrices concatenated together.
#' @export
@@ -156,6 +159,9 @@ subset_cells.MarchRProject <- function(
#' @param feature_subset (character vector; logical vector; numeric vector; list) If `by_assay` is TRUE,
#' which matrices to keep in the object. If `by_assay` is FALSE, a subset of features to keep in the matrices.
#' If a list, each element should be a character vector of features to keep for each matrix, named by the assay.
+#' With `by_assay = FALSE`, a single logical vector must contain one non-missing
+#' value per feature across the matrices in each dataset. Numeric indices in a
+#' single vector must be positive whole numbers within that feature count.
#' @param by_assay (logical) If TRUE, subset rows by matrix name. If FALSE, subset by feature name.
#' @param values_only (logical) If TRUE, return the matrices concatenated together.
#' @name subset_assays
diff --git a/R/transforms.R b/R/transforms.R
index d1e6533..4670e8c 100644
--- a/R/transforms.R
+++ b/R/transforms.R
@@ -312,6 +312,7 @@ normalize_log.MarchRProject <- function(
#' normalize_tfidf(mat, lsi_method = 1, scale_factpr = 1e4)
#'
#' @noRd
+#' @export
normalize_tfidf <- function(
x,
feature_means = NULL,
diff --git a/R/utils.R b/R/utils.R
index 919f34d..a2b7972 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -351,7 +351,7 @@ assert_has_package <- function(packages, n = 1) {
if (length(missing) > 0) {
stop(
sprintf("Missing required package(s): %s", toString(missing)),
- .call = FALSE
+ call. = FALSE
)
}
}
diff --git a/README.md b/README.md
index c291eee..fc49003 100644
--- a/README.md
+++ b/README.md
@@ -9,117 +9,89 @@
MarchR is an R package for analyzing large-scale multi-omics datasets with disk-backed storage, built on top of [BPCells](https://github.com/bnprks/BPCells), and feature-rich [ArchR](https://github.com/GreenleafLab/ArchR) functionality. It provides object-oriented interfaces for managing genomic datasets containing matrices (gene expression, ATAC-seq), fragments (ATAC-seq), and associated metadata.
-> **Alpha release.** MarchR is under active development. The API is
-> experimental and may change without a deprecation cycle. Pin a release
-> tag rather than tracking `main`, and please report issues.
+> **Public Beta.** MarchR is under active development and the API may change.
+> Install a tagged release for reproducible analyses.
-### Features
+

+
-### Installation
+## Installation
-#### Requirements
+### Requirements
-- R >= 4.4.0
-- A C++20-capable compiler (MarchR compiles C++ via Rcpp). On Linux use
- GCC >= 10 or Clang >= 11; on macOS install the Xcode command-line tools.
-- The HDF5 C library, required by [BPCells](https://github.com/bnprks/BPCells):
- ```sh
- # Debian/Ubuntu
- sudo apt install libhdf5-dev
+MarchR requires **R>=4.4.0**, a **C++20 compiler**, and the **HDF5 C library** for BPCells.
- # macOS
- brew install hdf5
- ```
+On Debian or Ubuntu, install the build tools and libraries needed to build
+MarchR and its R dependencies from source.
+```sh
+sudo apt update
+sudo apt install build-essential gfortran pkg-config \
+ libhdf5-dev libcurl4-openssl-dev libpng-dev
+```
-#### Install MarchR
-
-Once the system requirements are available, install MarchR from R:
+On macOS, install the Xcode Command Line Tools and HDF5 via Homebrew.
+On Apple Silicon, use arm64 builds of R and HDF5.
+[BPCells installation guide](https://bnprks.github.io/BPCells/)
-```r
-install.packages(
- c("BiocManager", "remotes"),
- repos = "https://cloud.r-project.org"
-)
-options(repos = BiocManager::repositories())
+```sh
+xcode-select --install
+brew install hdf5
+```
-# Alpha build currently requires BPCells main branch
-remotes::install_github("bnprks/BPCells/r")
+### Install MarchR
-# Installs MarchR and the packages required by the tutorial.
-install.packages("uwot") # Upgraded needed for v0.2.0 --> v0.3.0
-remotes::install_github("GreenleafLab/MarchR@v0.3.0", upgrade = "never")
+In R, install the beta release and its required packages. `pak` installs
+BPCells from GitHub and resolves the minimum versions declared by MarchR,
+including `uwot` 0.2.5 or later.
-# For Alpha-users, you may need to clone this repo and install locally:
-# git clone https://github.com/GreenleafLab/MarchR.git ~/software/MarchR
-# git -C ~/software/MarchR fetch --tags && git -C ~/software/MarchR checkout v0.3.0
-remotes::install_local("~/software/MarchR", upgrade = "never")
+```r
+install.packages("pak", repos = "https://cloud.r-project.org")
+pak::pkg_install("GreenleafLab/MarchR@v1.0.0")
+```
-# Replace CRAN igraph with development build, which fixes a memory overflow
-# in cluster_graph_leiden() on large datasets (igraph PR #2627, not yet on CRAN)
-install.packages("igraph", repos = "https://igraph.r-universe.dev")
-packageVersion("igraph") # Should be 2.3.3.9040 or later
+Open a fresh R session to check that MarchR loads and can create a project.
+```r
library(MarchR)
packageVersion("MarchR")
+MarchRProject()
```
-The required tutorial stack includes `uwot`, `RcppHNSW`, `RcppAnnoy`,
-`igraph`, `Seurat`, `MASS`, `patchwork`, `circlize`, and
-`ComplexHeatmap`. Installation may take several minutes when packages need to
-be compiled.
-
-
-Depending on your Linux/Ubuntu installation, you may not have certain required libraries. Run the following:
-```
-sudo apt update
-sudo apt install -y \
- r-base r-base-dev build-essential git \
- libhdf5-dev libcurl4-openssl-dev libssl-dev libxml2-dev \
- libfontconfig1-dev libfreetype6-dev libharfbuzz-dev libfribidi-dev \
- libpng-dev libtiff-dev libjpeg-dev
-```
-
-Afterward, run the R installation commands above.
-#### Optional dependencies
+### Optional dependencies
-The packages below support analyses outside the hematopoiesis tutorial and are loaded only when those features are used. Install the groups you need.
-
-From CRAN:
+Install the packages for the workflows you use.
```r
-install.packages(c(
+pak::pkg_install(c(
"harmony", # batch correction / integration
+ "Seurat", # RNA integration
"Rtsne", # t-SNE embeddings
- "scattermore", # fast embedding scatter plots
- "ggrepel", # non-overlapping plot labels
- "ggseqlogo", # motif sequence logos (plot_motif_logo)
- "dplyr", "tidyr"
+ "ggseqlogo" # motif sequence logos (plot_motif_logo)
))
```
-From Bioconductor:
+Genomic ranges, motif analysis, and export packages are available from Bioconductor.
```r
-# install.packages("BiocManager")
-BiocManager::install(c(
+pak::pkg_install(c(
"chromVAR", "motifmatchr", # TF motif deviations & matching
"TFBSTools", "JASPAR2020", # motif databases
"BSgenome", "Biostrings", # genome sequence access
- "BSgenome.Hsapiens.UCSC.hg19", # hg19 reference (swap for your genome)
+ "BSgenome.Hsapiens.UCSC.hg19", # use the reference for your genome assembly
"GenomicRanges", "IRanges",
- "SummarizedExperiment", "S4Vectors"
+ "SummarizedExperiment", "S4Vectors",
+ "Rsamtools" # bgzip and Tabix export
))
```
-From GitHub:
+Install curated motif sets from GitHub for motif enrichment or chromVAR.
```r
-# Curated motif sets used by motif enrichment / chromVAR
-remotes::install_github("GreenleafLab/chromVARmotifs")
+pak::pkg_install("GreenleafLab/chromVARmotifs")
```
#### External tools
@@ -128,11 +100,20 @@ remotes::install_github("GreenleafLab/chromVARmotifs")
(MACS3 preferred, MACS2 supported) on your `PATH`. Install via
`pip install macs3`.
+#### Troubleshooting large Leiden graphs
+
+If Leiden clustering with igraph 2.3.4 fails with a memory allocation error
+on a large dataset, install igraph 2.2.2 and restart R before loading MarchR.
+[Upstream igraph fix](https://github.com/igraph/rigraph/pull/2627)
+
+```r
+pak::pkg_install("igraph@2.2.2")
+```
+
#### Development setup
-To work on MarchR from a local clone, `package_setup_script.R` bootstraps a
-development environment. Install the system requirements for your platform,
-clone the repository, and from its root run:
+To work on MarchR from a local clone, install the system requirements and run
+the setup script from the repository root.
```r
source("package_setup_script.R")
@@ -148,12 +129,12 @@ MarchR is built around three main classes:
### Documentation
-- [Getting Started Tutorial](vignettes/marchr_hematopoiesis.html) -
- Hematopoiesis scATAC-seq workflow
-- [Function documentation](man/) (**WIP**)
-- [GitHub Repository](https://github.com/GreenleafLab/MarchR)
+- [Hematopoiesis tutorial](vignettes/marchr_hematopoiesis.Rmd) for a first scATAC-seq analysis
+- [Multiome tutorial](vignettes/marchr_multiome.Rmd) for joint ATAC and RNA analysis (work in progress)
+- [Function documentation](man/)
+- [Release notes](NEWS.md)
-Until the pkgdown site is published, developers can build and preview the rendered tutorial and function reference locally:
+Developers can build and preview the rendered tutorials and function reference locally.
```r
install.packages("pkgdown")
@@ -163,11 +144,17 @@ pkgdown::preview_site()
The first tutorial build downloads the hematopoiesis fragment files and runs the complete analysis.
+### Feedback
+
+Report beta bugs and installation problems on GitHub. Include the command that
+failed, the full error, and the output of `sessionInfo()`.
+[MarchR issues](https://github.com/GreenleafLab/MarchR/issues)
+
### Citation
If you use MarchR in your research, please cite:
```
Liu E, Abdi I. (2026). MarchR: Multi-Assay Multi-Dataset Disk-Backed Analysis.
-R package version 0.3.0. https://github.com/GreenleafLab/MarchR
+R package version 1.0.0. https://github.com/GreenleafLab/MarchR
```
diff --git a/man/MarchR.Rd b/man/MarchR.Rd
index bb4cc9c..fccec23 100644
--- a/man/MarchR.Rd
+++ b/man/MarchR.Rd
@@ -18,7 +18,8 @@ Authors:
Other contributors:
\itemize{
- \item Stanford University [copyright holder, funder]
+ \item MarchR Contributors [copyright holder]
+ \item Stanford University [funder]
}
}
diff --git a/man/PCA.Rd b/man/PCA.Rd
index 739f716..6c19985 100644
--- a/man/PCA.Rd
+++ b/man/PCA.Rd
@@ -49,8 +49,11 @@ Will be automatically limited to the number of available features in the matrix.
\item{n_dimensions}{(integer) Number of principal components to compute. Default is 50.
Will be automatically limited based on matrix dimensions after feature selection.}
-\item{threads}{(integer) Threads for normalization, feature selection, and the SVD. Default
-\code{get_threads()}. \code{project()} runs single-threaded by default.}
+\item{threads}{(integer) Maximum threads for normalization, default feature selection,
+and the SVD. Default \code{get_threads()}. PCA reduces the thread count for these
+steps when BPCells would split a small matrix into chunks with too few entries.
+Custom feature selectors receive the requested thread count.
+\code{project()} runs single-threaded by default.}
\item{verbose}{(logical) Print progress messages. Default \code{getOption("MarchR.verbose", FALSE)}.}
diff --git a/man/save_project.Rd b/man/save_project.Rd
index 6ab4795..231c568 100644
--- a/man/save_project.Rd
+++ b/man/save_project.Rd
@@ -31,8 +31,12 @@ set to \code{path} and its matrices and fragments read from the copies.
Save a MarchRProject to a directory
}
\details{
-A checkpoint (\code{copy = FALSE}) reads stored data where it lives, so rerunning a step that
-overwrites that data changes what the checkpoint loads; \code{load_project()} errors if the
-dimensions or cell names no longer match. Data it cannot reference, such as data in R's
-temporary directory, is written into \code{path}.
+A checkpoint (\code{copy = FALSE}) reads stored data where it lives. For newly saved
+checkpoints, \code{load_project()} checks matrix dimensions and the names and order of
+matrix rows and columns, fragment cells, and chromosomes. Rewrites that preserve these
+can still change the data the checkpoint reads. Data it cannot reference, such as data in
+R's temporary directory, is written into \code{path}.
+
+An interrupted or failed save with \code{overwrite = TRUE} can leave the previous
+save partially updated. Save to a new directory to preserve the previous save.
}
diff --git a/man/subset_assays.Rd b/man/subset_assays.Rd
index 9bd33a8..e2e24ad 100644
--- a/man/subset_assays.Rd
+++ b/man/subset_assays.Rd
@@ -15,7 +15,10 @@
\item{feature_subset}{(character vector; logical vector; numeric vector; list) If \code{by_assay} is TRUE,
which matrices to keep in the object. If \code{by_assay} is FALSE, a subset of features to keep in the matrices.
-If a list, each element should be a character vector of features to keep for each matrix, named by the assay.}
+If a list, each element should be a character vector of features to keep for each matrix, named by the assay.
+With \code{by_assay = FALSE}, a single logical vector must contain one non-missing
+value per feature across the matrices in each dataset. Numeric indices in a
+single vector must be positive whole numbers within that feature count.}
\item{by_assay}{(logical) If TRUE, subset rows by matrix name. If FALSE, subset by feature name.}
diff --git a/man/subset_cells.Rd b/man/subset_cells.Rd
index 1ca38f3..2e720c8 100644
--- a/man/subset_cells.Rd
+++ b/man/subset_cells.Rd
@@ -10,7 +10,10 @@ subset_cells(proj, ...)
\item{proj}{(MarchRDataset, MarchRProject) The project/dataset to subset.}
\item{cell_subset}{(character vector; logical vector; numeric vector) A subset of cells to keep in the matrices. Requires that
-the matrices are cell aligned if provided.}
+the matrices are cell aligned if provided.
+For a project with \code{by_dataset = FALSE}, a logical vector must contain one
+non-missing value per cell, and numeric indices must be positive whole numbers
+within the total number of cells.}
\item{subset_fragments}{(logical) If TRUE, subset fragments to only include the cells in \code{cell_subset}.}
diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp
index a3b5de7..34598fd 100644
--- a/src/RcppExports.cpp
+++ b/src/RcppExports.cpp
@@ -10,16 +10,6 @@ Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif
-// rcpp_hello_world
-List rcpp_hello_world();
-RcppExport SEXP _MarchR_rcpp_hello_world() {
-BEGIN_RCPP
- Rcpp::RObject rcpp_result_gen;
- Rcpp::RNGScope rcpp_rngScope_gen;
- rcpp_result_gen = Rcpp::wrap(rcpp_hello_world());
- return rcpp_result_gen;
-END_RCPP
-}
// steady_clock_seconds_rcpp
double steady_clock_seconds_rcpp();
RcppExport SEXP _MarchR_steady_clock_seconds_rcpp() {
@@ -43,12 +33,12 @@ BEGIN_RCPP
END_RCPP
}
// get_subset_from_integer_selection_rcpp
-List get_subset_from_integer_selection_rcpp(const IntegerVector& selection, const IntegerVector& dimension_sums);
+List get_subset_from_integer_selection_rcpp(const NumericVector& selection, const IntegerVector& dimension_sums);
RcppExport SEXP _MarchR_get_subset_from_integer_selection_rcpp(SEXP selectionSEXP, SEXP dimension_sumsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
- Rcpp::traits::input_parameter< const IntegerVector& >::type selection(selectionSEXP);
+ Rcpp::traits::input_parameter< const NumericVector& >::type selection(selectionSEXP);
Rcpp::traits::input_parameter< const IntegerVector& >::type dimension_sums(dimension_sumsSEXP);
rcpp_result_gen = Rcpp::wrap(get_subset_from_integer_selection_rcpp(selection, dimension_sums));
return rcpp_result_gen;
@@ -68,7 +58,6 @@ END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
- {"_MarchR_rcpp_hello_world", (DL_FUNC) &_MarchR_rcpp_hello_world, 0},
{"_MarchR_steady_clock_seconds_rcpp", (DL_FUNC) &_MarchR_steady_clock_seconds_rcpp, 0},
{"_MarchR_get_subset_from_logical_selection_rcpp", (DL_FUNC) &_MarchR_get_subset_from_logical_selection_rcpp, 2},
{"_MarchR_get_subset_from_integer_selection_rcpp", (DL_FUNC) &_MarchR_get_subset_from_integer_selection_rcpp, 2},
diff --git a/src/cpp/selections/selection_masks.cpp b/src/cpp/selections/selection_masks.cpp
index 16aa466..5716100 100644
--- a/src/cpp/selections/selection_masks.cpp
+++ b/src/cpp/selections/selection_masks.cpp
@@ -62,7 +62,7 @@ std::unordered_map> subset_kernel_logical(
// @return An unordered map mapping matrix names to integer vectors representing
// selection masks.
std::map> subset_kernel_integer(
- std::span selection, std::span dims,
+ std::span selection, std::span dims,
std::span names, std::vector& names_order
) {
std::map> res;
@@ -93,7 +93,7 @@ std::map> subset_kernel_integer(
std::sort(sorted_selection.begin(), sorted_selection.end());
// holds the current integer selection
- auto selection_idx = 0u;
+ std::size_t selection_idx = 0;
// int offset = 0;
std::unordered_map selection_to_bin;
// hold a mapping from selection to bin
diff --git a/src/rcpp_utils.cpp b/src/rcpp_utils.cpp
deleted file mode 100644
index e69de29..0000000
diff --git a/src/selections.cpp b/src/selections.cpp
index 4ca55c6..5d4e059 100644
--- a/src/selections.cpp
+++ b/src/selections.cpp
@@ -1,5 +1,8 @@
#include
#include
+#include
+#include
+#include
#include
#include "cpp/selections/selection_masks.cpp"
using namespace Rcpp;
@@ -14,15 +17,19 @@ make_cptr_array(const Rcpp::CharacterVector &cv)
return out;
}
-
-// [[Rcpp::export]]
-List rcpp_hello_world() {
- CharacterVector x = CharacterVector::create("foo", "bar");
- NumericVector y = NumericVector::create(0.0, 1.0);
- List z = List::create(x, y);
- return z;
+static std::uint64_t selection_size(const IntegerVector &dimension_sums) {
+ if (dimension_sums.size() > 0 && !dimension_sums.hasAttribute("names")) {
+ stop("Selection dimensions must be named.");
+ }
+ std::uint64_t total = 0;
+ for (int dim : dimension_sums) {
+ if (dim < 0) stop("Selection dimensions must be non-negative and cannot contain NA.");
+ total += dim;
+ }
+ return total;
}
+
// Seconds on a monotonic clock, so log durations never go negative when the wall clock is stepped.
// [[Rcpp::export]]
double steady_clock_seconds_rcpp() {
@@ -39,17 +46,19 @@ double steady_clock_seconds_rcpp() {
// [[Rcpp::export]]
List get_subset_from_logical_selection_rcpp(
const LogicalVector &selection, const IntegerVector &dimension_sums) {
- // view over the flattened logical mask
+ if (selection_size(dimension_sums) != static_cast(selection.size())) {
+ stop("Logical selection must contain exactly one value per cell or feature.");
+ }
+ if (selection.size() == 0) return List::create();
std::span sel(LOGICAL(selection), selection.size());
+ if (std::find(sel.begin(), sel.end(), NA_LOGICAL) != sel.end()) {
+ stop("Logical selection cannot contain NA.");
+ }
// view over the dimension-count buffer
std::span dims(dimension_sums.begin(), dimension_sums.size());
std::vector name_ptr = make_cptr_array(dimension_sums.names());
std::span names(name_ptr);
- // make sure that the number of logicals match the number of feature
- if (std::accumulate(dimension_sums.begin(), dimension_sums.end(), 0u) != sel.size()) {
- Rcerr << "Length of feature selection does not match total features";
- }
std::vector names_order;
auto matrix_map = subset_kernel_logical(sel, dims, names, names_order);
// output list that will receive per-matrix masks
@@ -65,11 +74,20 @@ List get_subset_from_logical_selection_rcpp(
return out;
}
-// [[Rcpp::export]]
+// [[Rcpp::export]]
List get_subset_from_integer_selection_rcpp(
- const IntegerVector &selection, const IntegerVector &dimension_sums) {
- // Numeric vectors are held internally as doubles, create internal representation as ints
- std::span sel(selection.begin(), selection.size());
+ const NumericVector &selection, const IntegerVector &dimension_sums) {
+ if (selection.size() == 0) return List::create();
+ const auto total = selection_size(dimension_sums);
+ if (total > std::numeric_limits::max()) {
+ stop("Too many cells or features for numeric selection. Select by name instead.");
+ }
+ for (double index : selection) {
+ if (!std::isfinite(index) || index < 1 || index > total || index != std::trunc(index)) {
+ stop("Numeric selection must contain whole-number indices between 1 and the total number of cells or features.");
+ }
+ }
+ std::span sel(selection.begin(), selection.size());
// view over the dimension-count buffer
std::span dims(dimension_sums.begin(), dimension_sums.size());
std::vector name_ptr = make_cptr_array(dimension_sums.names());
@@ -112,4 +130,4 @@ List get_subset_from_character_selection_rcpp(
}
}
return out;
-}
\ No newline at end of file
+}
diff --git a/tests/testthat/test-dimensionality_reduction.R b/tests/testthat/test-dimensionality_reduction.R
index d003036..6f93699 100644
--- a/tests/testthat/test-dimensionality_reduction.R
+++ b/tests/testthat/test-dimensionality_reduction.R
@@ -455,7 +455,8 @@ test_that("PCA training normalization divides by standard deviation", {
pca_res <- PCA(
mat,
n_dimensions = n_dimensions,
- n_features = nrow(mat)
+ n_features = nrow(mat),
+ threads = 2L
)$cell_embeddings
# Reference pipeline using an explicit z-score (divide by SD, not variance).
@@ -485,12 +486,19 @@ test_that("PCA parameter limiting works", {
rownames(mat) <- paste0("feat", seq_len(nrow(mat)))
colnames(mat) <- paste0("cell", seq_len(ncol(mat)))
- # Test n_features limiting
- pca_res_obj <- PCA(mat, n_features = 2000, n_dimensions = 3)
+ # Request multiple threads to exercise the small-matrix statistics workaround.
+ pca_res_obj <- PCA(mat, n_features = 2000, n_dimensions = 3, threads = 2L)
expect_equal(length(pca_res_obj$dim_reduction$fitted_params$variable_feature_names), 5)
+ expect_true(all(is.finite(pca_res_obj$cell_embeddings)))
# Test n_dimensions limiting
expect_equal(ncol(pca_res_obj$cell_embeddings), 3)
+
+ # In row-major storage, BPCells splits the five features instead of the cells.
+ row_major <- t(as(t(as(mat, "dgCMatrix")), "IterableMatrix"))
+ pca_row <- PCA(row_major, n_features = 5L, n_dimensions = 3L, threads = 2L)
+ expect_equal(dim(pca_row$cell_embeddings), c(12L, 3L))
+ expect_true(all(is.finite(pca_row$cell_embeddings)))
# Test with very small matrix
small_mat <- matrix(runif(12), nrow = 3) %>%
@@ -499,8 +507,8 @@ test_that("PCA parameter limiting works", {
rownames(small_mat) <- paste0("feat", seq_len(nrow(small_mat)))
colnames(small_mat) <- paste0("cell", seq_len(ncol(small_mat)))
- pca_small <- PCA(small_mat, n_dimensions = 10)
- expect_lt(ncol(pca_small$cell_embeddings), 10)
+ pca_small <- PCA(small_mat, n_dimensions = 10, threads = 2L)
+ expect_equal(dim(pca_small$cell_embeddings), c(4L, 2L))
})
test_that("PCA S3 generic works with MarchRProject", {
diff --git a/tests/testthat/test-doublet.R b/tests/testthat/test-doublet.R
index ebf7dc3..c62d0d1 100644
--- a/tests/testthat/test-doublet.R
+++ b/tests/testthat/test-doublet.R
@@ -344,6 +344,11 @@ test_that("project_doublets reports its LSI and UMAP projections", {
)
expect_no_message(suppressWarnings(run(force = TRUE, verbose = FALSE)))
+ # R^2 on this tiny fixture sits near 0.9 and varies by platform; force the NULL-model branch.
+ run_umap <- .run_umap_projections
+ local_mocked_bindings(.run_umap_projections = function(..., min_corr_threshold) {
+ run_umap(..., min_corr_threshold = 1.01)
+ })
expect_warning(msgs <- capture_messages(run(verbose = TRUE)), "Returning NULL UMAP model")
lines <- .strip_log(msgs)
expect_false("Projected 20 doublets into UMAP [Xs]" %in% lines)
diff --git a/tests/testthat/test-get_matrix.R b/tests/testthat/test-get_matrix.R
deleted file mode 100644
index e69de29..0000000
diff --git a/tests/testthat/test-project-io.R b/tests/testthat/test-project-io.R
index 727c40e..a4649fe 100644
--- a/tests/testthat/test-project-io.R
+++ b/tests/testthat/test-project-io.R
@@ -343,13 +343,55 @@ test_that("copy = FALSE writes data stored in R's temporary directory into the s
expect_identical(frag_values(loaded), before$frags)
})
-test_that("load_project reports copy = FALSE data that was rewritten or removed after saving", {
+test_that("load_project rejects reordered cells in a checkpoint matrix", {
+ proj <- create_test_project(cells = 5)
+ rna_dir <- file.path(withr::local_tempdir("stored_"), "RNA")
+ rna <- proj$datasets$dataset_1$matrices$RNA
+ proj$datasets$dataset_1$matrices$RNA <- write_matrix_dir(rna, rna_dir)
+ path <- withr::local_tempdir("checkpoint_")
+ suppressMessages(save_project(proj, path = path, copy = FALSE))
+
+ updated <- 2 * rna
+ write_matrix_dir(updated, rna_dir, compress = FALSE, overwrite = TRUE)
+ loaded <- suppressMessages(load_project(path))
+ expect_equal(as.matrix(loaded$datasets$dataset_1$matrices$RNA), as.matrix(updated))
+
+ write_matrix_dir(rna[, rev(seq_len(ncol(rna)))], rna_dir, overwrite = TRUE)
+ expect_error(load_project(path), "no longer matches")
+
+ # Older checkpoint references predate identity checks.
+ shell_path <- file.path(path, "project.rds")
+ shell <- readRDS(shell_path)
+ shell$datasets$dataset_1$matrices$RNA$names_hash <- NULL
+ saveRDS(shell, shell_path)
+ expect_no_error(suppressMessages(load_project(path)))
+})
+
+test_that("load_project rejects renamed cells in a checkpoint fragment directory", {
+ proj <- create_test_project(include_fragments = TRUE, cells = 5)
+ frag_dir <- file.path(withr::local_tempdir("stored_"), "fragments")
+ frags <- write_fragments_dir(proj$datasets$dataset_1$fragments$fragments, frag_dir)
+ proj$datasets$dataset_1$fragments$fragments <- frags
+ path <- withr::local_tempdir("checkpoint_")
+ suppressMessages(save_project(proj, path = path, copy = FALSE))
+ expect_no_error(suppressMessages(load_project(path)))
+
+ cellNames(frags) <- paste0("new_", cellNames(frags))
+ write_fragments_dir(frags, frag_dir, overwrite = TRUE)
+ expect_error(load_project(path), "no longer matches")
+})
+
+test_that("load_project reports changed or missing data behind checkpoint recipes", {
data_dir <- withr::local_tempdir("stored_")
proj <- stored_project(data_dir)
path <- withr::local_tempdir("checkpoint_")
suppressMessages(save_project(proj, path = path, copy = FALSE))
rna_dir <- file.path(data_dir, "RNA")
+ rna <- open_matrix_dir(rna_dir)
+ write_matrix_dir(rna[rev(seq_len(nrow(rna))), ], rna_dir, overwrite = TRUE)
+ expect_error(load_project(path), "no longer matches")
+
write_matrix_dir(open_matrix_dir(rna_dir)[1:2, ], rna_dir, overwrite = TRUE)
expect_error(load_project(path), "no longer matches")
diff --git a/tests/testthat/test-rcpp.R b/tests/testthat/test-rcpp.R
deleted file mode 100644
index 7491f4b..0000000
--- a/tests/testthat/test-rcpp.R
+++ /dev/null
@@ -1,3 +0,0 @@
-test_that("running works", {
- expect_no_error(rcpp_hello_world())
-})
diff --git a/tests/testthat/test-selections.R b/tests/testthat/test-selections.R
index 9a971d9..72435fd 100644
--- a/tests/testthat/test-selections.R
+++ b/tests/testthat/test-selections.R
@@ -206,6 +206,25 @@ test_that("subset_assays for MarchRDataset works", {
)
})
+test_that("malformed cell and feature selections raise R errors", {
+ selections <- list(
+ list(size = sum(lengths(cell_names(test_project))), select = function(x) {
+ subset_cells(test_project, x, by_dataset = FALSE)
+ }),
+ list(size = sum(vapply(test_dataset$matrices, nrow, integer(1))), select = function(x) {
+ subset_assays(test_dataset, x, by_assay = FALSE)
+ })
+ )
+ for (case in selections) {
+ expect_error(case$select(c(TRUE, FALSE)), "exactly one value per cell or feature")
+ expect_error(case$select(rep(TRUE, case$size + 1L)), "exactly one value per cell or feature")
+ expect_error(case$select(c(NA, rep(TRUE, case$size - 1L))), "cannot contain NA")
+ for (invalid in c(0, -1, 1.5, case$size + 1, NA, NaN, Inf)) {
+ expect_error(case$select(c(1, invalid)), "whole-number indices")
+ }
+ }
+})
+
test_that("Basic cell subsetting works", {
dataset <- test_dataset