Exporting participant polygenic scores to csv


I have been following along this example to create a polygenic risk score from my matrix table: Hail | Genetics

I would like to now export a csv that gives only the participant ID and the polygenic score. How do I do this? I did try to figure this out using the documentation, but all I could find is how to export snp-wise information, I cannot figure out how to export participant-wise data.

Thank you,

Hi @kforth !

Any Hail table can be exported as a CSV or a TSV using the general purpose exporters. In your case, you need to get the column (aka sample) table and export that. You could do that like this:

# get the column/sample table
cols = mt.cols()
# keep only the necessary columns (plus the sample identifier b/c it is the key)
cols = cols.select('prs')
# write the result to an efficient Hail format
cols = cols.write('data/my_prs.ht')
# convert the Hail format to a CSV
hl.read_table('data/my_prs.ht').export('data/my_prs.csv', delimiter=',')

Note that I write to a Hail table first and then export. I recommend always saving your results as a Hail Table or Hail Matrix Table before exporting because it tends to be more reliable and efficient than directly exporting.