genome_spy.when

genome_spy.when(predicate)View on GitHub

Start an Altair-style selection condition.

Accept a selection handle, a generated selection predicate, or a mapping using GenomeSpy’s and, or, not, selection-union, or named ref grammar. Selection handles can appear inside mappings, including as the param of an endpoint projection. Declare selections with add_params and named predicates with the unit view’s predicates property.

Parameters:

predicate – A selection parameter or a composed selection test.

Returns:

A builder whose then() method defines the selected branch.

Raises:
  • TypeError – If a value parameter or unsupported input is supplied.

  • SchemaValidationError – If the predicate does not match the Core grammar.

Example

>>> import genome_spy as gs
>>> brush = gs.selection_interval(encodings=["x"])
>>> condition = gs.when(brush).then(gs.value("red")).otherwise(
...     gs.value("gray")
... )
>>> condition.to_dict()["condition"]["param"] == brush.name
True