agglovar.expr.variant

Polars expressions used by variant calling routines.

Attributes

id_expr

Expression for generating variant IDs including alias "id" for the result (ideal for with_column()).

id_expr_noalias

Expression for generating variant IDs.

id_nonsnv_expr

Expression for generating non-SNV IDs.

id_snv_expr

Expression for generating SNV IDs.

sort_cols

Sort columns for variant tables.

Functions

id_expr_for_table(→ polars.Expr)

Get a variant ID expression for a single variant-type table.

lead_src_expr(→ polars.Expr)

Extract the lead source entry from a merged callset.

Module Contents

agglovar.expr.variant.id_expr_for_table(table: str, alias: str | None = 'id') → polars.Expr

Get a variant ID expression for a single variant-type table.

Single-type tables carry only the columns listed for their type in agglovar.schema.STANDARD_FIELDS, so id_expr cannot be applied to them (see its documentation). This routine returns the one branch that matches the table’s columns.

Parameters:
  • table – Table name from agglovar.schema.STANDARD_FIELDS (e.g. “snv”, “insdel”).

  • alias – Output column name for the resulting IDs, or None to leave it unaliased.

Returns:

An expression yielding variant IDs for table.

Raises:

ValueError – If table is not a known variant-type table.

agglovar.expr.variant.lead_src_expr(mg_src_col: str = 'mg_src', mg_src_lead_col: str = 'mg_src_lead', alias: str | None = 'lead_src') → polars.Expr

Extract the lead source entry from a merged callset.

A merge produces an mg_src list column with one struct per contributing source and an mg_src_lead column holding the integer position within that list of the lead (representative) source. This routine gathers that lead entry back out as a struct, so an API user can read the lead source directly instead of manually indexing the list with pl.col('mg_src').list.get(pl.col('mg_src_lead')).

Agglovar does not use this internally; the merge stores only the index to avoid duplicating the entry. It is provided as a convenience for downstream API users.

Parameters:
  • mg_src_col – Name of the mg_src list column.

  • mg_src_lead_col – Name of the mg_src_lead index column.

  • alias – Output column name for the resulting struct, or None to leave it unaliased.

Returns:

An expression yielding the lead source struct, carrying the same fields as an mg_src entry (“src_index”, “src_name”, “src_meta”, “var_index”, “var_id”).

agglovar.expr.variant.id_expr

Expression for generating variant IDs including alias “id” for the result (ideal for with_column()).

Requires both the SNV columns (ref, alt) and the non-SNV column (varlen) to be present: Polars resolves both branches of the expression regardless of which one a row selects. Use id_expr_for_table() for single-type tables, which carry only the columns listed in agglovar.schema.STANDARD_FIELDS for their type.

agglovar.expr.variant.id_expr_noalias

Expression for generating variant IDs.

agglovar.expr.variant.id_nonsnv_expr

Expression for generating non-SNV IDs.

agglovar.expr.variant.id_snv_expr

Expression for generating SNV IDs.

agglovar.expr.variant.sort_cols

Sort columns for variant tables.