-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_meta_analysis.sh
executable file
·78 lines (72 loc) · 2.22 KB
/
6_meta_analysis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/bash
export analysis=~/Caprion/analysis
export suffix=_dr
export TMPDIR=${HPC_WORK}/work
if [ ! -d ${analysis}/METAL${suffix} ]; then mkdir ${analysis}/METAL${suffix}; fi
function METAL_list()
# build the complete list of files
{
ls ${analysis}/pgwas${suffix}/caprion${suffix}-?-*.fastGWA.gz | \
xargs -l basename -s .fastGWA.gz | \
awk -vdir=${analysis}/pgwas${suffix} -vOFS="\t" '
{
split($1,a,"-")
p=$1;
print a[2], p, dir"/"$1".fastGWA.gz"
}' | \
sort -k2,2 -k1,1n > ${analysis}/METAL${suffix}/METAL.list
}
function METAL_files()
# generate individual METAL command files
{
for p in $(cat ${analysis}/output/caprion${suffix}.varlist)
do
(
echo SEPARATOR TAB
echo COLUMNCOUNTING STRICT
echo CHROMOSOMELABEL CHR
echo POSITIONLABEL POS
echo CUSTOMVARIABLE N
echo LABEL N as N
echo TRACKPOSITIONS ON
echo AVERAGEFREQ ON
echo MINMAXFREQ ON
echo ADDFILTER AF1 ">=" 0.001
echo ADDFILTER AF1 "<=" 0.999
echo MARKERLABEL SNP
echo ALLELELABELS A1 A2
echo EFFECTLABEL BETA
echo PVALUELABEL P
echo WEIGHTLABEL N
echo FREQLABEL AF1
echo STDERRLABEL SE
echo SCHEME STDERR
echo EFFECT_PRINT_PRECISION 8
echo STDERR_PRINT_PRECISION 8
echo GENOMICCONTROL OFF
echo LOGPVALUE ON
echo OUTFILE ${analysis}/METAL${suffix}/$p${suffix}- .tbl
awk '$2 == "caprion"ENVIRON["suffix"]"-"$1"-"token {print "PROCESS", $3}' token=${p} ${analysis}/METAL${suffix}/METAL.list
awk '$2 == "caprion"ENVIRON["suffix"]"-"$1"-"token {print "PROCESS", $3}' token=${p}-chrX ${analysis}/METAL${suffix}/METAL.list
echo ANALYZE HETEROGENEITY
echo CLEAR
) > ${analysis}/METAL${suffix}/${p}${suffix}.metal
done
}
function METAL_analysis()
# conduct the analysis
# module load metal/2011-03-25
{
export rt=${analysis}/METAL${suffix}
ls $rt/*.metal | \
xargs -l basename -s .metal | \
parallel -j1 --env rt -C' ' '
metal ${rt}/{}.metal 2>&1 | \
tee ${rt}/{}-1.tbl.log;
cat <(head -1 ${st}/{}-1.tbl) <(sed '1d' ${rt}/{}-1.tbl | sort -k1,1n -k2,2n) | \
bgzip -f ${rt}/{}-1.tbl.gz
tabix -S1 -s1 -b2 -e2 -f ${rt}/{}-1.tbl.gz
rm ${rt}/{}-1.tbl
'
}
for cmd in METAL_list METAL_files; do $cmd; done