Last updated: 2020-08-19

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 23b953f. 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:    .Rproj.user/

Untracked files:
    Untracked:  analysis/scATACseq_analysis_Lareau2019.Rmd
    Untracked:  analysis/scATACseq_data_Cusanovich2018.Rmd

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   analysis/references.Rmd

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/scATACseq_analysis_Cusanovich2018.Rmd) and HTML (docs/scATACseq_analysis_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 23b953f kevinlkx 2020-08-19 wflow_publish(“analysis/scATACseq_analysis_Cusanovich2018.Rmd”)

Cusanovich and Hill, et al. 2018 dataset

Reference: Cusanovich, D., Hill, A., Aghamirzaie, D., Daza, R., Pliner, H., Berletch, J., Filippova, G., Huang, X., Christiansen, L., DeWitt, W., Lee, C., Regalado, S., Read, D., Steemers, F., Disteche, C., Trapnell, C., Shendure, J. (2018). A Single-Cell Atlas of In Vivo Mammalian Chromatin Accessibility Cell 174(5), 1 35. https://dx.doi.org/10.1016/j.cell.2018.06.052

Data were downloaded from the website: https://atlas.gs.washington.edu/mouse-atac/data/. They also provided detail descriptions about these datasets.

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

The authors included nice tutorials on how to get started with analysis of sci-ATAC-seq data: http://atlas.gs.washington.edu/mouse-atac/docs/

R/python scripts referenced in this tutorial are available on: https://github.com/shendurelab/mouse-atac and downloaded to /project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/code_from_authors/mouse-atac on RCC.

Many of the initial steps of processing raw sci-ATAC-seq libraries used for this study are similar to their previous work of sci-ATAC-seq on Drosophila melanogaster embryos at 3 different stages of development. “Cusanovich, D., Reddington, J., Garfield, D. et al. The cis-regulatory dynamics of embryonic development at single-cell resolution. Nature 555, 538–542 (2018). https://doi.org/10.1038/nature25981”. Code and documentation on processing sequencing data can be found on the Fly ATAC Github. Documentation on various downstream steps can be found in the Fly ATAC documentation.

Matrix files

  • Binarized peak by cell matrix: atac_matrix.binary.qc_filtered.rds (only QC filtered cells are included).
library(Matrix)

## atac_matrix.binary.qc_filtered.rds: binarized peak by cell matrix in RDS format.
binarized_matrix <- readRDS("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/ATAC_matrices/atac_matrix.binary.qc_filtered.rds")
dim(binarized_matrix)
[1] 436206  81173
  • The subset of peaks used as input to TFIDF: atac_matrix.tfidf.qc_filtered.peaks.txt.
peaks_tfidf <- read.table("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/ATAC_matrices/atac_matrix.tfidf.qc_filtered.peaks.txt", header = FALSE, stringsAsFactors = TRUE)

cat(nrow(peaks_tfidf), "peaks used as input to TFIDF.")
167013 peaks used as input to TFIDF.
  • TFIDF normalized peak by cell matrix: atac_matrix.tfidf.qc_filtered.rds. This dataset has rare peaks filtered out and is then normalized with TFIDF to allow for input to PCA/TSNE (only QC filtered cells are included).
library(Matrix)

## atac_matrix.tfidf.qc_filtered.rds: TFIDF normalized peak by cell matrix in RDS format.
atac_matrix.tfidf <- readRDS("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/ATAC_matrices/atac_matrix.tfidf.qc_filtered.rds")
dim(atac_matrix.tfidf)
[1] 167013  81173

Metadata

  • cell_metadata.txt: Metadata for cells in TSV format, including several features such as TSNE coordinates, cluster assignments, and cell type assignments. Columns in this data:
    • cell: cell barcode (combined and corrected)
    • tissue: the tissue that this cell originated from
    • tissue_replicate: same as tissue, but each replicate has a unique id
    • cluster: cluster assignment in initial t-SNE
    • subset_cluster: cluster assignment in iterative t-SNE space
    • tsne_1: t-SNE1 coordinate in initial t-SNE
    • tsne_2: t-SNE2 coordinate in initial t-SNE
    • subset_tsne1: t-SNE1 coordinate in iterative t-SNE
    • subset_tsne2: t-SNE2 coordinate in iterative t-SNE
    • id: combined ID for major + iterative cluster assignment
    • cell_label: assigned cell type
cell_metadata <- read.table("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/metadata/cell_metadata.txt", header = TRUE, stringsAsFactors = TRUE, sep = "\t")

dim(cell_metadata)
[1] 81173    11
cell_metadata[1:3,]
                                  cell     tissue tissue.replicate cluster
1 AGCGATAGAACGAATTCGCCTCCGACGGCAGGACGT       Lung      Lung2_62216      10
2 AGCGATAGAACGAATTCGTTGGTAGTCGATAGAGGC     Spleen     Spleen_62016      10
3 AGCGATAGAACGCGCAGAAAGCTAGGTTAGGCGAAG BoneMarrow BoneMarrow_62016      10
  subset_cluster   tsne_1   tsne_2 subset_tsne1 subset_tsne2
1              1 16.25804 17.05674    -14.44873    -3.100071
2              1 15.28149 16.10859    -15.23808     1.123518
3              1 17.03914 14.69750    -16.88165     5.244815
                     id                cell_label
1 clusters_10.cluster_1 Hematopoietic progenitors
2 clusters_10.cluster_1 Hematopoietic progenitors
3 clusters_10.cluster_1 Hematopoietic progenitors
  • cell_metadata.tissue_freq_filtered.txt: Same as cell_metadata.txt, but removes cells in each tissue belonging to a cell_label that accounts for less than 0.5% of the cells in that tissue. These very low frequency labels are often not cell types expected their respective tissues and could be due to slight imperfections in clustering, for example. Provided matrices would need to be subsetted to match this set of cells if using this metadata.
cell_metadata <- read.table("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/metadata/cell_metadata.tissue_freq_filtered.txt", header = TRUE, stringsAsFactors = TRUE, sep = "\t")

dim(cell_metadata)
[1] 80254    11
cell_metadata[1:3,]
                                  cell     tissue tissue.replicate cluster
1 AGCGATAGAACGAATTCGCCTCCGACGGCAGGACGT       Lung      Lung2_62216      10
2 AGCGATAGAACGAATTCGTTGGTAGTCGATAGAGGC     Spleen     Spleen_62016      10
3 AGCGATAGAACGCGCAGAAAGCTAGGTTAGGCGAAG BoneMarrow BoneMarrow_62016      10
  subset_cluster   tsne_1   tsne_2 subset_tsne1 subset_tsne2
1              1 16.25804 17.05674    -14.44873    -3.100071
2              1 15.28149 16.10859    -15.23808     1.123518
3              1 17.03914 14.69750    -16.88165     5.244815
                     id                cell_label
1 clusters_10.cluster_1 Hematopoietic progenitors
2 clusters_10.cluster_1 Hematopoietic progenitors
3 clusters_10.cluster_1 Hematopoietic progenitors
  • cell_type_assignments.xlsx: Excel document with three tabs expected cell types, cell type markers, and Cell type assignments that contain a pairs of tissues and expected cell types, a list of positive markers for each cell type, and the table of cell type assignments with extra details about assignment criteria when applicable, respectively. This is meant to document justification for cell type assignments provided in cell_metadata.txt above.

  • peak_promoter_intersections.txt: Metadata for peaks-intersected TSS pairs in TSV format.

peak_promoter_intersections <- read.table("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/metadata/peak_promoter_intersections.txt", header = TRUE, stringsAsFactors = TRUE, sep = "\t")

dim(peak_promoter_intersections)
[1] 62545     9
peak_promoter_intersections[1:3,]
               peak_id peak_chr peak_start peak_end           ensembl_id
1 chr1_3206330_3206546     chr1    3206330  3206546 ENSMUSG00000051951.5
2 chr1_3456171_3457239     chr1    3456171  3457239 ENSMUSG00000089699.1
3 chr1_3660494_3662750     chr1    3660494  3662750 ENSMUSG00000051951.5
  gene_short_name ensembl_transcript_id              biotype strand
1            Xkr4  ENSMUST00000162897.1 processed_transcript      -
2          Gm1992  ENSMUST00000161581.1            antisense      +
3            Xkr4  ENSMUST00000070533.4       protein_coding      -

Dimensionality Reduction in the original paper

They used the LSI (Latent Semantic Indexing) appraoch for dimensionality reduction: first, transform the data using the frequency-inverse document frequency transformation (TF-IDF), and then use singular value decomposition (SVD) on the TF-IDF matrix to generate a lower dimensional representation of the data. Introduction to LSI from wikipedia.

TF-IDF: first weight all the sites for individual cells by the total number of sites accessible in that cell (term frequency); then multiply these weighted values by log(1 + the inverse frequency of each site across all cells), the inverse document frequency. Introduction to TF-IDF from wikipedia.

This representation was then used as input for the T-SNE (t-distributed Stochastic Neighbor Embedding) analysis using Rtsne package in R.

The code below uses an example function atac_dim_reduction in dim_reduction.R from the authors’ Github page that given a matrix will do TFIDF, PCA, and t-SNE and return the resulting PCA and TSNE coordinates. Note that this function takes the binarized matrix and a site_frequency_threshold argument (default 0.03 or site observed in at least 3% of cells).

source('/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/code_from_authors/mouse-atac/dim_reduction/dim_reduction.R')
binarized_matrix <- readRDS("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/ATAC_matrices/atac_matrix.binary.qc_filtered.rds")
# This function outputs a list with two items pca_coords and tsne_coords, which contain the PCA and t-SNE coordinates as dataframes where the cell IDs are included as the rownames.
results.dim_reduction <- atac_dim_reduction(binarized_matrix, site_frequency_threshold=0.02)

TF-IDF transformation

library(Matrix)
library(irlba)
dir_results <- "/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/results/"
dir.create(dir_results, showWarnings = FALSE, recursive = TRUE)

site_frequency_threshold <- 0.02
atac_matrix <- readRDS("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/ATAC_matrices/atac_matrix.binary.qc_filtered.rds")

## select sites/peaks observed in at least (site_frequency_threshold)% of cells
num_cells_ncounted <- Matrix::rowSums(atac_matrix)
threshold <- ncol(atac_matrix) * site_frequency_threshold

ncounts <- atac_matrix[num_cells_ncounted >= threshold,]

## Normalize the data with TF-IDF
nfreqs <- t(t(ncounts) / Matrix::colSums(ncounts)) # term frequency
tf_idf_counts <- nfreqs * log(1 + ncol(ncounts) / Matrix::rowSums(ncounts)) # term frequency * inverse document frequency

saveRDS(tf_idf_counts, paste0(dir_results, "/atac_matrix.tfidf.qc_filtered_freq", site_frequency_threshold, ".rds"))

LSI (TF-IDF and SVD) on ATAC-seq matrix (only QC filtered cells are included)

## LSI on ATAC-seq matrix
# atac_matrix: a peak x cell scATAC-seq matrix
# n_PCs: number of PCs (singular vectors) included
# site_frequency_threshold: site observed in at least % of cells
# adapted from the atac_dim_reduction function in https://github.com/shendurelab/mouse-atac/blob/master/dim_reduction/dim_reduction.R
LSI_atac <- function(atac_matrix, n_PCs = 50, site_frequency_threshold = 0.03){
  library(Matrix)
  library(irlba)
  
  ## select sites/peaks observed in at least (site_frequency_threshold)% of cells
  num_cells_ncounted <- Matrix::rowSums(atac_matrix)
  threshold <- ncol(atac_matrix) * site_frequency_threshold
  
  ncounts <- atac_matrix[num_cells_ncounted >= threshold,]
  
  ## Normalize the data with TF-IDF
  nfreqs <- t(t(ncounts) / Matrix::colSums(ncounts)) # term frequency
  tf_idf_counts <- nfreqs * log(1 + ncol(ncounts) / Matrix::rowSums(ncounts)) # term frequency * inverse document frequency
  
  ## Do SVD
  set.seed(0)
  # use IRLBA algorithm to compute a partial SVD
  # IRLBA: Fast Truncated Singular Value Decomposition and Principal Components Analysis for Large Dense and Sparse Matrices
  SVD <- irlba(tf_idf_counts, n_PCs, n_PCs, maxit=1000) 
  d_diag <- matrix(0, nrow=length(SVD$d), ncol=length(SVD$d))
  diag(d_diag) <- SVD$d
  SVD_vd <- t(d_diag %*% t(SVD$v))
  rownames(SVD_vd) <- colnames(atac_matrix)
  colnames(SVD_vd) <- paste0('pca_', 1:ncol(SVD_vd))
  # return SVD_vd: cell x PC matrix
  return(SVD_vd)
}
atac_LSI <- LSI_atac(atac_matrix, 50, 0.02)

Topic modeling of the sci-ATAC-seq matrix

  • Binarized peak by cell matrix: atac_matrix.binary.qc_filtered.rds (only QC filtered cells are included).
library(Matrix)

## atac_matrix.binary.qc_filtered.rds: binarized peak by cell matrix in RDS format.
binarized_matrix <- readRDS("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/ATAC_matrices/atac_matrix.binary.qc_filtered.rds")
dim(binarized_matrix)
[1] 436206  81173
counts <- t(binarized_matrix)

cat(sprintf("Number of cells (samples): %d\n",nrow(counts)))
Number of cells (samples): 81173
cat(sprintf("Number of peaks: %d\n",ncol(counts)))
Number of peaks: 436206
cat(sprintf("Proportion of counts that are non-zero: %0.1f%%.\n",
            100*mean(counts > 0)))
Proportion of counts that are non-zero: 1.2%.
# 100*nnzero(counts)/prod(dim(counts))
  • cell_metadata.txt: Metadata for cells in TSV format, including several features such as TSNE coordinates, cluster assignments, and cell type assignments. Columns in this data:
    • cell: cell barcode (combined and corrected)
    • tissue: the tissue that this cell originated from
    • tissue_replicate: same as tissue, but each replicate has a unique id
    • cluster: cluster assignment in initial t-SNE
    • subset_cluster: cluster assignment in iterative t-SNE space
    • tsne_1: t-SNE1 coordinate in initial t-SNE
    • tsne_2: t-SNE2 coordinate in initial t-SNE
    • subset_tsne1: t-SNE1 coordinate in iterative t-SNE
    • subset_tsne2: t-SNE2 coordinate in iterative t-SNE
    • id: combined ID for major + iterative cluster assignment
    • cell_label: assigned cell type
cell_metadata <- read.table("/project2/mstephens/kevinluo/scATACseq-topics/data/Cusanovich_2018/metadata/cell_metadata.txt", header = TRUE, stringsAsFactors = TRUE, sep = "\t")

dim(cell_metadata)
[1] 81173    11
cat(sprintf("Number of cells (samples): %d\n",nrow(cell_metadata)))
Number of cells (samples): 81173
print(cell_metadata[1:3,])
                                  cell     tissue tissue.replicate cluster
1 AGCGATAGAACGAATTCGCCTCCGACGGCAGGACGT       Lung      Lung2_62216      10
2 AGCGATAGAACGAATTCGTTGGTAGTCGATAGAGGC     Spleen     Spleen_62016      10
3 AGCGATAGAACGCGCAGAAAGCTAGGTTAGGCGAAG BoneMarrow BoneMarrow_62016      10
  subset_cluster   tsne_1   tsne_2 subset_tsne1 subset_tsne2
1              1 16.25804 17.05674    -14.44873    -3.100071
2              1 15.28149 16.10859    -15.23808     1.123518
3              1 17.03914 14.69750    -16.88165     5.244815
                     id                cell_label
1 clusters_10.cluster_1 Hematopoietic progenitors
2 clusters_10.cluster_1 Hematopoietic progenitors
3 clusters_10.cluster_1 Hematopoietic progenitors

sessionInfo()
R version 3.5.1 (2018-07-02)
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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Matrix_1.2-15   workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6    lattice_0.20-38 rprojroot_1.3-2 digest_0.6.25  
 [5] later_1.0.0     grid_3.5.1      R6_2.4.1        backports_1.1.7
 [9] git2r_0.27.1    magrittr_1.5    evaluate_0.14   stringi_1.4.6  
[13] rlang_0.4.6     fs_1.3.1        promises_1.1.0  whisker_0.4    
[17] rmarkdown_2.1   tools_3.5.1     stringr_1.4.0   glue_1.4.1     
[21] httpuv_1.5.3.1  xfun_0.14       yaml_2.2.0      compiler_3.5.1 
[25] htmltools_0.4.0 knitr_1.28