
Build a canonical exploreDE .h5ad from user-supplied data
Source: R/build_explore_h5ad.R
build_explore_h5ad.RdThe source-agnostic "bring your own data" constructor. x is a
DESeqDataSet (its counts, colData, rowData and factors are used), a
SummarizedExperiment (every assay under its name, its colData and its
rowData), or the counts themselves (a matrix, or a named list of matrices
such as list(counts=, normalised=, vst=, tpm=)). Assay and matrix names
become layer names: rawData and raw are raw intensities in proteomics,
transformedData the analysis-ready ones. DE tables and pathway statistics
are supplied as arguments. Only counts + coldata + omics are required;
coldata and rowdata, when given, replace those of x.
Usage
build_explore_h5ad(
x,
out,
omics,
feature_level = NULL,
coldata = NULL,
rowdata = NULL,
de = list(),
de_columns = NULL,
rowdata_columns = NULL,
pathways = list(),
enrichment_padj_max = NULL,
enrichment_fdr = NULL,
factors = NULL,
organism = NA_character_,
ref_build = NA_character_,
mirror = NULL,
compression = c("gzip", "none"),
contrasts = NULL
)Arguments
- x
A
DESeqDataSet, aSummarizedExperimentwith named assays, a counts matrix, or a named list of count matrices.- out
Output
.h5adpath.- omics
Required:
"rnaseq","proteomics","metabolomics", or"crispr". Metabolomics data is stored as proteomics data is (intensitieslayers), one feature per row.- feature_level
Optional override of the feature granularity within the omics — rnaseq
"gene"/"isoform", proteomics"protein"/"peptide"/"phospho". Omit to auto-detect fromrowdata(site-> phospho,peptide_Id-> peptide,transcript_id-> isoform).- coldata
Sample metadata
data.frame. Required unlessxis a rich object that carries it.- rowdata
Optional per-feature annotation (feature names/symbols/ids and per-feature pathway annotation columns, e.g.
GO BP).- de
Optional named list of DE tables keyed by contrast (
DESeqResults/data.frame). Name each contrast<test>_vs_<reference>, with both groups levels of onecoldatafactor (an error otherwise). Columns are recognised by the column dictionary (inst/dictionaries/column_patterns.json), overridable withde_columns. An optional extra score column (e.g. SAINTexpress'sSaintScore) is picked up by the dictionary alone and shown for display under its own column name. To name contrasts freely, e.g. several methods for one pair of groups, state their groups incontrasts.- de_columns
Optional DE column overrides:
list(effect_log2fc = "<col>", score_pvalue = "<col>", score_fdr = "<col>"), applied to all contrasts, or a named list of such lists keyed by contrast. Named columns are used as given; any not named are still found by the dictionary. A producer with no raw p-value (e.g. SAINTexpress) simply has none; the app degrades to FDR-only. Unknown keys are ignored with a warning. Overrides are persisted atuns$exploreDE$mapping$de, so the file stays self-describing.- rowdata_columns
Optional feature column overrides:
list(id_col = "<col>", symbol_col = "<col>")— whichrowdatacolumn supplies the feature id and the display symbol. Anything not named is still found by the dictionary. Unknown keys are ignored with a warning. Overrides are persisted atuns$exploreDE$mapping$feature.- pathways
Optional pathway statistics: a named list keyed by contrast (keys a subset of
de); each entry a named list of clusterProfiler objects and/ordata.frames.- enrichment_padj_max
Optional p.adjust cut-off applied to clusterProfiler results before they are stored (
p.adjust <= enrichment_padj_max).NULL(the default) stores every term, so users can filter at their own threshold in the app. Either one number for every method, or a named list keyed by the method names used inpathways(e.g.list(ora = 0.05, gsea = 0.05)); a method not named in the list uses the largest value given. The value(s) are recorded inuns$enrichment_filter; withoutenrichment_fdrthe app also uses them as its significance threshold.- enrichment_fdr
Optional FDR threshold(s) at which the app calls a pathway significant: one number, or a named list keyed by method (e.g.
list(ora = 0.05, gsea = 0.1), as SUSHI'sfdrThreshORAandfdrThreshGSEA). Recorded inuns$enrichment_filter$fdr; no term is dropped. Without it (orenrichment_padj_max) the app uses 0.05.- factors
Optional colData columns that are experimental factors (default: all character/factor-typed columns).
- organism, ref_build
Optional labels.
- mirror
Optional SummarizedExperiment to store in full, in
uns["se"](spec section 11), so thatse_from_h5ad()rebuilds it: Every assay,colDataandrowDatacolumn, andmetadata()element at its path, with its class and attributes. Values the exploreDE slots already hold are not stored twice. SUSHI passes its twoGroupsdeResult.- compression
HDF5 compression of the datasets:
"gzip"(default; readable by every HDF5 reader, Pythonanndataincluded) or"none".- contrasts
Optional: What each contrast of
decompares, so that its name can be anything (e.g.WT_vs_KO_limmaandWT_vs_KO_SAINT, two methods for the same groups). A list keyed by contrast name, each entrylist(factor = , test = , reference = , model = , thresholds = ):testandreferenceare levels of thecoldatacolumnfactor(left out, the factor holding both is used);referencemay list several levels, the pooled controls of SAINTexpress.model(optional) names the method, shown with the contrast in the app, e.g."limma"or"SAINTexpress".thresholds(optional) islist(fdr = , log2fc = ): The cut-offs at which this contrast's features count as up or down for pathway analysis (default FDR 0.05, |log2FC| 0). Contrasts not listed must be named<test>_vs_<reference>, as withoutcontrasts. Contrast names are stored lower-cased, with every run of other characters than letters and numbers turned into_, so they must stay distinct after that.
Examples
library(SummarizedExperiment)
# A prolfqua proteomics result: one contrast, nested in rowData
se <- readRDS(system.file("examples/proteomics/SummarizedExperiment.rds", package = "exploreDE"))
de <- as.data.frame(rowData(se)$constrast_B_vs_A)
path <- build_explore_h5ad(
x = list(raw = assay(se, "rawData"), transformed = assay(se, "transformedData")),
out = tempfile(fileext = ".h5ad"),
omics = "proteomics",
coldata = colData(se),
rowdata = de,
factors = "G_",
de = list(B_vs_A = de)
)
file.exists(path)
#> [1] TRUE
# The SummarizedExperiment itself: rawData and transformedData become the
# layers intensities_raw and intensities
se_path <- build_explore_h5ad(
se,
out = tempfile(fileext = ".h5ad"),
omics = "proteomics",
rowdata = de,
factors = "G_",
de = list(B_vs_A = de)
)
# Counts only
counts_only <- build_explore_h5ad(
assay(se, "rawData"),
out = tempfile(fileext = ".h5ad"),
omics = "proteomics",
coldata = colData(se)
)