> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bioptimus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# bioptimus.io.omics.gene_sets

File readers for gene sets and gene-identifier maps.

Provides:

* [`load_gmt`](https://docs.bioptimus.com/sdk-reference/io/omics/gene_sets#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`](https://docs.bioptimus.com/sdk-reference/io/omics/gene_sets#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`](https://docs.bioptimus.com/sdk-reference/io/omics/gene_sets#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

```python theme={null}
def load_gmt(path: str | Path) -> list[tuple[str, str, tuple[str, ...]]]
```

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**

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

```python theme={null}
def read_gene_set_records(source: str | Path | pd.DataFrame, *, set_col: str,
                          gene_col: str) -> list[tuple[str, tuple[str, ...]]]
```

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.

**source**

A path to a CSV/TSV file (separator inferred from the extension, `.tsv` -> tab, otherwise comma) or an in-memory `pandas.DataFrame`.

**set\_col**

Column holding the set name.

**gene\_col**

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

```python theme={null}
def load_gene_map(path: str | Path,
                  *,
                  symbol_column: str = "gene_name",
                  id_column: str = "gene_id",
                  drop_ambiguous: bool = True) -> dict[str, str]
```

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**

Path to the mapping table.

**symbol\_column**

Column holding the gene symbols (the map keys).

**id\_column**

Column holding the panel identifiers (the map values), for example Ensembl ids.

**drop\_ambiguous**

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

```python theme={null}
def read_gene_list(path: str | Path,
                   *,
                   gene_col: str = "gene_id") -> list[str]
```

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**

Path to the CSV/TSV file.

**gene\_col**

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`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.