-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathannot.nf
1720 lines (1412 loc) · 47.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_file = file("$baseDir" + "/.version")
VERSION = version_file.getText()
/*
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.gz")
ref_ann_prot = file(file(params.ref_dir).getParent() + "/all_annotated_proteins.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)
ref_meta_file = file(params.ref_dir + "/" + params.ref_species + "/metadata.json")
log.info ""
log.info "C O M P A N I O N ~ " + 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 ""
ref_meta_file.copyTo(params.dist_dir + "/reference_metadata.json")
version_file.copyTo(params.dist_dir + "/companion_version.txt")
// 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
// TODO might need to revert this if we handle soft-masking in future
"""
awk '/^>/ {print(\$0)}; /^[^>]/ {print(toupper(\$0))}' truncated.fasta > 1
sed 's/['\\''+&= ]/_/g' 1 | prinseq-lite.pl -fasta stdin -trim_ns_left 1 -trim_ns_right 1 -out_good sanitized
"""
}
// 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
// TODO If upgrading to DSL2, can just use json output and splitJson operator before circos_run_chrs process.
file 'ref_target_mapping.txt' into ref_target_mapping_circos
file 'ref_target_mapping.json' 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
file 'ref_target_mapping.json' into ref_target_mapping
"""
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_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_circos
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 }
ref_target_mapping.into{ ref_target_mapping_ratt
ref_target_mapping_integrate
ref_target_mapping_pseudo
ref_target_mapping_split }
// 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.transfer_tool == "ratt") {
process ratt_make_ref_embl {
afterScript 'bgzip genome.fasta'
input:
file ref_annot
file 'genome.fasta.gz' from ref_seq
val go_obo
output:
file '*.embl' into ref_embl
"""
bgzip -d genome.fasta.gz
gff3_to_embl.lua -o ${ref_annot} ${go_obo} Foo genome.fasta
"""
}
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
ratt -p Out -t ${params.RATT_TRANSFER_TYPE} . pseudo.pseudochr.fasta
"""
}
ratt_result.into{ ratt_result
ratt_result_ncrna }
process ratt_to_gff3 {
input:
file 'in*.embl' from ratt_result
file 'in*.report' from ratt_reports
file 'ref_target_mapping.json' from ref_target_mapping_ratt
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 \
-m ref_target_mapping.json -b ${params.mit_bypass} | \
gt gff3 -sort -retainids -tidy > ratt.gff3;
fi
"""
}
process ncrna_from_ratt {
input:
file 'in*.embl' from ratt_result_ncrna
output:
file 'ncrna.gff3' into transferred_ncrnas
"""
echo '##gff-version 3' > ncrna.gff3
ratt_embl_to_ncrna_gff3.lua in*.embl | \
gt gff3 -sort -retainids -tidy > \
ncrna.tmp.gff3
if [ -s ncrna.tmp.gff3 ]; then
cp ncrna.tmp.gff3 ncrna.gff3;
fi
"""
}
} else if (params.transfer_tool == "liftoff") {
process run_liftoff {
afterScript 'bgzip genome.fasta'
input:
file ref_annot
file 'genome.fasta.gz' from ref_seq
file 'pseudo.pseudochr.fasta' from pseudochr_seq_ratt
output:
file 'liftoff.gff3' into liftoff_gff3
"""
bgzip -d genome.fasta.gz
liftoff -g ${ref_annot} pseudo.pseudochr.fasta genome.fasta -o liftoff.gff3 -exclude_partial
"""
}
liftoff_gff3.into{ ratt_gff3
liftoff_gff3_ncrna }
process ncrna_from_liftoff {
input:
file 'liftoff.gff3' from liftoff_gff3_ncrna
output:
file 'ncrna.gff3' into transferred_ncrnas
"""
echo '##gff-version 3' > ncrna.tmp
# TODO removed "tRNA" as they were getting duplicated with the ones found by Aragorn. Should be a more robust way to define ncRNAs here.
awk '\$3=="rRNA"' liftoff.gff3 | grep -oP "Parent=\\K(?:[^;])*" > ncRNA_gene_ids || true
if [ -s ncRNA_gene_ids ]; then
grep -Ff ncRNA_gene_ids liftoff.gff3 | gt gff3 -sort -tidy -retainids > ncrna.tmp;
fi
cp ncrna.tmp ncrna.gff3
"""
}
} else {
process ratt_empty_models {
output:
file 'result.gff3' into ratt_gff3
file 'ncrna.gff3' into transferred_ncrnas
"""
echo '##gff-version 3' > result.gff3
echo '##gff-version 3' > ncrna.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
// ========
if (params.run_braker) {
cpus = config.poolSize
process run_braker_pseudo {
errorStrategy 'ignore'
time '3d'
input:
file 'pseudo.pseudochr.fasta' from pseudochr_seq_augustus
file 'ann_prot.fasta' from ref_ann_prot
output:
file 'braker/braker.gff3' into braker_pseudo_gff3
file 'braker/Augustus/augustus.hints.gff3' into braker_pseudo_gff3_backup
"""
JOB_ID="\$(basename \"${params.dist_dir}\")"
run_braker.sh \
pseudo.pseudochr.fasta \
ann_prot.fasta \
${augustus_modeldir} \
\$JOB_ID \
${cpus} \
${params.use_existing} \
${params.is_fungi} \
${params.is_softmasked}
"""
}
process parse_braker_pseudo {
input:
path "braker_out.gff3" from braker_pseudo_gff3
path "braker_backup.gff3" from braker_pseudo_gff3_backup
output:
path "braker.gff3" into parsed_braker_pseudo_gff3
val 'SUCCESS' into braker_status
"""
echo "##gff-version 3\n" > braker.tmp;
# BRAKER outputs a "full" output file (braker_out.gff3 a.k.a. braker.gff3) which includes untested merging with GeneMark output.
# This has led to issues in the past (see https://github.com/Gaius-Augustus/BRAKER/issues/457#issuecomment-1028738378)
# If such an issue is encountered, use the "backup" output file (braker_backup.gff3 a.k.a. augustus.hints.gff3)
clean_braker_output.sh braker_out.gff3 braker.tmp 2> braker_parsing.err || gt gff3 -sort -tidy braker_backup.gff3 > braker.tmp
augustus_mark_partial.lua braker.tmp > braker.gff3
"""
}
braker_status = braker_pseudo_gff3.ifEmpty('FAILED')
contigs_seq.into{ contigs_seq_in
contigs_seq_out }
// process run_braker_contigs {
// errorStrategy 'ignore'
// input:
// file 'pseudo.contigs.fasta' from contigs_seq_in
// file 'ann_prot.fasta' from ref_ann_prot
// output:
// file 'braker/braker.gff3' into braker_ctg_gff3
// script:
// """
// JOB_ID="\$(basename \"${params.dist_dir}\")"
// run_braker.sh \
// pseudo.contigs.fasta \
// ann_prot.fasta \
// ${augustus_modeldir} \
// "\$JOB_ID"_ctg \
// ${cpus} \
// ${params.use_existing} \
// ${params.is_fungi} \
// ${params.is_softmasked}
// """
// }
// process parse_braker_contigs {
// input:
// path "braker_out.gff3" from braker_ctg_gff3
// file 'pseudo.scaffolds.agp' from scaffolds_agp_augustus
// file 'pseudo.contigs.fasta' from contigs_seq_out
// 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
// output:
// file 'braker.scaf.pseudo.mapped.gff3' into augustus_ctg_gff3
// when:
// braker_ctg_gff3.exists()
// """
// echo "##gff-version 3\n" > braker.ctg.tmp;
// gffread braker_out.gff3 | awk '\$3=="transcript" || \$3=="gene"' > missing_transcripts
// cat missing_transcripts braker_out.gff3 | gt gff3 -sort -tidy | gt uniq > 1
// if [ -s 1 ]; then
// gt select -mingenescore ${params.AUGUSTUS_SCORE_THRESHOLD} 1 \
// > braker.ctg.tmp;
// fi
// augustus_mark_partial.lua braker.ctg.tmp > braker.ctg.gff3
// transform_gff_with_agp.lua \
// braker.ctg.gff3 \
// pseudo.scaffolds.agp \
// pseudo.contigs.fasta \
// pseudo.scaffolds.fasta | \
// gt gff3 -sort -tidy -retainids > \
// braker.ctg.scaf.mapped.gff3
// transform_gff_with_agp.lua \
// braker.ctg.scaf.mapped.gff3 \
// pseudo.pseudochr.agp \
// pseudo.scaffolds.fasta \
// pseudo.pseudochr.fasta | \
// gt gff3 -sort -tidy -retainids > \
// braker.scaf.pseudo.mapped.gff3
// if [ ! -s braker.scaf.pseudo.mapped.gff3 ]; then
// echo '##gff-version 3' > braker.scaf.pseudo.mapped.gff3
// fi
// """
// }
} else {
braker_status = Channel.value('')
parsed_braker_pseudo_gff3 = Channel.empty()
}
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
val braker_status
output:
file 'augustus.gff3' into parsed_augustus_pseudo_gff3
script:
if (!params.run_braker | "${braker_status}" == 'FAILED') {
"""
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
"""
} else {
"""
echo '##gff-version 3' > 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
val extrinsic_cfg
file augustus_modeldir
val braker_status
output:
file 'augustus.scaf.pseudo.mapped.gff3' into parsed_augustus_ctg_gff3
script:
if (!params.run_braker | "${braker_status}" == 'FAILED') {
"""
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 \
--extrinsicCfgFile=${extrinsic_cfg} \
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
"""
} else {
"""
echo '##gff-version 3' > augustus.scaf.pseudo.mapped.gff3
"""
}
}
process merge_genemodels {
cache 'deep'
input:
file 'braker.full.gff3' from parsed_braker_pseudo_gff3.ifEmpty('##gff-version 3')
file 'augustus.full.gff3' from parsed_augustus_pseudo_gff3
file 'augustus.ctg.gff3' from parsed_augustus_ctg_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 \
braker.full.gff3 augustus.full.gff3 augustus.ctg.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
file 'ref_target_mapping.json' from ref_target_mapping_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 \
-m ref_target_mapping.json -o ${params.MAX_OVERLAP} \
-b ${params.mit_bypass} < merged.gff3 | \
gt gff3 -sort -tidy -retainids > integrated.gff3
"""
else
"""
integrate_gene_calls.lua -s sequence.fasta \
-m ref_target_mapping.json -o ${params.MAX_OVERLAP} < 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()
file 'ref_target_mapping.json' from ref_target_mapping_pseudo
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 \
-m ref_target_mapping.json -o ${params.MAX_OVERLAP} > 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
file 'transferred_ncrna.gff3' from transferred_ncrnas
output:
file 'structural.full.gff3' into genemodels_gff3
"""
gt gff3 -sort -tidy ncrna.gff3 integrated.gff3 trna.gff3 transferred_ncrna.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
file 'ref_target_mapping.json' from ref_target_mapping_split
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 \