SwitchBuilder
- class hail.expr.builders.SwitchBuilder[source]
Class for generating conditional trees based on value of an expression.
Examples
>>> csq = hl.literal('loss of function') >>> expr = (hl.switch(csq) ... .when('synonymous', 1) ... .when('SYN', 1) ... .when('missense', 2) ... .when('MIS', 2) ... .when('loss of function', 3) ... .when('LOF', 3) ... .or_missing()) >>> hl.eval(expr) 3
Notes
All expressions appearing as the then parameters to
when()
ordefault()
method calls must be the same type.- Parameters:
expr (
Expression
) – Value to match against.
Attributes
Methods
Finish the switch statement by adding a default case.
Finish the switch statement by throwing an error with the given message.
Finish the switch statement by returning missing.
Add a value test.
Add a test for missingness.
- default(then)[source]
Finish the switch statement by adding a default case.
Notes
If no value from a
when()
call is matched, then then is returned.- Parameters:
then (
Expression
)- Returns:
- or_error(message)[source]
Finish the switch statement by throwing an error with the given message.
Notes
If no value from a
SwitchBuilder.when()
call is matched, then an error is thrown.- Parameters:
message (
Expression
of typetstr
)- Returns:
- or_missing()[source]
Finish the switch statement by returning missing.
Notes
If no value from a
when()
call is matched, then the result is missing.- Parameters:
then (
Expression
)- Returns:
- when(value, then)[source]
Add a value test. If the base expression is equal to value, then returns then.
Warning
Missingness always compares to missing. Both
NA == NA
andNA != NA
returnNA
. Usewhen_missing()
to test missingness.- Parameters:
value (
Expression
)then (
Expression
)
- Returns:
SwitchBuilder
– Mutates and returns self.
- when_missing(then)[source]
Add a test for missingness. If the base expression is missing, returns then.
- Parameters:
then (
Expression
)- Returns:
SwitchBuilder
– Mutates and returns self.