forked from alanmichaelpittman100/GWAS-Imputation-Protocol-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline_pre_Imputation_Checking_Formatting.sh
229 lines (141 loc) · 5.84 KB
/
pipeline_pre_Imputation_Checking_Formatting.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
#V1
#Alan Pittman 2018
###check the input plink file prior to imputation
###amend and/or discard any inconsisten alleles/ref-alleles/strand issues
###convert each plink file to a .vcf file ready for Impuation on the Michigan Imputation Server
###autosomes
###X-chromosome separate
file=$1 #specify your input file here
#--------------------------------------------------------------------------------------------
#resources
plink=/homes/athosnew/Genetics_Centre_Bioinformatics/resourses/plink_linux_x86_64/plink
SHAPEIT=/homes/athosnew/Genetics_Centre_Bioinformatics/resourses/shapeit.v2.904/bin/shapeit
checkVCF=/homes/athosnew/Alan/Alan_Bioinformatics_Projects/imputation/checkVCF.py
#Dirs
inPLINK=/homes/athosnew/Alan/Alan_Bioinformatics_Projects/imputation/starting_plink_files
freqOUT=/homes/athosnew/Alan/Alan_Bioinformatics_Projects/imputation/frequency_outputs
updatedOUT=/homes/athosnew/Alan/Alan_Bioinformatics_Projects/imputation/updated_plink_files
PhasedOUT=/homes/athosnew/Alan/Alan_Bioinformatics_Projects/imputation/shapeit_phase_out
VCF_out=/homes/athosnew/Alan/Alan_Bioinformatics_Projects/imputation/pre-phased_vcfs
#--------------------------------------------------------------------------------------------
chrNo="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22"
#--------------------------------------------------------------------------------------------
echo " "
echo " "
echo \
'''---------------------------------------------------------------------------------------------
AUTOMATED IMPUTATION CHECKING AND FORMATING
---------------------------------------------------------------------------------------------'''
date
echo " "
sleep 1
sleep 1
echo " "
echo \
'''---------------------------------------------------------------------------------------------
CALCULATING ALLELE FREQUENCIES
---------------------------------------------------------------------------------------------'''
echo " "
sleep 1
$plink --bfile $inPLINK/${file} --freq --out $freqOUT/$file
cp $inPLINK/${file}.* ./
sleep 1
echo " "
echo \
'''---------------------------------------------------------------------------------------------
EXECUTING HRC IMPUTATION CHECKING TOOL
---------------------------------------------------------------------------------------------'''
echo " "
sleep 1
###Execute checking script:
perl /homes/athosnew/Alan/Alan_Bioinformatics_Projects/imputation/HRC-1000G-check-bim-v4.2_AP_MODIFIED.pl \
-b $inPLINK/${file}.bim \
-f $freqOUT/${file}.frq \
-r /homes/athosnew/Genetics_Centre_Bioinformatics/resourses/HRC_reference/1000GP_Phase3_combined.legend \
-p EUR -g
sleep 1
echo " "
echo \
'''---------------------------------------------------------------------------------------------
EXECUTING PLINK COMMANDS TO REPAIR ALLELE CONFIGURATION
---------------------------------------------------------------------------------------------'''
echo " "
sleep 1
##run this self -generating script running plink commands to fix any snps/alleles/positions/names etc.
sh Run-plink.sh
#------------------------------------------------------------------------------------------------
#housekeeping
mv *.txt log_files/
mv *.log log_files/
mv /homes/athosnew/Alan/Alan_Bioinformatics_Projects/imputation/${file}-updated* updated_plink_files/
rm $file.fam $file.bed $file.bim
#------------------------------------------------------------------------------------------------
sleep 1
echo " "
echo \
'''---------------------------------------------------------------------------------------------
PRE PHASING HAPLOTYPES FOR IMPUTATION
---------------------------------------------------------------------------------------------'''
echo " "
sleep 1
for chr in $chrNo; do
$SHAPEIT --input-bed $updatedOUT/${file}-updated-chr$chr.bed $updatedOUT/${file}-updated-chr$chr.bim $updatedOUT/${file}-updated-chr$chr.fam \
-M /homes/athosnew/Genetics_Centre_Bioinformatics/resourses/shapeit.v2.904/bin/1000GP_Phase3/genetic_map_chr${chr}_combined_b37.txt \
--force \
-O $PhasedOUT/${file}_${chr}.phased \
-T 10
done
sleep 3
echo " "
echo \
'''---------------------------------------------------------------------------------------------
GENERATE VCF FILES
---------------------------------------------------------------------------------------------'''
echo " "
sleep 1
for chr in $chrNo; do
$SHAPEIT -convert \
--input-haps $PhasedOUT/${file}_${chr}.phased \
--output-vcf $VCF_out/${file}_${chr}.phased.vcf
done
sleep 1
echo " "
echo \
'''---------------------------------------------------------------------------------------------
CHECK OUR FINAL VCF FOR INTEGRITY
---------------------------------------------------------------------------------------------'''
echo " "
sleep 1
for chr in $chrNo; do
python checkVCF.py \
-r /homes/athosnew/Genetics_Centre_Bioinformatics/resourses/Genome_reference_files/human_g1k_v37.fasta \
-o $VCF_out/${file}_${chr}.phased.vcf.ref.check $VCF_out/${file}_${chr}.phased.vcf
done
sleep 1
echo " "
echo \
'''---------------------------------------------------------------------------------------------
ZIPPING AND INDEXING READY FOR IMPUTATION SERVER UPLOAD
---------------------------------------------------------------------------------------------'''
echo " "
sleep 1
for chr in $chrNo; do
/homes/athosnew/Genetics_Centre_Bioinformatics/resourses/tabix-0.2.6/bgzip $VCF_out/${file}_${chr}.phased.vcf
/homes/athosnew/Genetics_Centre_Bioinformatics/resourses/tabix-0.2.6/tabix $VCF_out/${file}_${chr}.phased.vcf.gz
done
#final folder housekeeping
mv *.log log_files/
mv *.mm log_files/
sleep 1
echo " "
echo \
'''---------------------------------------------------------------------------------------------
YOUR FILES ARE NOW READY! HAPPY GWASSING !!!!
---------------------------------------------------------------------------------------------'''
echo " "
sleep 1
exit
exit
exit
#now for the X chromosome