Skip to main content

Module gene_sets

Module gene_sets 

Source
Expand description

Gene-set sources for enrichment, reduced to one common term → gene-set form regardless of origin:

  • GAF (GO Consortium gene-association format): one annotation per row, gene → GO id; propagated up the ontology (true-path rule) into term → genes. Read read_gaf then GafRaw::into_gene_sets.
  • GMT (MSigDB): one gene-set per row, term <TAB> description <TAB> genes…; taken as-is, no propagation. Read read_gmt.

Each gene carries the identifier aliases the source provides (symbol / accession / synonyms for GAF) so a downstream reconciler can match it against an expression dictionary whether that uses HGNC, ENSG, or ENSG_HGNC.

Structs§

GafOpts
Options for read_gaf.
GafRaw
Raw GAF annotations before ontology propagation: gene key → direct GO ids, plus the per-gene identifier aliases harvested from the GAF.
GeneSets
A collection of gene-sets keyed by term id — the common form all sources (GAF/GMT/markers) reduce to before scoring.
Reconciled
Gene-sets reconciled against an expression dictionary: term → matched row indices, plus coverage statistics. This is the sparse membership the enrichment scorer consumes (term → its rows in the gene profile).

Constants§

COVERAGE_WARN_FRAC
Below this matched-gene fraction, Reconciled::log_coverage warns rather than logs at info — a thin overlap silently produces no enrichment.

Functions§

read_gaf
Parse a GAF (.gaf or .gaf.gz). Columns (1-based) used: 2 = object id / accession, 3 = symbol (the gene key), 4 = qualifier (rows with NOT are dropped), 5 = GO id, 7 = evidence code (for no_iea), 11 = synonyms, 12 = object type (only proteins and genes are kept). The symbol, accession, and pipe-split synonyms are kept as match aliases.
read_gmt
Read an MSigDB-style GMT: each non-comment line is term <TAB> description <TAB> gene1 <TAB> gene2 …. Terms are used verbatim (they become tree nodes only if they resolve against an --obo); genes are their own keys with no extra aliases; no propagation.
read_membership_pairs
Parse a two-column membership file — gene <TAB> label (a marker panel, a TF→target list, any gene→category table) — into (gene, label) pairs via the shared, gz-aware line reader (tab or comma delimited). Takes the first two tokens per line; skips blank lines, # comments, a gene/symbol header row and rows missing a label. Labels are kept verbatim; genes are not case-folded.