In this vignette we will demonstrate how to construct cell trajectories with Monocle 3 using single-cell ATAC-seq data. Please see the Monocle 3 website for information about installing Monocle 3.

To facilitate conversion between the Seurat (used by Signac) and CellDataSet (used by Monocle 3) formats, we will use a conversion function in the SeuratWrappers package available on GitHub.

Data loading

We will use a single-cell ATAC-seq dataset containing human CD34+ hematopoietic stem and progenitor cells published by Satpathy and Granja et al. (2019, Nature Biotechnology).

The processed dataset is available on NCBI GEO here: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE129785

Note that the fragment file is present inside the GSE129785_RAW.tar archive, and the index for the fragment file is not supplied. You can index the file yourself using tabix, for example: tabix -p bed <fragment_file>.

First we will load the dataset and perform some standard preprocessing using Signac.

filepath <- "../vignette_data/GSE129785/GSE129785_scATAC-Hematopoiesis-CD34"

peaks <- read.table(paste0(filepath, ".peaks.txt.gz"), header = TRUE)
cells <- read.table(paste0(filepath, ".cell_barcodes.txt.gz"), header = TRUE, stringsAsFactors = FALSE)
rownames(cells) <- make.unique(cells$Barcodes)

mtx <- readMM(file = paste0(filepath, ".mtx"))
mtx <- as(object = mtx, Class = "dgCMatrix")
colnames(mtx) <- rownames(cells)
rownames(mtx) <- peaks$Feature
bone_assay <- CreateChromatinAssay(
  counts = mtx,
  min.cells = 5,
  fragments = "../vignette_data/GSE129785/GSM3722029_CD34_Progenitors_Rep1_fragments.tsv.gz",
  sep = c("_", "_"),
  genome = "hg19"
)
bone <- CreateSeuratObject(
  counts = bone_assay,
  meta.data = cells,
  assay = "ATAC"
)

# The dataset contains multiple cell types
# We can subset to include just one replicate of CD34+ progenitor cells
bone <- bone[, bone$Group_Barcode == "CD34_Progenitors_Rep1"]

# add cell type annotations from the original paper
cluster_names <- c("HSC",   "MEP",  "CMP-BMP",  "LMPP", "CLP",  "Pro-B",    "Pre-B",    "GMP",
                  "MDP",    "pDC",  "cDC",  "Monocyte-1",   "Monocyte-2",   "Naive-B",  "Memory-B",
                  "Plasma-cell",    "Basophil", "Immature-NK",  "Mature-NK1",   "Mature-NK2",   "Naive-CD4-T1",
                  "Naive-CD4-T2",   "Naive-Treg",   "Memory-CD4-T", "Treg", "Naive-CD8-T1", "Naive-CD8-T2",
                  "Naive-CD8-T3",   "Central-memory-CD8-T", "Effector-memory-CD8-T",    "Gamma delta T")
num.labels <- length(cluster_names)
names(cluster_names) <- paste0( rep("Cluster", num.labels), seq(num.labels) )
bone$celltype <- cluster_names[as.character(bone$Clusters)]

bone[["ATAC"]]
## ChromatinAssay data with 570650 features for 9913 cells
## Variable features: 0 
## Genome: hg19 
## Annotation present: FALSE 
## Motifs present: FALSE 
## Fragment files: 1

Next we can add gene annotations for the hg19 genome to the object. This will be useful for computing quality control metrics (TSS enrichment score) and plotting.

library(EnsDb.Hsapiens.v75)

# extract gene annotations from EnsDb
annotations <- GetGRangesFromEnsDb(ensdb = EnsDb.Hsapiens.v75)

# change to UCSC style since the data was mapped to hg19
seqlevelsStyle(annotations) <- 'UCSC'
genome(annotations) <- "hg19"

# add the gene information to the object
Annotation(bone) <- annotations

Quality control

We’ll compute TSS enrichment, nucleosome signal score, and the percentage of counts in genomic blacklist regions for each cell, and use these metrics to help remove low quality cells from the datasets.

bone <- TSSEnrichment(bone)
bone <- NucleosomeSignal(bone)
bone$blacklist_fraction <- FractionCountsInRegion(bone, regions = blacklist_hg19)
VlnPlot(
  object = bone,
  features = c("nCount_ATAC", "TSS.enrichment", "nucleosome_signal", "blacklist_fraction"),
  pt.size = 0.1,
  ncol = 4
)

bone <- bone[, (bone$nCount_ATAC < 50000) &
               (bone$TSS.enrichment > 2) & 
               (bone$nucleosome_signal < 5)]

Dataset preprocessing

Next we can run a standard scATAC-seq analysis pipeline using Signac to perform dimension reduction, clustering, and cell type annotation.

bone <- FindTopFeatures(bone, min.cells = 10)
bone <- RunTFIDF(bone)
bone <- RunSVD(bone, n = 100)
DepthCor(bone)

bone <- RunUMAP(
  bone,
  reduction = "lsi",
  dims = 2:50,
  reduction.name = "UMAP"
)
bone <- FindNeighbors(bone, dims = 2:50, reduction = "lsi")
bone <- FindClusters(bone, resolution = 0.8, algorithm = 3)
## Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
## 
## Number of nodes: 9765
## Number of edges: 433498
## 
## Running smart local moving algorithm...
## Maximum modularity in 10 random starts: 0.8474
## Number of communities: 18
## Elapsed time: 5 seconds
DimPlot(bone, label = TRUE) + NoLegend()

Assign each cluster to the most common cell type based on the original annotations from the paper.

for(i in levels(bone)) {
  cells_to_reid <- WhichCells(bone, idents = i)
  newid <- names(sort(table(bone$celltype[cells_to_reid]),decreasing=TRUE))[1]
  Idents(bone, cells = cells_to_reid) <- newid
}
bone$assigned_celltype <- Idents(bone)
DimPlot(bone, label = TRUE)

Next we can subset the different lineages and create a trajectory for each lineage. Another way to build the trajectories is to use the whole dataset and build separate pseudotime trajectories for the different cell partitions found by Monocle 3.

DefaultAssay(bone) <- "ATAC"

erythroid <- bone[,  bone$assigned_celltype %in% c("HSC", "MEP", "CMP-BMP")]
lymphoid <- bone[, bone$assigned_celltype %in% c("HSC", "LMPP", "GMP", "CLP", "Pro-B", "pDC", "MDP", "GMP")]

Building trajectories with Monocle 3

We can convert the Seurat object to a CellDataSet object using the as.cell_data_set() function from SeuratWrappers and build the trajectories using Monocle 3. We’ll do this separately for erythroid and lymphoid lineages, but you could explore other strategies building a trajectory for all lineages together.

erythroid.cds <- as.cell_data_set(erythroid)
erythroid.cds <- cluster_cells(cds = erythroid.cds, reduction_method = "UMAP")
erythroid.cds <- learn_graph(erythroid.cds, use_partition = TRUE)

lymphoid.cds <- as.cell_data_set(lymphoid)
lymphoid.cds <- cluster_cells(cds = lymphoid.cds, reduction_method = "UMAP")
lymphoid.cds <- learn_graph(lymphoid.cds, use_partition = TRUE)

To compute pseudotime estimates for each trajectory we need to decide what the start of each trajectory is. In our case, we know that the hematopoietic stem cells are the progenitors of other cell types in the trajectory, so we can set these cells as the root of the trajectory. Monocle 3 includes an interactive function to select cells as the root nodes in the graph. This function will be launched if calling order_cells() without specifying the root_cells parameter. Here we’ve pre-selected some cells as the root, and saved these to a file for reproducibility. This file can be downloaded here.

# load the pre-selected HSCs
hsc <- readLines("../vignette_data/hsc_cells.txt")
# order cells
erythroid.cds <- order_cells(erythroid.cds, reduction_method = "UMAP", root_cells = hsc)
lymphoid.cds <- order_cells(lymphoid.cds, reduction_method = "UMAP", root_cells = hsc)

# plot trajectories colored by pseudotime
plot_cells(
  cds = erythroid.cds,
  color_cells_by = "pseudotime",
  show_trajectory_graph = TRUE
)

plot_cells(
  cds = lymphoid.cds,
  color_cells_by = "pseudotime",
  show_trajectory_graph = TRUE
)

Extract the pseudotime values and add to the Seurat object

bone <- AddMetaData(
  object = bone,
  metadata = erythroid.cds@principal_graph_aux@listData$UMAP$pseudotime,
  col.name = "Erythroid"
)

bone <- AddMetaData(
  object = bone,
  metadata = lymphoid.cds@principal_graph_aux@listData$UMAP$pseudotime,
  col.name = "Lymphoid"
)
FeaturePlot(bone, c("Erythroid", "Lymphoid"), pt.size = 0.1) & scale_color_viridis_c()

Acknowledgements

Thanks to the developers of Monocle 3, especially Cole Trapnell, Hannah Pliner, and members of the Trapnell lab. If you use Monocle please cite the Monocle papers.

Session Info

## R version 4.1.0 (2021-05-18)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.2 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    parallel  stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] EnsDb.Hsapiens.v75_2.99.0   ensembldb_2.16.4           
##  [3] AnnotationFilter_1.16.0     GenomicFeatures_1.44.2     
##  [5] AnnotationDbi_1.54.1        patchwork_1.1.1            
##  [7] ggplot2_3.3.5               Matrix_1.3-4               
##  [9] monocle3_1.0.0              SingleCellExperiment_1.14.1
## [11] SummarizedExperiment_1.22.0 GenomicRanges_1.44.0       
## [13] GenomeInfoDb_1.28.4         IRanges_2.26.0             
## [15] S4Vectors_0.30.0            MatrixGenerics_1.4.3       
## [17] matrixStats_0.61.0          Biobase_2.52.0             
## [19] BiocGenerics_0.38.0         SeuratWrappers_0.3.0       
## [21] SeuratObject_4.0.2          Seurat_4.0.4               
## [23] Signac_1.4.0               
## 
## loaded via a namespace (and not attached):
##   [1] rappdirs_0.3.3           SnowballC_0.7.0          rtracklayer_1.52.1      
##   [4] scattermore_0.7          R.methodsS3_1.8.1        ragg_1.1.3              
##   [7] tidyr_1.1.3              bit64_4.0.5              knitr_1.34              
##  [10] irlba_2.3.3              DelayedArray_0.18.0      R.utils_2.10.1          
##  [13] data.table_1.14.0        rpart_4.1-15             KEGGREST_1.32.0         
##  [16] RCurl_1.98-1.5           generics_0.1.0           leidenbase_0.1.3        
##  [19] cowplot_1.1.1            RSQLite_2.2.8            RANN_2.6.1              
##  [22] proxy_0.4-26             future_1.22.1            bit_4.0.4               
##  [25] spatstat.data_2.1-0      xml2_1.3.2               httpuv_1.6.3            
##  [28] assertthat_0.2.1         viridis_0.6.1            xfun_0.26               
##  [31] hms_1.1.0                jquerylib_0.1.4          evaluate_0.14           
##  [34] promises_1.2.0.1         fansi_0.5.0              restfulr_0.0.13         
##  [37] progress_1.2.2           dbplyr_2.1.1             igraph_1.2.6            
##  [40] DBI_1.1.1                htmlwidgets_1.5.4        sparsesvd_0.2           
##  [43] spatstat.geom_2.2-2      purrr_0.3.4              ellipsis_0.3.2          
##  [46] RSpectra_0.16-0          dplyr_1.0.7              backports_1.2.1         
##  [49] biomaRt_2.48.3           deldir_0.2-10            vctrs_0.3.8             
##  [52] remotes_2.4.0            ROCR_1.0-11              abind_1.4-5             
##  [55] cachem_1.0.6             withr_2.4.2              ggforce_0.3.3           
##  [58] BSgenome_1.60.0          checkmate_2.0.0          sctransform_0.3.2       
##  [61] GenomicAlignments_1.28.0 prettyunits_1.1.1        goftest_1.2-2           
##  [64] cluster_2.1.2            lazyeval_0.2.2           crayon_1.4.1            
##  [67] labeling_0.4.2           pkgconfig_2.0.3          slam_0.1-48             
##  [70] tweenr_1.0.2             nlme_3.1-152             ProtGenerics_1.24.0     
##  [73] nnet_7.3-16              rlang_0.4.11             globals_0.14.0          
##  [76] lifecycle_1.0.0          miniUI_0.1.1.1           filelock_1.0.2          
##  [79] BiocFileCache_2.0.0      rsvd_1.0.5               dichromat_2.0-0         
##  [82] rprojroot_2.0.2          polyclip_1.10-0          lmtest_0.9-38           
##  [85] ggseqlogo_0.1            zoo_1.8-9                base64enc_0.1-3         
##  [88] ggridges_0.5.3           png_0.1-7                viridisLite_0.4.0       
##  [91] rjson_0.2.20             bitops_1.0-7             R.oo_1.24.0             
##  [94] KernSmooth_2.23-20       Biostrings_2.60.2        blob_1.2.2              
##  [97] stringr_1.4.0            parallelly_1.28.1        jpeg_0.1-9              
## [100] scales_1.1.1             memoise_2.0.0            magrittr_2.0.1          
## [103] plyr_1.8.6               ica_1.0-2                zlibbioc_1.38.0         
## [106] compiler_4.1.0           BiocIO_1.2.0             RColorBrewer_1.1-2      
## [109] fitdistrplus_1.1-5       Rsamtools_2.8.0          XVector_0.32.0          
## [112] listenv_0.8.0            pbapply_1.5-0            htmlTable_2.2.1         
## [115] Formula_1.2-4            MASS_7.3-54              mgcv_1.8-36             
## [118] tidyselect_1.1.1         stringi_1.7.4            textshaping_0.3.5       
## [121] highr_0.9                yaml_2.2.1               latticeExtra_0.6-29     
## [124] ggrepel_0.9.1            grid_4.1.0               VariantAnnotation_1.38.0
## [127] sass_0.4.0               fastmatch_1.1-3          tools_4.1.0             
## [130] future.apply_1.8.1       rstudioapi_0.13          foreign_0.8-81          
## [133] lsa_0.73.2               gridExtra_2.3            farver_2.1.0            
## [136] Rtsne_0.15               digest_0.6.27            BiocManager_1.30.16     
## [139] shiny_1.6.0              qlcMatrix_0.9.7          Rcpp_1.0.7              
## [142] later_1.3.0              RcppAnnoy_0.0.19         httr_1.4.2              
## [145] biovizBase_1.40.0        colorspace_2.0-2         XML_3.99-0.8            
## [148] fs_1.5.0                 tensor_1.5               reticulate_1.22         
## [151] splines_4.1.0            uwot_0.1.10              RcppRoll_0.3.0          
## [154] spatstat.utils_2.2-0     pkgdown_1.6.1.9001       plotly_4.9.4.1          
## [157] systemfonts_1.0.2        xtable_1.8-4             jsonlite_1.7.2          
## [160] R6_2.5.1                 Hmisc_4.5-0              pillar_1.6.2            
## [163] htmltools_0.5.2          mime_0.11                glue_1.4.2              
## [166] fastmap_1.1.0            BiocParallel_1.26.2      codetools_0.2-18        
## [169] utf8_1.2.2               lattice_0.20-44          bslib_0.3.0             
## [172] spatstat.sparse_2.0-0    tibble_3.1.4             curl_4.3.2              
## [175] leiden_0.3.9             survival_3.2-11          rmarkdown_2.11          
## [178] docopt_0.7.1             desc_1.3.0               munsell_0.5.0           
## [181] GenomeInfoDbData_1.2.6   reshape2_1.4.4           gtable_0.3.0            
## [184] spatstat.core_2.3-0