Quick Start

library(cinaR)
data("atac_seq_consensus_bm")

Bed formatted consensus matrix (chr, start, end and samples)

dim(bed)
## [1] 1000   25
# bed formatted file
head(bed[,1:4])
##         Chr     Start       End B6-18mo-M-BM-47-GT18-01783
## 52834  chr5  24841478  24845196                       1592
## 29780 chr17   8162955   8164380                        109
## 67290  chr8  40577584  40578029                         72
## 51295  chr4 145277698 145278483                        110
## 4267   chr1 180808752 180815472                       2452
## 45102  chr3  88732151  88732652                         49

Create the contrasts you want to compare, here we create contrasts for 22 mice samples from different strains.

# create contrast vector which will be compared.
contrasts<- c("B6", "B6", "B6", "B6", "B6", "NZO", "NZO", "NZO", "NZO", "NZO", "NZO", 
              "B6", "B6", "B6", "B6", "B6", "NZO", "NZO", "NZO", "NZO", "NZO", "NZO")

cinaR function directly computes the differentially accessible peaks.

# If reference genome is not set hg38 will be used!
results <- cinaR(bed, contrasts, reference.genome = "mm10")
## >> preparing features information...      2021-04-07 22:06:23 
## >> identifying nearest features...        2021-04-07 22:06:24 
## >> calculating distance from peak to TSS...   2021-04-07 22:06:24 
## >> assigning genomic annotation...        2021-04-07 22:06:24 
## >> assigning chromosome lengths           2021-04-07 22:06:38 
## >> done...                    2021-04-07 22:06:38

Now, you can access differential accessibility (DA) and enrichment results.

names(results)
## [1] "DA.results"         "Enrichment.Results"

Inside DA.results, you have the consensus peaks (cp) and differentially accessible (DA) peaks. If batch correction was run, then cp will be a batch-corrected consensus matrix, otherwise it is the filtered and normalized version of original consensus peaks you provided.

names(results$DA.results)
## [1] "cp"       "DA.peaks"

There are many information cinaR provides such as adjusted p value, log fold-changes, gene names etc for each peak:

colnames(results$DA.results$DA.peaks$B6_NZO)
##  [1] "Row.names"     "seqnames"      "start"         "end"          
##  [5] "width"         "strand"        "annotation"    "geneChr"      
##  [9] "geneStart"     "geneEnd"       "geneLength"    "geneStrand"   
## [13] "geneId"        "transcriptId"  "distanceToTSS" "gene_name"    
## [17] "logFC"         "FDR"

Here is an overview of those DA peaks:

head(results$DA.results$DA.peaks$B6_NZO[,1:5])
##                  Row.names seqnames     start       end width
## 1 chr1_134559439_134560787     chr1 134559439 134560787  1349
## 2 chr1_138158514_138159483     chr1 138158514 138159483   970
## 3 chr1_164247654_164251852     chr1 164247654 164251852  4199
## 4 chr1_171631196_171631780     chr1 171631196 171631780   585
## 5 chr1_173954537_173955745     chr1 173954537 173955745  1209
## 6 chr1_177935969_177936852     chr1 177935969 177936852   884

Since the comparison is B6_NZO, if fold-changes are positive it means they are more accesible in B6 compared to NZO and vice versa for negative values!

and here is a little overview for enrichment analyses results:

head(results$Enrichment.Results$B6_NZO[,c("module.name","overlapping.genes", "adj.p")])
##                 module.name                   overlapping.genes      adj.p
## 1         Myeloid lineage 1 TFEB,FBXL5,PLXNC1,GM2A,AGTPBP1,CTSB 0.05914491
## 2  U_metabolism/replication             SLC2A6,GM2A,CTSB,PECAM1 0.05914491
## 3  U_mitochondrial proteins     PIK3R1,PAQR3,UBE3A,MAP4K4,PTPRC 0.32816305
## 4 U_proteasome/ubiquitin cx                  PIK3R1,IREB2,PTPRC 0.39112517
## 5   U_Immunity/cytoskeleton                          RPS6,RPS19 0.66488512
## 6         Myeloid lineage 2                        RNF157,MTUS1 0.66488512

PCA Plots

You can easily get the PCA plots of the samples:

pca_plot(results, contrasts, show.names = F)

You can overlay different information onto PCA plots as well!

# Overlaid information
overlaid.info <- c("B6-18mo", "B6-18mo", "B6-18mo", "B6-18mo", "B6-18mo", 
                   "NZO-18mo", "NZO-18mo", "NZO-18mo", "NZO-18mo", "NZO-18mo", "NZO-18mo", 
                   "B6-3mo", "B6-3mo", "B6-3mo", "B6-3mo", "B6-3mo", 
                   "NZO-3mo", "NZO-3mo", "NZO-3mo", "NZO-3mo", "NZO-3mo", "NZO-3mo")
# Sample IDs
sample.names <- c("S01783", "S01780", "S01781", "S01778", "S01779", 
"S03804", "S03805", "S03806", "S03807", "S03808", 
"S03809", "S04678", "S04679", "S04680", "S04681", 
"S04682", "S10918", "S10916", "S10919", "S10921", 
"S10917", "S10920")
pca_plot(results, overlaid.info, sample.names)

Heatmaps

Differential peaks

You can see the available comparisons using:

## [1] "B6_NZO"

Then, plot the differential peaks for a selected contrast using:

heatmap_differential(results, comparison = "B6_NZO")

Also, you can configure your heatmaps using the additional arguments of pheatmap function. For more information check out ?pheatmap.

heatmap_differential(results, comparison = "B6_NZO", show_colnames = FALSE)

Most variable peaks

You can also plot most variable 100 peaks for all samples:

Plus, you can set the number of peaks to be used in these plots, and again you can change the additional arguments of pheatmap function. For more information check out ?pheatmap.

heatmap_var_peaks(results, heatmap.peak.count = 200, cluster_cols = F)

Enrichment Plots

You can plot your enrichment results using:

dot_plot(results)
## Warning: Removed 54 rows containing missing values (geom_point).

if it gets too crowded, you can get rid of the irrelevant pathways as well:

dot_plot(results, filter.pathways = T)

Creating different contrasts

Note that you can further divide the resolution of contrasts, for instance this is also a valid vector

contrasts <- sapply(strsplit(colnames(bed), split = "-", fixed = T), 
                    function(x){paste(x[1:4], collapse = ".")})[4:25]
unique(contrasts)
## [1] "B6.18mo.M.BM"  "B6.18mo.F.BM"  "NZO.18mo.F.BM" "NZO.18mo.M.BM"
## [5] "B6.3mo.F.BM"   "B6.3mo.M.BM"   "NZO.3mo.F.BM"  "NZO.3mo.M.BM"

in this case, each of them will be compared to each other which will result in 28 different comparisons.

Comparison scheme

As default, cinaR will use one vs one (OVA) scheme, comparing each contrast to others one by one. However, this can be changed to one vs all (OVA) which will compare each contrast to rest:

# one-vs-one (results in n choose k comparisons, default)
cinaR(..., comparison.scheme = "OVO")

# one-vs-all (results in n comparisons)
cinaR(..., comparison.scheme = "OVA")

Running for bulk RNA-seq data

To run cinaR with RNA-seq experiments, just provide the count matrix, and specify the experiment type:

cinaR(matrix = count.matrix, ..., experiment.type = "RNA-Seq")

Note that, count.matrix should be in the form of \(g \times (1+n)\) where \(g\) is the number of genes and \(n\) is the number of samples, and plus one is for gene names.

Note that currently cinaR can only handle gene symbols (e.g. FOSL2, FOXA) and ensembl stable IDs (e.g. ENSG00000010404) for both human and mice!

Running enrichment with different dataset

You can run the enrichment analyses with a custom gene set:

cinaR(..., geneset = new_geneset)

cinaRgenesets

Easiest way to do this is to use cinaRgenesets package. You can select your gene set of interest and just plug it into your pipeline.

MSigDB

You can also download different gene sets from MSigDB site. Note that you should use the human gene symbol versions.

You can use read.gmt function from qusage package to read these genesets into your current environment.

Custom gene sets

A geneset must be a .gmt formatted symbol file.
You can familiarize yourself with the format by checking out :

# default geneset to be used
data("VP2008")

If you have gene and pathway names in a data.frame, you can use split function to create your own .gmt formatted gene sets e.g. split(df$genes, df$pathways).

Selecting different reference genomes

For now, cinaR supports 3 genomes for human and mice models:

  • hg38
  • hg19
  • mm10

You can set your it using reference.genome argument.

Batch Effect Correction

If you suspect your data have unknown batch effects, you can use:

cinaR(..., batch.correction = T)

This option will run Surrogate Variable Analysis (SVA) and try to adjust your data for unknown batch effects. If however, you already know the batches of the samples, you can simply set the batch.information argument as well. This will not run the SVA but just add the batches to design matrix.

# runs SVA
cinaR(..., batch.correction = T)

# runs SVA with 2 surrogate variables
cinaR(..., batch.correction = T, sv.number = 2)

# adds only batch information to the design matrix! (does not run SVA)
# batch.information should be number a vector where
# the length of it equals to the number of samples.
cinaR(..., batch.correction = T, batch.information = c(rep(0, 11), rep(1,11)))

Reminder - In our example data we have 22 samples

Adding extra covariates

Sometimes, one might want to add additional covariates to adjust the design matrix further, which affects the down-stream analyses. For instance, ages or sexes of the samples could be additional covariates. To account for those:

# Ages of the samples could be not in biological interests but should be accounted for!
cinaR(..., additional.covariates = c((18, 11), (3, 11)))

# More than one covariate for instance, sex and age
sex.info <- c("M", "F", "M", "F", "F", "F", "F", "F", "M", "M", "M", 
              "F", "F", "M", "M", "M", "F", "F", "M", "M", "F", "M")

age.info <- c((18, 11), (3, 11)
covs <- data.frame(Sex = sex.info, Age = age.info)

cinaR(..., additional.covariates = covs)

Saving DA peaks to excel

Setting save.DA.peaks = TRUE in cinaR function will create a DApeaks.xlsx file in the current directory. This file includes all the comparisons in different tabs. Additionally, you can set the path/name of the file using DA.peaks.path argument after setting save.DA.peaks = TRUE.

For instance,

results <- cinaR(..., save.DA.peaks = T, DA.peaks.path = "./Peaks_mice.xlsx")

will create an excel file with name Peaks_mice.xlsx in the current directory.

Using different GLM algorithms

Currently, cinaR supports 4 different algorithms, namely;

  • edgeR
  • limma-voom
  • limma-trend
  • DESeq2

If not set, it uses edgeR for differential analyses. You can change the used algorithm by simply setting DA.choice argument. For more information, ?cinaR

Some useful arguments

# new FDR threshold for DA peaks
results <- cinaR(..., DA.fdr.threshold = 0.1)

# filters out pathways
results <- cinaR(..., enrichment.FDR.cutoff = 0.1)

# does not run enrichment pipeline
results <- cinaR(..., run.enrichment = FALSE)

# creates the piechart from chIpSeeker package
results <- cinaR(..., show.annotation.pie = TRUE)

# change cut-off value for dot plots
dot_plot(..., fdr.cutoff = 0.05)

References

  • Robinson MD, McCarthy DJ, Smyth GK (2010). “edgeR: a Bioconductor package for differential expression analysis of digital gene expression data.” Bioinformatics, 26(1), 139-140. doi: 10.1093/bioinformatics/btp616.

  • Ritchie ME, Phipson B, Wu D, Hu Y, Law CW, Shi W, Smyth GK (2015). “limma powers differential expression analyses for RNA-sequencing and microarray studies.” Nucleic Acids Research, 43(7), e47.

  • Love, M.I., Huber, W., Anders, S. (2014) Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2. Genome Biology, 15:550. 10.1186/s13059-014-0550-8

Session Info

## R version 4.0.4 (2021-02-15)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur 10.16
## 
## 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] cinaR_0.2.2
## 
## loaded via a namespace (and not attached):
##   [1] shadowtext_0.0.7                         
##   [2] ChIPseeker_1.26.2                        
##   [3] fastmatch_1.1-0                          
##   [4] BiocFileCache_1.14.0                     
##   [5] systemfonts_1.0.1                        
##   [6] plyr_1.8.6                               
##   [7] igraph_1.2.6                             
##   [8] splines_4.0.4                            
##   [9] BiocParallel_1.24.1                      
##  [10] GenomeInfoDb_1.26.4                      
##  [11] ggplot2_3.3.3                            
##  [12] digest_0.6.27                            
##  [13] htmltools_0.5.1.1                        
##  [14] GOSemSim_2.16.1                          
##  [15] viridis_0.5.1                            
##  [16] GO.db_3.12.1                             
##  [17] fansi_0.4.2                              
##  [18] magrittr_2.0.1                           
##  [19] memoise_2.0.0                            
##  [20] limma_3.46.0                             
##  [21] Biostrings_2.58.0                        
##  [22] graphlayouts_0.7.1                       
##  [23] matrixStats_0.58.0                       
##  [24] askpass_1.1                              
##  [25] pkgdown_1.6.1                            
##  [26] enrichplot_1.10.2                        
##  [27] prettyunits_1.1.1                        
##  [28] colorspace_2.0-0                         
##  [29] blob_1.2.1                               
##  [30] rappdirs_0.3.3                           
##  [31] ggrepel_0.9.1                            
##  [32] textshaping_0.3.3                        
##  [33] xfun_0.22                                
##  [34] dplyr_1.0.5                              
##  [35] crayon_1.4.1                             
##  [36] RCurl_1.98-1.3                           
##  [37] jsonlite_1.7.2                           
##  [38] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2  
##  [39] scatterpie_0.1.5                         
##  [40] glue_1.4.2                               
##  [41] polyclip_1.10-0                          
##  [42] gtable_0.3.0                             
##  [43] zlibbioc_1.36.0                          
##  [44] XVector_0.30.0                           
##  [45] DelayedArray_0.16.3                      
##  [46] BiocGenerics_0.36.0                      
##  [47] scales_1.1.1                             
##  [48] DOSE_3.16.0                              
##  [49] pheatmap_1.0.12                          
##  [50] DBI_1.1.1                                
##  [51] edgeR_3.32.1                             
##  [52] Rcpp_1.0.6                               
##  [53] plotrix_3.8-1                            
##  [54] viridisLite_0.3.0                        
##  [55] progress_1.2.2                           
##  [56] bit_4.0.4                                
##  [57] stats4_4.0.4                             
##  [58] httr_1.4.2                               
##  [59] fgsea_1.16.0                             
##  [60] gplots_3.1.1                             
##  [61] RColorBrewer_1.1-2                       
##  [62] ellipsis_0.3.1                           
##  [63] pkgconfig_2.0.3                          
##  [64] XML_3.99-0.6                             
##  [65] farver_2.1.0                             
##  [66] sass_0.3.1                               
##  [67] dbplyr_2.1.0                             
##  [68] locfit_1.5-9.4                           
##  [69] utf8_1.2.1                               
##  [70] labeling_0.4.2                           
##  [71] tidyselect_1.1.0                         
##  [72] rlang_0.4.10                             
##  [73] reshape2_1.4.4                           
##  [74] AnnotationDbi_1.52.0                     
##  [75] munsell_0.5.0                            
##  [76] tools_4.0.4                              
##  [77] cachem_1.0.4                             
##  [78] generics_0.1.0                           
##  [79] RSQLite_2.2.5                            
##  [80] evaluate_0.14                            
##  [81] stringr_1.4.0                            
##  [82] fastmap_1.1.0                            
##  [83] yaml_2.2.1                               
##  [84] ragg_1.1.2                               
##  [85] knitr_1.31                               
##  [86] bit64_4.0.5                              
##  [87] fs_1.5.0                                 
##  [88] tidygraph_1.2.0                          
##  [89] caTools_1.18.2                           
##  [90] purrr_0.3.4                              
##  [91] ggraph_2.0.5                             
##  [92] DO.db_2.9                                
##  [93] xml2_1.3.2                               
##  [94] biomaRt_2.46.3                           
##  [95] compiler_4.0.4                           
##  [96] curl_4.3                                 
##  [97] tibble_3.1.0                             
##  [98] tweenr_1.0.2                             
##  [99] bslib_0.2.4                              
## [100] stringi_1.5.3                            
## [101] highr_0.8                                
## [102] GenomicFeatures_1.42.2                   
## [103] desc_1.3.0                               
## [104] lattice_0.20-41                          
## [105] Matrix_1.3-2                             
## [106] vctrs_0.3.6                              
## [107] pillar_1.5.1                             
## [108] lifecycle_1.0.0                          
## [109] BiocManager_1.30.12                      
## [110] jquerylib_0.1.3                          
## [111] data.table_1.14.0                        
## [112] cowplot_1.1.1                            
## [113] bitops_1.0-6                             
## [114] TxDb.Mmusculus.UCSC.mm10.knownGene_3.10.0
## [115] rtracklayer_1.50.0                       
## [116] GenomicRanges_1.42.0                     
## [117] qvalue_2.22.0                            
## [118] R6_2.5.0                                 
## [119] KernSmooth_2.23-18                       
## [120] gridExtra_2.3                            
## [121] IRanges_2.24.1                           
## [122] boot_1.3-27                              
## [123] MASS_7.3-53.1                            
## [124] gtools_3.8.2                             
## [125] assertthat_0.2.1                         
## [126] SummarizedExperiment_1.20.0              
## [127] openssl_1.4.3                            
## [128] rprojroot_2.0.2                          
## [129] GenomicAlignments_1.26.0                 
## [130] Rsamtools_2.6.0                          
## [131] S4Vectors_0.28.1                         
## [132] GenomeInfoDbData_1.2.4                   
## [133] parallel_4.0.4                           
## [134] hms_1.0.0                                
## [135] grid_4.0.4                               
## [136] tidyr_1.1.3                              
## [137] rmarkdown_2.7                            
## [138] rvcheck_0.1.8                            
## [139] MatrixGenerics_1.2.1                     
## [140] ggforce_0.3.3                            
## [141] Biobase_2.50.0