This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Calculate z-scores from GWAS summary stats

Hello,

I need to calculate the z-scores from meta-GWAS summary stats. The association file has the following header

rs_id   Allele1 Allele2 Freq1   Effect  StdErr  P.value

The 'effect' is the Beta coefficent. My understanding is

z-score=Effect/StdErr

Is that correct? Also, are there any R packages that can do this?

Many thanks

summary-stats gwas z-scores

1 answer

You are correct. This can be very easily done with basic AWK or R:

AWK:

awk '{if(NR == 1) print \$1; else if(NR > 1) print $0, \$5/\$6}' infile > outfile

R:

Infile<-read.table("infile.txt", head=T)
infile$z-score<-infile$Effect/infile$StdErr
head(Infile, 1)
rs_id   Allele1 Allele2 Freq1   Effect  StdErr  P.value z-score

thank you, very much! I actually tried awk before but end up with an error

awk: (FILENAME=summary_stats.txt FNR=1) fatal: division by zero attempted

Hi,

Please check following code to fix the issue. Actually, the issue backs to division by zero and also considering heading as string.

awk -v OFS='\t' 'NR==1 {$8="zscore"} NR>1 {$8 = ($6!=0) ? sprintf("%.3f", $5 / $6): "UND"} 1' input file > output file

Log in to answer this question.