library(SummarizedExperiment)
library(plyxp)
library(plyranges)
library(splicelogic)
library(here)
# Simulation helper functions
source(here("scripts", "demo_sims.R"))4 Event Annotation with plyxp + splicelogic
Following differential transcript usage (DTU) analysis (e.g., using satuRn), we may next want to examine the specific splicing events (skipped exons, alternative splice site usage, or entron retention, e.g.) underlying observed transcript-level differences.
In this chapter, we demonstrate how to use plyxp and splicelogic together to compute and visualize condition-specific isoform proportions and detect skipped-exon events, using simulated transcripts.
4.1 Setup and Dependencies
4.2 Simulating Transcript Abundances
To illustrate the workflow, we simulate a minimal SummarizedExperiment containing 2 genes with 2 isoforms each across 6 samples (3 control vs. 3 treated).
- Gene A: Undergoes isoform switching upon treatment (switching from isoform 201 to isoform 202).
- Gene B: Isoform ratios remain unchanged across conditions.
set.seed(5)
se <- simulate_se(n_per_group = 3)
seclass: SummarizedExperiment
dim: 4 6
metadata(0):
assays(2): counts mu
rownames(4): A-201 A-202 B-201 B-202
rowData names(2): isoform gene_id
colnames(6): s1 s2 ... s5 s6
colData names(1): condition
4.3 Computing Isoform Proportions with plyxp
We will start by using plyxp to wrap our SummarizedExperiment. This allows us to further manipulate the rows (features) and columns (samples) of our dataset using fast and intuitive tidy grammar. Here, we group by gene_id across rows to compute the relative isoform proportion per sample:
\[\text{Isoform Proportion} = \frac{\text{Counts}_{\text{isoform}}}{\sum \text{Counts}_{\text{gene}}}\]
xp <- se |>
new_plyxp()
# Compute isoform proportions per sample within each gene
xp <- xp |>
group_by(rows(gene_id)) |>
mutate(
iso_prop = t(t(counts) / colSums(counts))
) |>
ungroup()
# Verify that `iso_prop` was added as an assay
xp# A SummarizedExperiment-tibble Abstraction: 4 × 6
.features .samples | counts mu iso_prop | gene_id isoform | condition
<chr> <chr> | <int> <dbl> <dbl> | <chr> <chr> | <fct>
1 A-201 s1 | 72 80 0.809 | A A-201 | control
2 A-202 s1 | 17 20 0.191 | A A-202 | control
3 B-201 s1 | 50 50 0.446 | B B-201 | control
4 B-202 s1 | 62 50 0.554 | B B-202 | control
5 A-201 s2 | 74 80 0.787 | A A-201 | control
… … … … … … … … …
n-4 B-202 s5 | 47 50 0.461 | B B-202 | treated
n-3 A-201 s6 | 28 20 0.267 | A A-201 | treated
n-2 A-202 s6 | 77 80 0.733 | A A-202 | treated
n-1 B-201 s6 | 43 50 0.5 | B B-201 | treated
n B-202 s6 | 43 50 0.5 | B B-202 | treated
# ℹ n = 24
# Inspect calculated proportions
assay(xp, "iso_prop") |> round(2) s1 s2 s3 s4 s5 s6
A-201 0.81 0.79 0.85 0.24 0.23 0.27
A-202 0.19 0.21 0.15 0.76 0.77 0.73
B-201 0.45 0.47 0.44 0.50 0.54 0.50
B-202 0.55 0.53 0.56 0.50 0.46 0.50
Let’s check our work by comparing these empirical proportions against the true simulation means (\(\mu\)):
# Ground truth means for Gene A isoforms (201 and 202)
assay(xp, "mu")[1:2, ] s1 s2 s3 s4 s5 s6
A-201 80 80 80 20 20 20
A-202 20 20 20 80 80 80
4.4 Summarizing Statistics per Condition
Next, we summarize the mean and standard deviation of isoform proportions within each condition (control and treated):
iso_stats <- xp |>
group_by(cols(condition)) |>
summarize(
mean = rowMeans(iso_prop),
sd = rowSds(iso_prop),
cols(.samples = unique(condition))
)
# Inspect mean and SD matrices
assay(iso_stats, "mean") |> round(2) control treated
A-201 0.82 0.25
A-202 0.18 0.75
B-201 0.45 0.51
B-202 0.55 0.49
assay(iso_stats, "sd") |> round(3) control treated
A-201 0.031 0.018
A-202 0.031 0.018
B-201 0.014 0.023
B-202 0.014 0.023
4.5 Annotating Transcript Exons
To map statistical changes to genomic coordinates, we generate a GRanges representation of our simulated transcripts.
In this structure: * Isoform 201: Includes the middle cassette exon. * Isoform 202: Skips the middle cassette exon (associated with a positive DTU coefficient).
exons <- simulate_exons()
exonsGRanges object with 10 ranges and 5 metadata columns:
seqnames ranges strand | tx_id gene_id exon_rank
<Rle> <IRanges> <Rle> | <character> <character> <integer>
[1] chr1 101-300 + | A-201 A 1
[2] chr1 401-600 + | A-201 A 2
[3] chr1 700-900 + | A-201 A 3
[4] chr1 101-300 + | A-202 A 1
[5] chr1 700-900 + | A-202 A 2
[6] chr1 1101-1300 + | B-201 B 1
[7] chr1 1401-1600 + | B-201 B 2
[8] chr1 1700-1900 + | B-201 B 3
[9] chr1 1101-1300 + | B-202 B 1
[10] chr1 1700-1900 + | B-202 B 2
coefficient pvalue
<numeric> <numeric>
[1] -2.0 1e-06
[2] -2.0 1e-06
[3] -2.0 1e-06
[4] 2.0 1e-06
[5] 2.0 1e-06
[6] -0.1 6e-01
[7] -0.1 6e-01
[8] -0.1 6e-01
[9] 0.1 6e-01
[10] 0.1 6e-01
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
We now append the per-condition summary statistics (mean and sd) to each transcript’s exon annotations, matching by tx_id (transcript ID):
exons <- exons |>
mutate(
mean_ctl = assay(iso_stats, "mean")[tx_id, "control"],
mean_trt = assay(iso_stats, "mean")[tx_id, "treated"],
sd_ctl = assay(iso_stats, "sd")[tx_id, "control"],
sd_trt = assay(iso_stats, "sd")[tx_id, "treated"]
)4.6 Identifying Skipped Exons with splicelogic
Now that we have a summary of exonic effects per condition, we can characterize the types of splicing events underlying the observed changes using splicelogic
Here, we will use splicelogic to identify skipped exons. A skipped exon (SE) event is defined when an exon present in a transcript with a negative DTU coefficient is spliced out (skipped) in a positive-coefficient transcript of the same gene. (this is confusing - visual?)
4.6.1 Preprocessing Exon Metadata
The preprocess() function from splicelogic designates the coefficient column and retains relevant metadata for downstream reporting:
exons <- exons |>
preprocess(
coef_col = "coefficient",
additional_columns = c(
"pvalue",
"mean_ctl", "mean_trt",
"sd_ctl", "sd_trt"
)
)4.6.2 Finding Skipped Exons
In practical analyses, you would typically filter for statistically significant transcripts (e.g., FDR \(< 0.1\)) before running event detection. Here, we analyze all transcripts to evaluate both Gene A and Gene B:
skipped <- exons |>
find_skipped_exons()
# Select key summary columns
skipped |>
select(
gene_id,
pvalue,
up_pvalue = event_pvalue,
ctl = mean_ctl,
trt = mean_trt,
up_ctl = event_mean_ctl,
up_trt = event_mean_trt
)GRanges object with 2 ranges and 7 metadata columns:
seqnames ranges strand | gene_id pvalue up_pvalue ctl
<Rle> <IRanges> <Rle> | <character> <numeric> <numeric> <numeric>
[1] chr1 401-600 + | A 1e-06 1e-06 0.815093
[2] chr1 1401-1600 + | B 6e-01 6e-01 0.451985
trt up_ctl up_trt
<numeric> <numeric> <numeric>
[1] 0.247351 0.184907 0.752649
[2] 0.513072 0.548015 0.486928
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
4.6.3 Interpretation of Results
- Gene A: Two transcripts show significant DTU. The transcript containing the cassette exon is down-regulated upon treatment (mean proportion drops from \(0.80 \rightarrow 0.20\)), while the isoform excluding this exon is up-regulated (\(0.20 \rightarrow 0.80\)).
find_skipped_exons()successfully pinpoints this coordinates-level cassette exon event. - Gene B: No significant isoform shift occurs between conditions.