Last updated: 2023-06-03

Checks: 7 0

Knit directory: SCREE/

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(20210907) 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 dc5b2b2. 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

Untracked files:
    Untracked:  data/workflow.png
    Untracked:  img/
    Untracked:  output/workflow.png

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/SCREE.Rmd) and HTML (docs/SCREE.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
html 2c16336 HailinWei98 2021-09-23 Build site.
Rmd a2a5b0a HailinWei98 2021-09-23 Publish the initial files for myproject
html eeeebf3 HailinWei98 2021-09-23 Build site.
Rmd 94450d1 HailinWei98 2021-09-23 Publish the initial files for myproject
html 94450d1 HailinWei98 2021-09-23 Publish the initial files for myproject
html 518a5ca HailinWei98 2021-09-22 Build site.
Rmd ab04ccf HailinWei98 2021-09-22 Publish the initial files for myproject
html 855bd74 HailinWei98 2021-09-22 Build site.
Rmd e582e5c HailinWei98 2021-09-22 Publish the initial files for myproject

scATAC-seq in this tutorial means gene perturbation combined with scATAC-seq.

Data pre-processing and sgRNA assignment

sgRNAassign is a function to assign sgRNA to each cell and will return a data frame including 3 columns: "cell" (cell barcode the same as colnames in the matrix), "barcode" (name of sgRNA, like "gene_sgRNA1"), "gene" (perturbed gene). For this example data, we generate the correct cell barcode and change the sgRNA name before the sgRNA assignment.

# Read the table with sgRNA information

sg_lib <- read.csv(gzfile("Spear-ATAC/GSM5171478_sgRNA_K562_TimeCourse_Day21.csv.gz"))

# Define a function to change the sequence to its reverse compliment

reverse <- function(DNA) {
    from = c("A","T","G","C","a","g","t","c","N","n")
    to  = c("T","A","C","G","t","c","a","g","N","n")
    names(to) = from
    sep_DNA = unlist(strsplit(DNA, ""))
    complementary_DNA = to[sep_DNA]
    rev_complementary = rev(complementary_DNA)
    rev_complementary_DNA = paste(rev_complementary, collapse = "")
    return(rev_complementary_DNA)
}

# Change the cell barcode in the sgRNA table to its reverse compliment

for (i in 1 : nrow(sg_lib)) {
    dna <- sg_lib[i, "cellBC"]
    sg_lib[i, "cellBC"] <- reverse(dna)
}

# Rename cell barcode and sgRNA in the sgRNA table

sg_lib$cellBC <- paste(sg_lib$cellBC, "-1", sep = "")
sg_lib$sgRNA <- gsub("sg", "", sg_lib$sgRNA)
sg_lib$sgRNA <- gsub("_", "_sgRNA", sg_lib$sgRNA)
sg_lib$sgRNA <- gsub("NT", "NTC", sg_lib$sgRNA)

# Assign sgRNA to each cell

sg_lib <- sgRNAassign(sg_lib = sg_lib, 
  type = "DataFrame", 
  freq_cut = 20, 
  freq_percent = 0.8, 
  freq = "Freq", 
  cell = "cellBC", 
  barcode = "sgRNA"
  unique = TRUE)

Quality control and sgRNA information visualization

Add metadata to the SeuratObject

ATAC_Add_meta_data is a function to add metadata into the SeuratObject for scATAC-seq based data, similar to Add_meta_data, which will be used in the subsequent analyses, such as perturbations, Fraction of Reads in Peaks (FRiP) and replicate information.

peak <- ATAC_Add_meta_data(sg_lib = sg_lib, 
  mtx = mtx, 
  fragments = "Spear-ATAC/GSM5171459_scATAC_K562_TimeCourse_Day21.fragments.tsv.gz", 
  cal.FRiP = TRUE)

Single-cell ATAC-seq quality control

ATAC_scQC is a function to perform single-cell ATAC-seq quality control based on "nFeature_peak" (detected peak numbers), "nCount_peak" (total peak count), "FRiP" (Fraction of Reads in Peaks), similar to scQC. Since scmageck_lr takes negative control as the baseline for all input cells (assuming all cells have negative control), users can also remove cells without sgRNAs using this function. In addition, this function can visualize the three metrics before and after quality control. Here we only take the violin plot before quality control as an example.

peak_QC <- ATAC_scQC(mtx = peak, 
  prefix = "example/ATAC", 
  label = "", 
  peak_frac = 0.01, 
  nFeature = c(200, 500000), 
  nCount = 1000, 
  FRiP = 0.1, 
  blank_NTC = FALSE)

SgRNA information visualization

sgRNA_quality_plot is a function to visualize sgRNA information, including cell numbers for each sgRNA and sgRNA numbers in each cell. We only label the top 10 sgRNA with the most cell numbers in the plot of cell numbers for each sgRNA. In addition, for each gene, we also label all sgRNA of it, in the plot of cell numbers for each sgRNA.

sgRNA_quality_plot(sg_lib = sg_lib, 
  mtx = peak, 
  bar_width = 0.4, 
  prefix = "example/ATAC", 
  label = "")

Fragments Size Distribution

fragmentsSize is a function to visualize the distribution of fragments size, based on the fragments file.

fragmentsSize(mtx = peak, 
  fragments = "Spear-ATAC/GSM5171459_scATAC_K562_TimeCourse_Day21.fragments.tsv.gz", 
  CBCindex = 4, 
  startIndex = 2, 
  endIndex = 3, 
  maxSize = 1000, 
  prefix = "example/ATAC")

UMAP visualization for scATAC-seq

ATACumap is a function to perform dimension reduction, clustering, and UMAP visualization for scATAC-seq based data.

peak_QC <- ATACumap(mtx = peak_QC, 
  assays = "peak", 
  min.cutoff = "q5", 
  reduction.key = 'LSI_', 
  reduction.name = 'lsi', 
  nsvs = 50, 
  n = 20, 
  dims = NULL, 
  dims.cut = 0.5, 
  algorithm = 1, 
  resolution = 0.8, 
  title.size = 16, 
  legend.key.size = unit(0.1, "pt"), 
  legend.text.size = 8, 
  x.text.size = 10, 
  x.title.size = 12, 
  y.text.size = 10, 
  y.title.size = 12, 
  pt.size = 0.2, 
  raster = FALSE, 
  label.cut = 20, 
  plot.show = TRUE, 
  plot.return = FALSE, 
  plot.save = TRUE, 
  prefix = "example/ATAC", 
  label = "", 
  width = 3.5, 
  height = 3.5)

Gene activity matrix

Gene activity matrix generation

CalculateGeneActivity is a function to generate a gene activity matrix based on the peak count matrix, and the gene activity matrix is similar to the gene count matrix. To finish the downstream analysis, SCREE will convert the peak count matrix of scATAC-seq to the gene activity matrix.

mtx <- CalculateGeneActivity(mtx = peak, 
  fragments = "/Spear-ATAC/GSM5171459_scATAC_K562_TimeCourse_Day21.fragments.tsv.gz", 
  species = "Hs", 
  version = "v86", 
  gene_type = "Symbol", 
  protein_coding = TRUE, 
  pro_up = 2000, 
  pro_down = 0, 
  sep = c("-", "-"))

# Generate the metadata of mitochondrial gene percentage

mtx[["percent.mt"]] <- PercentageFeatureSet(mtx, pattern = "^MT-")


Gene activity matrix quality control and visualization

scQC is a function to perform single-cell RNA-seq quality control based on "nFeature_RNA" (expressed gene numbers), "nCount_RNA" (total UMI count), "percent.mt" (mitochondrial genes percentage). We only take the violin plot before quality control as an example. Here, we applied scQC to visualize the distribution of nFeature and nCount in the gene activity matrix and to remove low-quality cells and genes.

mtx_QC <- scQC(mtx = mtx, 
  species = "Hs", 
  prefix = "example/ATAC", 
  label = "", 
  gene_frac = 0.01, 
  nFeature = c(200, 100000), 
  nCount = 1000, 
  mt = 10, 
  blank_NTC = FALSE, 
  plot.show = FALSE,
  plot.save = TRUE)

Perturbation efficiency evaluation and perturbation enrichment calculation

IntegratedMixscape is an integrated function to calculate the enrichment ratio for each perturbation in each cluster, calculate perturb signature, and evaluate perturbation efficiency for each sgRNA. The main functions of IntegratedMixscape are derived from the tutorial of Mixscape. To quickly identify potential highly efficient sgRNAs, we only visualize the sgRNAs with perturbation efficiency of more than 0. Users can perform clustering and perturbation enrichment via umap and CalculatePerturbEnrichment separately.

# Normalize and scale the data

mtx_QC <- normalize_scale(mtx = mtx_QC)

mixscape <- IntegratedMixscape(sg_lib = "Spear-ATAC/sg_lib_all.txt", 
  mtx = mtx_QC, 
  NTC = "NTC", 
  prefix = "example/ATAC", 
  label = "")

# Clustering
mtx_umap <- umap(mtx = mtx_QC, 
  assays = "RNA", 
  plot.return = FALSE, 
  prefix = "example/ATAC")

# Calculate perturbation enrichment
ratio <- CalculatePerturbEnrichment(mtx = mtx_umap, 
  sg_lib  = "Spear-ATAC/sg_lib_all.txt",
  NTC = "NTC", 
  NTC.cal = TRUE, 
  range = c(0, 1), 
  prefix = "example/ATAC")

As Mixscape calculates perturb signature for each cell labeled with perturbation, SCREE compares the clustering results and perturbation ratio of each cluster to evaluate the perturbation efficiency of each perturbation from another point of view.

Regulatory score estimation and downstream analysis

Regulatory score estimation

improved_scmageck_lr is a modified function derived from scmageck_lr in the scmageck package, which can estimate the regulatory score of each perturbation to each gene, based on linear regression and estimate the corresponding p-value based on permutation. The output of improved_scmageck_lr is the transposed matrix of scmageck_lr output.

results <- improved_scmageck_lr(BARCODE = "Spear-ATAC/sg_lib_all.txt", 
  RDS = mtx_QC, 
  NEGCTRL = "NTC", 
  SELECT_GENE = NULL, 
  LABEL = "improved", 
  PERMUTATION = 10000, 
  SAVEPATH = "example/ATAC", 
  LAMBDA = 0.01
  NTC_baseline = TRUE)
score <- results[[1]][, -1]
pval <- results[[2]][, -1]

DE gene plot

DE_gene_plot is a function to visualize the distribution of potential target gene numbers that passed the threshold for each perturbation.

DE_gene_plot(score = score, 
  pval = pval, 
  project = "Spear-ATAC", 
  prefix = "example/ATAC", 
  label = "", 
  pval_cut = 0.05, 
  score_cut = 0.2, 
  sort_by = "number", 
  y_break = c(50, 150), 
  width = 8, 
  height = 6)

Volcano plot

volcano is a function to visualize the distribution of regulatory score and corresponding p-value via volcano plot. All potential targets that passed the threshold will be colored and some top genes with the highest regulatory score will be labeled.

volcano(score = score, 
  pval = pval, 
  selected = NULL, 
  prefix = "example/ATAC", 
  label = "", 
  score_cut = 0.2, 
  pval_cut = 0.05, 
  height = 6, 
  width = 6, 
  showCategory = 5))

Perturbation correlation

heatmap is an integrated function to calculate and visualize the correlation between perturbations, based on a union gene set of all the perturbations' potential targets.

heatmap(score = score, 
  pval = pval, 
  prefix = "example/ATAC", 
  cell = 40, 
  width = 5, 
  height = 5)

GO enrichment

GOenrichment is a function to perform GO enrichment analysis based on the score and p-value generated from improved_scmageck_lr. Users can only select a subset of perturbations to visualize.

GOenrichment(score = score, 
  pval = pval, 
  selected = NULL, 
  prefix = "example/ATAC", 
  score_cut = 0.2, 
  pval_cut = 0.05, 
  DE_gene_to_use = "all", 
  database = "org.Hs.eg.db", 
  gene_type = "Symbol", 
  showCategory = 10)

Regulatory relationships

ATACciceroPlot is a function to visualize the regulatory relationships between potential target regions of each perturbation and potential target genes nearby for scATAC-seq based data, based on regulatory score. This function will find the differential peaks between selected perturbations and negative control first. Potential enhancers are selected from differential peaks list, without overlap with potential promoter regions. The effect of the potential enhancers on genes close to it is equal to scores of the selected perturbations calculated by improved_scmageck_lr.

#Draw cicero plot for ATAC-seq input

ATACciceroPlot(mtx = peak_QC, 
  score = score, 
  pval = pval, 
  selected = NULL, 
  species = "Hs", 
  version = "v86", 
  gene_annotations = NULL, 
  pro_up = 2000, 
  pro_down = 0, 
  overlap_cut = 0, 
  pval_cut = 0.05, 
  score_cut = 0, 
  p_adj_cut = 0.05, 
  logFC_cut = 0.25, 
  NTC = "NTC", 
  min.pct = 0.1, 
  upstream = 2000000, 
  downstream = 2000000, 
  test.use = "wilcox", 
  track_size = c(1,.3,.2,.3), 
  include_axis_track = TRUE, 
  prefix = "example/ATAC", 
  html_config = TRUE)

HTML outputs

SCREE provides functions to generate a summary HTML file based on all the output results of SCREE. config_generation generates a config in string format including the basic information, output figures, and tables. html_output generates the summary HTML file based on a template HTML file and the config from config_generation.

# Generate string of config

config <- config_generation(mtx = peak, 
  mtx_QC = peak_QC, 
  sg_lib = sg_lib, 
  score = score, 
  pval = pval, 
  project = "Spear-ATAC_K562_D21", 
  prefix = "example/ATAC", 
  label = "", 
  species = "Hs", 
  version = "v86", 
  type = "ATAC", 
  NTC = "NTC", 
  article = "https://pubmed.ncbi.nlm.nih.gov/33649593/", 
  data = "https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE168851", 
  article_name = "High-throughput single-cell chromatin accessibility CRISPR screens enable unbiased identification of regulatory networks in cancer", 
  data_name = "GSE168851", 
  gene_type = "Symbol", 
  score_cut = 0.2, 
  pval_cut = 0.05, 
  DA = cicero[[2]], 
  cicero = cicero[[3]], 
  enhancer = NULL)

# Generate html file based on the template file and the config.

html_output(html_dir = "ATAC_template.html", 
config = config, 
prefix = "example/ATAC",
replace = 3, 
label = "")

sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        whisker_0.4       knitr_1.33        magrittr_2.0.1   
 [5] R6_2.5.0          rlang_0.4.11      fansi_0.5.0       stringr_1.4.0    
 [9] tools_4.0.2       xfun_0.25         utf8_1.2.2        git2r_0.28.0     
[13] jquerylib_0.1.4   htmltools_0.5.1.1 ellipsis_0.3.2    rprojroot_2.0.2  
[17] yaml_2.2.1        digest_0.6.27     tibble_3.1.3      lifecycle_1.0.0  
[21] crayon_1.4.1      later_1.2.0       sass_0.4.0        vctrs_0.3.8      
[25] promises_1.2.0.1  fs_1.5.0          glue_1.4.2        evaluate_0.14    
[29] rmarkdown_2.10    stringi_1.7.3     bslib_0.2.5.1     compiler_4.0.2   
[33] pillar_1.6.2      jsonlite_1.7.2    httpuv_1.6.1      pkgconfig_2.0.3