agglovar.merge.base

Base class for callset intersects.

Attributes

CallsetDefInputType

Alias for acceptable input types.

Classes

CallsetDef

Callset definition.

MergeBase

Base class for callset intersects.

Module Contents

class agglovar.merge.base.CallsetDef

Bases: NamedTuple

Callset definition.

Variables:
  • table – The callset table to be merged.

  • name – The name of the callset within a collection of callsets.

  • metadata – The metadata of the callset or None if no metadata is provided.

__repr__() → str

Return a string representation of the callset definition.

__str__() → str

Return a string representation of the callset definition.

metadata: str | None
name: str
table: polars.LazyFrame
class agglovar.merge.base.MergeBase

Bases: abc.ABC

Base class for callset intersects.

abstractmethod __call__(callsets: collections.abc.Iterable[CallsetDefInputType], retain_index: bool = False, pre_filter: collections.abc.Iterable[polars.Expr] | None = None, temp_dir: bool | str | pathlib.Path = False) → polars.LazyFrame

Intersect callsets.

Parameters:
  • callsets – Callsets to intersect.

  • retain_index – If True, do not drop an existing “_index” column if it exists.

  • pre_filter – If set, filter each table with these expressions. Filter is applied last (after “_index” is set).

  • temp_dir – How the underlying pairwise intersect materialises prepared tables before its chunked loop. False (default) keeps tables in memory; True writes them to the system temp directory as parquet; a str/Path writes them to that directory. Temp files are always removed on exit.

Returns:

A merged callset table.

static get_intersect_tuples(callsets: collections.abc.Iterable[CallsetDefInputType], retain_index: bool = False, pre_filter: collections.abc.Iterable[polars.Expr] | polars.Expr | None = None) → list[CallsetDef]

Transform input callset definitions into a normalized list of CallsetDef.

Each returned CallsetDef (a named tuple) has three fields:

  1. table: A lazy frame.

  2. name: A name for the source.

  3. metadata: A metadata string for this source, or None if none was given.

The source index is not stored on the definition; it is implicitly the position of the element in the returned list (0 for the first source, incrementing by 1).

If a source name is given, the given name is used. If it is not, then a default name is generated from the source index (e.g. “source_1” for the first source). Names are de-duplicated against names already seen.

Lazy frames are transformed to add a source index (“_mg_src_index” column) and to ensure a variant ID is present (“id” column), filling missing IDs from the index.

Parameters:
  • callsets – Callsets parameter. May be an iterable of DataFrames, LazyFrames, (table, name) tuples, (table, name, metadata) tuples, or CallsetDef objects.

  • retain_index – If True, do not drop an existing “_index” column if it exists.

  • pre_filter – If set, filter each table with these expressions. Filter is applied last (after “_index” is set).

Returns:

A list of CallsetDef, one per input source, in input order.

type agglovar.merge.base.CallsetDefInputType = pl.DataFrame | pl.LazyFrame | tuple[pl.DataFrame | pl.LazyFrame] | tuple[pl.DataFrame | pl.LazyFrame, str | None] | tuple[pl.DataFrame | pl.LazyFrame, str | None, str | dict | None] | CallsetDef

Alias for acceptable input types.