genome_spy.when

genome_spy.when(predicate)View on GitHub

Start an Altair-style selection condition.

GenomeSpy 0.86 supports selection parameters as conditional predicates. Expression predicates will become available only if the upstream schema adds that grammar.

Parameters:

predicate – A point or interval selection parameter.

Returns:

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

Raises:

TypeError – If predicate is not a selection parameter.

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