View source: R/add_exon_number.R
add_exon_number | R Documentation |
add_exon_number()
adds the exon number (the order the exons are transcribed
within each transcript) as a column in exons
. This can be useful when
visualizing long, complex transcript structures, in order to keep track of
specific exons of interest.
add_exon_number(exons, group_var = NULL)
exons |
|
group_var |
|
To note, a "strand" column must be present within exons
. The strand is used
to differentiate whether exon numbers should be calculated according to
ascending ("+") or descending ("-") genomic co-ordinates. For ambiguous
strands ("*"), add_exon_number()
will be assume the strand be "+".
data.frame()
equivalent to input exons
, with the additional
column "exon_number".
library(magrittr)
library(ggplot2)
# to illustrate the package's functionality
# ggtranscript includes example transcript annotation
sod1_annotation %>% head()
# extract exons
sod1_exons <- sod1_annotation %>% dplyr::filter(type == "exon")
sod1_exons %>% head()
# add the exon number for each transcript
sod1_exons <- sod1_exons %>% add_exon_number(group_var = "transcript_name")
base <- sod1_exons %>%
ggplot(aes(
xstart = start,
xend = end,
y = transcript_name
)) +
geom_range() +
geom_intron(
data = to_intron(sod1_exons, "transcript_name"),
strand = "+"
)
# it can be useful to annotate exons with their exon number
# using ggplot2::geom_text()
base +
geom_text(aes(
x = (start + end) / 2, # plot label at midpoint of exon
label = exon_number
),
size = 3.5,
nudge_y = 0.4
)
# Or alternatively, using ggrepel::geom_label_repel()
# to separate labels from exons
base +
ggrepel::geom_label_repel(ggplot2::aes(
x = (start + end) / 2,
label = exon_number
),
size = 3.5,
min.segment.length = 0
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.