Skip to content
Merged
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
^\.Rbuildignore$
^LICENSE\.md$
^\.git$
^\.Rproj\.user$
^\.Rprofile$
Expand Down
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +20,8 @@ Imports:
BiocGenerics,
circlize,
ComplexHeatmap,
digest,
dplyr,
ggplot2,
igraph,
magrittr,
Expand Down Expand Up @@ -64,7 +67,6 @@ Suggests:
S4Vectors,
knitr,
rmarkdown,
dplyr,
GenomicRanges,
IRanges,
Rsamtools,
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
1 change: 0 additions & 1 deletion R/MarchR.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
#' @importFrom Rcpp evalCpp
#' @importFrom Matrix t
#' @importFrom patchwork wrap_plots
#' @exportPattern "^[[:alpha:]]+"
"_PACKAGE"
4 changes: 0 additions & 4 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -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`)
}
Expand Down
1 change: 1 addition & 0 deletions R/assays.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 2 additions & 0 deletions R/coaccessibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
39 changes: 24 additions & 15 deletions R/dimensionality_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.
#'
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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', ]

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions R/enrichment.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 0 additions & 15 deletions R/feature_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions R/footprinting.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion R/fragments.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions R/peak2gene.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions R/peaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading
Loading