Skip to main content
File readers for gene sets and gene-identifier maps. Provides:
  • load_gmt — reads a GMT file (MSigDB / pathway format) into (name, description, genes) records consumed by bioptimus.data.omics.gene_set.GeneSetCollection.from_gmt.
  • read_gene_set_records — reads a long-form (set, gene) table into (name, genes) records consumed by bioptimus.data.omics.gene_set.GeneSetCollection.from_records.
  • load_gene_map — reads a two-column table of gene symbol to Ensembl id into a dict suitable for the mapping argument of the gene-set resolution helpers.

load_gmt

Reads a GMT (Gene Matrix Transposed) file. Each non-empty line is <set name>\t<description>\t<gene>\t<gene>.... Blank lines are ignored and surrounding whitespace is trimmed from every field; a leading UTF-8 BOM is stripped. Duplicate genes within a line are left as-is; the GeneSet de-duplicates on construction.
Path to the .gmt file.
Returns: A list of (name, description, genes) records, one per line, in file order. Raises:
  • BioptimusValueError - If a line has fewer than three tab-separated fields (no genes), or if the file is missing, unreadable, or not valid UTF-8, tagged BIO-CFG-001.

read_gene_set_records

Reads a long-form (set, gene) table into per-set gene records. Each row assigns one gene to one set, so a set spans multiple rows (the layout of MSigDB-style CSVs and the decoupler “net” format). Rows are grouped by set_col preserving first-seen order, both of the sets and of the genes within each set. Rows with a missing set or gene value are dropped, as are rows whose gene is a placeholder token (for example NA, NULL, or blank) that survives dropna() when the table is read as strings. Gene identifiers are whitespace-stripped.
A path to a CSV/TSV file (separator inferred from the extension, .tsv -> tab, otherwise comma) or an in-memory pandas.DataFrame.
Column holding the set name.
Column holding the gene identifier.
Returns: A list of (name, genes) records, one per distinct set, in first-seen order. Raises:
  • BioptimusValueError - If a required column is missing, or if a source file is missing, unreadable, or malformed, tagged BIO-CFG-001.

load_gene_map

Reads a gene symbol-to-identifier mapping from a CSV/TSV table. The separator is inferred from the file extension (.tsv -> tab, otherwise comma). The id_column is matched tolerantly against common spellings (for example "Ensembl ID" or "Ensembl_ID") when the exact name is absent.
Path to the mapping table.
Column holding the gene symbols (the map keys).
Column holding the panel identifiers (the map values), for example Ensembl ids.
When True (default), a symbol that maps to more than one distinct identifier is dropped with a warning, since keeping a single arbitrary id would silently mis-resolve. When False the last row for a symbol wins (and a warning is still emitted).
Returns: A dict mapping each gene symbol to its identifier. Raises:
  • BioptimusValueError - If a required column is missing, or if the file is missing, unreadable, or malformed, tagged BIO-CFG-001.

read_gene_list

Reads a flat single-column gene list from a CSV/TSV table. Reads a file that holds one gene identifier per row under a single column (the layout of the predefined panel/gene-list CSVs). The separator is inferred from the file extension (.tsv -> tab, otherwise comma), and the column is matched tolerantly against common spellings (for example "Ensembl ID") when the exact name is absent. Lines beginning with # are treated as comments and ignored. Blank and placeholder rows are dropped; duplicates are removed keeping first-seen order.
Path to the CSV/TSV file.
Column holding the gene identifiers.
Returns: The gene identifiers, de-duplicated in first-seen order. Raises:
  • BioptimusValueError - If the gene column is missing, or if the file is missing, unreadable, or malformed, tagged BIO-CFG-001.