# BREW3R.r

# Introduction

The BREW3R.r package has been written to be part of the BREW3R workflow. Today, the package contains a single function which enable to extend three prime of gene annotations using another gene annotation as template. This is very helpful when you are using a technique that only sequence three-prime end of genes like 10X scRNA-seq or BRB-seq.

# Installation

To install from Bioconductor use:

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

    BiocManager::install("BREW3R.r")

To install from github use:

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

    BiocManager::install("lldelisle/BREW3R.r")

# Example

## Load dependencies

    library(rtracklayer)

    ## Loading required package: GenomicRanges

    ## Loading required package: stats4

    ## Loading required package: BiocGenerics

    ## Loading required package: generics

    ##
    ## Attaching package: 'generics'

    ## The following objects are masked from 'package:base':
    ##
    ##     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
    ##     setequal, union

    ##
    ## Attaching package: 'BiocGenerics'

    ## The following objects are masked from 'package:stats':
    ##
    ##     IQR, mad, sd, var, xtabs

    ## The following object is masked from 'package:utils':
    ##
    ##     data

    ## The following objects are masked from 'package:base':
    ##
    ##     anyDuplicated, aperm, append, as.data.frame, basename, cbind,
    ##     colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
    ##     get, grep, grepl, is.unsorted, lapply, Map, mapply, match, mget,
    ##     order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    ##     rbind, Reduce, rownames, sapply, saveRDS, scale, sequence, table,
    ##     tapply, transform, unique, unsplit, which.max, which.min

    ## Loading required package: S4Vectors

    ##
    ## Attaching package: 'S4Vectors'

    ## The following object is masked from 'package:utils':
    ##
    ##     findMatches

    ## The following objects are masked from 'package:base':
    ##
    ##     expand.grid, I, unname

    ## Loading required package: IRanges

    ## Loading required package: Seqinfo

    library(GenomicRanges)

## Get gtfs

In this example, I will extend the transcripts from gencode using RefSeq on mm10. In order to decrease the size of the input files, the input files of this vignette have been subsetted to the chromosome 19. Original gtf for gencode is available here and gtf for RefSeq is available here.

    input_gtf_file_to_extend <-
        system.file(
            "extdata/chr19.gencode.vM25.annotation.gtf.gz",
            package = "BREW3R.r",
            mustWork = TRUE
        )
    input_gtf_file_template <-
        system.file(
            "extdata/chr19.mm10.ncbiRefSeq.gtf.gz",
            package = "BREW3R.r",
            mustWork = TRUE
        )

## Convert gtf files to GRanges

We will use the rtracklayer package to import gtf:

    input_gr_to_extend <- rtracklayer::import(input_gtf_file_to_extend)
    input_gr_template <- rtracklayer::import(input_gtf_file_template)

## Save annotations

The package only use exon information. It may be interesting to save the other annotations like ‘CDS’, ‘start_codon’, ‘end_codon’.

You should not save the ‘gene’ and ‘transcript’ annotations as they will be out of date. Same for three prime UTR.

    input_gr_CDS <- subset(input_gr_to_extend, type == "CDS")

## Extend the GRanges

Now we can run the main function of the package:

    library(BREW3R.r)
    new_gr_exons <- extend_granges(
        input_gr_to_extend = input_gr_to_extend,
        input_gr_to_overlap = input_gr_template
    )

    ## Found 4343 last exons to potentially extend.

    ## Compute overlap between 4343 exons and 38576 exons.

    ## 2331  exons may be extended.

    ## 2263 exons have been extended while preventing collision with other genes.

    ## Found 32563  exons that may be included into 723 transcripts.

    ## Stay 68 candidate exons that may be included into 26 transcripts.

    ## Finally 29 combined exons will be included into 26 transcripts.

By default, you get few statistics. You can change the verbosity with `options(rlib_message_verbosity = "quiet")` to mute it or on the contrary you can set `options(BREW3R.r.verbose = "progression")` to get messages with all steps. Among them, you can read that you extended about half of last exons, then you could add 29 exons to 26 transcripts.

## Explore your data

Here is an example for the Btrc gene that have been extended:

Here is an example for the Mrpl21 gene that have a new exon on the 3’ end of one of its transcript:

## Recompose the GRanges

We can put back annotations that have been stored:

    new_gr <- c(new_gr_exons, input_gr_CDS)

## Write new GRanges to gtf

    rtracklayer::export.gff(sort(new_gr), "my_new.gtf")

# Session Info

    sessionInfo()

    ## R version 4.6.0 (2026-04-24)
    ## Platform: x86_64-pc-linux-gnu
    ## Running under: Ubuntu 24.04.4 LTS
    ##
    ## Matrix products: default
    ## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    ## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
    ##
    ## 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
    ##
    ## time zone: Etc/UTC
    ## tzcode source: system (glibc)
    ##
    ## attached base packages:
    ## [1] stats4    stats     graphics  grDevices utils     datasets  methods
    ## [8] base
    ##
    ## other attached packages:
    ## [1] BREW3R.r_1.9.0       rtracklayer_1.73.0   GenomicRanges_1.65.0
    ## [4] Seqinfo_1.3.0        IRanges_2.47.2       S4Vectors_0.51.3
    ## [7] BiocGenerics_0.59.6  generics_0.1.4       BiocStyle_2.41.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] sass_0.4.10                 SparseArray_1.13.2
    ##  [3] bitops_1.0-9                lattice_0.22-9
    ##  [5] digest_0.6.39               evaluate_1.0.5
    ##  [7] grid_4.6.0                  fastmap_1.2.0
    ##  [9] jsonlite_2.0.0              Matrix_1.7-5
    ## [11] cigarillo_1.3.0             restfulr_0.0.16
    ## [13] BiocManager_1.30.27         httr_1.4.8
    ## [15] XML_3.99-0.23               Biostrings_2.81.2
    ## [17] codetools_0.2-20            jquerylib_0.1.4
    ## [19] abind_1.4-8                 cli_3.6.6
    ## [21] rlang_1.2.0                 crayon_1.5.3
    ## [23] XVector_0.53.0              Biobase_2.73.1
    ## [25] DelayedArray_0.39.3         cachem_1.1.0
    ## [27] yaml_2.3.12                 BiocBaseUtils_1.15.1
    ## [29] S4Arrays_1.13.0             tools_4.6.0
    ## [31] parallel_4.6.0              BiocParallel_1.47.0
    ## [33] Rsamtools_2.29.0            SummarizedExperiment_1.43.0
    ## [35] curl_7.1.0                  buildtools_1.0.0
    ## [37] R6_2.6.1                    BiocIO_1.23.3
    ## [39] matrixStats_1.5.0           lifecycle_1.0.5
    ## [41] bslib_0.11.0                xfun_0.57
    ## [43] GenomicAlignments_1.49.0    sys_3.4.3
    ## [45] MatrixGenerics_1.25.0       knitr_1.51
    ## [47] rjson_0.2.23                htmltools_0.5.9
    ## [49] rmarkdown_2.31              maketools_1.3.2
    ## [51] compiler_4.6.0              RCurl_1.98-1.18