forked from sanger-pathogens/companion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
annot.nf
1564 lines (1274 loc) · 41.4 KB
/
annot.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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env nextflow
VERSION = "1.0.2"
/*
Author: Sascha Steinbiss <[email protected]>
Copyright (c) 2014-2016 Genome Research Ltd
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
genome_file = file(params.inseq)
ref_annot = file(params.ref_dir + "/" + params.ref_species + "/annotation.gff3")
ref_seq = file(params.ref_dir + "/" + params.ref_species + "/genome.fasta")
ref_dir = file(params.ref_dir)
go_obo = file(params.GO_OBO)
ncrna_models = file(params.NCRNA_MODELS)
extrinsic_cfg = file(params.AUGUSTUS_EXTRINSIC_CFG)
omcl_gfffile = file(params.ref_dir + "/" + params.ref_species + "/annotation.gff3")
omcl_gaffile = file(params.ref_dir + "/" + params.ref_species + "/go.gaf")
omcl_pepfile = file(params.ref_dir + "/" + params.ref_species + "/proteins.fasta")
augustus_modeldir = file(params.ref_dir + "/" + params.ref_species)
log.info ""
log.info "C O M P A N I O N ~ version " + VERSION
log.info "query : ${params.inseq}"
log.info "reference : ${params.ref_species}"
log.info "reference directory : ${params.ref_dir}"
if (params.dist_dir) {
distDir = new File(params.dist_dir)
if(distDir.exists() && distDir.isFile()) {
exit 1, "cannot create output path: ${params.dist_dir} -- already exists as file"
}
if(!distDir.exists() && !distDir.mkdirs()) {
exit 1, "cannot create output path: ${params.dist_dir} -- check file system permissions"
}
if(!distDir.isDirectory()) {
exit 1, "cannot prepare output path: ${params.dist_dir} -- aborting"
}
log.info "output directory : ${params.dist_dir}"
}
log.info ""
// INPUT SANITIZATION
// ==================
if (params.truncate_input_headers) {
process truncate_input_headers {
input:
file genome_file
output:
file 'truncated.fasta' into truncated_genome_file
"""
truncate_header.lua < ${genome_file} > truncated.fasta
"""
}
} else {
genome_file.into { truncated_genome_file }
}
process sanitize_input {
input:
file 'truncated.fasta' from truncated_genome_file
output:
file 'sanitized.fasta' into sanitized_genome_file
"""
sed 's/['\\''+&= ]/_/g' truncated.fasta | trim_wildcards.lua > sanitized.fasta
"""
}
// PSEUDOCHROMOSOME CONTIGUATION
// =============================
if (params.do_contiguation) {
ref_chr = file(params.ref_dir + "/" + params.ref_species + "/chromosomes.fasta")
process contiguate_pseudochromosomes {
afterScript 'rm -rf Ref.* Res.*'
input:
file sanitized_genome_file
file ref_chr
file ref_dir
output:
file 'pseudo.pseudochr.fasta' into pseudochr_seq
file 'pseudo.pseudochr.agp' into pseudochr_agp
file 'pseudo.scafs.fasta' into scaffolds_seq
file 'pseudo.scafs.agp' into scaffolds_agp
file 'pseudo.contigs.fasta' into contigs_seq
file 'ref_target_mapping.txt' into ref_target_mapping
"""
abacas2.nonparallel.sh \
"${ref_chr}" "${sanitized_genome_file}" "${params.ABACAS_MATCH_SIZE}" \
"${params.ABACAS_MATCH_SIM}" 0 3000
abacas_combine.lua . pseudo "${ref_dir}" "${params.ref_species}" \
"${params.GENOME_PREFIX}" "${params.ABACAS_BIN_CHR}" \
"${params.GENOME_PREFIX}"
"""
}
} else {
process prepare_noncontiguated_input {
input:
file sanitized_genome_file
output:
file 'pseudo.pseudochr.fasta' into pseudochr_seq
file 'pseudo.pseudochr.agp' into pseudochr_agp
file 'pseudo.scafs.fasta' into scaffolds_seq
file 'pseudo.scafs.agp' into scaffolds_agp
file 'pseudo.contigs.fasta' into contigs_seq
"""
no_abacas_prepare.lua ${sanitized_genome_file} pseudo
"""
}
}
// fork important output streams
pseudochr_seq.into{ pseudochr_seq_tRNA
pseudochr_seq_ncRNA
pseudochr_seq_ratt
pseudochr_seq_augustus
pseudochr_seq_augustus_ctg
pseudochr_seq_snap
pseudochr_seq_make_gaps
pseudochr_seq_make_dist_1
pseudochr_seq_make_dist_2
pseudochr_seq_splitsplice
pseudochr_seq_pseudogene
pseudochr_seq_integrate
pseudochr_seq_tmhmm
pseudochr_seq_orthomcl
pseudochr_seq_exonerate }
scaffolds_seq.into{ scaffolds_seq_augustus
scaffolds_seq_make_gaps
scaffolds_seq_make_dist_1
scaffolds_seq_make_dist_2 }
scaffolds_agp.into{ scaffolds_agp_augustus
scaffolds_agp_rnaseq
scaffolds_agp_make_gaps
scaffolds_agp_make_dist }
pseudochr_agp.into{ pseudochr_agp_augustus
pseudochr_agp_rnaseq
pseudochr_agp_make_gaps
pseudochr_agp_make_dist }
// TRNA PREDICTION
// ===============
process predict_tRNA {
input:
file 'pseudo.pseudochr.fasta' from pseudochr_seq_tRNA
output:
file 'aragorn.gff3' into trnas
"""
aragorn -t pseudo.pseudochr.fasta > out
grep -E -C2 '(nucleotides|Sequence)' out > 1
aragorn_to_gff3.lua < 1 > 2
gt gff3 -sort -tidy -retainids 2 > aragorn.gff3
"""
}
// NCRNA PREDICTION
// ================
process press_ncRNA_cms {
input:
val ncrna_models
output:
file 'models.cm*' into ncrna_cmindex
"""
cp ${ncrna_models} ./models.cm
cmpress -F models.cm
"""
}
pseudochr_seq_ncRNA.splitFasta( by: 5, file: true).set { ncrna_genome_chunk }
process predict_ncRNA {
input:
file 'chunk' from ncrna_genome_chunk
file ncrna_models from ncrna_cmindex.first()
output:
file 'cm_out' into cmtblouts
"""
cmsearch --cpu 1 --tblout cm_out --cut_ga models.cm chunk
"""
}
process merge_ncrnas {
cache 'deep'
input:
file 'cmtblout' from cmtblouts.collectFile()
output:
file 'ncrna.gff3' into ncrnafile
"""
infernal_to_gff3.lua < ${cmtblout} > 1
gt gff3 -sort -tidy -retainids 1 > ncrna.gff3
"""
}
// PROTEIN-DNA ALIGNMENT
// =====================
if (params.run_exonerate) {
process make_exonerate_index {
input:
file 'genome.fasta' from pseudochr_seq_exonerate.first()
output:
file 'index.esi' into exn_index_esi
file 'index.esd' into exn_index_esd
file 'genome.fasta' into exn_index_fasta
"""
fasta2esd --softmask no genome.fasta index.esd
esd2esi index.esd index.esi --translate yes
"""
}
process make_ref_peps {
cache 'deep'
input:
file ref_annot
file ref_seq
output:
file 'ref.pep' into ref_pep
"""
gt gff3 -sort -tidy -retainids ${ref_annot} > 1
gt extractfeat -matchdescstart -seqfile ${ref_seq} \
-join -type CDS -translate -retainids 1 > ref.pep
"""
}
exn_prot_chunk = ref_pep.splitFasta( by: 200, file: true)
process run_exonerate {
cache 'deep'
// this process can fail for rogue exonerate processes
errorStrategy 'ignore'
time '3h'
input:
file 'index.esi' from exn_index_esi.first()
file 'index.esd' from exn_index_esd.first()
file 'genome.fasta' from exn_index_fasta.first()
file 'prot.fasta' from exn_prot_chunk
output:
file 'exn_out' into exn_results
"""
get_unused_port.sh > port
reaper.sh exonerate-server --port `cat port` --input index.esi &
sleep 10
exonerate -E false --model p2g --showvulgar no --showalignment no \
--showquerygff no --showtargetgff yes --percent 80 --geneseed 250 \
--ryo \"AveragePercentIdentity: %pi\n\" prot.fasta \
localhost:`cat port` > exn_out
kill `cat exonerate-server.pid`
rm -f exonerate-server.pid
"""
}
process exonerate_make_hints {
cache 'deep'
input:
file 'exnout' from exn_results.collectFile()
output:
file 'augustus.hints' into exn_hints
script:
"""
exonerate2hints.pl \
--source=P --maxintronlen=${params.AUGUSTUS_HINTS_MAXINTRONLEN} \
--in=${exnout} \
--out=augustus.hints
"""
}
} else {
process exonerate_empty_hints {
output:
file 'augustus.hints' into exn_hints
"""
touch augustus.hints
"""
}
}
// RATT
// ====
if (params.run_ratt) {
process ratt_make_ref_embl {
input:
file ref_annot
file ref_seq
val go_obo
output:
file '*.embl' into ref_embl
"""
gff3_to_embl.lua -o ${ref_annot} ${go_obo} Foo ${ref_seq}
"""
}
process run_ratt {
afterScript 'rm -rf Reference* Sequences Query query.*'
input:
file 'in*.embl' from ref_embl
file 'pseudo.pseudochr.fasta' from pseudochr_seq_ratt
output:
file 'Out*.final.embl' into ratt_result
file 'Out*.Report.txt' into ratt_reports
"""
touch Out.0.Report.txt
start.ratt.sh . pseudo.pseudochr.fasta Out ${params.RATT_TRANSFER_TYPE}
"""
}
process ratt_to_gff3 {
input:
file 'in*.embl' from ratt_result
file 'in*.report' from ratt_reports
output:
file 'ratt.gff3' into ratt_gff3
"""
echo '##gff-version 3' > ratt.gff3
ratt_embl_to_gff3.lua in*.embl | \
gt gff3 -sort -retainids -tidy > \
ratt.tmp.gff3
if [ -s ratt.tmp.gff3 ]; then
ratt_remove_problematic.lua ratt.tmp.gff3 in*report | \
gt gff3 -sort -retainids -tidy > ratt.gff3;
fi
"""
}
} else {
process ratt_empty_models {
output:
file 'result.gff3' into ratt_gff3
"""
echo '##gff-version 3' > result.gff3
"""
}
}
// TRANSCRIPT EVIDENCE PREPARATION
// ===============================
if (params.TRANSCRIPT_FILE) {
transcript_evidence = file(params.TRANSCRIPT_FILE)
process transform_input_gtf {
input:
file 'transcripts.gtf' from transcript_evidence
file 'pseudochr.agp' from pseudochr_agp_rnaseq
output:
file 'transcripts_transformed.gtf' into transcript_evidence_transformed
"""
LC_ALL='C' sort -k 1,1 -k 4,4n transcripts.gtf | uniq > 1
transform_gtf_with_agp.lua 1 pseudochr.agp > transcripts_transformed.gtf
"""
}
process prepare_transcript_hints {
input:
file 'transcripts.gtf' from transcript_evidence_transformed
output:
file 'transcripts.hints' into trans_hints
"""
LC_ALL='C' sort -k 1,1 -k 4,4n transcripts.gtf | uniq | \
cufflinks_to_hints.lua > transcripts.hints
"""
}
} else {
process transcript_empty_hints {
output:
file 'transcripts.hints' into trans_hints
"""
touch transcripts.hints
"""
}
}
// HINTS PREPARATION
// =================
process merge_hints {
cache 'deep'
input:
file 'hints.exon.txt' from exn_hints
file 'hints.trans.txt' from trans_hints
output:
set stdout, file('hints.txt') into all_hints
"""
touch hints.txt
cat hints.exon.txt hints.trans.txt > hints.concatenated.txt
if [ -s hints.concatenated.txt ] ; then
mv hints.concatenated.txt hints.txt;
echo -n '--alternatives-from-evidence=false --hintsfile=augustus.hints';
fi
"""
}
// AUGUSTUS
// ========
process run_augustus_pseudo {
cache 'deep'
input:
set val(hintsline), file('augustus.hints') from all_hints
file 'pseudo.pseudochr.fasta' from pseudochr_seq_augustus
val extrinsic_cfg
file augustus_modeldir
output:
file 'augustus.gff3' into augustus_pseudo_gff3
"""
echo "##gff-version 3\n" > augustus.full.tmp.2;
AUGUSTUS_CONFIG_PATH=${augustus_modeldir} \
augustus \
--species=augustus_species \
--stopCodonExcludedFromCDS=false \
--protein=off --codingseq=off --strand=both \
--genemodel=${params.AUGUSTUS_GENEMODEL} --gff3=on \
${hintsline} \
--noInFrameStop=true \
--extrinsicCfgFile=${extrinsic_cfg} \
pseudo.pseudochr.fasta > augustus.full.tmp
augustus_to_gff3.lua < augustus.full.tmp \
| gt gff3 -sort -tidy -retainids > 1
if [ -s 1 ]; then
gt select -mingenescore ${params.AUGUSTUS_SCORE_THRESHOLD} 1 \
> augustus.full.tmp.2;
fi
augustus_mark_partial.lua augustus.full.tmp.2 > augustus.gff3
"""
}
process run_augustus_contigs {
input:
file 'pseudo.contigs.fasta' from contigs_seq
file 'pseudo.scaffolds.agp' from scaffolds_agp_augustus
file 'pseudo.scaffolds.fasta' from scaffolds_seq_augustus
file 'pseudo.pseudochr.agp' from pseudochr_agp_augustus
file 'pseudo.pseudochr.fasta' from pseudochr_seq_augustus_ctg
file augustus_modeldir
output:
file 'augustus.scaf.pseudo.mapped.gff3' into augustus_ctg_gff3
"""
echo "##gff-version 3\n" > augustus.ctg.tmp.2;
AUGUSTUS_CONFIG_PATH=${augustus_modeldir} \
augustus --species=augustus_species \
--stopCodonExcludedFromCDS=false \
--protein=off --codingseq=off --strand=both --genemodel=partial \
--gff3=on \
--noInFrameStop=true \
pseudo.contigs.fasta > augustus.ctg.tmp
augustus_to_gff3.lua < augustus.ctg.tmp \
| gt gff3 -sort -tidy -retainids > 1
if [ -s 1 ]; then
gt select -mingenescore ${params.AUGUSTUS_SCORE_THRESHOLD} 1 \
> augustus.ctg.tmp.2;
fi
augustus_mark_partial.lua augustus.ctg.tmp.2 > augustus.ctg.gff3
transform_gff_with_agp.lua \
augustus.ctg.gff3 \
pseudo.scaffolds.agp \
pseudo.contigs.fasta \
pseudo.scaffolds.fasta | \
gt gff3 -sort -tidy -retainids > \
augustus.ctg.scaf.mapped.gff3
transform_gff_with_agp.lua \
augustus.ctg.scaf.mapped.gff3 \
pseudo.pseudochr.agp \
pseudo.scaffolds.fasta \
pseudo.pseudochr.fasta | \
gt gff3 -sort -tidy -retainids > \
augustus.scaf.pseudo.mapped.gff3
if [ ! -s augustus.scaf.pseudo.mapped.gff3 ]; then
echo '##gff-version 3' > augustus.scaf.pseudo.mapped.gff3
fi
"""
}
if (params.run_snap) {
snap_model = file(params.ref_dir + "/" + params.ref_species + "/snap.hmm")
process run_snap {
input:
file 'pseudo.pseudochr.fasta' from pseudochr_seq_snap
file 'snap.hmm' from snap_model
output:
file 'snap.gff3' into snap_gff3
"""
echo '##gff-version 3' > snap.gff3
snap -gff -quiet snap.hmm pseudo.pseudochr.fasta > snap.tmp
snap_gff_to_gff3.lua snap.tmp > snap.tmp.2
if [ -s 1 ]; then
gt gff3 -sort -tidy -retainids snap.tmp.2 > snap.gff3;
fi
"""
}
} else {
process make_empty_snap {
output:
file 'snap.gff3' into snap_gff3
"""
echo '##gff-version 3' > snap.gff3
"""
}
}
process merge_genemodels {
cache 'deep'
input:
file 'augustus.full.gff3' from augustus_pseudo_gff3
file 'augustus.ctg.gff3' from augustus_ctg_gff3
file 'snap.full.gff3' from snap_gff3
file 'ratt.full.gff3' from ratt_gff3
output:
file 'merged.gff3' into merged_gff3
"""
unset GT_RETAINIDS && \
gt gff3 -fixregionboundaries -retainids no -sort -tidy \
augustus.full.gff3 augustus.ctg.gff3 snap.full.gff3 ratt.full.gff3 \
> merged.pre.gff3 && \
export GT_RETAINIDS=yes
if [ ! -s merged.pre.gff3 ]; then
echo '##gff-version 3' > merged.pre.gff3
fi
# avoid huge gene clusters
gt select -maxgenelength ${params.MAX_GENE_LENGTH} merged.pre.gff3 > merged.gff3
"""
}
process integrate_genemodels {
cache 'deep'
afterScript 'rm -rf sequence.fasta.*'
input:
file 'merged.gff3' from merged_gff3
file 'sequence.fasta' from pseudochr_seq_integrate
output:
file 'integrated.gff3' into integrated_gff3
script:
if (params.WEIGHT_FILE.length() > 0)
"""
integrate_gene_calls.lua -w ${params.WEIGHT_FILE} -s sequence.fasta < merged.gff3 | \
gt gff3 -sort -tidy -retainids > integrated.gff3
"""
else
"""
integrate_gene_calls.lua -s sequence.fasta < merged.gff3 | \
gt gff3 -sort -tidy -retainids > integrated.gff3
"""
}
if (params.fix_polycistrons) {
process fix_polycistrons {
input:
file 'integrated.gff3' from integrated_gff3
output:
file 'integrated.fixed.sorted.gff3' into integrated_gff3_processed
"""
if [ ! -s integrated.gff3 ]; then
echo '##gff-version 3' > integrated.gff3
fi
fix_polycistrons.lua integrated.gff3 > integrated.fixed.gff3
# make sure final output is sorted
gt gff3 -sort -tidy -retainids \
integrated.fixed.gff3 > integrated.fixed.sorted.gff3
"""
}
} else {
integrated_gff3.into { integrated_gff3_processed }
}
process remove_exons {
input:
file 'integrated.gff3' from integrated_gff3_processed
output:
file 'integrated_clean.gff3' into integrated_gff3_clean
"""
if [ ! -s integrated.gff3 ]; then
echo '##gff-version 3' > integrated.gff3
fi
remove_exons.lua integrated.gff3 > integrated_clean.gff3
"""
}
if (params.do_pseudo) {
process pseudogene_indexing {
input:
file 'ref.peps.fasta' from omcl_pepfile
output:
file 'prot_index*' into pseudochr_last_index
"""
tantan -p -r0.02 ref.peps.fasta | lastdb -p -c prot_index
"""
}
pseudochr_seq_pseudogene.into{ pseudochr_seq_pseudogene_align; pseudochr_seq_pseudogene_calling }
pseudochr_seq_pseudogene_align.splitFasta( by: 3, file: true).set { pseudogene_align_chunk }
process pseudogene_last {
input:
file 'chunk.fasta' from pseudogene_align_chunk
file prot_index from pseudochr_last_index.first()
output:
file 'last.out' into pseudochr_last_out
"""
lastal -R01 -pBL80 -F15 -e400 -m10 -f0 prot_index chunk.fasta > last.out
"""
}
process pseudogene_calling {
cache 'deep'
input:
file 'pseudochr.fasta' from pseudochr_seq_pseudogene_calling
file 'genes.gff3' from integrated_gff3_clean
file 'last.out' from pseudochr_last_out.collectFile()
output:
file 'genes_and_pseudo.gff3' into gff3_with_pseudogenes
"""
# reconstruct frameshifted candidates from output
pseudo_merge_last.lua last.out pseudochr.fasta > last_gff.gff3
# merge with gene models
gt gff3 -sort -tidy -retainids last_gff.gff3 genes.gff3 > last_and_genes.gff3
if [ ! -s last_and_genes.gff3 ]; then
echo '##gff-version 3' > last_and_genes.gff3
fi
pseudo_merge_with_genes.lua last_and_genes.gff3 pseudochr.fasta > out_tmp.gff3
gt gff3 -sort -retainids -tidy out_tmp.gff3 > genes_and_pseudo.gff3
"""
}
} else {
gff3_with_pseudogenes = integrated_gff3_clean
}
// MERGE ALL GENES TO FINAL SET AND CLEANUP
// ========================================
process merge_structural {
cache 'deep'
input:
file 'ncrna.gff3' from ncrnafile
file 'trna.gff3' from trnas
file 'integrated.gff3' from gff3_with_pseudogenes
output:
file 'structural.full.gff3' into genemodels_gff3
"""
gt gff3 -sort -tidy ncrna.gff3 integrated.gff3 trna.gff3 \
> structural.full.gff3
"""
}
// ADD GAPS AND ADJUST GENES NOT TO SPAN GAPS
// ==========================================
process add_gap_features {
input:
file 'merged_in.gff3' from genemodels_gff3
file 'pseudo.scaffolds.agp' from scaffolds_agp_make_gaps
file 'pseudo.scaffolds.fasta' from scaffolds_seq_make_gaps
file 'pseudo.pseudochr.agp' from pseudochr_agp_make_gaps
file 'pseudo.pseudochr.fasta' from pseudochr_seq_make_gaps
output:
file 'merged_out.gff3' into genemodels_with_gaps_gff3
"""
set -ev
make_contig_features_from_agp.lua pseudo.scaffolds.agp "within scaffold" | \
gt gff3 -fixregionboundaries -sort -tidy -retainids > contigs.gff3
transform_gff_with_agp.lua contigs.gff3 \
pseudo.pseudochr.agp pseudo.scaffolds.fasta \
pseudo.pseudochr.fasta "between scaffolds" | \
gt gff3 -fixregionboundaries -sort -tidy -retainids > contigs2.gff3
if [ ! -s merged_in.gff3 ]; then
echo '##gff-version 3' > merged_in.gff3
fi
gt merge -force -o merged_out.gff3 \
merged_in.gff3 contigs2.gff3
"""
}
process split_splice_models_at_gaps {
input:
file 'input.gff3' from genemodels_with_gaps_gff3
file 'pseudo.pseudochr.fasta' from pseudochr_seq_splitsplice
output:
file 'merged_out.gff3' into genemodels_with_gaps_split_gff3
"""
# sort
gt gff3 -sort -retainids -tidy < input.gff3 > tmp2
# split genes at inter-scaffold gaps
split_genes_at_gaps.lua tmp2 | \
gt gff3 -sort -retainids -tidy > tmp3
# splice genes at inter-contig gaps, get rid of short partials
splice_genes_at_gaps_new.lua tmp3 | \
gt gff3 -sort -retainids -tidy | \
gt select -rule_files ${FILTER_SHORT_PARTIALS_RULE} > tmp4
# get rid of genes still having stop codons
filter_genes_with_stop_codons.lua \
tmp4 pseudo.pseudochr.fasta | \
gt gff3 -sort -retainids -tidy > merged_out.gff3
"""
}
process add_polypeptides {
input:
file 'input.gff3' from genemodels_with_gaps_split_gff3
output:
file 'output.gff3' into genemodels_with_polypeptides_gff3
script:
if (params.alphanumeric_ids)
"""
create_polypeptides.lua -r input.gff3 ${params.GENOME_PREFIX} \
"${params.CHR_PATTERN}" | gt gff3 -sort -retainids -tidy > output.gff3
"""
else
"""
create_polypeptides.lua input.gff3 ${params.GENOME_PREFIX} \
"${params.CHR_PATTERN}" | gt gff3 -sort -retainids -tidy > output.gff3
"""
}
// TMHMM
// =====
// disabled for now for license reasons
/* process run_tmhmm {
input:
file 'input.gff3' from genemodels_with_polypeptides_gff3
file 'pseudo.pseudochr.fasta' from pseudochr_seq_tmhmm
output:
file 'output.gff3' into genemodels_with_tmhmm_gff3
"""
gt extractfeat -type CDS -join -translate \
-seqfile pseudo.pseudochr.fasta -matchdescstart \
input.gff3 > proteins.fas
tmhmm --noplot < proteins.fas > tmhmm.out
tmhmm_to_gff3.lua tmhmm.out input.gff3 | \
gt gff3 -sort -retainids -tidy > output.gff3
"""
} */
// ORTHOMCL AND FUNCTIONAL TRANSFER
// ================================
genemodels_with_polypeptides_gff3.into{ genemodels_for_omcl_proteins; genemodels_for_omcl_annot }
process get_proteins_for_orthomcl {
input:
file 'input.gff3' from genemodels_for_omcl_proteins
file 'pseudo.pseudochr.fasta' from pseudochr_seq_orthomcl
output:
file 'input.gff3' into genemodels_orthomcl_gff3
file 'proteins.fas' into proteins_target
"""
gt extractfeat -type CDS -translate -join -retainids \
-seqfile pseudo.pseudochr.fasta -matchdescstart < input.gff3 \
| truncate_header.lua > proteins.fas
gt extractfeat -type pseudogenic_exon -translate \
-join -retainids \
-seqfile pseudo.pseudochr.fasta -matchdescstart < input.gff3 \
| truncate_header.lua >> proteins.fas
"""
}
proteins_target.into{ proteins_orthomcl
proteins_pfam
refcomp_protein_in
proteins_output }
process make_ref_input_for_orthomcl {
input:
file omcl_pepfile
output:
file 'out.gg' into gg_file
file 'shortname' into shortname
file 'mapped.fasta' into mapped_fasta
script:
"""
truncate_header.lua < ${omcl_pepfile} > pepfile.trunc
ln -s pepfile.trunc mapped.fasta
make_gg_line.lua ${params.ref_species} mapped.fasta > out.gg
echo "${params.ref_species}" > shortname
"""
}
process make_target_input_for_orthomcl {
input:
file 'pepfile.fas' from proteins_orthomcl
output:
file 'out.gg' into gg_file_ref
file 'shortname' into shortname_ref
file 'mapped.fasta' into mapped_fasta_ref
"""
truncate_header.lua < pepfile.fas > pepfile.trunc
ln -s pepfile.trunc mapped.fasta
make_gg_line.lua ${params.GENOME_PREFIX} mapped.fasta > out.gg
echo "${params.GENOME_PREFIX}" > shortname
"""
}
gg_file.mix(gg_file_ref).collectFile().set { full_gg }
shortname.mix(shortname_ref).collectFile().set { full_shortnames }
mapped_fasta.mix(mapped_fasta_ref).collectFile().set { full_mapped_fasta }
full_mapped_fasta.into{ full_mapped_fasta_for_index; full_mapped_fasta_for_query }
process blast_for_orthomcl_formatdb {
cache 'deep'
input:
file 'mapped.fasta' from full_mapped_fasta_for_index
output:
file 'mapped.fasta' into full_mapped_fasta_indexed
file 'mapped.fasta.phr' into full_mapped_fasta_indexed_phr
file 'mapped.fasta.psq' into full_mapped_fasta_indexed_psq
file 'mapped.fasta.pin' into full_mapped_fasta_indexed_pin
"""
makeblastdb -dbtype prot -in mapped.fasta
"""
}
proteins_orthomcl_blast_chunk = full_mapped_fasta_for_query.splitFasta( by: 50, file: true)
process blast_for_orthomcl {
cache 'deep'
input:
file 'mapped_chunk.fasta' from proteins_orthomcl_blast_chunk
file 'mapped.fasta' from full_mapped_fasta_indexed.first()
file 'mapped.fasta.phr' from full_mapped_fasta_indexed_phr.first()
file 'mapped.fasta.psq' from full_mapped_fasta_indexed_psq.first()
file 'mapped.fasta.pin' from full_mapped_fasta_indexed_pin.first()
output:
file 'blastout' into orthomcl_blastout
"""
blastall -p blastp -W 4 -F 'm S' -v 100000 -b 100000 -d mapped.fasta -m 8 \
-i mapped_chunk.fasta > blastout
"""
}
process run_orthomcl {
cache 'deep'
input:
file 'blastout' from orthomcl_blastout.collectFile()
file 'ggfile' from full_gg
output:
file 'orthomcl_out' into orthomcl_cluster_out
"""
orthomcl.pl --inflation 1.5 --mode 3 \
--blast_file blastout \
--gg_file ggfile
cp `find . -mindepth 1 -name all_orthomcl.out` orthomcl_out
"""
}
orthomcl_cluster_out.into{ orthomcl_cluster_out_annot; result_ortho }
process annotate_orthologs {
cache 'deep'
input:
file 'orthomcl_out' from orthomcl_cluster_out_annot
file 'input.gff3' from genemodels_for_omcl_annot
file 'gff_ref.gff3' from omcl_gfffile
file 'gaf_ref.gaf' from omcl_gaffile
output:
file 'with_func.gff3' into gff3_with_ortho_transferred
file 'orthomcl.gaf' into gaf_with_ortho_transferred
"""
# ensure sorting of input file
gt gff3 -sort -retainids -tidy input.gff3 > input.gff3.sorted
# annotate GFF with ortholog clusters and members
map_clusters_gff.lua input.gff3.sorted orthomcl_out > with_clusters.gff3
# transfer functional annotation from orthologs
transfer_annotations_from_gff.lua with_clusters.gff3 \
gff_ref.gff3 > with_func.gff3
# transfer GOs from orthologs GAF
transfer_annotations_from_gaf.lua with_func.gff3 \
gaf_ref.gaf ${params.DB_ID} \
${params.TAXON_ID} > orthomcl.gaf