Last updated: 2022-03-11

Checks: 7 0

Knit directory: scATACseq-topics/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). 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 e1e2329. 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:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/motif_analysis_Buenrostro2018_v2.Rmd
    Untracked:  output/clustering-Cusanovich2018.rds
    Untracked:  paper/
    Untracked:  scripts/postfit_Buenrostro2018_v2.sbatch

Unstaged changes:
    Modified:   analysis/analysis_Buenrostro2018_k10.Rmd
    Modified:   analysis/assess_fits_Buenrostro2018_Chen2019pipeline.Rmd
    Modified:   analysis/clusters_Cusanovich2018_k13.Rmd
    Modified:   analysis/gene_analysis_Buenrostro2018_Chen2019pipeline.Rmd
    Modified:   analysis/gene_analysis_Cusanovich2018.Rmd
    Modified:   analysis/motif_analysis_Buenrostro2018_Chen2019pipeline.Rmd
    Modified:   analysis/motif_analysis_Cusanovich2018.Rmd
    Modified:   analysis/plots_Cusanovich2018.Rmd
    Modified:   analysis/process_data_Buenrostro2018_different_options.Rmd
    Modified:   scripts/postfit_Buenrostro2018_v2.sh

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/process_data_Buenrostro2018.Rmd) and HTML (docs/process_data_Buenrostro2018.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 e1e2329 kevinlkx 2022-03-11 Only kept the data processing option 1 (from the original paper)
Rmd bd24884 kevinlkx 2022-03-11 wflow_rename("analysis/process_data_Buenrostro2018.Rmd", "analysis/process_data_Buenrostro2018_different_options.Rmd")
html e1b1e0f kevinlkx 2022-02-24 Build site.
Rmd 0be72fd kevinlkx 2022-02-24 output data processing messages
html 95a1145 kevinlkx 2022-02-24 Build site.
html 478d922 kevinlkx 2021-01-06 Build site.
Rmd 3890d38 kevinlkx 2021-01-06 wflow_publish("analysis/process_data_Buenrostro2018.Rmd")
html 17fc08a kevinlkx 2021-01-06 Build site.
Rmd 0c32e6a kevinlkx 2021-01-06 wflow_publish("analysis/process_data_Buenrostro2018.Rmd")
html 04cb767 kevinlkx 2021-01-06 Build site.
Rmd 97c421d kevinlkx 2021-01-06 put all four data processing options together
html 694fd3b kevinlkx 2020-11-19 Build site.
Rmd 4b7d5fa kevinlkx 2020-11-19 process data with peaks in less than 1% samples filtered out
html d5b411d kevinlkx 2020-11-18 Build site.
Rmd ee608fd kevinlkx 2020-11-18 process counts for aggregated single-cell peaks using chromVAR
html 594fd86 kevinlkx 2020-11-10 Build site.
Rmd 614814b kevinlkx 2020-11-10 process Buenrostro2018 data using Downloaded scATAC-seq processed data from GEO
Rmd c113844 kevinlkx 2020-11-10 wflow_rename("analysis/process_data_Buenrostro2018.Rmd", "analysis/process_data_Buenrostro2018_Chen2019pipeline.Rmd")
html c113844 kevinlkx 2020-11-10 wflow_rename("analysis/process_data_Buenrostro2018.Rmd", "analysis/process_data_Buenrostro2018_Chen2019pipeline.Rmd")
html 1905c58 kevinlkx 2020-11-05 Build site.
Rmd 1da32f8 kevinlkx 2020-11-05 set binarized counts as sparse matrix
html 89b45be kevinlkx 2020-11-04 Build site.
Rmd 857e1e8 kevinlkx 2020-11-04 process data from Buenrostro 2018 paper
html 907fa65 kevinlkx 2020-11-04 Build site.
Rmd 12bf4b3 kevinlkx 2020-11-04 process data from Buenrostro 2018 paper

About Buenrostro 2018 dataset

Reference: Buenrostro, J. D. et al. Integrated Single-Cell Analysis Maps the Continuous Regulatory Landscape of Human Hematopoietic Differentiation. Cell 173, 1535–1548.e16 (2018).

Data were downloaded from GEO: GSE96772

More details about the samples: https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSM2540299

RCC directory: /project2/mstephens/kevinluo/scATACseq-topics/data/Buenrostro_2018/

Prepare data for topic modeling

We used the processed counts and peaks from Buenrostro et al (2018) paper.

They called ATAC-seq peaks from the bulk ATAC-seq samples.

Using the previously described approach (Corces et al., 2016), we defined a peak list using all bulk hematopoietic data analyzed here, resulting in 491,437 500bp non-overlapping peaks which we use for the remainder of this study.

Downloaded scATAC-seq processed data from GEO: GSE96769

  • Peaks called from bulk ATAC-seq samples GSE96769_PeakFile_20160207.bed.gz
  • scATAC-seq sparse count matrix GSE96769_scATACseq_counts.txt.gz
library(Matrix)
library(tools)
library(readr)
library(data.table)

Load the fragment counts as a 2,953 x 491,437 sparse matrix.

# The first row has the sample names
file_counts <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Buenrostro_2018/GEO_data/GSE96769_scATACseq_counts.txt.gz"
sample_names <- readLines(file_counts,n = 1)
sample_names <- unlist(strsplit(sample_names,"\t",fixed = TRUE))
sample_names <- unlist(strsplit(sample_names,";",fixed = TRUE))
sample_names <- sample_names[-1]

# Load the fragment counts as sparse matrix.
dat <- fread(file_counts,sep = "\t",skip = 1)
class(dat) <- "data.frame"
names(dat) <- c("i","j","x")
counts <- sparseMatrix(i = dat$i,j = dat$j,x = dat$x)
counts <- t(counts)
rownames(counts) <- sample_names
dim(counts)
# [1]   2953 491437

Peaks (from bulk ATAC-seq)

peaks <- fread("/project2/mstephens/kevinluo/scATACseq-topics/data/Buenrostro_2018/GEO_data/GSE96769_PeakFile_20160207.bed.gz")
peak_names <- paste(peaks$V1,peaks$V2,peaks$V3,sep = "_")
rownames(peaks) <- peak_names
cat(sprintf("Number of peaks: %d\n",nrow(peaks)))

colnames(counts) <- peak_names
# Number of peaks: 491437

The supplementary Table S1 provides more details about these samples. https://ars.els-cdn.com/content/image/1-s2.0-S009286741830446X-mmc1.xlsx

Select the 2,034 samples (cells) passing quality filtering

Single-cell profiles were of consistent high-quality with 2,034 cells passing stringent quality filtering, yielding a median of 8,268 fragments per cell with 76% of those fragments mapping to peaks, resulting in a median of 6,442 fragments in peaks per cell (figure 1E).

Single-cells were filtered for quality requiring at least 60% of fragments in peaks and requiring greater than 1,000 fragments passing quality filters, quality filters are previously described (Corces et al., 2016) which includes removal of mitochondrial reads and low alignment quality (Q30).

The 2,034 samples (pass filter) were included in the metadata.tsv file on the scATAC-benchmarking website from Chen et al.

samples_filtered <- read.table('/project2/mstephens/kevinluo/scATACseq-topics/data/Buenrostro_2018/data/input_Chen_2019/metadata.tsv', header = TRUE, stringsAsFactors=FALSE, quote="",row.names=1)
samples_filtered$name <- rownames(samples_filtered)

idx_samples_filtered <- match(samples_filtered$name, sample_names)
sample_names_filtered <- sample_names[idx_samples_filtered]
counts <- counts[idx_samples_filtered,]
samples <- samples_filtered[,c("name", "label")]
dim(counts)
# [1]   2034 491437

Remove peaks not exist in any of the cells

j <- which(colSums(counts > 0) >= 1)
peaks <- peaks[j,]
counts <- counts[,j]
cat(length(j), "peaks left after filtering.  \n")

dim(counts)
sum(colSums(counts) == 0)
sum(rowSums(counts) == 0)
# 465536 peaks left after filtering.  
# [1]   2034 465536
# [1] 0
# [1] 0

Binarize counts

binarized_counts <- as.matrix((counts > 0) + 0)
binarized_counts <- Matrix(binarized_counts, sparse = TRUE) 

cat(sprintf("Matrix dimension after filtering: %d x %d.\n",nrow(binarized_counts),ncol(binarized_counts)))
# Matrix dimension after filtering: 2034 x 465536.

Save processed data: /project2/mstephens/kevinluo/scATACseq-topics/data/Buenrostro_2018/processed_data/

data.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Buenrostro_2018/processed_data/"
dir.create(data.dir, showWarnings = FALSE, recursive = TRUE)

save(list = c("samples", "peaks", "counts"), 
     file = file.path(data.dir, "Buenrostro_2018.RData"))

counts <- binarized_counts
save(list = c("samples", "peaks", "counts"), 
     file = file.path(data.dir, "Buenrostro_2018_binarized.RData"))
data.dir <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Buenrostro_2018/processed_data/"
load(file.path(data.dir, "Buenrostro_2018_binarized.RData"))
cat(sprintf("Loaded %d x %d counts matrix.\n",nrow(counts),ncol(counts)))

cat(sprintf("Number of samples (cells): %d\n",nrow(counts)))
cat(sprintf("Number of peaks: %d\n",ncol(counts)))
cat(sprintf("Proportion of counts that are non-zero: %0.1f%%.\n",
            100*mean(counts > 0)))
# Loaded 2034 x 465536 counts matrix.
# Number of samples (cells): 2034
# Number of peaks: 465536
# Proportion of counts that are non-zero: 1.5%.

sessionInfo()
# R version 4.0.4 (2021-02-15)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Scientific Linux 7.4 (Nitrogen)
# 
# Matrix products: default
# BLAS/LAPACK: /software/openblas-0.3.13-el7-x86_64/lib/libopenblas_haswellp-r0.3.13.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] data.table_1.14.2 readr_2.1.1       Matrix_1.4-0      workflowr_1.7.0  
# 
# loaded via a namespace (and not attached):
#  [1] Rcpp_1.0.8        highr_0.9         bslib_0.3.1       compiler_4.0.4   
#  [5] pillar_1.7.0      later_1.3.0       git2r_0.29.0      jquerylib_0.1.4  
#  [9] R.methodsS3_1.8.1 R.utils_2.11.0    getPass_0.2-2     digest_0.6.29    
# [13] lattice_0.20-45   jsonlite_1.7.3    evaluate_0.14     tibble_3.1.6     
# [17] lifecycle_1.0.1   pkgconfig_2.0.3   rlang_1.0.1       cli_3.2.0        
# [21] rstudioapi_0.13   yaml_2.2.2        xfun_0.29         fastmap_1.1.0    
# [25] httr_1.4.2        stringr_1.4.0     knitr_1.37        hms_1.1.1        
# [29] sass_0.4.0        fs_1.5.2          vctrs_0.3.8       grid_4.0.4       
# [33] rprojroot_2.0.2   glue_1.6.2        R6_2.5.1          processx_3.5.2   
# [37] fansi_1.0.2       rmarkdown_2.11    tzdb_0.2.0        callr_3.7.0      
# [41] magrittr_2.0.2    whisker_0.4       ps_1.6.0          promises_1.2.0.1 
# [45] htmltools_0.5.2   ellipsis_0.3.2    httpuv_1.6.5      utf8_1.2.2       
# [49] stringi_1.7.6     crayon_1.5.0      R.oo_1.24.0