-
Notifications
You must be signed in to change notification settings - Fork 13
/
long-read-rna-pipeline.wdl
542 lines (478 loc) · 17.9 KB
/
long-read-rna-pipeline.wdl
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
version 1.0
import "wdl/subworkflows/concatenate_files.wdl"
import "wdl/subworkflows/crop_reference_fasta_headers.wdl"
import "wdl/subworkflows/make_gtf_from_spikein_fasta.wdl"
import "wdl/tasks/gzip.wdl"
import "wdl/tasks/talon.wdl"
import "wdl/tasks/transcriptclean.wdl"
workflow long_read_rna_pipeline {
meta {
author: "Otto Jolanki"
version: "v2.1.0"
caper_docker: "encodedcc/long-read-rna-pipeline:v2.1.0"
caper_singularity: "docker://encodedcc/long-read-rna-pipeline:v2.1.0"
croo_out_def: "https://storage.googleapis.com/encode-pipeline-output-definition/longreadrna.output_definition.json"
description: "ENCODE Long-read-rna pipeline, see https://github.com/ENCODE-DCC/long-read-rna-pipeline for details."
}
input {
# Input fastqs, gzipped.
Array[Array[File]] fastqs
# Reference genome. Fasta format, gzipped.
File reference_genome
# Annotation file, gtf format, gzipped.
File annotation
# Spikein files, fasta format, gzipped.
Array[File] spikeins = []
# Variants file, vcf format, gzipped.
File? variants
# Prefix that gets added into output filenames. Default "my_experiment", can not be empty.
String experiment_prefix = "my_experiment"
# Is the data from "pacbio" or "nanopore"
String input_type = "pacbio"
# Array[String] of prefixes for naming novel discoveries in eventual TALON runs (default = "TALON").
# If defined, length of this array needs to be equal to number of replicates.
Array[String] talon_prefixes = []
# Genome build name, for TALON. This must be in the initial_talon_db
String genome_build
# Annotation name, for creating abundance from talon db. This must be in the initial_talon_db
String annotation_name
# If this option is set, TranscriptClean will only output transcripts that are either canonical
# or that contain annotated noncanonical junctions to the clean SAM and Fasta files at the end
# of the run.
Boolean canonical_only = true
String docker = "encodedcc/long-read-rna-pipeline:v2.1.0"
String singularity = "docker://encodedcc/long-read-rna-pipeline:v2.1.0"
# Resouces
Resources small_task_resources = {
"cpu": 2,
"memory_gb": 7,
"disks": "local-disk 50 SSD",
}
Resources medium_task_resources = {
"cpu": 6,
"memory_gb": 32,
"disks": "local-disk 100 SSD",
}
Resources large_task_resources = {
"cpu": 16,
"memory_gb": 60,
"disks": "local-disk 150 SSD",
}
Resources xlarge_task_resources = {
"cpu": 20,
"memory_gb": 120,
"disks": "local-disk 150 SSD",
}
}
RuntimeEnvironment runtime_environment = {
"docker": docker,
"singularity": singularity
}
if (length(spikeins) > 1) {
call concatenate_files.concatenate_files as combined_spikeins {
input:
files=spikeins,
resources=small_task_resources,
runtime_environment=runtime_environment,
}
}
if (length(spikeins) > 0) {
File spikes = select_first([combined_spikeins.concatenated_file,spikeins[0]])
call make_gtf_from_spikein_fasta.make_gtf_from_spikein_fasta {
input:
spikein_fasta=spikes,
resources=small_task_resources,
runtime_environment=runtime_environment,
}
call concatenate_files.concatenate_files as combined_annotation {
input:
files=[annotation,make_gtf_from_spikein_fasta.spikein_gtf],
resources=small_task_resources,
output_filename="combined_annotation.gtf.gz",
runtime_environment=runtime_environment,
}
call concatenate_files.concatenate_files as combined_reference {
input:
files=[reference_genome,spikes],
resources=small_task_resources,
output_filename="combined_reference.fasta.gz",
runtime_environment=runtime_environment,
}
}
File combined_fasta = select_first([combined_reference.concatenated_file,reference_genome])
File combined_gtf = select_first([combined_annotation.concatenated_file,annotation])
call crop_reference_fasta_headers.crop_reference_fasta_headers as clean_reference {
input:
reference_fasta=combined_fasta,
resources=small_task_resources,
runtime_environment=runtime_environment,
}
call gzip.gzip as decompressed_gtf {
input:
input_file=combined_gtf,
output_filename="combined_annotation.gtf",
params={
"decompress": true,
"noname": false,
},
resources=small_task_resources,
runtime_environment=runtime_environment,
}
call transcriptclean.get_SJs_from_gtf as get_splice_junctions {
input:
annotation_gtf=decompressed_gtf.out,
reference_fasta=clean_reference.decompressed,
resources=medium_task_resources,
output_filename="SJs.txt",
runtime_environment=runtime_environment,
}
scatter (i in range(length(fastqs))) {
String talon_prefix = if length(talon_prefixes) > 0 then talon_prefixes[i] else "TALON"
call concatenate_files.concatenate_files as combined_fastq {
input:
files=fastqs[i],
resources=small_task_resources,
output_filename="combined_"+(i+1)+"_fastq.gz",
runtime_environment=runtime_environment,
}
call init_talon_db { input:
annotation_gtf=decompressed_gtf.out,
annotation_name=annotation_name,
ref_genome_name=genome_build,
idprefix=talon_prefix,
output_prefix="rep"+(i+1)+experiment_prefix,
resources=medium_task_resources,
runtime_environment=runtime_environment,
}
call minimap2 { input:
fastq=combined_fastq.concatenated_file,
reference_genome=clean_reference.compressed,
output_prefix="rep"+(i+1)+experiment_prefix,
input_type=input_type,
resources=large_task_resources,
runtime_environment=runtime_environment,
}
call transcriptclean { input:
sam=minimap2.sam,
reference_genome=clean_reference.decompressed,
splice_junctions=get_splice_junctions.splice_junctions,
variants=variants,
output_prefix="rep"+(i+1)+experiment_prefix,
canonical_only=canonical_only,
resources=xlarge_task_resources,
runtime_environment=runtime_environment,
}
call talon.talon_label_reads {
input:
input_sam=transcriptclean.corrected_sam,
output_bam_filename="rep"+(i+1)+experiment_prefix+"_labeled.bam",
output_sam_filename="rep"+(i+1)+experiment_prefix+"_labeled.sam",
output_tsv_filename="rep"+(i+1)+experiment_prefix+"_labeled.tsv",
reference_genome=clean_reference.decompressed,
resources=small_task_resources,
runtime_environment=runtime_environment,
}
call talon { input:
talon_db=init_talon_db.database,
sam=talon_label_reads.labeled_sam,
genome_build=genome_build,
output_prefix="rep"+(i+1)+experiment_prefix,
platform=input_type,
resources=medium_task_resources,
runtime_environment=runtime_environment,
}
call create_abundance_from_talon_db { input:
talon_db=talon.talon_db_out,
annotation_name=annotation_name,
genome_build=genome_build,
output_prefix="rep"+(i+1)+experiment_prefix,
idprefix=talon_prefix,
resources=medium_task_resources,
runtime_environment=runtime_environment,
}
call create_gtf_from_talon_db { input:
talon_db=talon.talon_db_out,
annotation_name=annotation_name,
genome_build=genome_build,
output_prefix="rep"+(i+1)+experiment_prefix,
resources=medium_task_resources,
runtime_environment=runtime_environment,
}
}
if (length(fastqs) == 2) {
String rep1_idprefix = if length(talon_prefixes) > 0 then talon_prefixes[0] else "TALON"
String rep2_idprefix = if length(talon_prefixes) > 0 then talon_prefixes[1] else "TALON"
call calculate_spearman { input:
rep1_abundance=create_abundance_from_talon_db.talon_abundance[0],
rep2_abundance=create_abundance_from_talon_db.talon_abundance[1],
rep1_idprefix=rep1_idprefix,
rep2_idprefix=rep2_idprefix,
resources=small_task_resources,
output_prefix=experiment_prefix,
runtime_environment=runtime_environment,
}
}
}
task init_talon_db {
input {
File annotation_gtf
Resources resources
String annotation_name
String ref_genome_name
String output_prefix
String? idprefix
RuntimeEnvironment runtime_environment
}
command {
talon_initialize_database \
--f ~{annotation_gtf} \
--a ~{annotation_name} \
--g ~{ref_genome_name} \
~{"--idprefix " + idprefix} \
--o ~{output_prefix}
python3.7 $(which record_init_db_inputs.py) \
--annotation_name ~{annotation_name} \
--genome ~{ref_genome_name} \
--outfile ~{output_prefix}_talon_inputs.json
}
output {
File database = "~{output_prefix}.db"
File talon_inputs = "~{output_prefix}_talon_inputs.json"
}
runtime {
cpu: resources.cpu
memory: "~{resources.memory_gb} GB"
disks: resources.disks
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task minimap2 {
input {
File fastq
File reference_genome
Resources resources
String output_prefix
String input_type
RuntimeEnvironment runtime_environment
}
command <<<
if [ "~{input_type}" == "pacbio" ]; then
minimap2 -t ~{resources.cpu} -ax splice -uf --secondary=no -C5 \
~{reference_genome} \
~{fastq} \
> ~{output_prefix}.sam \
2> ~{output_prefix}_minimap2.log
fi
if [ "~{input_type}" == "nanopore" ]; then
minimap2 -t ~{resources.cpu} -ax splice -uf -k14 \
~{reference_genome} \
~{fastq} \
> ~{output_prefix}.sam \
2> ~{output_prefix}_minimap2.log
fi
gzip -cd ~{fastq} | grep "^@" | wc -l > FLNC.txt
samtools view ~{output_prefix}.sam | awk '{if($2 == "0" || $2 == "16") print $1}' | sort -u | wc -l > mapped.txt
python3.7 $(which make_minimap_qc.py) --flnc FLNC.txt --mapped mapped.txt --outfile ~{output_prefix}_mapping_qc.json
samtools view -S -b ~{output_prefix}.sam > ~{output_prefix}.bam
>>>
output {
File sam = "~{output_prefix}.sam"
File bam = "~{output_prefix}.bam"
File log = "~{output_prefix}_minimap2.log"
File mapping_qc = "~{output_prefix}_mapping_qc.json"
}
runtime {
cpu: resources.cpu
memory: "~{resources.memory_gb} GB"
disks: resources.disks
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task transcriptclean {
input {
File sam
File reference_genome
File splice_junctions
File? variants
Resources resources
String output_prefix
Boolean canonical_only
RuntimeEnvironment runtime_environment
}
command {
test -f ~{variants} && gzip -cd ~{variants} > variants.vcf
python3.7 $(which TranscriptClean.py) --sam ~{sam} \
--genome ~{reference_genome} \
--spliceJns ~{splice_junctions} \
~{if defined(variants) then "--variants variants.vcf" else ""} \
--maxLenIndel 5 \
--maxSJOffset 5 \
-m true \
-i true \
--correctSJs true \
--primaryOnly \
--outprefix ~{output_prefix} \
--threads ~{resources.cpu} \
~{if canonical_only then "--canonOnly" else ""}
samtools view -S -b ~{output_prefix}_clean.sam > ~{output_prefix}_clean.bam
Rscript $(which generate_report.R) ~{output_prefix}
}
output {
File corrected_bam = "~{output_prefix}_clean.bam"
File corrected_sam = "~{output_prefix}_clean.sam"
File corrected_fasta = "~{output_prefix}_clean.fa"
File transcript_log = "~{output_prefix}_clean.log"
File transcript_error_log = "~{output_prefix}_clean.TE.log"
File report = "~{output_prefix}_report.pdf"
}
runtime {
cpu: resources.cpu
memory: "~{resources.memory_gb} GB"
disks: resources.disks
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task talon {
input {
File talon_db
File sam
Resources resources
String genome_build
String output_prefix
String platform
RuntimeEnvironment runtime_environment
}
command {
export TMPDIR=/tmp
echo ~{output_prefix},~{output_prefix},~{platform},~{sam} > ~{output_prefix}_talon_config.csv
cp ~{talon_db} ./~{output_prefix}_talon.db
talon --f ~{output_prefix}_talon_config.csv \
--db ~{output_prefix}_talon.db \
--build ~{genome_build} \
--o ~{output_prefix}
}
output {
File talon_config = "~{output_prefix}_talon_config.csv"
File talon_log = "~{output_prefix}_QC.log"
File talon_db_out = "~{output_prefix}_talon.db"
}
runtime {
cpu: resources.cpu
memory: "~{resources.memory_gb} GB"
disks: resources.disks
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task create_abundance_from_talon_db {
input {
File talon_db
Resources resources
String annotation_name
String genome_build
String output_prefix
String idprefix
RuntimeEnvironment runtime_environment
}
command {
talon_abundance --db=~{talon_db} \
-a ~{annotation_name} \
--build ~{genome_build} \
--o=~{output_prefix}
python3.7 $(which calculate_number_of_genes_detected.py) --abundance ~{output_prefix}_talon_abundance.tsv \
--counts_colname ~{output_prefix} \
--idprefix ~{idprefix} \
--outfile ~{output_prefix}_number_of_genes_detected.json
}
output {
File talon_abundance = "~{output_prefix}_talon_abundance.tsv"
File number_of_genes_detected = "~{output_prefix}_number_of_genes_detected.json"
}
runtime {
cpu: resources.cpu
memory: "~{resources.memory_gb} GB"
disks: resources.disks
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task create_gtf_from_talon_db {
input {
File talon_db
Resources resources
String annotation_name
String genome_build
String output_prefix
RuntimeEnvironment runtime_environment
}
command {
talon_create_GTF --db ~{talon_db} \
-a ~{annotation_name} \
--build ~{genome_build} \
--o ~{output_prefix}
gzip -n ~{output_prefix}_talon.gtf
}
output {
File gtf = "~{output_prefix}_talon.gtf.gz"
}
runtime {
cpu: resources.cpu
memory: "~{resources.memory_gb} GB"
disks: resources.disks
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task calculate_spearman {
input {
File rep1_abundance
File rep2_abundance
Resources resources
String rep1_idprefix
String rep2_idprefix
String output_prefix
RuntimeEnvironment runtime_environment
}
command {
python3.7 $(which calculate_correlation.py) --rep1_abundance ~{rep1_abundance} \
--rep2_abundance ~{rep2_abundance} \
--rep1_idprefix ~{rep1_idprefix} \
--rep2_idprefix ~{rep2_idprefix} \
--outfile ~{output_prefix}_spearman.json
}
output {
File spearman = "~{output_prefix}_spearman.json"
}
runtime {
cpu: resources.cpu
memory: "~{resources.memory_gb} GB"
disks: resources.disks
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task skipNfirstlines {
input {
File input_file
Resources resources
String output_fn
Int lines_to_skip
RuntimeEnvironment runtime_environment
}
command {
sed 1,~{lines_to_skip}d ~{input_file} > ~{output_fn}
}
output {
File output_file = output_fn
}
runtime {
cpu: resources.cpu
memory: "~{resources.memory_gb} GB"
disks: resources.disks
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}