| Title: | Metadata-Driven Downstream Analysis for RSEM Gene-Level Results |
|---|---|
| Description: | A command-line and R interface for reproducible downstream analysis of RSEM gene-level expression estimates. 'rsemflow' imports '*.genes.results' files together with ordinary sample metadata, computes expression-level summaries, normalization, principal component analysis, sample correlation, 'DESeq2' differential expression, preranked gene set enrichment analysis, 'GSVA' or 'ssGSEA' pathway scores, and Ensembl gene annotation. Every result is written as a tab-separated table; the package does not draw figures. |
| Authors: | Daiki Kumakura [aut, cre] |
| Maintainer: | Daiki Kumakura <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-10-22 11:59:27 UTC |
| Source: | https://github.com/DaikiKumakura/rsemflow |
Adds the stable Ensembl ID (version suffix removed), gene symbol, Entrez ID,
and description from org.Hs.eg.db or org.Mm.eg.db. The
original RSEM gene_id is always kept. When an Ensembl ID maps to several
Entrez records, the record with the most filled fields is kept.
annotation_status is mapped when the OrgDb returned at least one of the
symbol, Entrez ID, or description, and unmapped otherwise (including
non-Ensembl IDs such as spike-ins).
annotate_ensembl(study, species = "auto")annotate_ensembl(study, species = "auto")
study |
A |
species |
|
A gene annotation data frame.
Reads the gene records of the GTF used to build the RSEM reference and
returns gene_name, gene_type/gene_biotype, and description. IDs are
matched on the full versioned ID first and on the stable Ensembl ID second.
annotate_gtf(study, gtf)annotate_gtf(study, gtf)
study |
A |
gtf |
Path to a GTF or GTF.GZ file. |
A gene annotation data frame.
Parses rsemflow <module> <action> [options] and calls the matching R
function. Options use the prefixes --i- (inputs), --m- (metadata),
--p- (parameters), and --o- (outputs). Add --help at any level for
usage.
cli_main(args = commandArgs(trailingOnly = TRUE))cli_main(args = commandArgs(trailingOnly = TRUE))
args |
Character vector of command-line arguments. |
The installed launcher script (system.file("exec", "rsemflow", package = "rsemflow")) calls this function. Without the launcher, use
Rscript -e "rsemflow::cli_main()" <module> <action> [options].
Invisibly returns zero on success. Errors are raised as R errors.
cli_main("--help") cli_main(c("differential", "deseq2", "--help"))cli_main("--help") cli_main(c("differential", "deseq2", "--help"))
Compute sample correlation
compute_correlation( study, transform = c("vst", "log2-tpm"), method = c("pearson", "spearman") )compute_correlation( study, transform = c("vst", "log2-tpm"), method = c("pearson", "spearman") )
study |
A |
transform |
|
method |
|
A sample-by-sample correlation matrix.
Selects the ntop genes with the highest variance after transformation and
runs stats::prcomp() with samples as observations, centering on, and no
scaling.
compute_pca( study, transform = c("vst", "log2-tpm"), ntop = 500L, components = 10L )compute_pca( study, transform = c("vst", "log2-tpm"), ntop = 500L, components = 10L )
study |
A |
transform |
|
ntop |
Number of most variable genes to use. |
components |
Maximum number of PCs to return. |
A list containing scores, loadings, and variance data
frames, plus the transform and the number of genes used (ntop).
ex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) p <- compute_pca(study, ntop = 100, components = 3) p$varianceex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) p <- compute_pca(study, ntop = 100, components = 3) p$variance
Fits a DESeq2 model from the tximport-derived counts of a study and returns one result table per comparison.
differential_deseq2( study, formula, term, metadata = NULL, reference = character(), contrast = character(), at = character(), test = c("wald", "lrt"), reduced = NULL, categorical = character(), numeric = character(), alpha = 0.05 )differential_deseq2( study, formula, term, metadata = NULL, reference = character(), contrast = character(), at = character(), test = c("wald", "lrt"), reduced = NULL, categorical = character(), numeric = character(), alpha = 0.05 )
study |
A |
formula |
R formula or formula string. |
term |
Metadata variable or interaction term to report. |
metadata |
Optional replacement metadata path/data.frame. |
reference |
Character vector like |
contrast |
Character vector like |
at |
Optional conditioning specification like |
test |
|
reduced |
Reduced formula required for LRT. |
categorical |
Metadata columns to force categorical. |
numeric |
Metadata columns to force numeric. |
alpha |
Significance threshold passed to DESeq2 results. |
Which tables are produced depends on term:
a categorical variable: every level versus the reference level;
a numeric variable: the per-unit coefficient;
an interaction such as genotype:treatment: every interaction coefficient.
Extra comparisons can be requested with contrast. With at, a single
simple effect is returned instead (for example the treatment effect within
one genotype in a ~ genotype * treatment model). With test = "lrt", one
omnibus table is returned and log2FoldChange/lfcSE are set to NA
because the likelihood-ratio test has no single direction.
Log fold changes are not shrunk.
A list with the fitted DESeqDataSet (dds), the metadata used,
the formula(s), the design matrix, a contrast manifest, and the named
result tables (results).
ex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) de <- differential_deseq2( study, formula = ~ batch + condition, term = "condition", reference = "condition::Control" ) head(de$results$condition_Drug_vs_Control)ex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) de <- differential_deseq2( study, formula = ~ batch + condition, term = "condition", reference = "condition::Control" ) head(de$results$condition_Drug_vs_Control)
vst: DESeq2 size factors, then varianceStabilizingTransformation(blind = TRUE).
normalized-counts: counts divided by DESeq2 size factors (with the
tximport average-length offsets).
log2-tpm: log2(TPM + 1).
normalize_expression(study, method = c("vst", "normalized-counts", "log2-tpm"))normalize_expression(study, method = c("vst", "normalized-counts", "log2-tpm"))
study |
A |
method |
One of |
A gene-by-sample numeric matrix.
Finds every *.genes.results file in rsem_dir, takes the sample ID from
the file name (S01.genes.results -> S01), matches the files to the
sample_id column of metadata, and imports the counts with
tximport(type = "rsem").
read_rsem_study( rsem_dir, metadata, categorical = character(), numeric = character() )read_rsem_study( rsem_dir, metadata, categorical = character(), numeric = character() )
rsem_dir |
Directory containing |
metadata |
Path to TSV or CSV metadata with a |
categorical |
Optional metadata columns to force to categorical. |
numeric |
Optional metadata columns to force to numeric. |
Import stops when a file lacks the standard RSEM columns, when sample IDs do not match the metadata one-to-one, or when the files do not share an identical gene table (same IDs in the same order, without duplicates).
Metadata columns whose values all parse as numbers become numeric; the rest
become factors. Use categorical/numeric to override.
An object of class rsemflow_study.
ex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) studyex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) study
write_study() saves the study as study.rds plus plain TSV copies of the
metadata, the expected-count, TPM, and effective-length matrices, a
sample-to-file table, and study-info.tsv. read_study() restores the
study.rds.
read_study(path) write_study(study, path)read_study(path) write_study(study, path)
path |
Study directory or a |
study |
A |
read_study() returns an object of class rsemflow_study;
write_study() invisibly returns path.
ex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) out <- file.path(tempdir(), "study") write_study(study, out) list.files(out) identical(read_study(out)$sample_ids, study$sample_ids)ex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) out <- file.path(tempdir(), "study") write_study(study, out) list.files(out) identical(read_study(out)$sample_ids, study$sample_ids)
Run preranked GSEA
run_gsea( differential, species = "auto", collection = "hallmark", subcollection = NULL, genesets = NULL, rank = "stat", min_size = 15L, max_size = 500L, eps = 0, seed = 42L )run_gsea( differential, species = "auto", collection = "hallmark", subcollection = NULL, genesets = NULL, rank = "stat", min_size = 15L, max_size = 500L, eps = 0, seed = 42L )
differential |
Differential-expression table or path. |
species |
|
collection |
MSigDB collection alias or raw collection code. |
subcollection |
Optional MSigDB subcollection. |
genesets |
Optional named gene-set list or GMT path. |
rank |
Column used as ranking statistic, default |
min_size |
Minimum mapped gene-set size. |
max_size |
Maximum mapped gene-set size. |
eps |
Passed to |
seed |
Random seed for |
Gene IDs are matched to gene sets by stable Ensembl gene ID. When several rows share a stable ID, the row with the largest absolute ranking statistic is kept.
Unsigned statistics, such as the stat column of an LRT table, are
rejected because preranked GSEA needs a direction.
A data frame of GSEA results, sorted by padj and then by
decreasing |NES|.
ids <- sprintf("ENSG%011d", 1:100) de <- data.frame(ensembl_gene_id = ids, stat = seq(5, -5, length.out = 100)) sets <- list(UP = ids[1:20], DOWN = ids[81:100], MIXED = ids[seq(1, 100, 5)]) run_gsea(de, genesets = sets, min_size = 10, max_size = 50)ids <- sprintf("ENSG%011d", 1:100) de <- data.frame(ensembl_gene_id = ids, stat = seq(5, -5, length.out = 100)) sets <- list(UP = ids[1:20], DOWN = ids[81:100], MIXED = ids[seq(1, 100, 5)]) run_gsea(de, genesets = sets, min_size = 10, max_size = 50)
Scores each gene set in each sample from log2(TPM + 1). Rows sharing a
stable Ensembl ID are averaged first. GSVA uses a Gaussian kernel
(kcdf = "Gaussian"). Scores are descriptive; no test between groups is run.
run_gsva( study, species = "auto", collection = "hallmark", subcollection = NULL, genesets = NULL, method = c("gsva", "ssgsea"), min_size = 10L, max_size = 500L )run_gsva( study, species = "auto", collection = "hallmark", subcollection = NULL, genesets = NULL, method = c("gsva", "ssgsea"), min_size = 10L, max_size = 500L )
study |
A |
species |
|
collection |
MSigDB collection alias or raw collection code. |
subcollection |
Optional MSigDB subcollection. |
genesets |
Optional named list or GMT file. |
method |
|
min_size |
Minimum gene-set size. |
max_size |
Maximum gene-set size. |
A pathway-by-sample data frame with gene-set metadata columns.
Sample- and gene-level summaries computed from the RSEM expected counts and TPM. A gene is "detected" when its expected count is above zero. These are descriptive numbers only; no sample is flagged or removed.
summarize_study(study)summarize_study(study)
study |
A |
A list with samples and genes data frames.
ex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) s <- summarize_study(study) s$samplesex <- system.file("extdata", "example", package = "rsemflow") study <- read_rsem_study(file.path(ex, "data"), file.path(ex, "metadata.tsv")) s <- summarize_study(study) s$samples