Last updated: 2021-02-03
Checks: 7 0
Knit directory: scATACseq-topics/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it's best to always run the code in an empty environment.
The command set.seed(20200729)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version f0fc814. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: output/plotly/Buenrostro_2018_Chen2019pipeline/
Untracked files:
Untracked: analysis/gene_analysis_Buenrostro2018_Chen2019pipeline.Rmd
Untracked: analysis/process_data_Buenrostro2018_Chen2019.Rmd
Untracked: output/clustering-Cusanovich2018.rds
Untracked: scripts/fit_all_models_Buenrostro_2018_chromVar_scPeaks_filtered.sbatch
Untracked: scripts/fit_models_Cusanovich2018_tissues.sh
Unstaged changes:
Modified: analysis/assess_fits_Cusanovich2018.Rmd
Modified: analysis/gene_analysis_Cusanovich2018.Rmd
Modified: analysis/motif_analysis_Buenrostro2018_Chen2019pipeline.Rmd
Modified: analysis/process_data_Cusanovich2018.Rmd
Modified: scripts/fit_poisson_nmf.sbatch
Modified: scripts/prefit_poisson_nmf.sbatch
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/plots_Cusanovich2018.Rmd
) and HTML (docs/plots_Cusanovich2018.html
) files. If you've configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | f0fc814 | kevinlkx | 2021-02-03 | added PreFrontalCortex, whole brain and kidney |
html | 3f607ce | kevinlkx | 2021-02-02 | Build site. |
Rmd | 0d189ac | kevinlkx | 2021-02-02 | added bone marrow plots |
html | ad13ef4 | kevinlkx | 2020-09-11 | Build site. |
Rmd | 6d64de6 | kevinlkx | 2020-09-11 | add t-SNE and membership pie charts |
html | 7c0b14f | kevinlkx | 2020-09-11 | Build site. |
Rmd | dc70e46 | kevinlkx | 2020-09-11 | add t-SNE and membership pie charts |
html | 5a8479b | kevinlkx | 2020-09-10 | Build site. |
Rmd | b9993e2 | kevinlkx | 2020-09-10 | initial structure plots |
Here we examine and compare the topic modeling results for the scATAC-seq dataset from the mouse single-cell atlas paper Cusanovich et al (2018)
Load the packages used in the analysis below, as well as additional functions that will be used to generate some of the plots.
library(fastTopics)
library(Matrix)
library(tools)
library(dplyr)
library(ggplot2)
library(cowplot)
library(mapplots)
source("code/plots.R")
Load the data
data.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/processed_data/"
load(file.path(data.dir, "Cusanovich_2018.RData"))
cat(sprintf("%d x %d counts matrix.\n",nrow(counts),ncol(counts)))
rm(counts)
# 81173 x 436206 counts matrix.
About the samples: The study measured single cell chromatin accessibility for 17 samples spanning 13 different tissues in 8-week old mice.
cat(nrow(samples), "samples (cells). \n")
# 81173 samples (cells).
Tissues:
samples$tissue <- as.factor(samples$tissue)
cat(length(levels(samples$tissue)), "tissues. \n")
table(samples$tissue)
# 13 tissues.
#
# BoneMarrow Cerebellum Heart Kidney
# 8403 2278 7650 6431
# LargeIntestine Liver Lung PreFrontalCortex
# 7086 6167 9996 5959
# SmallIntestine Spleen Testes Thymus
# 4077 4020 2723 7617
# WholeBrain
# 8766
Cell types labels:
samples$cell_label <- as.factor(samples$cell_label)
cat(length(levels(samples$cell_label)), "cell types \n")
table(samples$cell_label)
# 40 cell types
#
# Activated B cells Alveolar macrophages
# 500 559
# Astrocytes B cells
# 1666 5772
# Cardiomyocytes Cerebellar granule cells
# 4076 4099
# Collecting duct Collisions
# 164 1218
# DCT/CD Dendritic cells
# 506 958
# Distal convoluted tubule Endothelial I (glomerular)
# 319 552
# Endothelial I cells Endothelial II cells
# 952 3019
# Enterocytes Erythroblasts
# 4783 2811
# Ex. neurons CPN Ex. neurons CThPN
# 1832 1540
# Ex. neurons SCPN Hematopoietic progenitors
# 1466 3425
# Hepatocytes Immature B cells
# 5664 571
# Inhibitory neurons Loop of henle
# 1828 815
# Macrophages Microglia
# 711 422
# Monocytes NK cells
# 1173 321
# Oligodendrocytes Podocytes
# 1558 498
# Proximal tubule Proximal tubule S3
# 2570 594
# Purkinje cells Regulatory T cells
# 320 507
# SOM+ Interneurons Sperm
# 553 2089
# T cells Type I pneumocytes
# 8954 1622
# Type II pneumocytes Unknown
# 157 10029
The structure plots below summarize the topic proportions in the samples grouped by different tissues.
\(k = 13\):
fit.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/output/Cusanovich_2018"
fit <- readRDS(file.path(fit.dir, "/fit-Cusanovich2018-scd-ex-k=13.rds"))$fit
fit_multinom <- poisson2multinom(fit)
set.seed(10)
colors_topics <- c("#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c",
"#fdbf6f","#ff7f00","#cab2d6","#6a3d9a","#ffff99","#b15928",
"gray")
samples$tissue <- as.factor(samples$tissue)
idx_selected_samples <- sample(nrow(fit$L),4000)
p.structure <- structure_plot(select(fit_multinom,loadings = idx_selected_samples),
grouping = samples[idx_selected_samples, "tissue"],
n = Inf,gap = 40, perplexity = 50,
topics = 1:13,colors = colors_topics,
num_threads = 4,verbose = FALSE)
print(p.structure)
Version | Author | Date |
---|---|---|
3f607ce | kevinlkx | 2021-02-02 |
Plot samples by tissues on the t-SNE coordinates provided by the original paper:
colors_tissues <- c("BoneMarrow" = "darkblue",
"Lung" = "lightblue",
"Thymus" = "orange",
"Spleen" = "pink",
"Liver" = "purple",
"Testes" = "yellow",
"SmallIntestine" = "darkgreen",
"LargeIntestine" = "brown",
"Kidney" = "green",
"Heart" = "red",
"WholeBrain" = "gray",
"PreFrontalCortex" = "black",
"Cerebellum" = "darkgray")
colors_tissues <- colors_tissues[order(names(colors_tissues))]
dat <- samples[, c("tsne_1", "tsne_2", "tissue")]
ggplot(dat, aes(x = tsne_1, y = tsne_2, colour=tissue)) +
geom_point(size = 0.5, na.rm = TRUE) +
scale_colour_manual(values=colors_tissues) +
labs(x = 't-SNE 1', y = 't-SNE 2', title = '') +
theme_cowplot()
Version | Author | Date |
---|---|---|
3f607ce | kevinlkx | 2021-02-02 |
Visualize topic membership using pie-charts for cells on t-SNE coordinates provided by the original paper
Plot the subset of 2000 samples:
\(k = 13\):
idx_selected_samples <- sample(nrow(fit$L),2000)
plot(NA,NA, main = paste("K = 13"),
xlab = 't-SNE 1', ylab = 't-SNE 2',
xlim=c(min(samples$tsne_1),max(samples$tsne_1)),
ylim=c(min(samples$tsne_2),max(samples$tsne_2)))
res <- lapply(idx_selected_samples, function(r)
add.pie(z=as.integer(100*fit_multinom$L[r,]),
x=samples[r,"tsne_1"],
y=samples[r,"tsne_2"], labels=c("","",""),
radius = 1, col = colors_topics))
Load the data
data.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/processed_data/"
load(file.path(data.dir, "Cusanovich_2018_BoneMarrow.RData"))
cat(sprintf("%d x %d counts matrix.\n",nrow(counts),ncol(counts)))
rm(counts)
# 8403 x 436206 counts matrix.
Cell types labels:
cat(nrow(samples), "samples (cells). \n")
samples$cell_label <- as.factor(samples$cell_label)
cat(length(levels(samples$cell_label)), "cell types \n")
table(samples$cell_label)
# 8403 samples (cells).
# 18 cell types
#
# Activated B cells Alveolar macrophages
# 17 1
# B cells Collisions
# 300 210
# Dendritic cells Endothelial I (glomerular)
# 112 4
# Endothelial II cells Enterocytes
# 3 1
# Erythroblasts Hematopoietic progenitors
# 2758 3047
# Immature B cells Macrophages
# 560 124
# Monocytes NK cells
# 827 43
# Podocytes Regulatory T cells
# 3 51
# T cells Unknown
# 72 270
The structure plots below summarize the topic proportions in the samples grouped by different cell labels.
\(k = 8\)
fit.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/output/Cusanovich_2018_BoneMarrow"
fit <- readRDS(file.path(fit.dir, "/fit-Cusanovich2018-scd-ex-k=8.rds"))$fit
fit_multinom <- poisson2multinom(fit)
set.seed(10)
samples$cell_group <- as.character(samples$cell_label)
samples$cell_group[grep("B cells", samples$cell_group)] <- "B cells"
samples$cell_group[grep("T cells", samples$cell_group)] <- "T cells"
samples$cell_group[samples$cell_group %in% names(which(table(samples$cell_group) <= 5))] <- "Others"
table(samples$cell_group)
samples$cell_group <- factor(samples$cell_group, levels = c("Hematopoietic progenitors",
"Erythroblasts",
"B cells", "T cells", "NK cells","Dendritic cells",
"Monocytes","Macrophages",
"Collisions", "Others", "Unknown"))
idx_selected_samples <- sample(nrow(fit$L),4000)
p.structure <- structure_plot(select(fit_multinom,loadings = idx_selected_samples),
grouping = samples[idx_selected_samples, "cell_group"],
n = Inf,gap = 40, perplexity = 50,
topics = 1:8, num_threads = 6,verbose = FALSE)
print(p.structure)
Version | Author | Date |
---|---|---|
3f607ce | kevinlkx | 2021-02-02 |
#
# B cells Collisions Dendritic cells
# 877 210 112
# Erythroblasts Hematopoietic progenitors Macrophages
# 2758 3047 124
# Monocytes NK cells Others
# 827 43 12
# T cells Unknown
# 123 270
Load the data
data.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/processed_data/"
load(file.path(data.dir, "Cusanovich_2018_PreFrontalCortex.RData"))
cat(sprintf("%d x %d counts matrix.\n",nrow(counts),ncol(counts)))
rm(counts)
# 5959 x 436206 counts matrix.
Cell types labels:
cat(nrow(samples), "samples (cells). \n")
samples$cell_label <- as.factor(samples$cell_label)
cat(length(levels(samples$cell_label)), "cell types \n")
table(samples$cell_label)
# 5959 samples (cells).
# 22 cell types
#
# Astrocytes B cells Cerebellar granule cells
# 551 4 1
# Collisions Dendritic cells Endothelial I cells
# 177 2 9
# Endothelial II cells Ex. neurons CPN Ex. neurons CThPN
# 77 1391 995
# Ex. neurons SCPN Immature B cells Inhibitory neurons
# 1160 1 320
# Macrophages Microglia Monocytes
# 12 197 1
# Oligodendrocytes Podocytes Purkinje cells
# 458 10 1
# Regulatory T cells SOM+ Interneurons T cells
# 1 386 1
# Unknown
# 204
The structure plots below summarize the topic proportions in the samples grouped by different cell labels.
\(k = 7\)
fit.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/output/Cusanovich_2018_PreFrontalCortex/"
fit <- readRDS(file.path(fit.dir, "/fit-Cusanovich2018-scd-ex-k=7.rds"))$fit
fit_multinom <- poisson2multinom(fit)
set.seed(10)
samples$cell_group <- as.character(samples$cell_label)
samples$cell_group[grep("Endothelial", samples$cell_group)] <- "Endothelial cells"
samples$cell_group[grep("Interneurons", samples$cell_group)] <- "Interneurons"
samples$cell_group[samples$cell_group %in% names(which(table(samples$cell_group) <= 5))] <- "Others"
table(samples$cell_group)
samples$cell_group <- factor(samples$cell_group, levels = c("Ex. neurons CPN", "Ex. neurons CThPN", "Ex. neurons SCPN",
"Inhibitory neurons", "Interneurons",
"Astrocytes", "Oligodendrocytes",
"Macrophages", "Microglia", "Podocytes",
"Collisions", "Others", "Unknown"))
idx_selected_samples <- sample(nrow(fit$L),4000)
p.structure <- structure_plot(select(fit_multinom,loadings = idx_selected_samples),
grouping = samples[idx_selected_samples, "cell_group"],
n = Inf, gap = 40, perplexity = 50,
topics = 1:7, num_threads = 6,verbose = FALSE)
print(p.structure)
#
# Astrocytes Collisions Endothelial cells Ex. neurons CPN
# 551 177 86 1391
# Ex. neurons CThPN Ex. neurons SCPN Inhibitory neurons Interneurons
# 995 1160 320 386
# Macrophages Microglia Oligodendrocytes Others
# 12 197 458 12
# Podocytes Unknown
# 10 204
Load the data
data.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/processed_data/"
load(file.path(data.dir, "Cusanovich_2018_WholeBrain.RData"))
cat(sprintf("%d x %d counts matrix.\n",nrow(counts),ncol(counts)))
rm(counts)
# 8766 x 436206 counts matrix.
Cell types labels:
cat(nrow(samples), "samples (cells). \n")
samples$cell_label <- as.factor(samples$cell_label)
cat(length(levels(samples$cell_label)), "cell types \n")
table(samples$cell_label)
# 8766 samples (cells).
# 23 cell types
#
# Astrocytes B cells Cerebellar granule cells
# 749 1 3004
# Collisions Dendritic cells Endothelial I cells
# 489 1 18
# Endothelial II cells Ex. neurons CPN Ex. neurons CThPN
# 161 439 543
# Ex. neurons SCPN Hematopoietic progenitors Immature B cells
# 303 4 1
# Inhibitory neurons Macrophages Microglia
# 1205 28 191
# Oligodendrocytes Podocytes Purkinje cells
# 969 2 195
# Regulatory T cells SOM+ Interneurons Sperm
# 1 148 1
# T cells Unknown
# 4 309
The structure plots below summarize the topic proportions in the samples grouped by different cell labels.
\(k = 7\)
fit.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/output/Cusanovich_2018_WholeBrain/"
fit <- readRDS(file.path(fit.dir, "/fit-Cusanovich2018-scd-ex-k=7.rds"))$fit
fit_multinom <- poisson2multinom(fit)
set.seed(10)
samples$cell_group <- as.character(samples$cell_label)
samples$cell_group[grep("Endothelial", samples$cell_group)] <- "Endothelial cells"
samples$cell_group[grep("Interneurons", samples$cell_group)] <- "Interneurons"
samples$cell_group[samples$cell_group %in% names(which(table(samples$cell_group) <= 5))] <- "Others"
table(samples$cell_group)
samples$cell_group <- factor(samples$cell_group, levels = c("Ex. neurons CPN", "Ex. neurons CThPN", "Ex. neurons SCPN",
"Inhibitory neurons", "Interneurons",
"Cerebellar granule cells", "Purkinje cells",
"Astrocytes", "Oligodendrocytes",
"Macrophages", "Microglia",
"Collisions", "Others", "Unknown"))
idx_selected_samples <- sample(nrow(fit$L),4000)
p.structure <- structure_plot(select(fit_multinom,loadings = idx_selected_samples),
grouping = samples[idx_selected_samples, "cell_group"],
n = Inf, gap = 40, perplexity = 50,
topics = 1:7, num_threads = 6,verbose = FALSE)
print(p.structure)
#
# Astrocytes Cerebellar granule cells Collisions
# 749 3004 489
# Endothelial cells Ex. neurons CPN Ex. neurons CThPN
# 179 439 543
# Ex. neurons SCPN Inhibitory neurons Interneurons
# 303 1205 148
# Macrophages Microglia Oligodendrocytes
# 28 191 969
# Others Purkinje cells Unknown
# 15 195 309
Load the data
data.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/processed_data/"
load(file.path(data.dir, "Cusanovich_2018_Kidney.RData"))
cat(sprintf("%d x %d counts matrix.\n",nrow(counts),ncol(counts)))
rm(counts)
# 6431 x 436206 counts matrix.
Cell types labels:
cat(nrow(samples), "samples (cells). \n")
samples$cell_label <- as.factor(samples$cell_label)
cat(length(levels(samples$cell_label)), "cell types \n")
table(samples$cell_label)
# 6431 samples (cells).
# 26 cell types
#
# Activated B cells Alveolar macrophages
# 10 1
# B cells Collecting duct
# 27 164
# Collisions DCT/CD
# 1 499
# Dendritic cells Distal convoluted tubule
# 13 319
# Endothelial I (glomerular) Endothelial I cells
# 534 24
# Endothelial II cells Enterocytes
# 15 1
# Hematopoietic progenitors Hepatocytes
# 5 1
# Loop of henle Macrophages
# 814 50
# Monocytes NK cells
# 3 3
# Podocytes Proximal tubule
# 447 2565
# Proximal tubule S3 Regulatory T cells
# 594 8
# Sperm T cells
# 1 18
# Type II pneumocytes Unknown
# 1 313
The structure plots below summarize the topic proportions in the samples grouped by different cell labels.
\(k = 9\)
fit.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/output/Cusanovich_2018_Kidney/"
fit <- readRDS(file.path(fit.dir, "/fit-Cusanovich2018-scd-ex-k=9.rds"))$fit
fit_multinom <- poisson2multinom(fit)
set.seed(10)
samples$cell_group <- as.character(samples$cell_label)
samples$cell_group[grep("Endothelial", samples$cell_group)] <- "Endothelial cells"
samples$cell_group[grep("T cells", samples$cell_group)] <- "T cells"
samples$cell_group[grep("B cells", samples$cell_group)] <- "B cells"
samples$cell_group[grep("DCT/CD", samples$cell_group)] <- "Distal convoluted tubule/Collecting duct"
samples$cell_group[samples$cell_group %in% names(which(table(samples$cell_group) <= 5))] <- "Others"
table(samples$cell_group)
samples$cell_group <- factor(samples$cell_group, levels = c("Podocytes", "Proximal tubule", "Proximal tubule S3",
"Loop of henle", "Distal convoluted tubule",
"Distal convoluted tubule/Collecting duct",
"Collecting duct", "Endothelial cells",
"Others", "Unknown"))
idx_selected_samples <- sample(nrow(fit$L),4000)
p.structure <- structure_plot(select(fit_multinom,loadings = idx_selected_samples),
grouping = samples[idx_selected_samples, "cell_group"],
n = Inf, gap = 40, perplexity = 50,
topics = 1:9, num_threads = 6,verbose = FALSE)
print(p.structure)
#
# B cells
# 37
# Collecting duct
# 164
# Dendritic cells
# 13
# Distal convoluted tubule
# 319
# Distal convoluted tubule/Collecting duct
# 499
# Endothelial cells
# 573
# Loop of henle
# 814
# Macrophages
# 50
# Others
# 17
# Podocytes
# 447
# Proximal tubule
# 2565
# Proximal tubule S3
# 594
# T cells
# 26
# Unknown
# 313
sessionInfo()
# R version 3.6.1 (2019-07-05)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Scientific Linux 7.4 (Nitrogen)
#
# Matrix products: default
# BLAS/LAPACK: /software/openblas-0.2.19-el7-x86_64/lib/libopenblas_haswellp-r0.2.19.so
#
# 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] tools stats graphics grDevices utils datasets methods
# [8] base
#
# other attached packages:
# [1] mapplots_1.5.1 cowplot_1.1.1 ggplot2_3.3.3 dplyr_1.0.3
# [5] Matrix_1.2-18 fastTopics_0.4-29 workflowr_1.6.2
#
# loaded via a namespace (and not attached):
# [1] ggrepel_0.9.1 Rcpp_1.0.6 lattice_0.20-41 tidyr_1.1.2
# [5] prettyunits_1.1.1 rprojroot_2.0.2 digest_0.6.27 R6_2.5.0
# [9] MatrixModels_0.4-1 evaluate_0.14 coda_0.19-4 httr_1.4.2
# [13] pillar_1.4.7 rlang_0.4.10 progress_1.2.2 lazyeval_0.2.2
# [17] data.table_1.13.6 irlba_2.3.3 SparseM_1.78 whisker_0.4
# [21] rmarkdown_2.6 labeling_0.4.2 Rtsne_0.15 stringr_1.4.0
# [25] htmlwidgets_1.5.3 munsell_0.5.0 compiler_3.6.1 httpuv_1.5.4
# [29] xfun_0.19 pkgconfig_2.0.3 mcmc_0.9-7 htmltools_0.5.1.1
# [33] tidyselect_1.1.0 tibble_3.0.6 quadprog_1.5-8 matrixStats_0.58.0
# [37] viridisLite_0.3.0 withr_2.4.1 crayon_1.4.0 conquer_1.0.2
# [41] later_1.1.0.1 MASS_7.3-53 grid_3.6.1 jsonlite_1.7.2
# [45] gtable_0.3.0 lifecycle_0.2.0 DBI_1.1.0 git2r_0.27.1
# [49] magrittr_2.0.1 scales_1.1.1 RcppParallel_5.0.2 stringi_1.5.3
# [53] farver_2.0.3 fs_1.3.1 promises_1.1.1 ellipsis_0.3.1
# [57] generics_0.1.0 vctrs_0.3.6 glue_1.4.2 purrr_0.3.4
# [61] hms_1.0.0 yaml_2.2.1 colorspace_2.0-0 plotly_4.9.3
# [65] knitr_1.30 quantreg_5.83 MCMCpack_1.5-0