Export GWAS summary statistics to a .txt file

Hi there,

I used Hail’s “hl.agg.linreg” function to run GWAS and would like to export the summary statistics into a .txt file. Specifically, here’s my code for GWAS:

mt = mt.annotate_rows(gwas = hl.agg.linreg(mt.quant_pheno, [1, mt.GT.n_alt_alleles()]))

And here’s my code to export the output:


I only have ~6000 SNPs in the summary statistics, but it took about 5 minutes to generate the output. Also, the “flatten” function didn’t work properly, as the statistics were clumped together instead of showing up in separate columns when I read the .txt file into R. May I ask if there’s any mistake in my code? Also, how could I improve the speed of exporting output? Thank you very much!


Thank you for your question, EZXYZ! Our apologies for getting back to you after awhile.

A few follow up questions:

  1. I am assuming that you are exporting everything in gwas regardless of magnitude of point estimates or significance threshold?
  2. If you were to export the mt, I would suggest first saving the gwas annotated rows of your summary statistics into a Hail table and then export without flattening the data into the table. Happy to help further if I possibly got your question wrong.


Great, this really helps, thanks!

Could you please be more explicit? I am new to hail. Suppose your gwas is in “mt.gwas”, and you want to save the summary stats to “gwas.summary.txt”, what would be the code snippet?

Thanks a lot!

I would highly suggest going through the tutorial for GWAS Hail | GWAS Tutorial
After you are done with running your GWAS, you should be able to export it as a csv table

I was going to say it would be very helpful to include that part of the code in the GWAS tutorial. I did go through the GWAS tutorial multiple times, but was unable to find the code to save the results to a csv file. I was able to use mt.gwas.flatten().export(‘<myfile.tsv’) to save the results, though.