| Title: | splicelogic: differential transcripts to splice events |
|---|---|
| Description: | Translate differential transcript usage results into discrete splice events. |
| Authors: | Beatriz Campillo [aut, cre] (ORCID: <https://orcid.org/0000-0001-7323-9125>), Michael Love [aut] (ORCID: <https://orcid.org/0000-0001-8401-0545>), NIH NHGRI [fnd], Wellcome Trust [fnd] |
| Maintainer: | Beatriz Campillo <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.1.5 |
| Built: | 2026-11-03 13:08:47 UTC |
| Source: | https://github.com/bioc/splicelogic |
For more details on the features of splicelogic, read the vignette:
browseVignettes(package = "splicelogic")
Maintainer: Beatriz Campillo [email protected] (ORCID)
Authors:
Beatriz Campillo [email protected] (ORCID)
Michael Love [email protected] (ORCID)
Other contributors:
NIH NHGRI [funder]
Wellcome Trust [funder]
Useful links:
Report bugs at https://github.com/thelovelab/splicelogic/issues
Create mock GRanges data for splicing event testing
create_mock_data( n_genes = 1, n_tx_per_gene = 2, n_exons_per_tx = 5, coef_range = c(-1, 1), strand = c("+", "-", "*") )create_mock_data( n_genes = 1, n_tx_per_gene = 2, n_exons_per_tx = 5, coef_range = c(-1, 1), strand = c("+", "-", "*") )
n_genes |
Number of genes to simulate |
n_tx_per_gene |
Number of transcripts per gene. Use 2 or more:
the first transcript of each gene is given a negative estimate and
the second a positive one, so a single transcript per gene leaves
the set all-negative and the |
n_exons_per_tx |
Number of exons per transcript |
coef_range |
Range of coefficient values to sample from |
strand |
Strand to place every transcript on: |
A GRanges object with simulated transcripts and exons
# create mock data with 2 genes, 4 transcripts # per gene, and 4 exons per transcript gr <- create_mock_data(n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4) # the same, on the minus strand gr_minus <- create_mock_data(n_genes = 2, n_exons_per_tx = 4, strand = "-")# create mock data with 2 genes, 4 transcripts # per gene, and 4 exons per transcript gr <- create_mock_data(n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4) # the same, on the minus strand gr_minus <- create_mock_data(n_genes = 2, n_exons_per_tx = 4, strand = "-")
One pastel colour per event_type returned by the find_*() functions,
chosen together with the soft blue and red plot_transcripts() uses for
the up- and down-regulated transcripts, so the eleven stay as far apart as
pastels allow, including under protanopia and deuteranopia. Pastels leave
less room between colours than saturated ones, which is why event exons
are also outlined and labelled with their type.
event_palette()event_palette()
A character vector of colours, named by event type.
event_palette()event_palette()
Functions to find different types of alternative splicing events from preprocessed GRanges exon data. Events include skipped exon (se), included exon (ie), mutatualy exclusive exons (mxe), retained intron (ri), spliced intron (si), alternative 5' and 3' splice sites (a5ss / a3ss), and alternative transcription start and end sites (atss / ates).
find_ie() and find_si() are the reverse of find_se() and
find_ri(): the same comparison with the up and down transcripts
swapped. A spliced intron is an intron of an up transcript that a down
transcript retains, i.e. an intron that the up transcript splices out.
find_a5ss() / find_a3ss() do not require either boundary of an exon
to be shared with its partner, so an exon that moved both boundaries is
reported as an a5ss and an a3ss. A first exon has no acceptor and a
last exon has no donor, so those boundaries never produce an a3ss /
a5ss; find_atss() / find_ates() report them instead by comparing
where each transcript begins and ends. exon_rank runs in
transcription order, so this holds on both strands.
When an exon overlaps two or more exons of its partner (a retained or
spliced intron), the boundaries facing the intron are left to
find_ri() / find_si(); only the outer boundaries of the group are
compared. An exon that retains an intron and uses a different outer
splice site is therefore reported as both an ri (or si) and an a5ss /
a3ss.
find_se(gr, type = c("over", "boundary", "identical"), inverse = FALSE, ...) find_skipped_exons( gr, type = c("over", "boundary", "identical"), inverse = FALSE, ... ) find_ie(gr, type = c("over", "boundary", "identical"), ...) find_included_exons(gr, type = c("over", "boundary", "identical"), ...) find_mxe(gr, type = c("over", "boundary", "identical"), ...) find_mutually_exclusive_exons( gr, type = c("over", "boundary", "identical"), ... ) find_ri(gr, inverse = FALSE) find_retained_introns(gr, inverse = FALSE) find_si(gr) find_spliced_introns(gr) find_a5ss(gr) find_alternative_5_prime_splice_sites(gr) find_a3ss(gr) find_alternative_3_prime_splice_sites(gr) find_atss(gr) find_alternative_transcription_start_sites(gr) find_ates(gr) find_alternative_transcription_end_sites(gr) find_all_events( gr, type = c("over", "boundary", "identical"), verbose = TRUE, ... )find_se(gr, type = c("over", "boundary", "identical"), inverse = FALSE, ...) find_skipped_exons( gr, type = c("over", "boundary", "identical"), inverse = FALSE, ... ) find_ie(gr, type = c("over", "boundary", "identical"), ...) find_included_exons(gr, type = c("over", "boundary", "identical"), ...) find_mxe(gr, type = c("over", "boundary", "identical"), ...) find_mutually_exclusive_exons( gr, type = c("over", "boundary", "identical"), ... ) find_ri(gr, inverse = FALSE) find_retained_introns(gr, inverse = FALSE) find_si(gr) find_spliced_introns(gr) find_a5ss(gr) find_alternative_5_prime_splice_sites(gr) find_a3ss(gr) find_alternative_3_prime_splice_sites(gr) find_atss(gr) find_alternative_transcription_start_sites(gr) find_ates(gr) find_alternative_transcription_end_sites(gr) find_all_events( gr, type = c("over", "boundary", "identical"), verbose = TRUE, ... )
gr |
A GRanges object with exon annotations, including 'tx_id', 'exon', and 'coef_col' metadata columns and preprocessed with preprocess(). |
type |
How an exon flanking a candidate is matched to an exon of the partner transcript. One of:
|
inverse |
If TRUE, swaps the up and down transcripts: |
... |
Further arguments passed to |
verbose |
If TRUE, prints progress messages. Default TRUE. |
A GRanges object with the detected exon ranges and the following additional metadata columns:
event_typeThe type of splicing event detected (e.g.
"se", "ie", "mxe", "ri", "si",
"a5ss", "a3ss", "atss", "ates").
event_tx_idTranscript ID of the paired transcript involved in the event.
event_estimateDTU coefficient of the paired transcript.
event_<col>One column per name in
metadata(gr)$additional_columns, prefixed with event_,
carrying the corresponding value from the paired transcript.
find_se(): skipped exons
find_ie(): included exons
find_mxe(): mutually exclusive exons
find_ri(): retained introns
find_si(): spliced introns
find_a5ss(): alternative 5' splice sites
find_a3ss(): alternative 3' splice sites
find_atss(): alternative transcription start sites — first
exons that begin transcription at a different coordinate
find_ates(): alternative transcription end sites — last
exons that end transcription at a different coordinate
find_all_events(): all detected events
# make some mock data and run the function gr <- create_mock_data(n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4) |> preprocess(coef_col = "estimate") |> generate_se(n_events = 1) # this should find the skipped exon events we generated find_se(gr, type = "boundary") find_ie(gr, type = "boundary") # detect mutually exclusive exons gr_mx <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_mxe(n_events = 1) find_mxe(gr_mx, type = "boundary") # detect retained introns gr_ri <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_ri(n_events = 1) find_ri(gr_ri) # the same data with the signs flipped: the introns retained above are # now spliced out by the up transcripts gr_si <- gr_ri |> dplyr::mutate(estimate = -estimate) find_si(gr_si) # detect alternative 5' splice sites gr_a5 <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_a5ss(n_events = 1) find_a5ss(gr_a5) # detect alternative 3' splice sites gr_a3 <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_a3ss(n_events = 1) find_a3ss(gr_a3) gr_tss <- data.frame( seqnames = "chr1", start = c(1, 21, 41, 5, 21, 41), end = c(10, 30, 50, 10, 30, 50), strand = "+", gene_id = "g1", tx_id = rep(c("down", "up"), each = 3), exon_rank = rep(seq_len(3), 2), estimate = rep(c(-1, 1), each = 3) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") find_atss(gr_tss) # detect all event types at once gr_all <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_se(n_events = 1) find_all_events(gr_all, type = "boundary", verbose = FALSE)# make some mock data and run the function gr <- create_mock_data(n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4) |> preprocess(coef_col = "estimate") |> generate_se(n_events = 1) # this should find the skipped exon events we generated find_se(gr, type = "boundary") find_ie(gr, type = "boundary") # detect mutually exclusive exons gr_mx <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_mxe(n_events = 1) find_mxe(gr_mx, type = "boundary") # detect retained introns gr_ri <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_ri(n_events = 1) find_ri(gr_ri) # the same data with the signs flipped: the introns retained above are # now spliced out by the up transcripts gr_si <- gr_ri |> dplyr::mutate(estimate = -estimate) find_si(gr_si) # detect alternative 5' splice sites gr_a5 <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_a5ss(n_events = 1) find_a5ss(gr_a5) # detect alternative 3' splice sites gr_a3 <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_a3ss(n_events = 1) find_a3ss(gr_a3) gr_tss <- data.frame( seqnames = "chr1", start = c(1, 21, 41, 5, 21, 41), end = c(10, 30, 50, 10, 30, 50), strand = "+", gene_id = "g1", tx_id = rep(c("down", "up"), each = 3), exon_rank = rep(seq_len(3), 2), estimate = rep(c(-1, 1), each = 3) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") find_atss(gr_tss) # detect all event types at once gr_all <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) |> preprocess(coef_col = "estimate") |> generate_se(n_events = 1) find_all_events(gr_all, type = "boundary", verbose = FALSE)
Functions to introduce specific types of alternative splicing events into mock GRanges data for testing purposes.
generate_se(gr, n_events = 1) generate_mxe(gr, n_events = 1) generate_ri(gr, n_events = 1) generate_a5ss(gr, n_events = 1) generate_a3ss(gr, n_events = 1) generate_atss(gr, n_events = 1, mode = c("shift", "drop")) generate_ates(gr, n_events = 1, mode = c("shift", "drop"))generate_se(gr, n_events = 1) generate_mxe(gr, n_events = 1) generate_ri(gr, n_events = 1) generate_a5ss(gr, n_events = 1) generate_a3ss(gr, n_events = 1) generate_atss(gr, n_events = 1, mode = c("shift", "drop")) generate_ates(gr, n_events = 1, mode = c("shift", "drop"))
gr |
A GRanges object with metadata columns: 'exon_rank', 'gene_id', 'tx_id', and 'estimate'. |
n_events |
Number of events to generate |
mode |
How to move the site: |
generate_se(): A GRanges object with skipped exon
events introduced
generate_mxe(): A GRanges object with mutually exclusive exon
events introduced
generate_ri(): A GRanges object with retained intron
events introduced
generate_a5ss(): A GRanges object with alternative 5' splice site
events introduced
generate_a3ss(): A GRanges object with alternative 3' splice site
events introduced
generate_atss(): A GRanges object with alternative
transcription start site events introduced
generate_ates(): A GRanges object with alternative
transcription end site events introduced
gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_se(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_mxe(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_ri(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_a5ss(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_a3ss(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_atss(gr, n_events = 1) # the non-overlapping variant: drop the first exon altogether generate_atss(gr, n_events = 1, mode = "drop") gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_ates(gr, n_events = 1)gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_se(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_mxe(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_ri(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_a5ss(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_a3ss(gr, n_events = 1) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_atss(gr, n_events = 1) # the non-overlapping variant: drop the first exon altogether generate_atss(gr, n_events = 1, mode = "drop") gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4 ) generate_ates(gr, n_events = 1)
Given a GRanges, look up the DNA or RNA sequence
of each range in a reference genome. This is a simple
helper function that rearranges the getSeq arguments
and combines it with other helper functions to refer
to genomes by name.
get_seq(gr, genome, as_rna = FALSE)get_seq(gr, genome, as_rna = FALSE)
gr |
A GRanges object. |
genome |
Either a character string naming an installed BSgenome
package (e.g. |
as_rna |
If |
A DNAStringSet (or RNAStringSet if
as_rna = TRUE), one entry per range in gr, in the
same order. Assign it onto gr (e.g. gr$seq <- ...)
to keep it as a metadata column.
gr <- GenomicRanges::GRanges( "chr1", IRanges::IRanges(start = c(1e6, 1.1e6), width = 50) ) suppressPackageStartupMessages( library(Biostrings) ) get_seq(gr, "hg38") get_seq(gr, "hg38", as_rna = TRUE) set.seed(123) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 3, n_exons_per_tx = 6 ) |> generate_se(n_events = 1) |> GenomicRanges::shift(50e6) # move mock data skipped <- find_se(gr) suppressPackageStartupMessages( library(magrittr) ) # magrittr pipe needed for the `.` placeholder below skipped %>% plyranges::flank_upstream(100) %>% dplyr::mutate(seq = get_seq(., "hg38"))gr <- GenomicRanges::GRanges( "chr1", IRanges::IRanges(start = c(1e6, 1.1e6), width = 50) ) suppressPackageStartupMessages( library(Biostrings) ) get_seq(gr, "hg38") get_seq(gr, "hg38", as_rna = TRUE) set.seed(123) gr <- create_mock_data( n_genes = 2, n_tx_per_gene = 3, n_exons_per_tx = 6 ) |> generate_se(n_events = 1) |> GenomicRanges::shift(50e6) # move mock data skipped <- find_se(gr) suppressPackageStartupMessages( library(magrittr) ) # magrittr pipe needed for the `.` placeholder below skipped %>% plyranges::flank_upstream(100) %>% dplyr::mutate(seq = get_seq(., "hg38"))
Draws one diverging bar per transcript appearing in tx_id or
event_tx_id of events: left of zero for a negative value and right for
a positive one. It is the companion to plot_transcripts(): given the same
events the two plots share their row order and y limits, so they line up
when placed side by side, e.g. with patchwork.
plot_transcript_lfc( events, tx_lfc, title = NULL, lfc_max = NULL, lfc_label = "log2 fold change", lfc_ends = NULL, bar_color = "grey30", transcript_label = FALSE )plot_transcript_lfc( events, tx_lfc, title = NULL, lfc_max = NULL, lfc_label = "log2 fold change", lfc_ends = NULL, bar_color = "grey30", transcript_label = FALSE )
events |
A GRanges returned by |
tx_lfc |
Numeric vector named by transcript id, e.g. a log2 fold change from a differential expression analysis. Transcripts not named in it keep their row but get no bar. |
title |
Plot title. Default |
lfc_max |
Half-width of the x axis. |
lfc_label |
x-axis title. |
lfc_ends |
Optional length-2 character vector naming the negative and
positive ends of the axis, e.g. |
bar_color |
Colour of the bars. Default |
transcript_label |
Whether to print the transcript ids on the y axis,
for use on its own. Default |
A ggplot object.
exons <- data.frame( seqnames = "chr1", start = c(1, 201, 401, 1, 401), end = c(100, 300, 500, 100, 500), strand = "+", gene_id = "g1", tx_id = c("down", "down", "down", "up", "up"), exon_rank = c(1, 2, 3, 1, 2), estimate = c(-1, -1, -1, 1, 1) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") events <- find_all_events(exons, verbose = FALSE) tx_lfc <- c(down = -1.8, up = 0.6) if (requireNamespace("ggplot2", quietly = TRUE)) { plot_transcript_lfc(events, tx_lfc, transcript_label = TRUE) }exons <- data.frame( seqnames = "chr1", start = c(1, 201, 401, 1, 401), end = c(100, 300, 500, 100, 500), strand = "+", gene_id = "g1", tx_id = c("down", "down", "down", "up", "up"), exon_rank = c(1, 2, 3, 1, 2), estimate = c(-1, -1, -1, 1, 1) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") events <- find_all_events(exons, verbose = FALSE) tx_lfc <- c(down = -1.8, up = 0.6) if (requireNamespace("ggplot2", quietly = TRUE)) { plot_transcript_lfc(events, tx_lfc, transcript_label = TRUE) }
Draws one row per transcript appearing in tx_id or event_tx_id of
events. Transcripts are coloured by the sign of their estimate (blue when
positive, red when negative), and the exons called as events are filled by
event type, outlined, and labelled with the type. An exon called as several
types at once, e.g. an a5ss and an a3ss when both of its boundaries moved,
is filled with the first type and striped diagonally with the others. A
bent arrow over the first exon marks where each transcript starts and which
way it runs.
plot_transcripts( events, exons, title = NULL, up_color = "#1f77b4", down_color = "#d62728", event_colors = event_palette(), unknown_color = "#999999", rescale_introns = TRUE, new_intron_length = 50, flanking_length = c(50, 50), transcript_label = TRUE, label_events = TRUE, label_size = 2.6, legend = TRUE, tx_annot = NULL, stripe_multi_events = TRUE )plot_transcripts( events, exons, title = NULL, up_color = "#1f77b4", down_color = "#d62728", event_colors = event_palette(), unknown_color = "#999999", rescale_introns = TRUE, new_intron_length = 50, flanking_length = c(50, 50), transcript_label = TRUE, label_events = TRUE, label_size = 2.6, legend = TRUE, tx_annot = NULL, stripe_multi_events = TRUE )
events |
A GRanges returned by |
exons |
A flat GRanges of exons with a |
title |
Plot title. Default |
up_color, down_color
|
Colours for transcripts with a positive and a negative estimate. |
event_colors |
Named vector mapping event type to fill colour.
Default |
unknown_color |
Fill for event types absent from |
rescale_introns |
Whether gaps between exons are shortened to
|
new_intron_length |
Length (bp) of each gap after rescaling.
Default |
flanking_length |
Length (bp) of the region drawn before the first
and after the last exon. Default |
transcript_label |
Whether to print the transcript id and estimate
above each row. Default |
label_events |
Whether to print the event type below each event exon.
Default |
label_size |
Size of the event labels. Default |
legend |
Whether to draw the fill legend. Default |
tx_annot |
Optional character vector named by transcript id, appended to that transcript's label (e.g. novel status). Transcripts not named in it keep the plain label. |
stripe_multi_events |
Whether an exon called as several event types is
striped with the types its fill leaves out. Default |
All events passed in are drawn on one panel, so they must come from a
single gene; events from several genes are an error. Subset first, or use
plot_transcripts_by_gene() for one plot per gene and
plot_transcripts_by_pair() for one plot per transcript pair. A single
event, e.g. plot_transcripts(events[1], exons), draws its two transcripts.
A per-transcript value such as a fold change is drawn separately by
plot_transcript_lfc(). Given the same events, the two plots share
their row order and y limits, so they line up side by side.
A ggplot object.
# one gene: "down" has three exons, "up" skips the middle one exons <- data.frame( seqnames = "chr1", start = c(1, 201, 401, 1, 401), end = c(100, 300, 500, 100, 500), strand = "+", gene_id = "g1", tx_id = c("down", "down", "down", "up", "up"), exon_rank = c(1, 2, 3, 1, 2), estimate = c(-1, -1, -1, 1, 1) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") events <- find_all_events(exons, verbose = FALSE) if (requireNamespace("ggplot2", quietly = TRUE)) { plot_transcripts(events, exons) }# one gene: "down" has three exons, "up" skips the middle one exons <- data.frame( seqnames = "chr1", start = c(1, 201, 401, 1, 401), end = c(100, 300, 500, 100, 500), strand = "+", gene_id = "g1", tx_id = c("down", "down", "down", "up", "up"), exon_rank = c(1, 2, 3, 1, 2), estimate = c(-1, -1, -1, 1, 1) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") events <- find_all_events(exons, verbose = FALSE) if (requireNamespace("ggplot2", quietly = TRUE)) { plot_transcripts(events, exons) }
Splits events by gene_id and draws each gene with
plot_transcripts().
plot_transcripts_by_gene(events, exons, genes = NULL, title = NULL, ...)plot_transcripts_by_gene(events, exons, genes = NULL, title = NULL, ...)
events |
A GRanges returned by |
exons |
A flat GRanges of exons with a |
genes |
Optional character vector of gene ids to restrict to. |
title |
Optional prefix for the plot titles, which are otherwise the gene id. |
... |
Passed to |
A named list of ggplot objects, one per gene.
exons <- data.frame( seqnames = "chr1", start = c(1, 201, 401, 1, 401), end = c(100, 300, 500, 100, 500), strand = "+", gene_id = "g1", tx_id = c("down", "down", "down", "up", "up"), exon_rank = c(1, 2, 3, 1, 2), estimate = c(-1, -1, -1, 1, 1) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") events <- find_all_events(exons, verbose = FALSE) if (requireNamespace("ggplot2", quietly = TRUE)) { plots <- plot_transcripts_by_gene(events, exons) plots[["g1"]] }exons <- data.frame( seqnames = "chr1", start = c(1, 201, 401, 1, 401), end = c(100, 300, 500, 100, 500), strand = "+", gene_id = "g1", tx_id = c("down", "down", "down", "up", "up"), exon_rank = c(1, 2, 3, 1, 2), estimate = c(-1, -1, -1, 1, 1) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") events <- find_all_events(exons, verbose = FALSE) if (requireNamespace("ggplot2", quietly = TRUE)) { plots <- plot_transcripts_by_gene(events, exons) plots[["g1"]] }
Splits events by transcript pair, so each plot shows two transcripts and
every event between them. The pair is unordered, so events reported from
either side land in the same plot.
plot_transcripts_by_pair(events, exons, title = NULL, ...)plot_transcripts_by_pair(events, exons, title = NULL, ...)
events |
A GRanges returned by |
exons |
A flat GRanges of exons with a |
title |
Optional prefix for the plot titles, which are otherwise the transcript pair. |
... |
Passed to |
A named list of ggplot objects, one per transcript pair.
exons <- data.frame( seqnames = "chr1", start = c(1, 201, 401, 1, 401), end = c(100, 300, 500, 100, 500), strand = "+", gene_id = "g1", tx_id = c("down", "down", "down", "up", "up"), exon_rank = c(1, 2, 3, 1, 2), estimate = c(-1, -1, -1, 1, 1) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") events <- find_all_events(exons, verbose = FALSE) if (requireNamespace("ggplot2", quietly = TRUE)) { plots <- plot_transcripts_by_pair(events, exons) plots[["down-up"]] }exons <- data.frame( seqnames = "chr1", start = c(1, 201, 401, 1, 401), end = c(100, 300, 500, 100, 500), strand = "+", gene_id = "g1", tx_id = c("down", "down", "down", "up", "up"), exon_rank = c(1, 2, 3, 1, 2), estimate = c(-1, -1, -1, 1, 1) ) |> plyranges::as_granges() |> preprocess(coef_col = "estimate") events <- find_all_events(exons, verbose = FALSE) if (requireNamespace("ggplot2", quietly = TRUE)) { plots <- plot_transcripts_by_pair(events, exons) plots[["down-up"]] }
Extracts exon ranges from a TxDb object, merges them with
differential transcript usage (DTU) results, and returns a flat
GRanges ready for preprocess.
prepare_exons( txdb, dtu_table, coef_col, tx_id_col = "tx_id", gene_id_col = "gene_id", verbose = TRUE )prepare_exons( txdb, dtu_table, coef_col, tx_id_col = "tx_id", gene_id_col = "gene_id", verbose = TRUE )
txdb |
A |
dtu_table |
A data.frame or tibble with DTU results. Must contain columns for transcript ID, gene ID, and a coefficient. |
coef_col |
Column name in |
tx_id_col |
Column name in |
gene_id_col |
Column name in |
verbose |
Whether to print progress messages. Default |
A GRanges object with metadata columns: gene_id,
tx_id, exon_rank, the coefficient column, and any
additional columns from dtu_table.
library(AnnotationHub) library(AnnotationDbi) library(GenomicFeatures) library(tibble) ah <- AnnotationHub() txdb <- ah[["AH84134"]] # fly TxDb (Drosophila melanogaster) # build a simulated DTU table from the TxDb transcripts txps <- txdb |> AnnotationDbi::select( keys(txdb, "TXID"), c("TXNAME", "GENEID"), "TXID" ) |> tibble::as_tibble() |> dplyr::select(tx_id = TXNAME, gene_id = GENEID)|> dplyr::filter(!is.na(gene_id)) sim_dtu_table <- txps |> dplyr::mutate( padj = runif(dplyr::n()), effect_est = rnorm(dplyr::n()) ) fly_exons <- prepare_exons( txdb, sim_dtu_table, coef_col = "effect_est", verbose = TRUE )library(AnnotationHub) library(AnnotationDbi) library(GenomicFeatures) library(tibble) ah <- AnnotationHub() txdb <- ah[["AH84134"]] # fly TxDb (Drosophila melanogaster) # build a simulated DTU table from the TxDb transcripts txps <- txdb |> AnnotationDbi::select( keys(txdb, "TXID"), c("TXNAME", "GENEID"), "TXID" ) |> tibble::as_tibble() |> dplyr::select(tx_id = TXNAME, gene_id = GENEID)|> dplyr::filter(!is.na(gene_id)) sim_dtu_table <- txps |> dplyr::mutate( padj = runif(dplyr::n()), effect_est = rnorm(dplyr::n()) ) fly_exons <- prepare_exons( txdb, sim_dtu_table, coef_col = "effect_est", verbose = TRUE )
Combines two transcript partitions (up- and down-regulated) and assigns
an estimate coefficient: +1 to up and -1 to
down. Accepts either GRanges objects or character vectors of
transcript IDs (in which case txdb is required to look up exon
coordinates). The result is ready to pass to preprocess
with coef_col = "estimate".
prepare_exons_by_partition( up, down, txdb = NULL, tx_id_col = "TXNAME", verbose = TRUE )prepare_exons_by_partition( up, down, txdb = NULL, tx_id_col = "TXNAME", verbose = TRUE )
up |
A GRanges object or character vector of transcript IDs for
the upregulated partition (assigned |
down |
A GRanges object or character vector of transcript IDs for
the downregulated partition (assigned |
txdb |
A |
tx_id_col |
The keytype in |
verbose |
Whether to print progress messages. Default |
When up and down are GRanges, both must have
exon_rank, gene_id, and tx_id metadata columns.
Extra columns are kept; if one object lacks a column present in the
other, those entries receive NA.
A combined GRanges object with an estimate column
(+1 for up, -1 for down),
ready for preprocess.
# GRanges input gr <- create_mock_data(n_genes = 1, n_tx_per_gene = 4, n_exons_per_tx = 4) gr <- generate_se(gr, n_events = 1) gr_down <- gr[gr$estimate < 0] gr_up <- gr[gr$estimate > 0] prepare_exons_by_partition(gr_up, gr_down) |> preprocess(coef_col = "estimate")# GRanges input gr <- create_mock_data(n_genes = 1, n_tx_per_gene = 4, n_exons_per_tx = 4) gr <- generate_se(gr, n_events = 1) gr_down <- gr[gr$estimate < 0] gr_up <- gr[gr$estimate > 0] prepare_exons_by_partition(gr_up, gr_down) |> preprocess(coef_col = "estimate")
This function checks that the input is a valid GRanges object with required metadata columns, then adds a unique key, the number of exons per transcript, and an 'internal' flag for each exon.
preprocess(gr, coef_col, method_string = NULL, additional_columns = NULL)preprocess(gr, coef_col, method_string = NULL, additional_columns = NULL)
gr |
A GRanges object with metadata columns: 'exon_rank', 'gene_id', 'tx_id', 'coef'. |
coef_col |
The name of the metadata column indicating upregulated (+1) and downregulated (-1) exons. |
method_string |
The Differential Transcript Usage (DTU) method used to obtain the coef_col, for annotation purposes (optional). |
additional_columns |
A character vector of metadata column
names to record for downstream use. Stored in
|
A GRanges object with added 'key', 'nexons', and 'internal' columns.
# create mock data and run preprocessing gr <- create_mock_data(n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4) |> preprocess(coef_col = "estimate", method_string = "mock_method")# create mock data and run preprocessing gr <- create_mock_data(n_genes = 2, n_tx_per_gene = 4, n_exons_per_tx = 4) |> preprocess(coef_col = "estimate", method_string = "mock_method")