-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
313 lines (290 loc) · 12.2 KB
/
Snakefile
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#We're using a .py suffix so that we get some text highlighting in RStudio
#Invoke via -s flag, example:
#snakemake -np gliph -s Snakefile.py -j 8
#Basic metadata exploration and validation
rule new_metadata:
input:
rmd="00_new_metadata.Rmd",
script="src/utils/rmarkdown.R",
dgeUpdated = "dataset/BrCa-dataset-201218_updatedClinicalInfo080821.RData",
dgePrevious = "dataset/BrCa-dataset-201218.RData"
output:
html="00_new_metadata.html"
shell:
"echo $PWD\n"
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Assign samples to fixed data partitions for 1:1 comparison PSO vs enet
rule sample_labels:
input:
rmd="01_sample_label_allocation.Rmd",
script="src/utils/rmarkdown.R",
dgeIncludedSamples = "dataset/BrCa-dataset-201218_updatedClinicalInfo080821.RData",
old_allo = "pso-vs-hc/01_sample_labels.csv"
output:
html = "01_sample_label_allocation.html",
dgeFiltered = "Rds/01_dgeFiltered.Rds",
dgeFiltered2 = "Rds/01_dgeFiltered_v2.Rds", #Compatible with R 3.4.4, otherwise identical
sample_labels = "01_sample_labels.csv"
shell:
"echo $PWD\n"
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#This step is EXTREMELY slow, >1 week most of the time
#We therefore do not include it as part of the Snakemake pipeline, to avoid any inadvertant reruns that delete the output data
#However, the commented-out version is included here for the sake of good documentation
#Run the particle swarm, by necessity on fixed data partitions
#The PSO results are in ./pso-enhanced-thromboseq, which is hardcoded in the ThromboSeq code.
#New runs will overwrite the results. To prevent this from accidentally occuring, rename the dir.
#rule pso:
# input:
# script="02_swarm_brca_vs_hc.R",
# thrombo_anova = "bin/thromboSeqTools_ANOVA.R",
# thrombo_preproc = "bin/thromboSeqTools_PreProcessing_2.R",
# thrombo_PSO = "bin/thromboSeqTools_PSO.R",
# dgeFiltered = "Rds/01_dgeFiltered.Rds"
# output:
# dir("pso-enhanced-thromboseq1")
# shell:
# "Rscript {input.script}"
# "mv -v ./pso-enhanced-thromboseq ./pso-enhanced-thromboseq1"
#Assess PSO performance on internal validation set
rule pso_results:
input:
rmd = "03_pso_results_vs_hc.Rmd",
script="src/utils/rmarkdown.R",
dgeFiltered = "Rds/01_dgeFiltered.Rds",
thrombo_anova = "bin/thromboSeqTools_ANOVA.R",
thrombo_preproc = "bin/thromboSeqTools_PreProcessing_2.R",
thrombo_PSO = "bin/thromboSeqTools_PSO.R",
output:
html = "03_pso_results_vs_hc.html",
dgeParticle = "Rds/03_dgeParticle.Rds",
pso_preds = "03_pso_sample_predictions.csv",
pso_summary = "03_pso_performance_summary.csv",
detailed_pso = "03_pso_detailed_stats.csv"
shell:
"echo $PWD\n"
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Train elastic net on fixed data partitions, and assess performance
#Also compare with pso results
rule enet:
input:
rmd = "04_enet_vs_hc.Rmd",
script = "src/utils/rmarkdown.R",
tmm = "bin/tmm_training_norm.R",
thrombo_anova = "bin/thromboSeqTools_ANOVA.R",
thrombo_preproc = "bin/thromboSeqTools_PreProcessing_2.R",
thrombo_PSO = "bin/thromboSeqTools_PSO.R",
thromboPSO = "Rds/02_thromboPSO.Rds",
pso_summary = "03_pso_performance_summary.csv",
detailed_pso = "03_pso_detailed_stats.csv",
dgeFiltered = "Rds/01_dgeFiltered.Rds"
output:
glmlambda = "Rds/04_model_glmlambda.Rds",
altlambda = "Rds/04_model_altlambda.Rds",
enet_pred = "04_enet_sample_predictions.csv",
detailed_enet = "04_enet_detailed_performance.csv",
pso_vs_enet_summary = "04_enet_vs_psosvm_summary.csv",
detailed_comparison = "04_enet_vs_psosvm_detailed.csv",
html = "04_enet_vs_hc.html"
shell:
"echo $PWD\n"
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Graph ROCs for enet and pso together
rule combine_rocs:
input:
rmd = "04b_combine_ROCs.Rmd",
script = "src/utils/rmarkdown.R",
output:
html = "04b_combine_ROCs.html"
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Train elastic net using leave-one-out cross validation
rule enet_xval:
input:
script = "05_enet_xval.R",
tmm = "bin/tmm_training_norm.R",
dgeFiltered = "Rds/01_dgeFiltered.Rds"
output:
loocv_enet = "Rds/05_LOOCV_enet.Rds"
shell:
"echo $PWD\n"
"Rscript {input.script}"
#Report on enet LOOCV performance
rule report_enet_xval:
input:
dgeFiltered = "Rds/01_dgeFiltered.Rds",
loocv_enet = "Rds/05_LOOCV_enet.Rds", #Very large file that will take a while to load
rmd = "05_enet_Xval.Rmd",
script = "src/utils/rmarkdown.R"
output:
loocv_summary = "05_enet_LOOCV_performance.csv",
loocv_predictions = "05_enet_LOOCV_predictions.csv",
html = "05_enet_Xval.html"
shell:
"echo $PWD\n"
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Make predictions on blind validation set originating from NKI
rule predict_blindval:
input:
#dir(dataset/NKI-htseq), #loose htseq.ssv files from the blind validation set
dgeFiltered = "Rds/01_dgeFiltered.Rds",
best_pso="Rds/02_thromboPSO.Rds",
best_enet = "Rds/04_model_altlambda.Rds",
tmm = "bin/tmm_training_norm.R",
rmd = "06_predict_blindval.Rmd",
script = "src/utils/rmarkdown.R"
output:
dgeBlindVal = "dataset/blindVal.Rds", #data matrix produced by collect.read.counts()
dgeVal = "Rds/06_dgeVal.Rds", #dgeList containing blind validation samples
dgeRUV = "Rds/06_dgeRUV.Rds", #RUV normalized validation samples for PSO predictions
preds_rds = "Rds/06_predictions.Rds",
preds_excel = "06_predictions.xlsx",
html = "06_predict_blindval.html"
shell:
"echo $PWD\n"
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Check the performance of both classifiers on the now-unblinded validation samples
#Also cross-reference with performance reported by independent third party
rule blindval_performance:
input:
perf_summary = "dataset/third_party_val/Blind_tep_performance_summary.csv", #Performance reported by the third party
detailed_enet = "04_enet_detailed_performance.csv",
detailed_pso = "03_pso_detailed_stats.csv",
dgeFiltered = "Rds/01_dgeFiltered.Rds",
cc_third = "dataset/third_party_val/06_predictions_NKI.xlsx", #Sample predictions and true labels by third party
preds_excel = "06_predictions.xlsx", #Own predictions
sample_keys = "dataset/third_party_val/sample_keys/Overview_NKI_breast_6-8-2020.xlsx", #For blinded samples
sample_labels = "dataset/third_party_val/sample_keys/202007_Validationset_caco_charact_anonymous.xlsx", #For blinded samples
dgeVal = "Rds/06_dgeVal.Rds", #For matching names from NKI with those received from VUMC
rmd = "07_blind_val_performance.Rmd",
script = "src/utils/rmarkdown.R"
output:
html = "07_blind_val_performance.html",
sample_dict = "07_validated_sample_dictionary.csv", #Unblinded cases/controls
perf_blindval = "07_blind_val_performance.csv" #Previous and current performance of both classifiers on (un)blinded data
shell:
"echo $PWD\n"
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Create a DGEList that contains both the original data and the now-unblinded validation samples
rule dgeAll:
input:
dgeVal = "Rds/06_dgeVal.Rds",
sample_dict = "07_validated_sample_dictionary.csv",
pellet_qual = "dataset/third_party_val/Classify BRCA NKI july 2020 plus ery data 24-7-2020_VU.xlsx", #Pellet quality info
dgeFiltered = "Rds/01_dgeFiltered.Rds",
script = "07b_dgeAll.R",
output:
dgeVal = "Rds/07b_dgeVal.Rds", #validation sample DGEList with metadata
dgeAll = "Rds/07b_dgeAll.Rds" #All samples, original & blindval, with metadata
shell:
"Rscript {input.script}"
#Post hoc analysis: dimensionality plots (PCA, t-SNE etc, and a few heatmaps)
rule dimensionality:
input:
dgeAll = "Rds/07b_dgeAll.Rds",
enet = "Rds/04_model_altlambda.Rds",
pso = "Rds/02_thromboPSO.Rds",
rmd = "08_dimensionality.Rmd",
script = "src/utils/rmarkdown.R",
output:
html = "08_dimensionality.html",
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Post hoc analysis: differential expression
rule post_hoc_diffex:
input:
dgeAll = "Rds/07b_dgeAll.Rds",
enet = "Rds/04_model_altlambda.Rds",
pso = "Rds/02_thromboPSO.Rds",
rmd = "09_post_hoc_diffex.Rmd",
script = "src/utils/rmarkdown.R",
output:
#martFile = "Rds/martFile.Rds",
html = "09_post_hoc_diffex.html",
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Post hoc: interhospital classifiers
#Train on NKI, predict on MGH/VUMC/blindval
rule interhosp:
input:
dgeAll = "Rds/07b_dgeAll.Rds",
enet = "Rds/04_model_altlambda.Rds",
loocv="05_enet_LOOCV_predictions.csv",
rmd = "10_interhosp_classifiers.Rmd",
script = "src/utils/rmarkdown.R",
output:
kappaNKImodel = "Rds/10_interhosp_kappa.Rds",
dsNKImodel = "Rds/10_interhosp_ds.Rds",
interhosp_res = "10_interhospital_performance_summary.csv",
html = "10_interhosp_classifiers.html"
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Variance partition
rule varpar:
input:
dgeAll = "Rds/07b_dgeAll.Rds",
enet = "Rds/04_model_altlambda.Rds",
pso = "Rds/02_thromboPSO.Rds",
rmd = "11_variancepartition.Rmd",
script = "src/utils/rmarkdown.R",
output:
html = "11_variancepartition.html"
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Feature plots
rule features:
input:
dgeAll = "Rds/07b_dgeAll.Rds",
enet = "Rds/04_model_altlambda.Rds",
pso = "Rds/02_thromboPSO.Rds",
rmd = "12_features.Rmd",
script = "src/utils/rmarkdown.R",
output:
html = "12_features.html"
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Exploration of the efficacy of batch correction methods
rule batchcor:
input:
dgeAll = "Rds/07b_dgeAll.Rds",
tmmnorm = "bin/tmm_training_norm.R",
enet_preds = "04_enet_sample_predictions.csv",
blindval_preds = "06_predictions.xlsx",
dgeRUV = "Rds/01_dgeQC.Rds",
dgeBlindRUV = "Rds/06_dgeRUV.Rds",
rmd = "13_batch_correction.Rmd",
script = "src/utils/rmarkdown.R",
output:
enet_combat = "Rds/13_combat.Rds",
enet_ruv = "Rds/13_RUV.Rds",
enet_blindcombat = "Rds/13_blind_combat.Rds",
enet_blindruv = "Rds/13_blind_RUV.Rds",
batchres = "13_batch_summary.csv",
html = "13_batch_correction.html"
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Assess potential lymphocyte & erythrocyte contamination
rule contam:
input:
dgeAll = "Rds/07b_dgeAll.Rds",
erydf = "dataset/third_party_val/20201217_NKI_ValSet_VU_ID_merged_redness_complete.xlsx",
enet_preds = "04_enet_sample_predictions.csv",
blindval_preds = "06_predictions.xlsx",
sampledict = "07_validated_sample_dictionary.csv",
rmd = "14_ery_lymph_contam.Rmd",
script = "src/utils/rmarkdown.R",
output:
dgePred = "Rds/14_dgePred.Rds", #As dgeAll but includes predictions in the metadata
html = "14_ery_lymph_contam.html"
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"
#Manuscript figures (WIP)
rule figures:
input:
rmd = "15_manuscript_figures.Rmd",
script = "src/utils/rmarkdown.R",
output:
html = "15_manuscript_figures.html",
metadata_tbl = "15_metadata_table.csv"
shell:
"Rscript {input.script} {input.rmd} $PWD/{output.html}"