forked from timoast/signac-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
399 lines (357 loc) · 10.9 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
datasets = ["pbmc", "biccn", "mito"]
rule all:
input:
"figures/figure2.png",
"figures/dimreduc_pbmc.png",
"figures/figure4.png",
"figures/figure5a.png",
"figures/figure5b.png",
"figures/peakcalls.png",
"figures/cluster_param_sweep.png",
"figures/multimodal_label_transfer.png"
# ------- Install -------
rule install:
output: "install.done"
threads: 4
shell:
"""
Rscript install_r_packages.R
touch install.done
"""
# ------- Data download -------
rule download:
input:
"datasets/{dset}.txt"
output:
"data/{dset}/done.txt"
message: "Download datasets"
threads: 1
shell:
"""
wget -i {input} -P data/{wildcards.dset}
touch data/{wildcards.dset}/done.txt
"""
rule download_pbmc_atac:
input:
"datasets/pbmc_atac.txt"
output:
"data/pbmc_atac/done.txt"
message: "Download PBMC scATAC fragment files"
threads: 1
shell:
"""
wget -i {input} -P data/pbmc_atac
touch data/pbmc_atac/done.txt
"""
rule download_gtex:
input:
"datasets/gtex.txt"
output:
"data/gtex/GTEx_v8_finemapping_CAVIAR/CAVIAR_Results_v8_GTEx_LD_HighConfidentVariants.gz"
message: "Download GTEx data"
threads: 1
shell:
"""
wget -i {input} -P data/gtex
cd data/gtex
tar -xvf GTEx_v8_finemapping_CAVIAR.tar
rm GTEx_v8_finemapping_CAVIAR.tar
"""
rule download_chen:
input: "datasets/chen.txt"
output: "data/chen/scATAC-benchmarking-master/Synthetic_Data/BoneMarrow_cov250/input/bonemarrow_cov250.rds"
message: "Downloading Chen et al. dataset"
threads: 1
shell:
"""
wget -i {input} -P data/chen
cd data/chen
unzip master.zip
rm master.zip
"""
# ------- Data processing -------
rule combine_fragments:
input:
"data/pbmc_atac/done.txt"
output:
"data/pbmc_atac/fragments.bed.gz"
threads: 4
message: "Combine PBMC scATAC fragment files"
shell:
"""
cd data/pbmc_atac
gzip -d *.tsv.gz
awk 'BEGIN {{FS=OFS="\\t"}} {{print $1,$2,$3,"10kng_"$4,$5}}' atac_pbmc_10k_nextgem_fragments.tsv > 1.bed
awk 'BEGIN {{FS=OFS="\\t"}} {{print $1,$2,$3,"10k_"$4,$5}}' atac_pbmc_10k_v1_fragments.tsv > 2.bed
awk 'BEGIN {{FS=OFS="\\t"}} {{print $1,$2,$3,"5kng_"$4,$5}}' atac_pbmc_5k_nextgem_fragments.tsv > 3.bed
awk 'BEGIN {{FS=OFS="\\t"}} {{print $1,$2,$3,"5k_"$4,$5}}' atac_pbmc_5k_v1_fragments.tsv > 4.bed
cat *.bed > frags.bed
sort -k1,1 -k2,2n frags.bed > fragments.bed
bgzip -@ {threads} fragments.bed
tabix -p bed fragments.bed.gz
rm *.bed *.tsv
"""
rule process_pbmc_atac:
input:
"data/pbmc_atac/fragments.bed.gz"
output:
"objects/pbmc_atac.rds"
message: "Processing PBMC scATAC-seq data"
threads: 1
shell: "Rscript code/process_pbmc_atac.R"
rule process:
input:
"data/{dset}/done.txt",
"install.done"
output:
"objects/{dset}.rds"
message: "Process data"
shell: "Rscript code/process_{wildcards.dset}.R"
# ------- Cell Downsampling -------
rule downsample_cells:
input:
"objects/biccn.rds",
"objects/pbmc_atac.rds"
output:
"/scratch/tim/biccn/downsampling/50000.rds",
"/scratch/tim/pbmc_atac/downsampling/25000.rds"
message: "Downsample fragment files"
threads: 1
shell: "Rscript code/downsampling_code/downsample.R"
rule create_archr_files:
input:
"/scratch/tim/biccn/downsampling/50000.rds",
"/scratch/tim/pbmc_atac/downsampling/25000.rds"
output:
"archr_pbmc/1000/Save-ArchR-Project.rds",
"archr_biccn/700000/Save-ArchR-Project.rds"
message: "Creating ArchR projects"
threads: 1
shell: "code/downsampling_code/downsample_archr.R"
rule create_annotations:
input: "install.done"
output:
"data/biccn/annotations.rds",
"data/pbmc_atac/annotations.rds"
message: "Extracting annotations"
threads: 1
shell: "Rscript code/downsampling_code/get_annotations.R"
rule benchmark_biccn:
input:
"/scratch/tim/biccn/downsampling/50000.rds",
"data/biccn/annotations.rds"
output:
"data/biccn/downsampling/svd_50000.rds"
message: "Running BICCN benchmarks"
threads: 8
shell: "bash code/biccn_downsampling/benchmark.sh"
rule benchmark_pbmc_atac:
input:
"/scratch/tim/pbmc_atac/downsampling/25000.rds",
"data/pbmc_atac/annotations.rds"
output:
"data/pbmc_atac/downsampling/svd_25000.rds"
message: "Running PBMC scATAC benchmarks"
threads: 8
shell: "bash code/pbmc_atac_downsampling/benchmark.sh"
rule archr_pbmc_atac:
input: "archr_pbmc/1000/Save-ArchR-Project.rds"
output: "data/pbmc_atac/archr_lsi_runtime_1000_1.txt"
message: "Running PBMC scATAC ArchR benchmarks"
threads: 8
shell: "bash code/pbmc_atac_downsampling/benchmark_archr.sh"
rule archr_biccn:
input: "archr_biccn/700000/Save-ArchR-Project.rds"
output: "data/biccn/archr_lsi_runtime_700000_1.txt"
message: "Running BICCN scATAC ArchR benchmarks"
threads: 8
shell: "bash code/biccn_downsampling/benchmark_archr.sh"
rule gather_benchmark_timings:
input:
"data/biccn/downsampling/svd_50000.rds",
"data/pbmc_atac/downsampling/svd_25000.rds",
output:
"data/biccn/timings.tsv",
"data/pbmc_atac/timings.tsv"
message: "Collating benchmark data"
shell:
"""
Rscript code/biccn_downsampling/collate_timings.R
Rscript code/pbmc_atac_downsampling/collate_timings.R
"""
# ------- Count Downsampling -------
rule tfidf_downsampling:
input: "objects/pbmc.rds"
output: "data/pbmc/downsamples/1.rds"
message: "Downsampling count matrix"
threads: 1
shell: "Rscript code/pbmc_downsampling/run_pbmc_downsample.R"
rule downsample_lsi:
input:
"data/pbmc/downsamples/1.rds",
"data/chen/scATAC-benchmarking-master/Synthetic_Data/BoneMarrow_cov250/input/bonemarrow_cov250.rds"
output:
"data/pbmc/downsamples/lsi_1_1.rds",
"data/chen/embeddings/lsi_250_1.rds"
message: "Running LSI on downsampled counts"
threads: 1
shell: "Rscript code/pbmc_downsampling/run_lsi.R"
rule downsample_cistopic:
input:
"data/pbmc/downsamples/1.rds",
"data/chen/scATAC-benchmarking-master/Synthetic_Data/BoneMarrow_cov250/input/bonemarrow_cov250.rds"
output:
"data/pbmc/downsamples/cistopic_warp_1.rds",
"data/pbmc/downsamples/cistopic_cgs_1.rds",
"data/chen/embeddings/cistopic_warp_250.rds",
"data/chen/embeddings/cistopic_cgs_250.rds"
message: "Running cisTopic on downsampled counts"
threads: 1
shell: "Rscript code/pbmc_downsampling/run_cistopic.R"
rule downsample_snapatac:
input:
"data/pbmc/downsamples/1.rds",
"data/chen/scATAC-benchmarking-master/Synthetic_Data/BoneMarrow_cov250/input/bonemarrow_cov250.rds"
output:
"data/pbmc/downsamples/snapatac_1.rds",
"data/chen/embeddings/snapatac_250.rds"
message: "Running SnapATAC on downsampled counts"
threads: 1
shell: "Rscript code/pbmc_downsampling/run_snapatac.R"
rule downsample_scale:
input:
"data/pbmc/downsamples/1.rds",
"data/chen/scATAC-benchmarking-master/Synthetic_Data/BoneMarrow_cov250/input/bonemarrow_cov250.rds"
output:
"data/pbmc/downsamples/scale_1/adata.h5ad",
"data/chen/embeddings/scale_250/adata.h5ad"
message: "Running SCALE on downsampled counts"
threads: 6
shell: "Rscript code/pbmc_downsampling/run_scale.R"
rule evaluate_dimreduc:
input:
"data/pbmc/downsamples/lsi_1_1.rds",
"data/pbmc/downsamples/cistopic_warp_1.rds",
"data/pbmc/downsamples/snapatac_1.rds",
"data/pbmc/downsamples/scale_1/adata.h5ad",
"data/chen/embeddings/lsi_250_1.rds",
"data/chen/embeddings/cistopic_warp_250.rds",
"data/chen/embeddings/snapatac_250.rds",
"data/chen/embeddings/scale_250/adata.h5ad"
output: "figures/dimreduc_pbmc.png", "figures/dimreduc_chen.png"
message: "Evaluating dimension reduction methods"
threads: 1
shell: "Rscript code/pbmc_downsampling/evaluate_dimreducs.R"
# ------- Total runtime -------
rule get_total_runtime:
input: "objects/biccn.rds", "objects/pbmc_atac.rds"
output:
"data/biccn/archr_total_runtime.txt",
"data/biccn/signac_total_runtime.txt",
"data/pbmc_atac/archr_total_runtime.txt",
"data/pbmc_atac/signac_total_runtime.txt"
threads: 8
message: "Computing total runtime for ArchR and Signac"
shell:
"""
Rscript code/create_biccn_signac.R
Rscript code/create_biccn_archr.R
Rscript code/create_pbmc_atac_signac.R
Rscript code/create_pbmc_atac_archr.R
"""
# ------- Links -------
rule links:
input:
"objects/pbmc.rds"
output:
"objects/pbmc_links.rds"
threads: 8
shell:
"""
Rscript code/link_peaks.R
"""
# ------- Analysis -------
rule analyze_eqtl:
input:
"objects/pbmc.rds",
"objects/pbmc_links.rds",
"data/gtex/GTEx_v8_finemapping_CAVIAR/CAVIAR_Results_v8_GTEx_LD_HighConfidentVariants.gz"
output:
"eqtl.done"
shell:
"""
Rscript code/analyze_pbmc.R
touch eqtl.done
"""
rule multimodal_transfer:
input:
"objects/pbmc.rds"
output:
"objects/multimodal_label_transfer.rds"
message: "Running multimodal label transfer"
threads: 1
shell:
"""
Rscript code/multimodal_label_transfer.R
"""
rule analyze_pbmc:
input:
"objects/pbmc.rds",
"objects/pbmc_links.rds",
"objects/multimodal_label_transfer.rds",
"eqtl.done"
output:
"figures/tss_enrichment.rds",
"figures/multimodal_label_transfer.png"
shell:
"""
Rscript code/analyze_pbmc.R
"""
# ------- Figures -------
rule fig2:
input:
"figures/tss_enrichment.rds"
output:
"figures/figure2.png"
shell:
"""
Rscript code/figure2.R
"""
rule fig4:
input:
"objects/mito.rds"
output:
"figures/figure4.png"
shell:
"""
Rscript code/figure4.R
"""
rule fig5:
input:
"objects/biccn.rds",
"data/biccn/timings.tsv"
output:
"figures/figure5a.png",
"figures/figure5b.png"
shell:
"""
Rscript code/figure5.R
"""
rule fig_s1:
input:
"objects/pbmc.rds"
output:
"figures/peakcalls.png"
shell:
"""
Rscript code/peak_calling.R
"""
rule fig_s2:
input:
"objects/pbmc.rds"
output:
"figures/cluster_param_sweep.png"
shell:
"""
Rscript code/clustering.R
"""