forked from MRCIEU/godmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-check_data.sh
executable file
·208 lines (147 loc) · 4.25 KB
/
01-check_data.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
#!/bin/bash
set -e
source ./config
exec &> >(tee ${section_01_logfile})
print_version
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
echo "There is no method for ${1}."
echo "Please run:"
echo "./01-check_data [arg]"
echo "where arg is an optional argument that can be one of:"
printf '%s\n' ${@:2}
return 1
}
arg="all"
declare -a sections=('all' 'config' 'download' 'requirements' 'genetic' 'methylation' 'covariates' 'phenotypes' 'cnv' 'summary')
if [ -n "${1}" ]; then
arg="${1}"
containsElement ${1} ${sections[@]}
fi
section_message () {
echo "-----------------------------------------------"
echo ""
echo "$1 section"
echo ""
echo "to run this part on its own type:"
echo "$ ./01-check_data.sh $1"
echo ""
echo "-----------------------------------------------"
echo ""
echo ""
}
if [ "$arg" = "config" ] || [ "$arg" = "all" ]
then
section_message "config"
if ! [[ "$study_name" =~ [^a-zA-Z0-9_\ ] ]] && ! [ "$study_name" = "" ]
then
echo "The study name '${study_name}' will be used for this analysis. Change this in the config file if necessary."
echo ""
else
echo "The study name '${study_name}' is invalid. Please use only alphanumeric or underscore characters, with no spaces or special characters etc."
exit
fi
fi
if [ "$arg" = "download" ] || [ "$arg" = "all" ]
then
section_message "download"
sftp ${sftp_username}@${sftp_address}:${sftp_path}/resources <<EOF
get 1kg_phase3_eur_allchrs_polymorphic.recoded.nodup.frq.gz
get 1kg_phase3_eur_allchrs_polymorphic.recoded.nodup.frq.gz.md5sum
EOF
mv 1kg_phase3_eur_allchrs_polymorphic.recoded.nodup.frq.gz* ${home_directory}/resources/genetics
fi
if [ "$arg" = "requirements" ] || [ "$arg" = "all" ]
then
section_message "requirements"
Rscript resources/datacheck/requirements.R $related
fi
if [ "$arg" = "genetic" ] || [ "$arg" = "all" ]
then
section_message "genetic"
Rscript resources/datacheck/genetic_data.R \
${bfile_raw}.bim \
${bfile_raw}.fam \
${quality_scores} \
${control_snps} \
${snpchrtxt} \
${snpchrplot} \
${genetic_descriptives} \
${quality_scores_plot}
# Check missingness, there should be a small percentage of missingness (--hard-call-threshold 0.499999)
${plink} --bfile ${bfile_raw} --missing gz --out ${section_01_dir}/data
nrow=`zcat ${section_01_dir}/data.imiss.gz | awk 'NR>1 && $6>0.02 {print $0}' |wc -l`
nrow_all=`zcat ${section_01_dir}/data.imiss.gz | awk 'NR>1 {print $0}' |wc -l`
prop=$( printf '%.2f' $(echo "$nrow / $nrow_all" | bc -l) )
echo "Proportion with >= 0.02 missingness: $prop"
if [ "$prop" \> 0.01 ]
then
echo "Error: $prop of genotypes have more than 2% of missing values. Please don't use a genotype probability cut-off when generating best guess data."
exit 1
else
echo "\n"
echo "Best guess data appears to be correct"
fi
fi
if [ "$arg" = "methylation" ] || [ "$arg" = "all" ]
then
section_message "methylation"
Rscript resources/datacheck/methylation_data.R \
${betas} \
${bfile_raw}.fam \
${predicted_cellcounts} \
${predicted_cellcounts_type} \
${measured_cellcounts} \
${meth_ids} \
${methylation_descriptives} \
${methylation_summary} \
${intersect_ids} \
${intersect_ids_plink}
fi
if [ "$arg" = "covariates" ] || [ "$arg" = "all" ]
then
section_message "covariates"
Rscript resources/datacheck/covariates.R \
${covariates} \
${bfile_raw}.fam \
${meth_ids} \
${ageplot} \
${covariate_descriptives}
fi
if [ "$arg" = "phenotypes" ] || [ "$arg" = "all" ]
then
section_message "phenotypes"
Rscript resources/datacheck/phenotypes.R \
${phenotypes} \
${meth_ids} \
${covariates} \
${phenotype_descriptives} \
${phenotype_list}
fi
if [ "$arg" = "cnv" ] || [ "$arg" = "all" ]
then
section_message "cnv"
Rscript resources/datacheck/cnv_data.R \
${cnvs} \
${meth_ids} \
${covariates} \
${cnv_descriptives}
fi
if [ "$arg" = "summary" ] || [ "$arg" = "all" ]
then
section_message "summary"
Rscript resources/datacheck/collect_descriptives.R \
${genetic_descriptives} \
${methylation_descriptives} \
${covariate_descriptives} \
${phenotype_descriptives} \
${cnv_descriptives} \
${cohort_descriptives}
fi
if [ "$arg" = "all" ]
then
echo ""
echo ""
echo "You successfully performed all data checks!"
fi