# BREW3R.r

Lucille Lopez-Delisle

#### 2024-02-21

# Contents

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

# 2 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")

# 3 Example

## 3.1 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 objects are masked from 'package:base':
    ##
    ##     Filter, Find, Map, Position, Reduce, anyDuplicated, aperm, append,
    ##     as.data.frame, basename, cbind, colnames, dirname, do.call,
    ##     duplicated, eval, evalq, get, grep, grepl, is.unsorted, lapply,
    ##     mapply, match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
    ##     rank, rbind, rownames, sapply, saveRDS, table, tapply, 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':
    ##
    ##     I, expand.grid, unname

    ## Loading required package: IRanges

    ##
    ## Attaching package: 'IRanges'

    ## The following object is masked from 'package:grDevices':
    ##
    ##     windows

    ## Loading required package: GenomeInfoDb

    library(GenomicRanges)

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

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

## 3.4 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")

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

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

## 3.7 Recompose the GRanges

We can put back annotations that have been stored:

    new_gr <- c(new_gr_exons, input_gr_CDS)

## 3.8 Write new GRanges to gtf

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

# 4 Session Info

    sessionInfo()

    ## R version 4.5.0 (2025-04-11 ucrt)
    ## Platform: x86_64-w64-mingw32/x64
    ## Running under: Windows Server 2022 x64 (build 20348)
    ##
    ## Matrix products: default
    ##   LAPACK version 3.12.1
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.utf8
    ## [3] LC_MONETARY=English_United States.utf8
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.utf8
    ##
    ## time zone: America/New_York
    ## tzcode source: internal
    ##
    ## attached base packages:
    ## [1] stats4    stats     graphics  grDevices utils     datasets  methods
    ## [8] base
    ##
    ## other attached packages:
    ## [1] BREW3R.r_1.5.0       rtracklayer_1.69.0   GenomicRanges_1.61.0
    ## [4] GenomeInfoDb_1.45.4  IRanges_2.43.0       S4Vectors_0.47.0
    ## [7] BiocGenerics_0.55.0  generics_0.1.4       BiocStyle_2.37.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] sass_0.4.10                 SparseArray_1.9.0
    ##  [3] bitops_1.0-9                lattice_0.22-7
    ##  [5] magrittr_2.0.3              digest_0.6.37
    ##  [7] evaluate_1.0.3              grid_4.5.0
    ##  [9] bookdown_0.43               fastmap_1.2.0
    ## [11] jsonlite_2.0.0              Matrix_1.7-3
    ## [13] restfulr_0.0.15             tinytex_0.57
    ## [15] BiocManager_1.30.25         httr_1.4.7
    ## [17] UCSC.utils_1.5.0            XML_3.99-0.18
    ## [19] Biostrings_2.77.1           codetools_0.2-20
    ## [21] jquerylib_0.1.4             abind_1.4-8
    ## [23] cli_3.6.5                   rlang_1.1.6
    ## [25] crayon_1.5.3                XVector_0.49.0
    ## [27] Biobase_2.69.0              cachem_1.1.0
    ## [29] DelayedArray_0.35.1         yaml_2.3.10
    ## [31] S4Arrays_1.9.1              tools_4.5.0
    ## [33] parallel_4.5.0              BiocParallel_1.43.3
    ## [35] Rsamtools_2.25.0            SummarizedExperiment_1.39.0
    ## [37] curl_6.2.3                  R6_2.6.1
    ## [39] magick_2.8.6                BiocIO_1.19.0
    ## [41] matrixStats_1.5.0           lifecycle_1.0.4
    ## [43] bslib_0.9.0                 Rcpp_1.0.14
    ## [45] xfun_0.52                   GenomicAlignments_1.45.0
    ## [47] MatrixGenerics_1.21.0       knitr_1.50
    ## [49] rjson_0.2.23                htmltools_0.5.8.1
    ## [51] rmarkdown_2.29              compiler_4.5.0
    ## [53] RCurl_1.98-1.17