-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.nf
1624 lines (1224 loc) · 46.8 KB
/
main.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
/*
========================================================================================
IKMB - de.NBI | Genome Annotation Pipeline
========================================================================================
Genome Annotation Pipeline. Started 2018-10-17.
#### Homepage / Documentation
https://github.com/ikmb-denbi/genome-annotation/
#### Authors
MTorres m.torres <[email protected]> - https://git.ikmb.uni-kiel.de/m.torres>
MHoeppner m.hoeppner <[email protected]>
----------------------------------------------------------------------------------------
*/
def helpMessage() {
log.info"""
=================================================================
IKMB - de.NBI | Genome Annotation Pipeline | v${workflow.manifest.version}
=================================================================
Usage:
The typical command for running the pipeline is as follows:
nextflow run ikmb-denbi/genome-annotation --genome 'Genome.fasta' --proteins 'Proteins.fasta' --reads 'data/*_R{1,2}.fastq' -c nextflow.config
Mandatory arguments:
--genome Genome reference
At least one of:
--proteins Proteins from other species
--ESTs ESTs or transcriptome
--reads Path to RNA-seq data (must be surrounded with quotes)
Options:
-profile Hardware config to use (optional, will default to 'standard')
Programs to run:
--trinity Run transcriptome assembly with Trinity and produce hints from the transcripts [ true (default) | false ]
--augustus Run Augustus to predict genes [ true (default) | false ]
--training Run de novo model training for Augustus with complete proteins (from Pasa + Transdecoder). Only if RNA-seq data provided. [ true | false ]. You must provide a name for your model with "--model". If you use the name of an existing model, this will be re-trained.
--pasa Run the transcriptome-based gene builder PASA (also required when running --training). [ true | false (default) ]. Requires --ESTs and/or --reads with --trinity.
Programs parameters:
--rm_species Species database for RepeatMasker [ default = 'mammal' ]
--rm_lib Additional repeatmasker library in FASTA format [ default = 'false' ]
--train_perc What percentage of complete proteins (from Pasa + Transdecoder) should be used for training. The rest will be used for testing model accuracy [ default = 90 ]]
--training_models How many PASA gene models to select for training [ default = 1000 ]
--model Species model for Augustus [ default = 'human' ]. If "--training true" and you want to do de novo training, give a NEW name to your species
--augCfg Location of augustus configuration file [ default = 'bin/augustus_default.cfg' ]
--max_intron_size Maximum length of introns to consider for spliced alignments [ default = 20000 ]
--evm Whether to run EvicenceModeler at the end to produce a consensus gene build [true | false (default) ]
--evm_weights Custom weights file for EvidenceModeler (overrides the internal default)
Evidence tuning
--pri_prot A positive number between 1 and 5 - the higher, the more important the hint is for gene calling (default: 5)
--pri_est A positive number between 1 and 5 - the higher, the more important the hint is for gene calling (default: 3)
--pri_rnaseq A positive number between 1 and 5 - the higher, the more important the hint is for gene calling (default: 4)
How to split programs:
--nblast Chunks (# of sequences) to divide genome for blastx jobs [ default = 100 ]
--nexonerate Chunks (# of blast hits) to divide Exonerate jobs [ default = 200 ]
--nchunks Chunks (# of scaffolds) to divide RepeatMasker and Augustus jobs [ default = 30 ]
--chunk_size Size of sub-regions of the genome on which to run Blastx jobs [ default = 50000 ]
Other options:
--singleEnd Specifies that the input is single end reads [ true | false (default) ]
--rnaseq_stranded Whether the RNAseq reads were sequenced using a strand-specific method (dUTP) [ true | false (default) ]
--outdir The output directory where the results will be saved [ default = 'output' ]
-name Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic.
""".stripIndent()
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// Show help message
if (params.help){
helpMessage()
exit 0
}
// -----------------------------
// Validate and set input options
// -----------------------------
OUTDIR = params.outdir
pasa_config = "${baseDir}/assets/pasa/alignAssembly.config"
evm_weights = params.evm_weights ?: "${baseDir}/assets/evm/weights.txt"
EVM_WEIGHTS = file(evm_weights)
uniprot_path = "${baseDir}/assets/Eumetazoa_UniProt_reviewed_evidence.fa"
if (params.pasa) {
PASA_CONFIG = file(pasa_config)
if ( !PASA_CONFIG.exists()) exit 1; "Could not find the pasa config file that should be bundled with this pipeline, exiting..."
}
Uniprot = file(uniprot_path)
if ( !Uniprot.exists()) exit 1; "Could not find the Uniprot data that should be bundled with this pipeline, exiting...."
Genome = file(params.genome)
if( !Genome.exists() || !params.genome ) exit 1; "No genome assembly found, please specify with --genome"
if (params.proteins) {
Proteins = file(params.proteins)
if( !Proteins.exists() ) exit 1, "Protein file not found: ${Proteins}. Specify with --proteins."
}
if ( params.ESTs ){
ESTs = file(params.ESTs)
if( !ESTs.exists() ) exit 1, "ESTs file not found: ${ESTs}. Specify with --ESTs."
}
if (params.rm_lib) {
RM_LIB = file(params.rm_lib)
if (!RM_LIB.exists() ) exit 1, "Repeatmask library does not exist (--rm_lib)!"
if (params.rm_species) {
println "Provided both a custom repeatmask library (--rm_lib) AND a species/taxonomic group for RM - will only use the library!"
}
}
// Make it fail if basic requirements are unmet
if (!binding.variables.containsKey("Proteins") && !binding.variables.containsKey("ESTs") && params.reads == false) {
exit 1, "At least one type of input data must be specified (--proteins, --ESTs, --reads)"
}
if (params.trinity && !params.reads ) {
exit 1, "Cannot run Trinity de-novo assembly without RNA-seq reads (specify both --reads and --trinity)"
}
// Use a default config file for Augustus if none is provided
if (params.augustus && !params.augCfg ) {
AUG_CONF = "$workflow.projectDir/assets/augustus/augustus_default.cfg"
} else if (params.augustus) {
AUG_CONF = file(params.augCfg)
}
// Check prereqs for training a new model
if (params.training && !params.model) {
exit 1; "You requested for a new prediction profile to be trained, but did not provide a name for the model (--model)"
} else if (params.training && !params.trinity && !params.ESTs) {
exit 1; "You requested for a new prediction profile to be trained, but we need transcriptome data for that (--trinity and/or --ESTs)"
} else if (params.training && !params.pasa) {
println "You requested a model to be trained; this requires Pasa to be enabled. We will do that for your now..."
params.pasa = true
}
// Check if we can run EVM
if (params.evm && !params.augustus && !params.pasa) {
exit 1; "Requested to run EvidenceModeler, but we need gene models for that (--augustus and/or --pasa)."
}
//Check if we can run Pasa
if (params.pasa && !params.ESTs && !params.trinity) {
exit 1; "Requested to run Pasa, but we need transcriptome data for that (--ESTs or --trinity)"
}
// Check prereqs for repeatmasking
if (!params.rm_lib && !params.rm_species) {
println "No repeat library provided, will model repeats de-novo instead using RepeatModeler."
}
// give this run a name
run_name = ( !params.run_name) ? "${workflow.sessionId}" : "${params.run_name}"
def summary = [:]
summary['Assembly'] = params.genome
summary['ESTs'] = params.ESTs
summary['Proteins'] = params.proteins
summary['RNA-seq'] = params.reads
summary['RM species'] = params.rm_species
summary['RM library'] = params.rm_lib
summary['Augustus model'] = params.model
summary['ModelTraining'] = params.training
// ----------------------
// ----------------------
// Starting the pipeline
// ----------------------
// ----------------------
// --------------------------
// Set various input channels
// --------------------------
Channel.fromPath(Genome)
.set { GenomeHisat }
// Split the genome for parallel processing
Channel
.fromPath(Genome)
.set { genome_for_splitting }
// if proteins are provided
if (params.proteins ) {
// goes to blasting of proteins
Channel
.fromPath(Proteins)
.set { protein_to_blast_db }
// create a cdbtools index for the protein file
Channel
.fromPath(Proteins)
.set { index_prots }
} else {
prot_exonerate_hints = Channel.empty()
// Protein Exonerate files to EVM
exonerate_protein_evm = Channel.empty()
}
// if ESTs are provided
if (params.ESTs) {
// goes to blasting the ESTs
Channel
.fromPath(ESTs)
.set {fasta_ests}
// create a cdbtools index for the EST file
Channel
.fromPath(ESTs)
.into { ests_index; est_to_pasa }
} else {
// EST hints to Augustus
est_minimap_hints = Channel.empty()
// EST file to Pasa assembly
est_to_pasa = Channel.empty()
// EST exonerate files to EVM
minimap_ests_to_evm = Channel.empty()
}
// if RNAseq reads are provided
if (params.reads) {
// Make a HiSat index
Channel
.fromPath(Genome)
.set { inputMakeHisatdb }
// Pass reads to trimming
Channel
.fromFilePairs( params.reads, size: params.singleEnd ? 1 : 2 )
.ifEmpty { exit 1, "Cannot find any reads matching: ${params.reads}\nNB: Path needs to be enclosed in quotes!\nIf this is single-end data, please specify --singleEnd on the command line." }
.set {read_files_trimming }
// can use reads without wanting to run a de-novo transcriptome assembly
if (!params.trinity) {
trinity_minimap_hints = Channel.empty()
minimap_trinity_to_evm = Channel.empty()
trinity_to_pasa = Channel.empty()
}
} else {
// Trinity hints to Augustus
trinity_minimap_hints = Channel.empty()
// RNAseq hints to Augustus
rnaseq_hints = Channel.empty()
// Trinity assembly to Pasa assembly
trinity_to_pasa = Channel.empty()
// Trinity exonerate files to EVM
minimap_trinity_to_evm = Channel.empty()
}
if (!params.pasa) {
// Pasa data to EVM
pasa_genes_to_evm = Channel.empty()
pasa_align_to_evm = Channel.empty()
}
// Trigger de-novo repeat prediction if no repeats were provided
if (!params.rm_lib && !params.rm_species ) {
Channel
.fromPath(Genome)
.set { inputRepeatModeler }
} else {
repeats_fa = Channel.empty()
}
// Provide the path to the augustus config folder
// If it's in a container, use the hard-coded path, otherwise the augustus env variable
if (!workflow.containerEngine) {
Channel.from(file(System.getenv('AUGUSTUS_CONFIG_PATH')))
.ifEmpty { exit 1; "Looks like the Augustus config path is not set? This shouldn't happen!" }
.set { augustus_config_folder }
} else {
// this is a bit dangerous, need to make sure this is updated when we bump to the next release version
Channel.from(file("/opt/conda/envs/genome-annotation-1.0/config"))
.set { augustus_config_folder }
}
// Header log info
log.info "========================================="
log.info "ESGA Genome Annotation Pipeline v${workflow.manifest.version}"
log.info "Genome assembly: ${params.genome}"
if (params.rm_lib) {
log.info "Repeatmasker lib: ${params.rm_lib}"
} else if (params.rm_species) {
log.info "Repeatmasker species: ${params.rm_species}"
} else {
log.info "Repeatmasking: Compute de-novo"
}
log.info "-----------------------------------------"
log.info "Evidences:"
log.info "Proteins: ${params.proteins}"
log.info "ESTs: ${params.ESTs}"
log.info "RNA-seq: ${params.reads}"
if (params.augustus) {
log.info "Augustus profile ${params.model}"
}
if (params.augustus && AUG_CONF) {
log.info "Augustus config file ${AUG_CONF}"
}
if (params.training) {
log.info "Model training: yes (${params.model})"
}
log.info "-----------------------------------------"
log.info "Parallelization settings"
log.info "Chunk size for assembly: ${params.chunk_size}"
log.info "Chunk size for Blast: ${params.nblast}"
log.info "Chunk size for Exonerate: ${params.nexonerate}"
log.info "Chunk size for RepeatMasker: ${params.nchunks}"
log.info "-----------------------------------------"
log.info "Nextflow Version: $workflow.nextflow.version"
log.info "Command Line: $workflow.commandLine"
log.info "Run name: ${params.run_name}"
log.info "========================================="
def check_file_size(fasta) {
if (file(fasta).isEmpty()) {
log.info "No repeats were modelled, will use the built-in repeat library that ships with RepeatMasker"
}
}
// *******************************************
// Split Genome in parts of roughly equal size
// *******************************************
process splitGenome {
input:
file(genome_fa) from genome_for_splitting
output:
file("*_chunk_*") into fasta_chunks
script:
ref_name = genome_fa.getBaseName() + "_chunk_%3.3d"
"""
fastasplitn -in $genome_fa -n ${params.nchunks} -t $ref_name
"""
}
// We split the list of chunks into channel emissions
fasta_chunk_for_rm_lib = fasta_chunks.flatMap()
// ************************************
// Model Repeats if nothing is provided
// ************************************
if (!params.rm_lib && !params.rm_species) {
process repeatModel {
publishDir "${OUTDIR}/repeatmodeler/", mode: 'copy'
scratch true
input:
file(genome_fa) from inputRepeatModeler
output:
file(repeats) into (repeats_fa, check_repeats)
script:
repeats = "consensi.fa"
"""
BuildDatabase -name genome_source -engine ncbi $genome_fa
RepeatModeler -engine ncbi -pa ${task.cpus} -database genome_source
cp RM_*/consensi.fa .
"""
}
// Let the user know if the repeat search was unsuccesful
check_repeats
.filter { fasta -> check_file_size(fasta) }
.set { checked_repeats }
}
// ---------------------------
// RUN REPEATMASKER
//----------------------------
// RepeatMasker library needs ot be writable. Need to do this so we can work with locked containers
process repeatLib {
label 'short_running'
publishDir "${OUTDIR}/repeatmasker/", mode: 'copy'
output:
file("Library") into RMLibPath
script:
if (params.rm_lib) {
"""
cp ${baseDir}/assets/repeatmasker/my_genome.fa .
cp ${baseDir}/assets/repeatmasker/repeats.fa .
mkdir -p Library
cp ${baseDir}/assets/repeatmasker/DfamConsensus.embl Library/
gunzip -c ${baseDir}/assets/repeatmasker/taxonomy.dat.gz > Library/taxonomy.dat
export REPEATMASKER_LIB_DIR=\$PWD/Library
RepeatMasker -lib repeats.fa my_genome.fa > out
"""
} else {
"""
mkdir -p Library
cp ${baseDir}/assets/repeatmasker/DfamConsensus.embl Library/
gunzip -c ${baseDir}/assets/repeatmasker/taxonomy.dat.gz > Library/taxonomy.dat
"""
}
}
// To get the repeat library path combined with each genome chunk, we do this...
// toString() is needed as RM touches the location each time it runs and thus modifies it.
rm_lib_path = RMLibPath
.map { it.toString() }
.combine(fasta_chunk_for_rm_lib)
// generate a soft-masked sequence for each assembly chunk
// if nothing was masked, return the original genome sequence instead and an empty gff file.
process repeatMask {
//scratch true
publishDir "${OUTDIR}/repeatmasker/chunks"
input:
file(repeats) from repeats_fa.collect().ifEmpty('')
set env(REPEATMASKER_LIB_DIR),file(genome_fa) from rm_lib_path
output:
file(genome_rm) into RMFastaChunks
file(genome_rm) into (genome_to_minimap_chunk,genome_chunk_to_augustus)
file(rm_gff) into RMGFF
set file(rm_gff),file(rm_tbl),file(rm_out)
script:
def options = ""
if (params.rm_lib) {
options = "-lib $params.rm_lib"
} else if (params.rm_species) {
options = "-species $params.rm_species"
} else {
if (repeats.size() == 0) {
options = "-species eukaryota"
} else {
options = "-lib $repeats"
}
}
genome_rm = "${genome_fa.getName()}.masked"
rm_gff = "${genome_fa.getName()}.out.gff"
rm_tbl = "${genome_fa.getName()}.tbl"
rm_out = "${genome_fa.getName()}.out"
"""
echo \$REPEATMASKER_LIB_DIR > lib_dir.txt
RepeatMasker $options -gff -xsmall -q -pa ${task.cpus} $genome_fa
test -f ${genome_rm} || cp $genome_fa $genome_rm && touch $rm_gff
"""
}
// Merge the repeat-masked assembly chunks
process repeatMerge {
label 'short_running'
publishDir "${OUTDIR}/repeatmasker", mode: 'copy'
input:
file(genome_chunks) from RMFastaChunks.collect()
output:
file(masked_genome) into (rm_to_blast_db, rm_to_partition)
set file(masked_genome),file(masked_genome_index) into (RMGenomeIndexProtein, genome_to_trinity_minimap, genome_to_pasa, genome_to_evm, genome_to_evm_merge, RMGenomeMinimapEst, genome_to_minimap_pasa)
script:
masked_genome = "${Genome.baseName}.rm.fa"
masked_genome_index = masked_genome + ".fai"
"""
cat $genome_chunks >> merged.fa
fastasort -f merged.fa > $masked_genome
samtools faidx $masked_genome
rm merged.fa
"""
}
// ---------------------
// PROTEIN DATA PROCESSING
// ---------------------
if (params.proteins) {
// ----------------------------
// Protein BLAST against genome
// ----------------------------
// Split the genome into smaller chunks for Blastx
process prepSplitAssembly {
publishDir "${OUTDIR}/databases/genome/", mode: 'copy'
label 'short_running'
input:
file(genome_fa) from rm_to_blast_db
output:
file(genome_chunks) into genome_chunks_blast
file(genome_agp) into genome_chunks_agp
script:
genome_chunks = genome_fa + ".chunk"
genome_agp = genome_fa + ".agp"
"""
chromosome_chunk.pl -fasta_file $genome_fa -size $params.chunk_size
"""
}
genome_chunks_blast_split = genome_chunks_blast.splitFasta(by: params.nblast, file: true)
// Make a blast database
process protMakeDB {
label 'medium_running'
publishDir "${OUTDIR}/databases/blast/", mode: 'copy'
input:
file(protein_fa) from protein_to_blast_db
output:
file("${dbName}.dmnd") into blast_db_prots
script:
dbName = protein_fa.getBaseName()
"""
diamond makedb --in $protein_fa --db $dbName
"""
}
// create a cdbtools compatible index
// we need this to do very focused exonerate searches later
process protIndex {
label 'short_running'
publishDir "${OUTDIR}/databases/cdbtools/proteins", mode: 'copy'
input:
file(fasta) from index_prots
output:
set file(fasta),file(protein_index) into ProteinDB
script:
protein_index = fasta.getName()+ ".cidx"
"""
cdbfasta $fasta
"""
}
// Blast each genome chunk against the protein database
// This is used to define targets for exhaustive exonerate alignments
process protDiamondx {
publishDir "${OUTDIR}/evidence/proteins/blastx/chunks", mode: 'copy'
scratch true
input:
file(genome_chunk) from genome_chunks_blast_split
file(blastdb_files) from blast_db_prots.collect()
output:
file(protein_blast_report) into ProteinBlastReport
script:
db_name = blastdb_files[0].baseName
chunk_name = genome_chunk.getName().tokenize('.')[-2]
protein_blast_report = "${genome_chunk.baseName}.blast"
"""
diamond blastx --sensitive --threads ${task.cpus} --evalue ${params.blast_evalue} --outfmt ${params.blast_options} --db $db_name --query $genome_chunk --out $protein_blast_report
"""
}
// Parse Protein Blast output for exonerate processing
process protDiamondToTargets {
label 'short_running'
publishDir "${OUTDIR}/evidence/proteins/tblastn/chunks", mode: 'copy'
input:
file(blast_reports) from ProteinBlastReport.collect()
file(genome_agp) from genome_chunks_agp
output:
file(query2target_result_uniq_targets) into query2target_uniq_result_prots
script:
query_tag = Proteins.baseName
query2target_result_uniq_targets = "${query_tag}.targets"
"""
cat $blast_reports > merged.txt
blast_chunk_to_toplevel.pl --blast merged.txt --agp $genome_agp > merged.translated.txt
blast2exonerate_targets.pl --infile merged.translated.txt --max_intron_size $params.max_intron_size > $query2target_result_uniq_targets
rm merged.*.txt
"""
}
// split Blast hits for parallel processing in exonerate
query2target_uniq_result_prots
.splitText(by: params.nexonerate, file: true)
.combine(ProteinDB)
.set{ query2target_chunk_prots }
// Run Exonerate on the blast regions
process protExonerate {
publishDir "${OUTDIR}/evidence/proteins/exonerate/chunks", mode: 'copy'
//scratch true
input:
set file(hits_chunk),file(protein_db),file(protein_db_index) from query2target_chunk_prots
set file(genome),file(genome_faidx) from RMGenomeIndexProtein
output:
file(exonerate_chunk) into (exonerate_result_prots, exonerate_protein_chunk_evm)
file(commands)
script:
query_tag = protein_db.baseName
chunk_name = hits_chunk.getName().tokenize('.')[-2]
commands = "commands." + chunk_name + ".txt"
exonerate_chunk = "${hits_chunk.baseName}.${query_tag}.exonerate.out"
// get the protein fasta sequences, produce the exonerate command and genomic target interval fasta, run the whole thing,
// merge it all down to one file and translate back to genomic coordinates
// remove all the untracked intermediate files
"""
extractMatchTargetsFromIndex.pl --matches $hits_chunk --db $protein_db_index
exonerate_from_blast_hits.pl --matches $hits_chunk --assembly_index $genome --max_intron_size $params.max_intron_size --query_index $protein_db_index --analysis protein2genome --outfile $commands
parallel -j ${task.cpus} < $commands
echo "Finished exonerate run" >> log.txt
echo "# from ${chunk_name}" > merged.${chunk_name}.exonerate.out ;
cat *.exonerate.align | grep -v '#' | grep 'exonerate:protein2genome:local' >> merged.${chunk_name}.exonerate.out 2>/dev/null
echo "Finished merging exonerate alignments" >> log.txt
exonerate_offset2genomic.pl --infile merged.${chunk_name}.exonerate.out --outfile $exonerate_chunk
echo "Finished translating genomic coordinates" >> log.txt
test -f $exonerate_chunk || cat "#" > $exonerate_chunk
"""
}
exonerate_protein_evm = exonerate_protein_chunk_evm.collectFile()
// merge the exonerate hits and create the hints
process protExonerateToHints {
label 'medium_running'
publishDir "${OUTDIR}/evidence/proteins/exonerate/", mode: 'copy'
input:
file(chunks) from exonerate_result_prots.collect()
output:
file(exonerate_gff) into prot_exonerate_hints
script:
query_tag = Proteins.baseName
exonerate_gff = "proteins.exonerate.${query_tag}.hints.gff"
"""
cat $chunks > all_chunks.out
exonerate2gff.pl --infile all_chunks.out --pri ${params.pri_prot} --source protein --outfile $exonerate_gff
"""
}
} // close protein loop
// --------------------------
// -------------------
// EST DATA PROCESSING
//-------------------
// --------------------------
if (params.ESTs) {
/*
* EST alignment
*/
// Align all ESTs against the masked genome
process estMinimap {
publishDir "${OUTDIR}/evidence/EST/minimap", mode: 'copy'
scratch true
input:
file(est_chunks) from fasta_ests
set file(genome_rm),file(genome_index) from RMGenomeMinimapEst
output:
file(minimap_gff) into (minimap_est_gff, minimap_ests_to_evm)
script:
minimap_gff = "ESTs.minimap.gff"
minimap_bam = "ESTS.minimap.bam"
"""
minimap2 -t ${task.cpus} -ax splice:hq -c -G ${params.max_intron_size} $genome_rm $est_chunks | samtools sort -O BAM -o $minimap_bam
minimap2_bam2gff.pl $minimap_bam > $minimap_gff
"""
}
// Combine exonerate hits and generate hints
process estMinimapToHints {
label 'short_running'
publishDir "${OUTDIR}/evidence/EST/minimap/", mode: 'copy'
input:
file(minimap_gff) from minimap_est_gff
output:
file(minimap_hints) into est_minimap_hints
script:
minimap_hints = "ESTs.minimap.hints.gff"
"""
minimap2hints.pl --source est2genome --pri ${params.pri_est} --infile $minimap_gff --outfile $minimap_hints
"""
}
} // close EST loop
// ++++++++++++++++++
// RNA-seq PROCESSING
// ++++++++++++++++++
if (params.reads) {
// trim reads
process rseqTrim {
publishDir "${OUTDIR}/evidence/rnaseq/fastp", mode: 'copy'
scratch true
input:
set val(name), file(reads) from read_files_trimming
output:
file("*_trimmed.fastq.gz") into trimmed_reads
set file(json),file(html) into trimmed_reads_qc
script:
prefix = reads[0].toString().split("_R1")[0]
json = prefix + ".fastp.json"
html = prefix + ".fastp.html"
if (params.singleEnd) {
left = file(reads[0]).getBaseName() + "_trimmed.fastq.gz"
"""
fastp -i ${reads[0]} --out1 ${left} -w ${task.cpus} -j $json -h $html
"""
} else {
left = file(reads[0]).getBaseName() + "_trimmed.fastq.gz"
right = file(reads[1]).getBaseName() + "_trimmed.fastq.gz"
"""
fastp --detect_adapter_for_pe --in1 ${reads[0]} --in2 ${reads[1]} --out1 $left --out2 $right -w ${task.cpus} -j $json -h $html
"""
}
}
// Generate an alignment index from the genome sequence
process rseqMakeDB {
label 'long_running'
publishDir "${OUTDIR}/databases/HisatDB", mode: 'copy'
input:
file(genome) from inputMakeHisatdb
output:
file "${dbName}.*.ht2" into hs2_indices
script:
dbName = genome.baseName
dbName_1 = dbName + ".1.ht2"
prefix = dbName
"""
hisat2-build $genome $dbName -p ${task.cpus}
"""
}
/*
* STEP RNAseq.3 - Hisat2
*/
process rseqMap {
publishDir "${OUTDIR}/evidence/rnaseq/Hisat2/libraries", mode: 'copy'
scratch true
input:
file reads from trimmed_reads
file hs2_indices from hs2_indices.collect()
output:
file "*accepted_hits.bam" into accepted_hits2merge
script:
indexBase = hs2_indices[0].toString() - ~/.\d.ht2/
ReadsBase = reads[0].toString() - ~/(_R1)?(_trimmed)?(_val_1)?(\.fq)?(\.fastq)?(\.gz)?$/
prefix = ReadsBase
if (params.singleEnd) {
"""
hisat2 -x $indexBase -U $reads -p ${task.cpus} | samtools view -bS - | samtools sort -m 2G -@ 4 - > ${prefix}_accepted_hits.bam
"""
} else {
"""
hisat2 -x $indexBase -1 ${reads[0]} -2 ${reads[1]} -p ${task.cpus} | samtools view -bS - | samtools sort -m 2G -@4 - > ${prefix}_accepted_hits.bam
"""
}
}
// Combine all BAM files for hint generation
process rseqMergeBams {
publishDir "${OUTDIR}/evidence/rnaseq/Hisat2", mode: 'copy'
scratch true
input:
file hisat_bams from accepted_hits2merge.collect()
output:
file(bam) into (Hisat2Hints, bam2trinity)
script:
bam = "hisat2.merged.bam"
avail_ram_per_core = (task.memory/task.cpus).toGiga()-1
"""
samtools merge - $hisat_bams | samtools sort -@ ${task.cpus} -m${avail_ram_per_core}G - > $bam
"""
}
/*
* STEP RNAseq.4 - Hisat2 into Hints
*/
process rseqHints {
publishDir "${OUTDIR}/evidence/rnaseq/hints", mode: 'copy'
input:
file(bam) from Hisat2Hints
output:
file(hisat_hints) into rnaseq_hints
script:
hisat_hints = "RNAseq.hisat.hints.gff"
"""
bam2hints --intronsonly 0 -p ${params.pri_rnaseq} -s 'E' --in=$bam --out=$hisat_hints
"""
}
// ----------------------------
// run trinity de-novo assembly
// ----------------------------
if (params.trinity) {
process rseqTrinity {
publishDir "${OUTDIR}/evidence/rnaseq/trinity", mode: 'copy'
scratch true
input:
file(hisat_bam) from bam2trinity
output:
file "transcriptome_trinity/Trinity-GG.fasta" into (trinity_transcripts, trinity_to_minimap , trinity_to_pasa)
script:
trinity_option = ( params.rnaseq_stranded == true ) ? "--SS_lib_type RF" : ""
"""
Trinity --genome_guided_bam $hisat_bam \
--genome_guided_max_intron ${params.max_intron_size} \
--CPU ${task.cpus} \
--max_memory ${task.memory.toGiga()-1}G \
--output transcriptome_trinity \
$trinity_option
"""
}
process rseqMinimapTrinity {
publishDir "${OUTDIR}/evidence/rnaseq/trinity", mode: 'copy'
input:
file(trinity_fasta) from trinity_to_minimap
set file(genome_rm),file(genome_index) from genome_to_trinity_minimap
output:
file(trinity_gff) into (minimap_trinity_gff,minimap_trinity_to_evm)
script:
trinity_gff = "trinity.minimap.gff"
"""
minimap2 -t ${task.cpus} -ax splice:hq -c $genome_rm $trinity_fasta | samtools sort -O BAM -o minimap.bam
minimap2_bam2gff.pl minimap.bam > $trinity_gff
"""
}
process rseqTrinityToHints {
label 'short_running'
publishDir "${OUTDIR}/evidence/EST/minimap/", mode: 'copy'
input:
file(trinity_gff) from minimap_trinity_gff
output:
file(minimap_hints) into trinity_minimap_hints
script:
minimap_hints = "trinity.minimap.hints.gff"
"""
minimap2hints.pl --source est2genome --pri ${params.pri_est} --infile $trinity_gff --outfile $minimap_hints
"""
}
} // Close Trinity loop
} // Close RNAseq loop
/*
* RUN PASA WITH TRANSCRIPTS
*/
if (params.pasa) {
// use trinity transcripts, ESTs or both
if (params.trinity != false || params.ESTs != false ) {
// Clean transcripts
// This is a place holder until we figure out how to make Seqclean work within Nextflow
process transSeqclean {
label 'short_running'
publishDir "${OUTDIR}/evidence/rnaseq/pasa/seqclean/", mode: 'copy'
input:
file(trinity) from trinity_to_pasa.ifEmpty('')