Gnomad allele frequency query

hi, as I am still learning hail (python), I have a very basic question, because I do not yet fully understand hail tables and how to query them.

I want to get allele frequencies for all gnomAD populations for a subset of variants and export it as table or vcf.

I tried exemplarily for one random variant:

ht = hl.read_table(‘data/gnomad.genomes.v3.1.sites.ht/’)
favorite_locus = hl.parse_locus(‘chr1:156129878’, ‘GRCh38’)

When comparing it with the data on the gnomAD-browser, I can see that:

ht.filter(ht.locus == favorite_locus).freq[0].show()
±---------------±-----------±----------±----------±----------±------------------------+
| locus | alleles | .AC | .AF | .AN | .homozygote_count |
±---------------±-----------±----------±----------±----------±------------------------+
| locus | array | int32 | float64 | int32 | int32 |
±---------------±-----------±----------±----------±----------±------------------------+
| chr1:156129878 | [“T”,“G”] | 27542 | 1,81e-01 | 151952 | 4757 |
±---------------±-----------±----------±----------±----------±------------------------+

gives the information for total AF and

ht.filter(ht.locus == favorite_locus).freq[2].show()

±---------------±-----------±----------±----------±----------±------------------------+
| locus | alleles | .AC | .AF | .AN | .homozygote_count |
±---------------±-----------±----------±----------±----------±------------------------+
| locus | array | int32 | float64 | int32 | int32 |
±---------------±-----------±----------±----------±----------±------------------------+
| chr1:156129878 | [“T”,“G”] | 4832 | 7,11e-02 | 67994 | 180 |
±---------------±-----------±----------±----------±----------±------------------------+

for NFE AF.

Can someone explain me how to use the “meta” information to more easily query for populations. Or more general, how to get names for the information stored in an array of a row-field ?

Thanks a lot for you help!

The gnomAD Hail Tables have a global field named freq_meta. Each entry in freq_meta describes the freq entry at the same index (freq_meta[0] contains information about freq[0], freq_meta[1] about freq[1], etc.).

To get freq_meta as a Python list, use hl.eval(ht.globals.freq_meta).

Thanks! That already helps. Again, sorry for the basic questions, but can you tell me how to combine this information to:
a) generate a ht with e.g. freq[0] and freq[2]
and
b) finally export it to a tab, tsv or csv delimited text file which looks like this:

locus | alleles | gnomAD.AC | gnomAD.AF | gnomAD.AN | gnomAD.homozygote_count | nfe.AC | nfe.AF | nfe.AN | nfe.homozygote_count

Thanks!

Something along the lines of:

ht.select(
  "locus",
  "alleles",
  gnomad_ac=ht.freq[0].AC,
  gnomad_af=ht.freq[0].AF,
  gnomad_an=ht.freq[0].AN,
  gnomad_homozygote_count=ht.freq[0].homozygote_count,
).export("/path/to/export.tsv")

To include more columns, include expressions for them in the select call.

Thanks a lot, that really helped.
It worked without the “locus”, “alleles” part.