def add_most_severe_consequence( tc: hl.expr.StructExpression) -> hl.expr.StructExpression: """ Add most_severe_consequence annotation to transcript consequences This is for a given transcript, as there are often multiple annotations for a single transcript: e.g. splice_region_variant&intron_variant -> splice_region_variant """ return tc.annotate(most_severe_consequence=csqs.find( lambda c: tc.consequence_terms.contains(c)))
def add_most_severe_consequence_to_consequence_minus_splice( tc: hl.expr.StructExpression) -> hl.expr.StructExpression: """ Copied from gnomad_hail but slight change """ csqs = hl.literal(all_coding_minus_splice) return tc.annotate(most_severe_consequence=csqs.find( lambda c: tc.consequence_terms.contains(c)))
def split_info_annotation( info_expr: hl.expr.StructExpression, a_index: hl.expr.Int32Expression ) -> hl.expr.StructExpression: """ Splits multi-allelic allele-specific info fields. :param info_expr: Field containing info struct. :param a_index: Allele index. Output by hl.split_multi or hl.split_multi_hts. :return: Info struct with split annotations. """ # Index AS annotations info_expr = info_expr.annotate( **{ f: info_expr[f][a_index - 1] for f in info_expr if f.startswith("AC") or (f.startswith("AS_") and not f == "AS_SB_TABLE") }, AS_SB_TABLE=info_expr.AS_SB_TABLE[0].extend(info_expr.AS_SB_TABLE[a_index]), ) return info_expr