-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSnakemake.sm
265 lines (242 loc) · 10.7 KB
/
Snakemake.sm
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# -----------------------------------------------------------------------------
# Snakemake file to run the eQTM meta analysis
#
# @author Johann Hawe, Katharina Schmid
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# First part: eQTM meta-analysis
# -----------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Generate genotype regressed version of the methylation and expression data
# ------------------------------------------------------------------------------
rule regress_genotype_methylation:
input:
data = "results/current/eqtm_full_updated/input_files/methylation_{cohort}_sorted.RDS",
position = "results/current/trans_eqtm_full/cpg_positions.RData",
qtls = "results/current/eqtm_full_updated/input_files/eqtls.tsv",
snps = "results/current/eqtm_full_updated/input_files/geno_full_sorted_{cohort}.bgz",
snps_indiv = "results/current/eqtm_full_updated/input_files/indivuals_{cohort}.csv"
output:
data = "results/current/eqtm_full_updated/input_files/methylation_{cohort}_GTregressed_sorted.RDS"
log:
"logs/eqtm_fullanalysis_update/regress_qtls_methylation_{correction}.log"
benchmark:
"benchmarks/eqtm_fullanalysis_update/regress_qtls_methylation_{correction}.bmk"
threads: 6
resources:
mem_mb = 50000
params:
time = "1-00:00:00"
script:
"R/matrixeqtl_for_eqtms_fullset.R"
rule regress_genotype_expression:
input:
data = "results/current/eqtm_full_updated/input_files/expression_{cohort}_sorted.RDS",
position = "results/current/trans_eqtm_full/genePos_biomart_hg19.txt",
qtls = "results/current/eqtm_full_updated/input_files/meqtls.tsv",
snps = "results/current/eqtm_full_updated/input_files/geno_full_sorted_{cohort}.bgz",
snps_indiv = "results/current/eqtm_full_updated/input_files/indivuals_{cohort}.csv"
output:
data = "results/current/eqtm_full_updated/input_files/expression_{cohort}_GTregressed_sorted.RDS"
log:
"logs/eqtm_fullanalysis_update/regress_qtls_expression_{cohort}.log"
benchmark:
"benchmarks/eqtm_fullanalysis_update/regress_qtls_expression_{cohort}.bmk"
threads: 6
resources:
mem_mb = 50000
params:
time = "1-00:00:00"
script:
"R/matrixeqtl_for_eqtms_fullset.R"
# ------------------------------------------------------------------------------
# Generate cell type regressed version of the methylation and expression data
# ------------------------------------------------------------------------------
rule regress_cell_prop:
input:
data = "results/current/eqtm_full_updated/input_files/{dataset}_{cohort}_GTregressed_sorted.RDS",
houseman = "results/current/eqtm_full_updated/input_files/houseman_{cohort}.tsv"
output:
data = "results/current/eqtm_full_updated/input_files/{dataset}_{cohort}_CPregressed_sorted.RDS"
log:
"logs/eqtm_fullanalysis_update/regress_houseman_{dataset}_{cohort}.log"
benchmark:
"benchmarks/eqtm_fullanalysis_update/regress_houseman_{dataset}_{cohort}.bmk"
threads: 1
resources:
mem_mb = 36000
params:
time = "12:00:00"
script:
"R/regress_houseman.R"
# ------------------------------------------------------------------------------
# Run eQTM analysis on the full set of CpG-gene pairs
# ------------------------------------------------------------------------------
rule matrixeqtl_eqtm_full:
input:
methylation = "results/current/eqtm_full_updated/input_files/methylation_{cohort}_{correction}_sorted.RDS",
expression = "results/current/eqtm_full_updated/input_files/expression_{cohort}_{correction}_sorted.RDS",
covariates = "results/current/eqtm_full_updated/input_files/covariates_{cohort}_sorted.RDS",
output:
eqtms = "results/current/eqtm_full_updated/eqtms_full_{cohort}_{correction}.tsv"
log:
"logs/eqtm_fullanalysis_update/eqtms_{cohort}_{correction}.log"
benchmark:
"benchmarks/eqtm_fullanalysis_update/eqtms_{cohort}_{correction}.bmk"
threads: 6
resources:
mem_mb = 50000
params:
time = "1-00:00:00"
script:
"R/matrixeqtl_for_eqtms_fullset.R"
# ----------------------------------------------------------------------------------
# Get meta analysis results
# ----------------------------------------------------------------------------------
rule meta_eqtm_full:
input:
eurk = "results/current/eqtm_full_updated/eqtms_full_KORA_{correction}.tsv",
eur = "results/current/eqtm_full_updated/eqtms_full_LOLIPOP_EUR_{correction}.tsv",
sa = "results/current/eqtm_full_updated/eqtms_full_LOLIPOP_{correction}.tsv"
output:
result = "results/current/eqtm_full_updated/eqtms_full_{correction}_meta.tsv"
log:
"logs/eqtm_fullanalysis_update/{correction}.log"
benchmark:
"benchmarks/eqtm_fullanalysis_update/{correction}.bmk"
threads: 6
resources:
mem_mb = 50000
params:
time = "2-00:00:00"
script:
"R/meta_analyze_eqtm.R"
# ------------------------------------------------------------------------------
# Filter according to bonferroni corrected P<0.05
# (total number of comparisons was 5738181750)
# ------------------------------------------------------------------------------
rule filter_eqtm_sign:
input:
"results/current/eqtm_full_updated/eqtms_full_{correction}_meta.tsv"
output:
"results/current/eqtm_full_updated/eqtms_full_{correction}_meta_sign.tsv"
params:
cutoff = 8.7e-12
shell:
"""
# header will be included
awk '{{if(($15+0) <= {params.cutoff}) print; }}' {input} > {output}
"""
# ------------------------------------------------------------------------------
# Annotate eQTMs
# ------------------------------------------------------------------------------
rule annotate_meta_eqtm:
input:
eqtms = "results/current/eqtm_full_updated/eqtms_full_{correction}_meta_sign.tsv",
cpg_pos = "results/current/trans_eqtm_full/cpg_positions.RData",
gene_pos = "results/current/trans_eqtm_full/genePos_biomart_hg19.txt"
output:
eqtms = "results/current/eqtm_full_updated/eqtms_full_{correction}_meta_annotated.tsv.gz"
log:
"logs/eqtm_fullanalysis_update/annotate_eqtm_{correction}.log"
benchmark:
"benchmarks/eqtm_fullanalysis_update/annotate_eqtm_{correction}.bmk"
threads: 1
resources:
mem_mb = 32000
params:
time = "4:00:00"
script:
"R/annotate_meta_eqtms.R"
# ------------------------------------------------------------------------------
# Add meta beta and se (CPregressed: all eQTMs, GTregressed: only cis eQTMs)
# ------------------------------------------------------------------------------
rule annotate_meta_eqtm_beta_CP:
input:
eqtms = "results/current/eqtm_full_updated/eqtms_full_CPregressed_meta_annotated.tsv.gz",
output:
eqtms = "results/current/eqtm_full_updated/eqtms_full_CPregressed_meta_annotated_beta.tsv.gz"
log:
"logs/eqtm_fullanalysis_update/annotate_eqtm_CPregressed_beta.log"
benchmark:
"benchmarks/eqtm_fullanalysis_update/annotate_eqtm_CPregressed_beta.bmk"
threads: 1
resources:
mem_mb = 16000
params:
time = "0:30:00",
cis = "FALSE"
script:
"R/eqtl_eqtm_enrichment/annotate_meta_eqtms_beta.R"
rule annotate_meta_eqtm_beta_GT:
input:
eqtms = "results/current/eqtm_full_updated/eqtms_full_GTregressed_meta_annotated.tsv.gz",
output:
eqtms = "results/current/eqtm_full_updated/eqtms_full_GTregressed_meta_annotated_beta_cis.tsv.gz"
log:
"logs/eqtm_fullanalysis_update/annotate_eqtm_GTregressed_beta.log"
benchmark:
"benchmarks/eqtm_fullanalysis_update/annotate_eqtm_GTregressed_beta.bmk"
threads: 1
resources:
mem_mb = 32000
params:
time = "2:00:00",
cis = "TRUE"
script:
"R/eqtl_eqtm_enrichment/annotate_meta_eqtms_beta.R"
# -----------------------------------------------------------------------------
# Target rule to calculate all meta significant eqtms
# -----------------------------------------------------------------------------
rule all_annotated_eqtm:
input:
"results/current/eqtm_full_updated/eqtms_full_CPregressed_meta_annotated_beta.tsv.gz",
"results/current/eqtm_full_updated/eqtms_full_GTregressed_meta_annotated_beta_cis.tsv.gz"
# -----------------------------------------------------------------------------
# Second part: replication between cohorts
# -----------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Replication analysis for eQTM
#
# Scripts used to create adjusted files can be found under 'scripts'.
# Were run to use 'localscratch'. make sure that any system has enough
# localscratch available to sort files (at least 0.5T).
#
# scripts/sort-local.sh: sort input (raw matrixEQTL outputs) descreasingly by pvalue
# scripts/padjust_naive.py: adds BH adjusted p-value to results files sorted decr. by
# p-calue
#
# Run the scripts:
# scripts/sort-local.sh results/current/eqtm_full_updated/eqtms_full_{cohort}_{correction}.tsv
# scripts/padjust_naive.py results/current/eqtm_full_updated/eqtms_full_{cohort}_{correction}.tsv.sorted
# > results/current/eqtm_full_updated/eqtms_full_{cohort}_{correction}.tsv.sorted.adjusted
#
# ------------------------------------------------------------------------------
rule replicate_eqtm:
input:
cpg_positions = "results/current/eqtm_full_updated/cpg_positions.RData",
gene_positions = "results/current/eqtm_full_updated/genePos_biomart_hg19.txt",
eur = "results/current/eqtm_full_updated/eqtms_full_KORA_{correction}.tsv.sorted.adjusted",
sa = "results/current/eqtm_full_updated/eqtms_full_LOLIPOP_{correction}.tsv.sorted.adjusted"
output:
kora = "results/current/eqtm_full_updated/eqtms_full_KORA_{correction}_filtered_FDRSign.tsv",
lolipop = "results/current/eqtm_full_updated/eqtms_full_LOLIPOP_{correction}_filtered_FDRSign.tsv",
counts = "results/current/eqtm_full_updated/eqtms_full_{correction}_counts.rds"
log:
"logs/replicate_eqtm/{correction}.log"
benchmark:
"benchmarks/replicate_eqtm/{correction}.bmk"
threads: 6
resources:
mem_mb = 50000
params:
time = "2-00:00:00"
script:
"../R/replicate_eqtm.R"
# -----------------------------------------------------------------------------
# Target rule to calculate replication rates
# -----------------------------------------------------------------------------
rule all_replicate_eqtm:
input:
"results/current/eqtm_full_updated/eqtms_full_GTregressed_counts.rds",
"results/current/eqtm_full_updated/eqtms_full_GTregressed_counts.rds"