R/exons_to_genes.R

Defines functions exons_to_genes

Documented in exons_to_genes

#' Convert exon annotation to genes
#'
#' @param x the exon level annotation containing columns "gene_id", "chr",
#'   "strand" and "symbol".
#'
#' @return the gene level annotation where each gene is taken to span the
#'   earliest start position and latest end position of its exons.
#' @export
#'
#' @examples
#' nmr <- load_example_nanomethresult()
#' exons_to_genes(NanoMethViz::exons(nmr))
exons_to_genes <- function(x) {
    if (is(x, "NanoMethResult") | is(x, "ModBamResult")) {
        x <- NanoMethViz::exons(x)
    }

    x %>%
        dplyr::group_by(.data$gene_id, .data$chr, .data$strand, .data$symbol) %>%
        dplyr::summarise(start = min(.data$start), end = max(.data$end), .groups = "drop") %>%
        dplyr::ungroup()
}
Shians/NanoMethViz documentation built on June 8, 2024, 10:48 p.m.