Aggregating entry-level parameters satisfied with some conditions by row

Hello,

I am doing the site-level annotation from the entry-level parameter values. I used the script for just mean aggregation as below.

info_expr=info_expr.annotate(qd=hl.agg.mean(mt.gvcf_info.QD))

In this script, I want to add the condition which only get the mean value of entry-level QD parameters with mt.GT.is_het()==True or mt.GT.is_hom_var() ==True.

If possible, could you suggest some solution for this issue? Thank you.

Best,
Jina

You can do this with hl.agg.filter:

info_expr=info_expr.annotate(
    qd=hl.agg.mean(mt.gvcf_info.QD),
    qd_het = hl.agg.filter(mt.GT.is_het(), hl.agg.mean(mt.gvcf_info.QD)),
    qd_hv = hl.agg.filter(mt.GT.is_hom_var(), hl.agg.mean(mt.gvcf_info.QD)),
)

Thanks, @tpoterba !!!