samples2ags: Create altered gene sets from continuous sample profiles

View source: R/data-access-io-prepare.R

samples2agsR Documentation

Create altered gene sets from continuous sample profiles

Description

Convert a gene-by-sample matrix, such as expression, copy-number, protein, or methylation measurements, into one altered gene set (AGS) per sample. "top" ranks absolute, unstandardized deviations from each gene's across-sample mean; "toppos" ranks signed deviations in descending order, selecting the upper side of the value distribution. Both remain fixed-size methods and apply no significance or positivity cutoff. "topnorm" ranks absolute within-gene z-scores. "bestp" ranks one-sided upper-tail probabilities calculated from abs(z), whereas "significant" retains genes below cutoff_q after Benjamini-Hochberg adjustment of the same probabilities. This adjustment is applied to both directions of deviation and does not use the enrichment-only q-value convention of nea.render(). "toprandom" samples genes without replacement.

Usage

samples2ags(
  x,
  n_top = NULL,
  sample_columns = NULL,
  column_pattern = NULL,
  method = c("significant", "top", "toppos", "topnorm", "bestp", "toprandom"),
  cutoff_q = 0.05,
  case_sensitive = FALSE,
  species,
  input_id_format = master_id_format(species),
  id_mappings = NULL,
  ambiguous = c("error", "drop", "first", "expand"),
  unmapped = c("keep", "drop", "error"),
  duplicate_ids = c("error", "mean", "sum", "max")
)

Arguments

x

Numeric gene-by-sample matrix with gene identifiers as row names.

n_top

Number of genes retained by top-ranking methods. Values around 30–300 are often useful; very large sets may reduce specificity.

sample_columns

Optional names or indices selecting sample columns.

column_pattern

Optional regular expression selecting sample columns.

method

Preparation method. "top", "toppos", "topnorm", "bestp", and "toprandom" require n_top; "significant" uses cutoff_q and can return an empty AGS.

cutoff_q

Benjamini-Hochberg-adjusted probability cutoff for method = "significant".

case_sensitive

Use case-sensitive identifier matching. The default treats all gene identifiers case-insensitively.

species

Required species identifier accepted by available_id_formats(). Use explicit NULL for unsupported species or non-biological data.

input_id_format

Submitted identifier format. Defaults to master_id_format() for species; required when species = NULL.

id_mappings

Optional object from load_id_mappings().

ambiguous, unmapped

Mapping policies passed to map_identifiers().

duplicate_ids

Policy for rows that collapse to one identifier after mapping: error, mean, sum, or maximum.

Value

A named list containing one altered gene vector per sample, with normalization metadata available through normalization_info().

See Also

mutations2ags(), import_gene_sets(), save_gs_list()

Examples

profiles <- matrix(c(
  9, 1, 2, 8, 5, 5,
  1, 9, 8, 2, 5, 5), nrow = 6,
  dimnames = list(paste0("gene", 1:6), c("sample_1", "sample_2")))
top <- samples2ags(profiles, n_top = 2, method = "top",
  species = NULL, input_id_format = "custom")
toppos <- samples2ags(profiles, n_top = 2, method = "toppos",
  species = NULL, input_id_format = "custom")
top
toppos

NEArender documentation built on Nov. 28, 2026, 5:10 p.m.