-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimple_MR.sh
107 lines (99 loc) · 2.54 KB
/
Simple_MR.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
script_DIR="$( cd "$( dirname "$0" )" && pwd -P )"
## defualt values
Presso="YES"
if ! options=$(getopt -o h,e:,o:,d:,p:,b:,P: -l help,Exposure:,Outcome:,OutDIRPrefix:,Presso:,bfile:,prink -- "$@")
then
echo "ERROR: check usage"
cat $script_DIR/Help
exit 1
fi
eval set -- "$options"
while true; do
case "$1" in
-h|--help)
cat $script_DIR/Help
shift ;;
-o|--Outcome)
Outcome="$2"
echo "-o $Outcome"
shift 2 ;;
-e|--Exposure)
Exposure="$2"
echo "-e $Exposure"
shift 2 ;;
-d|--OutDIRPrifix)
OutDIRPrefix="$2"
echo "output dir" $OutDIRPrefix
shift 2 ;;
-p|--Presso)
Presso="$2"
if [ $Presso != "NO" ]&&[ $Presso != "YES" ]
then
Presso="YES"
fi
echo $Presso
shift 2 ;;
-b|--bfile)
bfile="$2"
echo "-b $bfile"
shift 2 ;;
-P|--plink)
plink="$2"
echo "-P|--plink $plink"
shift 2 ;;
-|--)
shift
break
esac
done
#Options : help,Exposure:,Outcome:,OutDIRPrefix:,Presso ,bfile prink
### MAKE OUTPUT DIR
if [ ! -d $OutDIRPrefix ];
then
mkdir $OutDIRPrefix
fi
if [ "$plink" != "" ] && [ $bfile != "" ];
then
## LD CLUMPING
$plink --bfile $bfile --allow-no-sex --clump $Exposure --out $OutDIRPrefix/Exposure
## make Clumped Exposure and Outcome
awk '{print $3}' $OutDIRPrefix/Exposure.clumped | sed '/^$/d' > $OutDIRPrefix/Exposure.Sig.SNP
fgrep -f $OutDIRPrefix/Exposure.Sig.SNP -w $Exposure > $OutDIRPrefix/Exposure.sig
fgrep -f $OutDIRPrefix/Exposure.Sig.SNP -w $Outcome > $OutDIRPrefix/Outcome.sig
## removeCovariate info
EX_idx=`fgrep ADD $OutDIRPrefix/Exposure.sig`
OUT_idx=`fgrep ADD $OutDIRPrefix/Outcome.sig`
if [ "$OUT_idx" != "" ];
then
egrep 'ADD|SNP' $OutDIRPrefix/Outcome.sig >$OutDIRPrefix/temp
mv $OutDIRPrefix/temp $OutDIRPrefix/Outcome.sig
fi
if [ "$EX_idx" != "" ];
then
egrep 'ADD|SNP' $OutDIRPrefix/Exposure.sig > $OutDIRPrefix/temp
mv $OutDIRPrefix/temp $OutDIRPrefix/Exposure.sig
fi
else
## NO Plink mode
EX_idx=`fgrep ADD $Exposure`
OUT_idx=`fgrep ADD $Outcome`
if [ "$OUT_idx" != "" ];
then
egrep 'ADD|SNP' $Outcome >$OutDIRPrefix/temp
mv $OutDIRPrefix/temp $OutDIRPrefix/Outcome.sig
else
ln -s $Outcome $OutDIRPrefix/Outcome.sig
fi
if [ "$EX_idx" != "" ];
then
egrep 'ADD|SNP' $Exposure > $OutDIRPrefix/temp
mv $OutDIRPrefix/temp $OutDIRPrefix/Exposure.sig
else
ln -s $Exposure $OutDIRPrefix/Exposure.sig
fi
fi
Ex=$OutDIRPrefix/Exposure.sig
Ot=$OutDIRPrefix/Outcome.sig
echo $OutDIRPrefix ,$Presso
Rscript $script_DIR/MR.R $Ex $Ot $Presso $OutDIRPrefix