forked from darcyabjones/pclust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpannot.nf
executable file
·690 lines (529 loc) · 15.7 KB
/
pannot.nf
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
#!/usr/bin/env nextflow
/*
vim: syntax=groovy
-*- mode: groovy;-*-
*/
def helpMessage() {
log.info"""
=================================
pclust/pannot
=================================
Usage:
abaaab
Mandatory Arguments:
--seqs description
Options:
--nodedup
--min_size
Outputs:
""".stripIndent()
}
if (params.help){
helpMessage()
exit 0
}
params.seqs = false
params.nodedup = false
params.min_size = false
params.noeffectorp = false
params.nosignalp = false
params.notmhmm = false
params.nophobius = false
params.notargetp = false
params.noapoplastp = false
params.nolocalizer = false
if ( !params.seqs ) {
log.info "I need some sequences to work with please."
exit 1
}
if ( !params.nodedup ) {
/*
* Create the mmseqs2 sequence database
*/
process createSequenceDB {
label 'mmseqs'
input:
file fasta from Channel.fromPath( params.seqs )
output:
file "proteins" into seqdb
"""
mkdir -p proteins
mmseqs createdb "${fasta}" proteins/db --max-seq-len 14000
"""
}
seqdb.into { seqdb4Cluster; seqdb4Extract }
/*
* Select only unique sequences to cluster.
*/
process clusterDedup {
label 'mmseqs'
publishDir "${params.outdir}/annotations"
input:
file "sequence" from seqdb4Cluster
output:
file "dedup" into dedupClu
file "dedup.tsv" into dedupCluTSV
"""
mmseqs clusthash sequence/db result --threads ${task.cpus} --min-seq-id 1.0
mkdir -p dedup
mmseqs clust sequence/db result dedup/db --threads ${task.cpus}
mmseqs createtsv sequence/db sequence/db dedup/db dedup.tsv --threads ${task.cpus}
sed -i '1i cluster\tmember' dedup.tsv
"""
}
dedupClu.set { dedupClu4Extract }
/*
* Select only unique sequences to cluster.
*/
process getDedupSequences {
label 'mmseqs'
publishDir "${params.outdir}/annotations"
input:
file "sequence" from seqdb4Extract
file "cluster" from dedupClu4Extract
output:
file "dedup.fasta" into seqs
"""
mmseqs result2repseq sequence/db cluster/db dedup --threads ${task.cpus}
mmseqs result2flat sequence/db sequence/db dedup dedup.fasta --use-fasta-header
"""
}
} else {
seqs = Channel.fromPath( params.seqs )
}
if ( params.min_size ) {
/*
* Filter sequences to minimum size
*/
process filterSeqSize {
label "seqkit"
publishDir "${params.outdir}/annotations"
input:
file "seqs.fasta" from seqs
output:
file "dedup_filtered.fasta" into filteredFasta
"""
seqkit seq -m ${params.min_size} < seqs.fasta > dedup_filtered.fasta
"""
}
seqs4Split = filteredFasta
} else {
seqs4Split = seqs
}
/* Split the channel for reuse.
* Note that targetp will be split separately into smaller bits because it's
* temperamental.
*/
seqs4Split
.tap { seqs4Targetp }
.splitFasta( by: 1000, file: true )
.into {
seqs4Effectorp;
seqs4Signalp3HMM;
seqs4Signalp3NN;
seqs4Signalp4;
seqs4Tmhmm;
seqs4Phobius;
seqs4Apoplastp;
seqs4LocalizerPlant;
}
/*
* Run effectorp on each sequence.
*/
process effectorp {
label "sperschneider"
input:
file fasta from seqs4Effectorp
output:
file "${fasta}.tsv" into effectorpChunkedResults
when:
!params.noeffectorp
"""
EffectorP.py -s -i "${fasta}" -o "${fasta}.tsv"
"""
}
/*
* Combine chunks of effectorp results into file.
*/
process gatherEffectorp {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from effectorpChunkedResults.collect()
output:
file "effectorp.tsv" into effectorpResults
when:
!params.noeffectorp
"""
echo "seqid\teffector\tprobability" > effectorp.tsv
cat tables* \
| grep -v "#" \
| awk -F'\t' 'OFS="\t" { sub(/[[:space:]].*/, "", \$1); print \$1, \$2, \$3}' \
>> effectorp.tsv
"""
}
if ( !params.nosignalp ) {
/*
* Run signalp3 HMM predictions for each sequence.
* This is known to be more sensitive for detecting oomycete effectors.
* See doi: 10.3389/fpls.2015.01168
*/
process signalp3HMM {
label "signalp3"
input:
file fasta from seqs4Signalp3HMM
output:
file "${fasta}.tsv" into signalp3HMMChunkedResults
"""
signalp -type euk -method "hmm" -short "${fasta}" > "${fasta}.tsv"
"""
}
/*
* Combine signalp3 results into file.
*/
process gatherSignalp3HMM {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from signalp3HMMChunkedResults.collect()
output:
file "signalp3_hmm.tsv" into signalp3HMMResults
"""
echo "seqid\tsecreted\tcmax\tpos\tpos_decision\tsprob\tsprob_decision" > signalp3_hmm.tsv
cat tables* | grep -v "#" | sed "s/ \\+/\t/g" | sed "s/\t\$//g" >> signalp3_hmm.tsv
"""
}
/*
* Run signalp3 neural net predictions for each sequence.
* This is known to be more sensitive for detecting fungal effectors.
* See doi: 10.3389/fpls.2015.01168
process signalp3NN {
label "signalp3"
input:
file fasta from seqs4Signalp3NN
output:
file "${fasta}.tsv" into signalp3NNChunkedResults
"""
signalp -type euk -method "nn" -short "${fasta}" > "${fasta}.tsv"
"""
}
*/
/*
* Combine signalp3 results into file.
process gatherSignalp3NN {
publishDir "${params.outdir}/annotations"
input:
file "tables" from signalp3NNChunkedResults.collect()
output:
file "signalp3_nn.tsv" into signalp3NNResults
"""
echo "seqid\tsecreted\tcmax\tpos\tpos_decision\tsprob\tsprob_decision" > signalp3_nn.tsv
cat tables* | grep -v "#" | sed "s/ \\+/\t/g" >> signalp3_nn.tsv
"""
}
*/
/*
* Run signalp4 for all sequences. Also get mature proteins for later use.
* If there were no secreted proteins, don't emit fasta.
*/
process signalp4 {
label "signalp4"
input:
file fasta from seqs4Signalp4
output:
file "${fasta}.tsv" into signalp4ChunkedResults
file "${fasta}_mature.fasta" optional true into matureProteins
"""
signalp -t euk -f short -m "${fasta}_mature.fasta" "${fasta}" > "${fasta}.tsv"
if [ ! -s "${fasta}_mature.fasta" ]; then
rm -f "${fasta}_mature.fasta"
fi
"""
}
/*
* Combine signalp4 chunks into file.
*/
process gatherSignalp4 {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from signalp4ChunkedResults.collect()
output:
file "signalp4.tsv" into signalp4Results
"""
echo "seqid\tcmax\tcmax_pos\tymax\tymax_pos\tsmax\tsmax_pos\tsmean\td\tsecreted\tdmaxcut\tnetworks" > signalp4.tsv
cat tables* | grep -v "#" | sed "s/ \\+/\t/g" >> signalp4.tsv
"""
}
} // endif !nosignalp
if ( !params.notmhmm ) {
/*
* Run tmhmm transmembrane domain prediction.
*/
process tmhmm {
label "tmhmm"
input:
file fasta from seqs4Tmhmm
output:
file "${fasta}.tsv" into tmhmmChunkedResults
"""
tmhmm -short -d < "${fasta}" > "${fasta}.tsv"
"""
}
/*
* Collect results into file
*/
process gatherTmhmm {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from tmhmmChunkedResults.collect()
output:
file "tmhmm.tsv" into tmhmmResults
"""
echo "seqid\tlen\texpaa\tfirst60\tpredhel\ttopology" > tmhmm.tsv
cat tables* \
| sed "s/len=\\|ExpAA=\\|First60=\\|PredHel=\\|Topology=//g" \
| sed "s/ \\+/\t/g" \
>> tmhmm.tsv
"""
}
}
if ( !params.notargetp ) {
/*
* Because targetp is a bit finicky, process it in smaller chunks.
*/
seqs4Targetp
.splitFasta(by: 100)
.into {
seqs4Targetp1;
seqs4Targetp2;
}
/*
* Run targetp using non-plant networks for chunks.
*/
process targetp {
label "targetp"
input:
file fasta from seqs4Targetp1
output:
file "${fasta}.tsv" into targetpChunkedResults
"""
targetp -c -N < ${fasta} | tail -n+9 | head -n-2 > "${fasta}.tsv"
"""
}
/*
* Collect targetp chunks into file
*/
process gatherTargetp {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from targetpChunkedResults.collect()
output:
file "targetp.tsv" into targetpResults
"""
echo "seqid\tlen\tmtp\tsp\tother\tloc\trc\ttplen" > targetp.tsv
cat tables* | sed 's/ \\+/\t/g' >> targetp.tsv
"""
}
/*
* Run targetp using plant networks for chunks.
*/
process targetpPlant {
label "targetp"
input:
file fasta from seqs4Targetp2
output:
file "${fasta}.tsv" into targetpPlantChunkedResults
"""
targetp -c -P < ${fasta} | tail -n+9 | head -n-2 > "${fasta}.tsv"
"""
}
/*
* Collect targetp chunks into file.
*/
process gatherTargetpPlant {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from targetpPlantChunkedResults.collect()
output:
file "targetp_plant.tsv" into targetpPlantResults
"""
echo "seqid\tlen\tctp\tmtp\tsp\tother\tloc\trc\ttplen" > targetp_plant.tsv
cat tables* | sed 's/ \\+/\t/g' >> targetp_plant.tsv
"""
}
} // endif !notargetp
if ( !params.nophobius ) {
/*
* Run phobius predictions for chunks.
* Phobius has comparable sensitivity to signalp nn models and also runs tm prediction.
*/
process phobius {
label "phobius"
input:
file fasta from seqs4Phobius
output:
file "${fasta}.tsv" into phobiusChunkedResults
"""
sed 's/\\*\$//g' "${fasta}" | sed '/>/!s/[\\*J]/X/g' | phobius -short | tail -n+2 > "${fasta}.tsv"
"""
}
/*
* Collect phobius results into file.
*/
process gatherPhobius {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from phobiusChunkedResults.collect()
output:
file "phobius.tsv" into phobiusResults
"""
echo "seqid\ttm\tsp\tprediction" > phobius.tsv
cat tables* | sed 's/ \\+/\t/g' >> phobius.tsv
"""
}
}
if ( !params.noapoplastp ) {
/*
* Run apoplastp for chunks
*/
process apoplastp {
label "sperschneider"
input:
file fasta from seqs4Apoplastp
output:
file "${fasta}.tsv" into apoplastpChunkedResults
"""
ApoplastP.py -s -i "${fasta}" -o "${fasta}.tsv"
"""
}
/*
* Collect chunked apoplastp results into file.
*/
process gatherApoplastp {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from apoplastpChunkedResults.collect()
output:
file "apoplastp.tsv" into apoplastpResults
"""
echo "seqid\tprediction\tprobability" > apoplastp.tsv
cat tables* \
| grep -v "#" \
| awk -F'\t' 'OFS="\t" { sub(/[[:space:]].*/, "", \$1); print \$1, \$2, \$3}' \
>> apoplastp.tsv
"""
}
}
if ( !params.nolocalizer && !params.nosignalp ) {
/*
* Run localizer in "effector" mode using mature peptides from signalp
*/
process localizerEffector {
label "sperschneider"
input:
file fasta from matureProteins
output:
file "${fasta}.tsv" into localizerEffectorChunkedResults
"""
LOCALIZER.py -e -M -i "${fasta}" -o results
grep -v "^#" results/Results.txt \
| tail -n+2 \
| sed '/^\\s*\$/d' \
| awk -F'\t' 'OFS="\t" { sub(/[[:space:]].*/, "", \$1); print \$1, \$2, \$3, \$4}' \
> "${fasta}.tsv"
"""
}
/*
* Collect localizer results into a file.
*/
process gatherLocalizerEffector {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from localizerEffectorChunkedResults.collect()
output:
file "localizer_effector.tsv" into localizerEffectorResults
"""
echo "seqid\tchloroplast\tmitochondria\tnucleus" > localizer_effector.tsv
cat tables* >> localizer_effector.tsv
"""
}
}
if ( !params.nolocalizer ) {
/*
* Run localizer using plant mode.
*/
process localizerPlant {
label "sperschneider"
input:
file fasta from seqs4LocalizerPlant
output:
file "${fasta}.tsv" into localizerPlantChunkedResults
"""
LOCALIZER.py -p -i "${fasta}" -o results
grep -v "^#" results/Results.txt \
| tail -n+2 \
| sed '/^\\s*\$/d' \
| awk -F'\t' 'OFS="\t" { sub(/[[:space:]].*/, "", \$1); print \$1, \$2, \$3, \$4}' \
> "${fasta}.tsv"
"""
}
/*
* Collect localizer results into file.
*/
process gatherLocalizerPlant {
label "posix"
publishDir "${params.outdir}/annotations"
input:
file "tables" from localizerPlantChunkedResults.collect()
output:
file "localizer_plant.tsv" into localizerPlantResults
"""
echo "seqid\tchloroplast\tmitochondria\tnucleus" > localizer_plant.tsv
cat tables* >> localizer_plant.tsv
"""
}
}
if ( !(params.noeffectorp || params.nosignalp || params.notmhmm || params.nophobius || params.notargetp || params.noapoplastp || params.nolocalizer) ) {
/*
* Combine annotation results into single file.
*/
process combineAnnotations {
label "R"
publishDir "${params.outdir}/annotations"
input:
file "apoplastp.tsv" from apoplastpResults
file "effectorp.tsv" from effectorpResults
file "localizer_effector.tsv" from localizerEffectorResults
file "localizer_plant.tsv" from localizerPlantResults
file "signalp3_hmm.tsv" from signalp3HMMResults
file "signalp4.tsv" from signalp4Results
file "targetp_non_plant.tsv" from targetpResults
file "targetp_plant.tsv" from targetpPlantResults
file "tmhmm.tsv" from tmhmmResults
file "phobius.tsv" from phobiusResults
output:
file "combined.tsv" into combinedResults
"""
join_annotations.R \
apoplastp.tsv \
effectorp.tsv \
localizer_effector.tsv \
localizer_plant.tsv \
signalp3_hmm.tsv \
dummy \
signalp4.tsv \
targetp_non_plant.tsv \
targetp_plant.tsv \
tmhmm.tsv \
phobius.tsv \
> combined.tsv
"""
}
}