---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>",
    fig.path = "man/figures/README-",
    out.width = "100%"
)
```

# raer <a href="https://rnabioco.github.io/raer"><img src="man/figures/logo.png" align="right" height="138" /></a>

<!-- badges: start -->
[![R-CMD-check-bioc](https://github.com/rnabioco/raer/actions/workflows/check-bioc.yml/badge.svg)](https://github.com/rnabioco/raer/actions/workflows/check-bioc.yml)
[![Codecov test coverage](https://codecov.io/gh/rnabioco/raer/branch/devel/graph/badge.svg)](https://app.codecov.io/gh/rnabioco/raer?branch=devel)
[![platforms](https://bioconductor.org/shields/availability/devel/raer.svg)](https://bioconductor.org/checkResults/release/bioc-LATEST/raer)
[![bioc](https://bioconductor.org/shields/years-in-bioc/raer.svg)](https://bioconductor.org/packages/release/bioc/html/raer.html)
<!-- badges: end -->

raer facilitates analysis of RNA adenosine editing in the
[Bioconductor](https://bioconductor.org/) ecosystem.

## Installation

`raer` is available on [Bioconductor](https://bioconductor.org/packages/release/bioc/html/raer.html):

```{r, eval = FALSE}
if (!require("BiocManager", quietly = TRUE)) {
    install.packages("BiocManager")
}

BiocManager::install("raer")
```

You can install the development version of raer from [GitHub](https://github.com/rnabioco/raer) with:

```{r, eval = FALSE}
BiocManager::install("rnabioco/raer")
```

## Quick start

![raer workflow overview](man/figures/raer_workflow.png)

raer provides methods to compute per site read count summaries from BAM
alignment files, either for known editing sites, or for all detected sites.

```{r pileup_sites}
library(raer)
bam1fn <- raer_example("SRR5564269_Aligned.sortedByCoord.out.md.bam")
bam2fn <- raer_example("SRR5564277_Aligned.sortedByCoord.out.md.bam")
fafn <- raer_example("human.fasta")

bams <- c("ko" = bam1fn, "wt" = bam2fn)

rse <- pileup_sites(bams, fafn)
```


To facilitate comparisons across groups, base count data and genomic coordinates 
are stored in a  `RangedSummarizedExperiment`. 

```{r}
suppressMessages(library(SummarizedExperiment))
rse
assays(rse)
colData(rse)
```

```{r}
assays(rse)$nRef[1:4, ]
assays(rse)$nAlt[1:4, ]
```


The `FilterParam()` class holds multiple options for customizing the output of `pileup_sites()`.

```{r params}
fp <- FilterParam(
    only_keep_variants = TRUE,
    library_type = "fr-first-strand",
    min_depth = 2
)

rse <- pileup_sites(bams, fafn, param = fp)
rse
```

`pileup_cells()` provides support for quantifying editing sites in single cell libraries.

```{r scrnaseq}
scbam_fn <- raer_example("5k_neuron_mouse_possort.bam")
outdir <- tempdir()

editing_sites <- GRanges(
    c(
        "2:579:-",
        "2:625:-",
        "2:589:-"
    ),
    REF = "A",
    ALT = "G"
)

cbs <- c(
    "CACCAAACAACAACAA-1",
    "TATTCCACACCCTCTA-1",
    "GACCTTCAGTTGTAAG-1"
)

sce <- pileup_cells(scbam_fn,
    sites = editing_sites,
    cell_barcodes = cbs,
    param = fp,
    output_directory = outdir
)
sce
```

```{r}
assays(sce)$nRef
assays(sce)$nAlt
```

## Related work

Core routines in `raer` are implemented using the `htslib` library and methods from `samtools` and `bcftools`. `raer` builds off of approaches from other RNA editing detection tools:  

 - [REDItools](https://github.com/BioinfoUNIBA/REDItools) from [Picardi E, Pesole G](https://doi.org/10.1093/bioinformatics/btt287)   
 - [JACUSA2](https://github.com/dieterich-lab/JACUSA2)  from [Piechotta M et al ](https://doi.org/10.1186/s12859-016-1432-8)    
 - [deNovo-Detect](https://github.com/a2iEditing/deNovo-Detect) from [Gabay O et al ](https://doi.org/10.1038/s41467-022-28841-4)   
 - [RNAEditingIndexer](https://github.com/a2iEditing/RNAEditingIndexer) from [Roth SH et al](https://doi.org/10.1038/s41592-019-0610-9)  
- [SAILOR](https://github.com/YeoLab/sailor) from [Washburn MC et al](https://10.1016/j.celrep.2014.01.011)