Combining scans

Hello again!

I’m having some trouble combining one scan annotation with another. I’ve created one scan on a table and would like to use that first scan to create a second one:

context_ht = context_ht.annotate(
    variant_count=hl.scan.group_by(
        context_ht.grouping,
        hl.scan.count()
    )
)
context_ht = context_ht.annotate(
    mu_agg=hl.scan.group_by(
            context_ht.grouping,
            hl.or_missing(
                hl.len(context_ht.variant_count) > 0,
                hl.scan.sum(
                    context_ht.mu_snp * context_ht.variant_count[context_ht.grouping]
                ),
            )
        )
)


I’d like to use variant_count to create a new scan annotation but keep running into this error:

Error summary: HailException: Key 'ACA-C-T-0-false-70'    not found in dictionary. Keys: []

Am I not skipping the first line of the table correctly? Is there a better way to combine these scans?

My guess is because the scan is not inclusive of the line you’re in? If you trust that it should always be there, you could context_ht.variant_count.get(context_ht.grouping, 0) maybe (default to 0 if not seen yet)?

1 Like