Skip to contents

Introduction

This is a brief MarchR tutorial, based upon the ArchR Tutorial. It does not showcase all of MarchR’s functionality or each step in detail. Importantly, this tutorial assumes that your are running MarchR locally.

Setup

First, load MarchR. If this fails, we recommend revisiting the MarchR installation instructions.

set_threads() sets a session-wide thread count for operations that benefit from parallelization (Certain functions will remain single-threaded).

Output
## Set default MarchR threads to 4.

Downloads, references and the project are kept in cache_dir, so they persist across sessions and runs. To keep the project in R’s temporary directory instead, set project_dir <- file.path(tempdir(), "marchr_project"). MarchR creates each directory as needed.

cache_dir <- path.expand("~/.cache/marchr_hematopoiesis")
data_dir <- file.path(cache_dir, "data")
ref_dir <- file.path(cache_dir, "references")
project_dir <- file.path(cache_dir, "project")

Download Fragments

get_tutorial_data() downloads the same three fragment files as ArchR’s getTutorialData("Hematopoiesis"), skipping any already in dir. The dataset contains three scATAC-seq fragment files (bone marrow, CD34+sorted bone marrow, and PBMC).

input_files <- get_tutorial_data("hematopoiesis", dir = data_dir)
input_files
Output
##                                                                         scATAC_BMMC_R1 
##      "~/.cache/marchr_hematopoiesis/data/scATAC_BMMC_R1.fragments.tsv.gz" 
##                                                                    scATAC_CD34_BMMC_R1 
## "~/.cache/marchr_hematopoiesis/data/scATAC_CD34_BMMC_R1.fragments.tsv.gz" 
##                                                                         scATAC_PBMC_R1 
##      "~/.cache/marchr_hematopoiesis/data/scATAC_PBMC_R1.fragments.tsv.gz"

Initialize a MarchRProject

Each sample becomes its own MarchRDataset within one MarchRProject, all backed by the same on-disk project directory.

proj <- MarchRProject(dir = project_dir)
for (sample_name in names(input_files)) {
  frags <- open_fragments_10x(input_files[[sample_name]]) %>%
    write_fragments_dir(file.path(project_dir, "fragments", sample_name), overwrite = TRUE)
  proj <- add_fragments(
    proj,
    frags,
    frags_name = "ATAC",
    dataset_name = sample_name
  )
}
proj
Output
## MarchRProject Object
## Directory: ~/.cache/marchr_hematopoiesis/project
## 3 Datasets:
##   scATAC_BMMC_R1:
##     5000 cells: scATAC_BMMC_R1#TAGGAGGGTTAACCGT-1, scATAC_BMMC_R1#CCTTGGTAGTTCTCCC-1, scATAC_BMMC_R1#GCCAGCAGTTCTGAGT-1, scATAC_BMMC_R1#TAGCATGGTGACCAGA-1 ... scATAC_BMMC_R1#CTGCTCAAGTGTCGGA-1
##     Fragments: ATAC
##   scATAC_CD34_BMMC_R1:
##     3723 cells: scATAC_CD34_BMMC_R1#ATTTGTCTCAATCGTG-1, scATAC_CD34_BMMC_R1#CACATGAGTGATAAGT-1, scATAC_CD34_BMMC_R1#GCATTCCTCGTTGTTT-1, scATAC_CD34_BMMC_R1#TGTACAGAGGTAGGAA-1 ... scATAC_CD34_BMMC_R1#AACTTGGAGCGTTAGG-1
##     Fragments: ATAC
##   scATAC_PBMC_R1:
##     3000 cells: scATAC_PBMC_R1#CAGGGCTTCTTTCGAT-1, scATAC_PBMC_R1#GATGATCCACGTTACA-1, scATAC_PBMC_R1#TTTGCGCTCTATCTAC-1, scATAC_PBMC_R1#ATGTACGAGTATGCTC-1 ... scATAC_PBMC_R1#CACAACACAGTAACTC-1
##     Fragments: ATAC
## All datasets aligned.
## Empty genome object

Genome Annotations

The ArchR tutorial fragments are aligned to hg19. Transcripts are used for TSS enrichment QC, genes for gene scores, and exons for the gene track in genome browser plots.

proj <- set_gene_annotations(
  proj,
  annotation_type = "transcripts",
  name = "transcripts",
  dir_name = ref_dir,
  release = "19",
  transcript_choice = "all",
  annotation_set = "comprehensive"
)
proj <- set_gene_annotations(
  proj,
  annotation_type = "genes",
  name = "genes",
  dir_name = ref_dir,
  release = "19",
  annotation_set = "comprehensive"
)
proj <- set_gene_annotations(
  proj,
  annotation_type = "exons",
  name = "exons",
  dir_name = ref_dir,
  release = "19",
  transcript_choice = "all",
  annotation_set = "comprehensive"
)
proj <- set_blacklist(proj, genome = "hg19", dir_name = ref_dir)
proj <- set_chrom_sizes(proj, genome = "hg19", dir_name = ref_dir)
proj <- set_genome_sequence(proj, genome = "hg19")

Quality Control

Filter cells with qc_fragments() using the ArchR tutorial’s thresholds (minFrags = 1000, minTSS = 4).

for (sample_name in names(input_files)) {
  proj <- qc_fragments(
    proj,
    dataset_name = sample_name,
    frags_name = "ATAC",
    n_frags = 1000,
    tss_enrichment = 4
  )
}

Inspect the TSS enrichment vs. fragment count relationship and fragment length distribution per sample.

for (sample_name in names(input_files)) {
  p_tss <- plot_tss_scatter(
    proj, dataset_name = sample_name, frags_name = "ATAC",
    min_tss = 4
  )
  p_frag <- plot_fragment_length(
    proj, dataset_name = sample_name, frags_name = "ATAC"
  )
  print(p_tss + p_frag)
}

Plot normalized Tn5 insertion signal around the TSS, aggregated per sample.

Tile Matrix and Gene Score Matrix

Build a genome-wide 500bp tile matrix and a gene score matrix across all three datasets.

proj <- add_tile_matrix(proj, frags_name = "ATAC")
proj <- add_gene_score_matrix(proj, frags_name = "ATAC")

align_cells() reconciles the fragments and every matrix onto a single, consistent set of cells; it needs at least one matrix built first.

proj <- align_cells(proj)

Doublet Scoring and Filtering

add_doublet_scores() simulates synthetic doublets and scores each real cell by its local doublet enrichment, matching ArchR’s addDoubletScores() defaults.

proj <- add_doublet_scores(
  proj,
  assay_name = "TileMatrix",
  verbose = TRUE
)
Output
## 2026-12-04 01:27:12 Doublet scoring: 3 datasets, 10,681 cells, 4 threads
## [scATAC_BMMC_R1]
##   Simulated 20,000 doublets (1,000 x 20 trials)
##   Iterative LSI: 4,939 cells, 2 iterations, 30 dims, 4 threads
##     [Iteration 1/2]
##       Selected 25,000 features (top accessible) [1.5s]
##       Fit LSI on 4,939 cells [1.1s]
## Warning in .fn(threads = 1L, verbose = FALSE, k = 20L, metric = "euclidean", :
## KNN search didn't find self-neighbor for 19 datapoints. Try higher ef value
##       Found 15 clusters, merged to 6 [0.6s]
##       Pseudobulked 6 clusters [0.4s]
##       Iteration finished [3.7s]
##     [Iteration 2/2]
##       Selected 25,000 variable features [0.5s]
##       Fit LSI on 4,939 cells [1.3s]
##       Iteration finished [1.9s]
##   Iterative LSI finished [5.8s]: 4,939 x 30 embedding
##   Projected 20,000 doublets into LSI [6.7s]
##   Fit UMAP, re-projection R^2 = 0.984 [4.8s]
##   Projected 20,000 doublets into UMAP [1.3s]
##   Scored 4,939 cells by doublet neighbors in UMAP [0.7s]
##   Dataset finished [19.8s]
## [scATAC_CD34_BMMC_R1]
##   Simulated 15,000 doublets (1,000 x 15 trials)
##   Iterative LSI: 3,280 cells, 2 iterations, 30 dims, 4 threads
##     [Iteration 1/2]
##       Selected 25,000 features (top accessible) [0.9s]
##       Fit LSI on 3,280 cells [0.9s]
## Warning in .fn(threads = 1L, verbose = FALSE, k = 20L, metric = "euclidean", :
## KNN search didn't find self-neighbor for 16 datapoints. Try higher ef value
##       Found 13 clusters, merged to 6 [0.4s]
##       Pseudobulked 6 clusters [0.3s]
##       Iteration finished [2.5s]
##     [Iteration 2/2]
##       Selected 25,000 variable features [0.2s]
##       Fit LSI on 3,280 cells [0.7s]
##       Iteration finished [1.2s]
##   Iterative LSI finished [3.9s]: 3,280 x 30 embedding
##   Projected 15,000 doublets into LSI [4.8s]
##   Fit UMAP, re-projection R^2 = 0.994 [3.9s]
##   Projected 15,000 doublets into UMAP [0.8s]
##   Scored 3,280 cells by doublet neighbors in UMAP [0.5s]
##   Dataset finished [14.4s]
## [scATAC_PBMC_R1]
##   Simulated 10,000 doublets (1,000 x 10 trials)
##   Iterative LSI: 2,462 cells, 2 iterations, 30 dims, 4 threads
##     [Iteration 1/2]
##       Selected 25,000 features (top accessible) [1.0s]
##       Fit LSI on 2,462 cells [0.9s]
## Warning in .fn(threads = 1L, verbose = FALSE, k = 20L, metric = "euclidean", :
## KNN search didn't find self-neighbor for 19 datapoints. Try higher ef value
##       Found 12 clusters, merged to 6 [0.3s]
##       Pseudobulked 6 clusters [0.3s]
##       Iteration finished [2.5s]
##     [Iteration 2/2]
##       Selected 25,000 variable features [0.2s]
##       Fit LSI on 2,462 cells [1.0s]
##       Iteration finished [1.3s]
##   Iterative LSI finished [4.0s]: 2,462 x 30 embedding
##   Projected 10,000 doublets into LSI [4.2s]
##   Fit UMAP, re-projection R^2 = 0.951 [3.6s]
##   Projected 10,000 doublets into UMAP [0.6s]
##   Scored 2,462 cells by doublet neighbors in UMAP [0.3s]
##   Dataset finished [13.2s]
## 2026-12-04 01:27:56 Doublet scoring finished [47.3s]: added doublet scores to 3 datasets (10,681 cells)
for (sample_name in names(input_files)) {
  print(plot_doublet_scores(proj, dataset_name = sample_name))
}

filter_doublets() removes the highest-enrichment predicted doublets from every dataset in the project.

proj <- filter_doublets(proj, verbose = TRUE)
Output
## 2026-12-04 01:28:00 Doublet filtering: 3 datasets, 10,681 cells (enrichment >= 1, filter ratio 1)
## scATAC_BMMC_R1: removed 243 of 4,939 cells (4.9%) [0.5s]
## scATAC_CD34_BMMC_R1: removed 107 of 3,280 cells (3.3%) [0.5s]
## scATAC_PBMC_R1: removed 60 of 2,462 cells (2.4%) [0.9s]
## 2026-12-04 01:28:02 Doublet filtering finished [2.0s]: removed 410 of 10,681 cells (3.8%), cleared doublet data

Iterative LSI

IterativeLSI() alternates between low-resolution clustering and TF-IDF/SVD feature reselection, following ArchR’s iterative LSI procedure.

proj <- IterativeLSI(
  proj, assay_name = "TileMatrix",
  cluster_method = cluster_cells_graph(
    knn_method = knn_hnsw(k = 20L),
    knn_to_graph_method = knn_to_snn_graph,
    cluster_graph_method = cluster_graph_leiden(resolution = 0.2)
  ),
  max_clusters = 25,
  verbose = TRUE
)
Output
## 2026-12-04 01:28:08 Iterative LSI: 10,271 cells, 2 iterations, 30 dims, 4 threads
## [Iteration 1/2]
##   Selected 25,000 features (top accessible) [1.4s]
##   Fit LSI on 9,596 cells, projected 404 depth outliers [5.4s]
##   Dropped LSI component 1 (r = 0.80 with log10(nFrags))
##   Found 8 clusters [1.4s]
##   Pseudobulked 8 clusters [1.3s]
##   Iteration finished [9.7s]
## [Iteration 2/2]
##   Selected 25,000 variable features [0.2s]
##   Fit LSI on 9,855 cells, projected 416 depth outliers [5.4s]
##   Dropped LSI component 1 (r = 0.77 with log10(nFrags))
##   Iteration finished [5.7s]
## 2026-12-04 01:28:24 Iterative LSI finished [16.9s]: added dim reduction 'IterativeLSI' (10,271 x 29)

Clustering

To call clusters in the reduced dimension sub-space, use the add_clusters() function.

proj <- add_clusters(
  proj,
  embedding_name = "IterativeLSI",
  col_name = "atac_clusters",
  verbose = TRUE,
  cluster_graph_method = cluster_graph_leiden(resolution = 0.8),
  knn_method = knn_hnsw(k = 20L)
)
Output
## 2026-12-04 01:28:26 Clustering: 10,271 cells on 'IterativeLSI' (29 dims)
## Found 11 clusters [1.7s]
## 2026-12-04 01:28:27 Clustering finished [1.7s]: added cell metadata column 'atac_clusters' (11 clusters)

UMAP Embedding

To visualize the data, we can use a 2-dimensional representation such as Uniform Manifold Approximation and Projection (UMAP) This function uses the uwot package with the updated umap2() function.

proj <- add_umap(
  proj,
  embedding_name = "IterativeLSI",
  n_neighbors = 30L,
  min_dist = 0.5,
  verbose = TRUE
)
Output
## 2026-12-04 01:28:27 UMAP: 10,271 cells on 'IterativeLSI' (29 dims), 4 threads
## Fit 2D UMAP (30 neighbors, min_dist 0.5, cosine) [5.5s]
## Saved UMAP model [0.2s]
## 2026-12-04 01:28:33 UMAP finished [5.7s]: added cell metadata columns 'UMAP_1', 'UMAP_2', embedding model 'UMAP'

We can visualize the attributes of our cells, using the plot_embedding() function, specifying the coloration via the col_name parameter.

plot_embedding(proj, col_name = "atac_clusters", title = "UMAP - Clusters") +
  plot_embedding(proj, col_name = "dataset_name", title = "UMAP - Samples")

Assigning Clusters with Gene Scores

We can assign biological labels to our atac_clusters using gene scores of known hematopoietic regulators. The marker gene scores overlayed onto the UMAP embedding and visualized:

gene_score_markers <- c(
  "CD34",                 # Early progenitor
  "GATA1",                # Erythroid
  "PAX5", "MS4A1", "MME", # B-cell trajectory
  "CD14", "MPO",          # Monocytes
  "CD3D", "CD8A"          # T cells
)

plot_gene_scores(
  proj,
  genes = gene_score_markers,
  impute = FALSE,
  colors_continuous = palette_continuous("horizonExtra"),
  patchwork = TRUE
)

Raw gene scores can be noisy at the single-cell level. add_impute_weights() computes MAGIC diffusion weights from the LSI embedding.

proj <- add_impute_weights(proj, embedding_name = "IterativeLSI", verbose = TRUE)
Output
## 2026-12-04 01:28:44 Impute weights: 10,271 cells on 'IterativeLSI' (29 dims), 2 replicates x 2 blocks (~5,136 cells), td = 3, ka = 4
## Replicate 1/2: built 2 diffusion graphs [3.0s]
## Replicate 2/2: built 2 diffusion graphs [2.4s]
## 2026-12-04 01:28:49 Impute weights finished [5.5s]: added impute weights (2 replicates x 2 blocks)
plot_gene_scores(
  proj,
  genes = gene_score_markers,
  impute = TRUE,
  quant_cut = c(0.01, 0.95),
  colors_continuous = palette_continuous("horizonExtra"),
  patchwork = TRUE
)

Genome Browser Tracks

We can use the plot_browser_track() to browse the local chromatin accessibility at these marker genes (e.g. CD14) on a per cluster basis. The gene track draws each gene body as a line, with its merged exons from the exons annotation as thicker blocks.

region <- gene_region(
  get_gene_annotations(proj, "genes"),
  gene_symbol = "CD14",
  upstream = 50000L,
  downstream = 50000L
)

plot_browser_track(
  proj,
  region = region,
  group_by = "atac_clusters",
  frags_name = "ATAC",
  tracks = c("coverage", "gene"),
  bins = 400L,
  norm_method = "ReadsInTSS",
  title = "CD14"
)

Project Saving

save_project() writes a self-contained copy of the MarchRProject so you can run load_project() and load your project into a fresh R session.

saved_project_dir <- file.path(cache_dir, "saved_project")
proj <- save_project(proj, path = saved_project_dir, overwrite = TRUE)

When you are ready to load the saved project, simply provide the cached project directory,

proj <- load_project(saved_project_dir)
proj
Output
## MarchRProject Object
## Directory: ~/.cache/marchr_hematopoiesis/saved_project
## 3 Datasets:
##   scATAC_BMMC_R1:
##     4696 cells: scATAC_BMMC_R1#TAGGAGGGTTAACCGT-1, scATAC_BMMC_R1#CCTTGGTAGTTCTCCC-1, scATAC_BMMC_R1#GCCAGCAGTTCTGAGT-1, scATAC_BMMC_R1#TAGCATGGTGACCAGA-1 ... scATAC_BMMC_R1#GTGGATTCATCACAGT-1
##     Assays: TileMatrix, GeneScoreMatrix, IterativeLSI
##     Fragments: ATAC
##     Cell metadata: 3 features (atac_clusters, UMAP_1, UMAP_2)
##   scATAC_CD34_BMMC_R1:
##     3173 cells: scATAC_CD34_BMMC_R1#ATTTGTCTCAATCGTG-1, scATAC_CD34_BMMC_R1#CACATGAGTGATAAGT-1, scATAC_CD34_BMMC_R1#GCATTCCTCGTTGTTT-1, scATAC_CD34_BMMC_R1#TGCTTTAGTAACAATG-1 ... scATAC_CD34_BMMC_R1#AACGAGGTCTGAAAGA-1
##     Assays: TileMatrix, GeneScoreMatrix, IterativeLSI
##     Fragments: ATAC
##     Cell metadata: 3 features (atac_clusters, UMAP_1, UMAP_2)
##   scATAC_PBMC_R1:
##     2402 cells: scATAC_PBMC_R1#CAGGGCTTCTTTCGAT-1, scATAC_PBMC_R1#GATGATCCACGTTACA-1, scATAC_PBMC_R1#TTTGCGCTCTATCTAC-1, scATAC_PBMC_R1#ATGTACGAGTATGCTC-1 ... scATAC_PBMC_R1#TTCGGTCTCATTCGGA-1
##     Assays: TileMatrix, GeneScoreMatrix, IterativeLSI
##     Fragments: ATAC
##     Cell metadata: 3 features (atac_clusters, UMAP_1, UMAP_2)
## All datasets aligned.
## Assays:
##   TileMatrix: 
##     6072620 features
##   GeneScoreMatrix: 
##     20561 features
##   IterativeLSI: 
##     29 features
## Genome object: 
##   Chromosomes: 
##     chr1, chr2 ... chr21
##   Annotation names: 
##     transcripts, genes ... blacklist
##   Sequence: 
##     BSgenome.Hsapiens.UCSC.hg19
## DimReductions: IterativeLSI
## Impute Weights: 2 blocks (embedding = IterativeLSI)