Diploid to haploid chrX calls

Hello,
I need to transform chrX non_par regions for male samples from diploid calls in the matrixtable to haploid before exporting them to VCF. Is there a recommended way to change the diploid to haploid calls?

These matrixtables had been modified before to change the haploid calls to diploid calls with this code snippet:
pl_expr = (hl.zip_with_index(mt.PL) .flatmap(lambda x: hl.range(x[0] + 1) .map(lambda i: hl.cond(i == x[0], x[1], 999)))) gt_allele = mt.GT.n_alt_alleles() gt_and_pl = (hl.switch(mt.GT.ploidy) .when(1, (hl.call(gt_allele, gt_allele), pl_expr)) .default((mt.GT, mt.PL))) mt = mt.annotate_entries(GT = gt_and_pl[0], PL = gt_and_pl[1])

We want to reverse this now get the original haploid call before exporting to VCF.
If I do the following for the non_par male samples will it be correct? Since I am assuming the converted diploid calls would either be 0/0 or 1/1:
mt.annotate_entries(GT=hl.case() .when(mt.GT.is_diploid(), hl.call(mt.GT[0], phased=False)) .default(hl.null(hl.tcall)) )

I think this is right, if you run this annotate_entries only on the sex chromosomes of male samples.

1 Like