Skip to content

Instantly share code, notes, and snippets.

@mikelove
Last active May 7, 2026 17:52
Show Gist options
  • Select an option

  • Save mikelove/38e90a00d9ea2a8995016305e6a42e4b to your computer and use it in GitHub Desktop.

Select an option

Save mikelove/38e90a00d9ea2a8995016305e6a42e4b to your computer and use it in GitHub Desktop.
plyxp to compute isoform proportions
library(SummarizedExperiment)
set.seed(5)
## make object ##
gene_ids <- paste0("Gene-", sprintf("%02d", 1:5))
tx_ids <- paste0("Transcript-", sprintf("%02d", 1:20))
row_df <- data.frame(
gene_id = rep(gene_ids, each=4),
tx_id = tx_ids,
row.names = tx_ids
)
t_index <- rep(1:4, times=5)
counts <- do.call(rbind, lapply(t_index, function(t) {
rpois(10, lambda = 100 * t)
}))
rownames(counts) <- rownames(row_df)
colnames(counts) <- paste0("Sample", sprintf("%02d", 1:10))
col_df <- data.frame(
condition = factor(
rep(c("control", "treated"), each=5),
levels = c("control", "treated")
),
row.names = colnames(counts)
)
se <- SummarizedExperiment(
assays = list(counts = counts),
rowData = DataFrame(row_df),
colData = col_df
)
se
## compute average isoform proportions with plyxp ##
library(plyxp)
xp <- se |> new_plyxp()
xp <- xp |>
group_by(rows(gene_id)) |>
mutate(prop = t(t(counts) / colSums(counts))) |>
ungroup()
xp_ave_prop <- xp |>
group_by(cols(condition)) |>
summarize(
ave_prop = rowMeans(prop),
cols(.samples = unique(condition))
)
xp_ave_prop |>
assay("ave_prop") |>
head(4)
z <- assay(se)[1:4,1:5]
rowMeans( t(t(z) / colSums(z)) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment