Differential transcript usage
A gene can produce several transcripts, and their relative contributions can change without a matching change in the gene’s total expression. Differential transcript usage asks whether the transcript proportions within a gene differ between conditions. It requires transcript estimates and a transcript-to-gene mapping; a gene count matrix has already discarded that information.
This R lesson uses the public pasilla experiment from Brooks and colleagues. Four independent control samples and three independent pasilla knockdown samples provide the biological replication. Some libraries contain single reads and others contain paired reads, so the model includes library layout. The samples are not matched donor pairs.
Preserve the transcript annotation and sample identities
Section titled “Preserve the transcript annotation and sample identities”Download the input archive and extract
it into your working directory. It contains the original count and metadata
tables from PasillaTranscriptExpr 1.40.0, their source record, and their license.
The archive preserves an inputs/ directory used by the code below.
The estimates come from kallisto 0.42.1 against the Ensembl release 70 Drosophila melanogaster BDGP5 transcript reference. The gene mapping comes from the matching GTF release. These are archived estimates, so this lesson does not rerun the reads against a current annotation. Combining their transcript IDs with a newer gene mapping would change the analysis input.
The package records the original study as GSE18508. Its sample table distinguishes library layout from the experimental condition.
suppressPackageStartupMessages(library(DRIMSeq))metadata <- read.delim("inputs/metadata.txt", stringsAsFactors = FALSE)input_counts <- read.delim("inputs/counts.txt", stringsAsFactors = FALSE)sample_table <- data.frame( sample_id = metadata$SampleName, condition = factor(metadata$condition, levels = c("CTL", "KD")), library_layout = factor(metadata$LibraryLayout, levels = c("PAIRED", "SINGLE")))stopifnot(!anyNA(sample_table), !anyDuplicated(sample_table$sample_id))stopifnot(identical(names(input_counts)[-(1:2)], sample_table$sample_id))stopifnot(!anyDuplicated(input_counts$feature_id))stopifnot(!anyNA(input_counts), all(as.matrix(input_counts[, -(1:2)]) >= 0))dir.create("outputs", showWarnings = FALSE)cat("Input transcripts:", nrow(input_counts), "\n")cat("Input genes:", length(unique(input_counts$gene_id)), "\n")print(sample_table, row.names = FALSE)Input transcripts: 27142Input genes: 14112 sample_id condition library_layout GSM461176 CTL SINGLE GSM461177 CTL PAIRED GSM461178 CTL PAIRED GSM461179 KD SINGLE GSM461180 KD PAIRED GSM461181 KD PAIRED GSM461182 CTL SINGLEThe fractional counts are transcript estimates from kallisto. They are not independent observations, and rounding them does not create extra precision. Each sample contributes one vector of transcript counts within each gene.
Define the test family before fitting the model
Section titled “Define the test family before fitting the model”The filter requires a gene total of at least ten estimated counts in every sample and a transcript count of at least ten in at least three samples. The latter requirement permits a transcript present mainly in the smaller condition. DRIMSeq also removes genes with fewer than two retained transcripts.
These rules use expression before hypothesis tests. After transcript removal, the modeled proportions refer to the retained transcripts within each gene. The filter and annotation therefore define the denominator as well as the family of genes that can receive a test.
model_data <- dmDSdata(counts = input_counts, samples = sample_table)model_data <- dmFilter(model_data, min_samps_gene_expr = 7, min_gene_expr = 10, min_samps_feature_expr = 3, min_feature_expr = 10)design_full <- model.matrix(~ library_layout + condition, data = samples(model_data))stopifnot(qr(design_full)$rank == ncol(design_full))stopifnot(nrow(design_full) > ncol(design_full))cat("Retained transcripts:", nrow(counts(model_data)), "\n")cat("Tested gene family:", length(model_data), "\n")cat("Design rank:", qr(design_full)$rank, "\n")print(design_full, quote = FALSE)write.csv(sample_table, "outputs/samples.csv", row.names = FALSE)write.csv(counts(model_data), "outputs/filtered_counts.csv", row.names = FALSE)Retained transcripts: 10107Tested gene family: 3248Design rank: 3 (Intercept) library_layoutSINGLE conditionKD1 1 1 02 1 0 03 1 0 04 1 1 15 1 0 16 1 0 17 1 1 0attr(,"assign")[1] 0 1 2attr(,"contrasts")attr(,"contrasts")$library_layout[1] contr.treatment
attr(,"contrasts")$condition[1] contr.treatmentThe condition coefficient compares knockdown with control after adjustment for library layout. Both conditions contain both layouts, so the two effects are estimable. A dataset with all controls in one layout and all knockdowns in the other would fail this rank check; no model formula can separate those effects without additional information.
Fit a multivariate count model and test condition
Section titled “Fit a multivariate count model and test condition”DRIMSeq models the transcript count vector conditional on its gene total with a Dirichlet-multinomial distribution. Its precision parameter controls variation beyond multinomial sampling. The method estimates precision across genes before it estimates the condition-dependent transcript proportions.
The likelihood ratio test removes the condition term while retaining library layout. The null hypothesis says that the retained transcript proportions do not depend on condition under that model. It is not a test that the gene’s total expression stays constant.
set.seed(1307)parallel <- BiocParallel::MulticoreParam(workers = 2, RNGseed = 1307)model_data <- dmPrecision(model_data, design = design_full, verbose = 0, BPPARAM = parallel)model_data <- dmFit(model_data, design = design_full, verbose = 0, BPPARAM = parallel)model_data <- dmTest(model_data, coef = "conditionKD", verbose = 0, BPPARAM = parallel)gene_results <- results(model_data)gene_results$adj_pvalue <- p.adjust(gene_results$pvalue, method = "BH", n = nrow(gene_results))precision <- genewise_precision(model_data)gene_results$precision <- precision$genewise_precision[ match(gene_results$gene_id, precision$gene_id)]gene_results <- gene_results[order(gene_results$pvalue), ]stopifnot(nrow(gene_results) == length(model_data))cat("Gene tests:", nrow(gene_results), "\n")cat("Unavailable precision estimates:", sum(is.na(gene_results$precision)), "\n")cat("Unavailable tests:", sum(is.na(gene_results$pvalue)), "\n")cat("Genes with BH adjusted p < 0.05:", sum(gene_results$adj_pvalue < 0.05, na.rm = TRUE), "\n")print(head(gene_results, 6), row.names = FALSE, digits = 4)write.csv(gene_results, "outputs/gene_results.csv", row.names = FALSE)saveRDS(model_data, "outputs/drimseq_model.rds")Gene tests: 3248Unavailable precision estimates: 56Unavailable tests: 63Genes with BH adjusted p < 0.05: 289 gene_id lr df pvalue adj_pvalue precision FBgn0261451 970.1 12 5.050e-200 1.640e-196 85.62 FBgn0003360 535.6 3 9.123e-116 1.482e-112 90.05 FBgn0086902 518.0 5 1.035e-109 1.120e-106 85.77 FBgn0030796 397.5 2 4.764e-87 3.869e-84 73.17 FBgn0036449 364.7 1 2.714e-81 1.763e-78 43.68 FBgn0013733 378.6 7 9.230e-78 4.997e-75 336.13The Benjamini-Hochberg adjustment uses the full retained gene family, including genes whose tests are unavailable. This explicit denominator is conservative relative to DRIMSeq’s default adjustment over the available p-values. Unavailable precision estimates arise when the likelihood calculation fails at one or more points in the precision grid; additional model fits can also return unavailable tests. These genes remain in the export with missing p-values, which do not establish that their usage stayed constant. The complete gene result table preserves those missing values alongside the available tests.
A gene-level result identifies evidence of a composition change somewhere within that gene. It does not give each transcript a separately controlled discovery claim. Transcript-level follow-up requires its own error-control plan, such as a staged gene and transcript procedure.
Inspect the contributing samples
Section titled “Inspect the contributing samples”The figure below shows observed transcript proportions for the gene with the smallest gene-level p-value. This is a result selected for inspection, not an independent validation set. The lower panel shows each sample’s retained estimated gene count, which has a different scale from a proportion.
top_gene <- gene_results$gene_id[which.min(gene_results$pvalue)]filtered <- counts(model_data)selected <- filtered[filtered$gene_id == top_gene, ]count_matrix <- as.matrix(selected[, sample_table$sample_id])rownames(count_matrix) <- selected$feature_idgene_totals <- colSums(count_matrix)observed_proportions <- sweep(count_matrix, 2, gene_totals, "/")stopifnot(all(abs(colSums(observed_proportions) - 1) < 1e-12))sample_order <- order(sample_table$condition, sample_table$library_layout)labels <- paste(sample_table$sample_id, sample_table$condition, sample_table$library_layout, sep = "\n")colors <- grDevices::hcl.colors(nrow(count_matrix), "Dark 3")png("outputs/transcript_usage_proportions.png", width = 1600, height = 1200, res = 150)layout(matrix(c(1, 2), ncol = 1), heights = c(2, 1))par(mar = c(2, 5, 4, 11), xpd = NA)barplot(observed_proportions[, sample_order], col = colors, border = NA, names.arg = rep("", ncol(count_matrix)), ylab = "Fraction of retained transcript counts", main = paste(top_gene, "observed transcript composition"))legend("topright", inset = c(-0.3, 0), legend = rownames(count_matrix), fill = colors, border = NA, bty = "n", cex = 0.8)par(mar = c(6, 5, 2, 11), xpd = FALSE)barplot(gene_totals[sample_order], names.arg = labels[sample_order], col = "#46708c", border = NA, cex.names = 0.8, ylab = "Estimated counts", main = "Retained gene totals")invisible(dev.off())write.csv(data.frame(feature_id = rownames(observed_proportions), observed_proportions, check.names = FALSE), "outputs/observed_proportions.csv", row.names = FALSE)cat("Displayed gene:", top_gene, "\n")cat("Displayed transcripts:", nrow(selected), "\n")Displayed gene: FBgn0261451Displayed transcripts: 13
Library layout remains visible beside every sample. A condition pattern driven by one library should receive scrutiny even when its fitted gene test is small. The count panel is descriptive: it does not replace normalization and a separate differential gene expression model.
Kallisto estimated these transcript counts without bootstrap replicates in the archived preparation. This analysis therefore does not propagate transcript quantification uncertainty. Closely overlapping isoforms can be difficult to distinguish, so a usage result needs read-level support or another assay before it establishes a specific splicing mechanism.
Scientific references
Section titled “Scientific references”Nowicka and Robinson, 2016 describe the Dirichlet-multinomial model and regression tests implemented by DRIMSeq.
Nowicka, 2026 documents the archived pasilla transcript estimates and sample metadata used here.
Brooks and colleagues, 2011 describe the pasilla depletion experiment and its analysis of regulated splicing in Drosophila.
Bray and colleagues, 2016 describe kallisto, which produced the transcript estimates supplied by the data package.
Further reading
Section titled “Further reading”The DRIMSeq batch-adjusted example explains how nuisance variables enter the design. Compare its condition-only and layout-adjusted models before adapting the contrast.
The PasillaTranscriptExpr preparation records the transcript reference, matching annotation, and quantification commands. It explains what the archived count table represents.
The DRIMSeq staged-test example separates gene screening from transcript confirmation. Use that distinction when the reported discovery is a specific transcript rather than a gene-level composition change.