Author: E Onur Karakaslar
Date: 2026-02-04

# Introduction to cinaR

#### E Onur Karakaslar

#### 02/04/2026

    ##

## 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...      2026-02-04 15:02:14
    ## >> identifying nearest features...        2026-02-04 15:02:16
    ## >> calculating distance from peak to TSS...   2026-02-04 15:02:16
    ## >> assigning genomic annotation...        2026-02-04 15:02:16
    ## >> assigning chromosome lengths           2026-02-04 15:02:33
    ## >> done...                    2026-02-04 15:02:33

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 chr10_105840598_105842176    chr10 105840598 105842176  1579
    ## 2   chr10_59950325_59952673    chr10  59950325  59952673  2349
    ## 3   chr10_63176490_63176839    chr10  63176490  63176839   350
    ## 4   chr10_77220928_77221910    chr10  77220928  77221910   983
    ## 5   chr10_79751429_79751786    chr10  79751429  79751786   358
    ## 6   chr10_86021157_86023861    chr10  86021157  86023861  2705

> 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)

    ## Warning: ggrepel: 7 unlabeled data points (too many overlaps). Consider
    ## increasing max.overlaps

### Heatmaps

#### Differential peaks

You can see the available comparisons using:

    show_comparisons(results)

    ## [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:

    heatmap_var_peaks(results)

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 or values outside the scale range
    ## (`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!

## Single-cell ATAC-seq (10x scATAC) preprocessing

`cinaR` is designed for bulk ATAC-seq. For 10x scATAC, first pseudobulk your peak-by-cell matrix to preserve biological replicates, then run `cinaR` on the resulting consensus matrix.

    set.seed(1)
    counts <- matrix(rpois(4 * 8, lambda = 2), nrow = 4)
    rownames(counts) <- c("chr1:1-100", "chr1:101-200", "chr2:1-150", "chr2:151-300")
    colnames(counts) <- paste0("cell", 1:8)

    meta <- data.frame(
      sample = c("S1", "S1", "S2", "S2", "S3", "S3", "S4", "S4"),
      group = c("A", "A", "A", "A", "B", "B", "B", "B"),
      row.names = colnames(counts),
      stringsAsFactors = FALSE
    )

    prep <- prep_scATAC_cinaR(
      counts,
      meta,
      sample.col = "sample",
      group.col = "group",
      min.cells = 2
    )

    dim(prep$bed)

    ## [1] 4 7

    prep$contrasts

    ##  S1  S2  S3  S4
    ## "A" "A" "B" "B"

You can then pass `prep$bed` and `prep$contrasts` to `cinaR()` as usual.

If you use a Seurat/Signac object, you can prepare the data directly:

    prep <- prep_scATAC_seurat(seurat_obj,
                               sample.col = "sample",
                               group.col = "group",
                               assay = "peaks")

## 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

    sessionInfo()

    ## R version 4.2.2 (2022-10-31)
    ## Platform: aarch64-apple-darwin20 (64-bit)
    ## Running under: macOS 15.7.3
    ##
    ## Matrix products: default
    ## BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
    ## LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
    ##
    ## locale:
    ## [1] C/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.6
    ##
    ## loaded via a namespace (and not attached):
    ##   [1] shadowtext_0.1.2
    ##   [2] ChIPseeker_1.34.1
    ##   [3] fastmatch_1.1-3
    ##   [4] BiocFileCache_2.6.1
    ##   [5] plyr_1.8.8
    ##   [6] igraph_1.4.1
    ##   [7] lazyeval_0.2.2
    ##   [8] splines_4.2.2
    ##   [9] BiocParallel_1.32.6
    ##  [10] GenomeInfoDb_1.34.9
    ##  [11] ggplot2_3.5.1
    ##  [12] digest_0.6.31
    ##  [13] yulab.utils_0.0.6
    ##  [14] htmltools_0.5.5
    ##  [15] GOSemSim_2.24.0
    ##  [16] viridis_0.6.2
    ##  [17] GO.db_3.16.0
    ##  [18] magrittr_2.0.3
    ##  [19] memoise_2.0.1
    ##  [20] limma_3.54.2
    ##  [21] Biostrings_2.66.0
    ##  [22] graphlayouts_0.8.4
    ##  [23] matrixStats_1.5.0
    ##  [24] enrichplot_1.18.3
    ##  [25] prettyunits_1.1.1
    ##  [26] colorspace_2.1-1
    ##  [27] blob_1.2.4
    ##  [28] rappdirs_0.3.3
    ##  [29] ggrepel_0.9.3
    ##  [30] xfun_0.42
    ##  [31] dplyr_1.1.2
    ##  [32] crayon_1.5.2
    ##  [33] RCurl_1.98-1.16
    ##  [34] jsonlite_1.9.1
    ##  [35] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
    ##  [36] scatterpie_0.1.8
    ##  [37] ape_5.7-1
    ##  [38] glue_1.8.0
    ##  [39] polyclip_1.10-4
    ##  [40] gtable_0.3.6
    ##  [41] zlibbioc_1.44.0
    ##  [42] XVector_0.38.0
    ##  [43] DelayedArray_0.24.0
    ##  [44] BiocGenerics_0.44.0
    ##  [45] scales_1.3.0
    ##  [46] DOSE_3.24.2
    ##  [47] pheatmap_1.0.12
    ##  [48] edgeR_3.40.2
    ##  [49] DBI_1.1.3
    ##  [50] Rcpp_1.0.14
    ##  [51] plotrix_3.8-2
    ##  [52] viridisLite_0.4.2
    ##  [53] progress_1.2.2
    ##  [54] gridGraphics_0.5-1
    ##  [55] tidytree_0.4.2
    ##  [56] bit_4.0.5
    ##  [57] stats4_4.2.2
    ##  [58] httr_1.4.7
    ##  [59] fgsea_1.24.0
    ##  [60] gplots_3.1.3
    ##  [61] RColorBrewer_1.1-3
    ##  [62] pkgconfig_2.0.3
    ##  [63] XML_3.99-0.14
    ##  [64] farver_2.1.2
    ##  [65] sass_0.4.5
    ##  [66] dbplyr_2.3.2
    ##  [67] locfit_1.5-9.7
    ##  [68] labeling_0.4.3
    ##  [69] ggplotify_0.1.0
    ##  [70] tidyselect_1.2.0
    ##  [71] rlang_1.1.5
    ##  [72] reshape2_1.4.4
    ##  [73] AnnotationDbi_1.60.2
    ##  [74] munsell_0.5.1
    ##  [75] tools_4.2.2
    ##  [76] cachem_1.0.7
    ##  [77] cli_3.6.4
    ##  [78] generics_0.1.3
    ##  [79] RSQLite_2.3.1
    ##  [80] evaluate_0.20
    ##  [81] stringr_1.5.0
    ##  [82] fastmap_1.1.1
    ##  [83] yaml_2.3.7
    ##  [84] ggtree_3.6.2
    ##  [85] knitr_1.42
    ##  [86] bit64_4.0.5
    ##  [87] tidygraph_1.2.3
    ##  [88] caTools_1.18.2
    ##  [89] purrr_1.0.1
    ##  [90] KEGGREST_1.38.0
    ##  [91] ggraph_2.1.0
    ##  [92] nlme_3.1-162
    ##  [93] aplot_0.1.10
    ##  [94] xml2_1.3.3
    ##  [95] biomaRt_2.54.1
    ##  [96] compiler_4.2.2
    ##  [97] filelock_1.0.2
    ##  [98] curl_5.2.3
    ##  [99] png_0.1-8
    ## [100] treeio_1.22.0
    ## [101] tibble_3.2.1
    ## [102] tweenr_2.0.2
    ## [103] bslib_0.4.2
    ## [104] stringi_1.8.4
    ## [105] highr_0.10
    ## [106] GenomicFeatures_1.50.4
    ## [107] lattice_0.20-45
    ## [108] Matrix_1.5-4
    ## [109] markdown_1.5
    ## [110] vctrs_0.6.5
    ## [111] pillar_1.10.1
    ## [112] lifecycle_1.0.4
    ## [113] BiocManager_1.30.20
    ## [114] jquerylib_0.1.4
    ## [115] data.table_1.17.8
    ## [116] cowplot_1.1.1
    ## [117] bitops_1.0-9
    ## [118] TxDb.Mmusculus.UCSC.mm10.knownGene_3.10.0
    ## [119] patchwork_1.3.0
    ## [120] rtracklayer_1.58.0
    ## [121] GenomicRanges_1.50.2
    ## [122] qvalue_2.30.0
    ## [123] R6_2.6.1
    ## [124] BiocIO_1.8.0
    ## [125] KernSmooth_2.23-20
    ## [126] gridExtra_2.3
    ## [127] IRanges_2.32.0
    ## [128] codetools_0.2-19
    ## [129] boot_1.3-28.1
    ## [130] MASS_7.3-58.3
    ## [131] gtools_3.9.4
    ## [132] SummarizedExperiment_1.28.0
    ## [133] rjson_0.2.21
    ## [134] withr_3.0.2
    ## [135] GenomicAlignments_1.34.1
    ## [136] Rsamtools_2.14.0
    ## [137] S4Vectors_0.36.2
    ## [138] GenomeInfoDbData_1.2.9
    ## [139] parallel_4.2.2
    ## [140] hms_1.1.3
    ## [141] grid_4.2.2
    ## [142] ggfun_0.0.9
    ## [143] tidyr_1.3.0
    ## [144] HDO.db_0.99.1
    ## [145] rmarkdown_2.21
    ## [146] MatrixGenerics_1.10.0
    ## [147] ggforce_0.4.1
    ## [148] Biobase_2.58.0
    ## [149] restfulr_0.0.15