This repository has been archived by the owner on Mar 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.nf
1903 lines (1678 loc) · 79.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
/*
========================================================================================
nf-core/predictorthologs
========================================================================================
nf-core/predictorthologs Analysis Pipeline.
#### Homepage / Documentation
https://github.com/nf-core/predictorthologs
----------------------------------------------------------------------------------------
*/
def helpMessage() {
// TODO nf-core: Add to this help message with new command line parameters
log.info nfcoreHeader()
log.info"""
Usage:
The typical command for running the pipeline is as follows:
nextflow run nf-core/predictorthologs --reads '*_R{1,2}.fastq.gz' -profile docker
Mandatory arguments:
-profile [str] Configuration profile to use. Can use multiple (comma separated)
Available: conda, docker, singularity, test, awsbatch, <institute> and more
Input Options:
Sequencing reads (FASTQ format):
--reads [file] Path to input data (must be surrounded with quotes)
--csv Comma-separated variable file containing the columns "sample_id" and "fasta" at minimum
For differential hash expression, the columns "sig" and "group" are also required
Protein input:
--protein_fastas Path to protein fastas
Bam + bed file for intersection:
--bam Path to a single bam file whose reads to intersect with the bed
--bai Path to the above bam's bai index file, required for intersection
--bed Path to a bed file containing regions of interest in the bam file
hash2kmer options:
--hashes Path to file of hashes whose sequence to find in the protein fastas, default None
--sourmash_ksize K-mer size to use to find matching k-mers in sequence, default 21
--sourmash_molecule Molecule type to use to find matching k-mers in sequence, default "protein"
Differential hash expression options:
--diff_hash_expression If provided, compute enriched hashes in groups using logistic regression, by default don't do it
This requires the --csv option and additional columns of "group" and "sig" in the csv
--csv_has_is_aligned If provided, then the --csv provided has a column named "is_aligned" that can be used to
partition the signatures and differential hashes into aligned/unaligned bins
Options:
--single_end [bool] Specifies that the input is single-end reads
--skip_remove_duplicates_bam If provided, skip removal of duplicates from bam file
BLAST-like protein search options If not specified in the configuration file or you wish to overwrite any of the references
--refseq_release Valid terms from ftp://ftp.ncbi.nlm.nih.gov/refseq/release/,
e.g. "complete", "archea", "plasmid", "protozoa", "viral".
Default is "vertebrate_mammalian"
--diamond_protein_fasta Use all of manually curated, verified UniProt/SwissProt as the reference
proteome for searching for orthologs
--diamond_database Pre-created database with DIAMOND
--diamond_taxonmap_gz Mapping of protein IDs to taxa
Default is: "ftp://ftp.ncbi.nlm.nih.gov/pub/taxonomy/accession2taxid/prot.accession2taxid.gz"
--diamond_taxdmp_zip Taxonomy dump file from NCBI
Default is: "ftp://ftp.ncbi.nlm.nih.gov/pub/taxonomy/taxdmp.zip"
Other options:
--outdir [file] The output directory where the results will be saved
--email [email] Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits
--email_on_fail [email] Same as --email, except only send mail if the workflow is not successful
--max_multiqc_email_size [str] Theshold size for MultiQC report to be attached in notification email. If file generated by pipeline exceeds the threshold, it will not be attached (Default: 25MB)
-name [str] Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic
AWSBatch options:
--awsqueue [str] The AWSBatch JobQueue that needs to be set when running on AWSBatch
--awsregion [str] The AWS Region for your AWS Batch job to run on
--awscli [str] Path to the AWS CLI tool
""".stripIndent()
}
// Show help message
if (params.help) {
helpMessage()
exit 0
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// Check if genome exists in the config file
if (params.genomes && params.genome && !params.genomes.containsKey(params.genome)) {
exit 1, "The provided genome '${params.genome}' is not available in the iGenomes file. Currently the available genomes are ${params.genomes.keySet().join(", ")}"
}
// TODO nf-core: Add any reference files that are needed
// Configurable reference genomes
//
// NOTE - THIS IS NOT USED IN THIS PIPELINE, EXAMPLE ONLY
// If you want to use the channel below in a process, define the following:
// input:
// file fasta from ch_fasta
//
params.fasta = params.genome ? params.genomes[ params.genome ].fasta ?: false : false
if (params.fasta) { ch_fasta = file(params.fasta, checkIfExists: true) }
// Has the run name been specified by the user?
// this has the bonus effect of catching both -name and --name
custom_runName = params.name
if (!(workflow.runName ==~ /[a-z]+_[a-z]+/)) {
custom_runName = workflow.runName
}
////////////////////////////////////////////////////
/* -- AWS -- */
////////////////////////////////////////////////////
if (workflow.profile.contains('awsbatch')) {
// AWSBatch sanity checking
if (!params.awsqueue || !params.awsregion) exit 1, "Specify correct --awsqueue and --awsregion parameters on AWSBatch!"
// Check outdir paths to be S3 buckets if running on AWSBatch
// related: https://github.com/nextflow-io/nextflow/issues/813
if (!params.outdir.startsWith('s3:')) exit 1, "Outdir not on S3 - specify S3 Bucket to run on AWSBatch!"
// Prevent trace files to be stored on S3 since S3 does not support rolling files.
if (params.tracedir.startsWith('s3:')) exit 1, "Specify a local tracedir or run without trace! S3 cannot be used for tracefiles."
}
// Stage config files
ch_multiqc_config = file("$baseDir/assets/multiqc_config.yaml", checkIfExists: true)
ch_multiqc_custom_config = params.multiqc_config ? Channel.fromPath(params.multiqc_config, checkIfExists: true) : Channel.empty()
ch_output_docs = file("$baseDir/docs/output.md", checkIfExists: true)
////////////////////////////////////////////////////
/* -- Parse input reads -- */
////////////////////////////////////////////////////
if (params.hashes) {
Channel.fromPath(params.hashes)
.ifEmpty { exit 1, "params.hashes was empty - no input files supplied" }
.splitText()
.map{ row -> tuple("hash", row.replaceAll("\\s+", "") )}
.transpose()
.dump( tag: 'ch_hash_to_group' )
.into { ch_hash_to_group_for_joining; ch_hash_to_group_for_hash2kmer }
ch_hash_to_group_for_hash2kmer
.map{ it -> it[1] }
.into{ ch_hashes_for_hash2kmer; ch_hashes_for_hash2sig }
}
if (params.bam && params.bed && params.bai && !(params.reads || params.readPaths )) {
// params needed for intersection
log.info "supplied bam, not looking at any supplied --reads"
Channel.fromPath(params.bai)
.ifEmpty { exit 1, "params.bai was empty - no input files supplied" }
.set { ch_bai }
Channel.fromPath(params.bam)
.ifEmpty { exit 1, "params.bam was empty - no input files supplied" }
.combine(ch_bai)
.set { ch_bam_bai }
Channel.fromPath(params.bed)
.ifEmpty { exit 1, "params.bed was empty - no input files supplied" }
.splitText()
.map {row -> row.split()}
.map { row -> [ row[3], row[0], row[1], row[2] ] } // get interval name, chrm, start and stop
.combine(ch_bam_bai)
.dump ( tag: 'ch_bam_bai' )
.set {ch_bed_bam_bai}
} else if (params.bam && !params.skip_remove_duplicates_bam && !params.bai) {
// deciding if sambamba steps are needed
log.info "supplied bam and no skip_remove_duplicates flag specified"
Channel.fromPath(params.bam)
.ifEmpty { exit 1, "params.bam was empty, no input file supplied" }
.into { ch_bam_for_dedup }
} else if (params.input_is_protein) {
log.info 'Using protein fastas as input -- ignoring reads and bams'
////////////////////////////////////////////////////
/* -- Parse protein fastas -- */
////////////////////////////////////////////////////
if (params.protein_fastas){
Channel.fromPath(params.protein_fastas)
.ifEmpty { exit 1, "params.protein_fastas was empty - no input files supplied" }
.dump ( tag: 'ch_protein_fastas' )
.set { ch_protein_fastas }
} else if (params.csv && params.input_is_protein) {
// Provided a csv file mapping sample_id to protein fasta path
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row -> tuple(row.sample_id, tuple(file(row.fasta)))}
.ifEmpty { exit 1, "params.csv (${params.csv}) was empty - no input files supplied" }
.dump( tag: 'ch_protein_fastas__from_csv' )
.set { ch_protein_fastas }
} else if (params.protein_fasta_paths){
Channel
.from(params.protein_fasta_paths)
.map { row -> file(row[1][0], checkIfExists: true) }
.ifEmpty { exit 1, "params.protein_fasta_paths was empty - no input files supplied" }
.dump(tag: "protein_fasta_paths")
.set { ch_protein_fastas }
}
if (!(params.diff_hash_expression || params.hashes)) {
// No hashes - just do a diamond blastp search for each peptide fasta
// Not extracting the sequences containing hashes of interest
ch_protein_fastas
// add false for "hash" part
.map { it -> tuple(false,
file(it, checkIfExists: true).getBaseName(),
file(it, checkIfExists: true))
}
// filter for non empty fasta files
.filter { it -> it[2].size() > 0 }
.dump ( tag: 'ch_protein_fastas__ch_protein_seq_for_diamond' )
.set { ch_protein_seq_for_diamond }
}
} else {
// * Create a channel for input read files
if (params.csv && params.csv_has_reads) {
// Provided a csv file mapping sample_id to read(s) fastq path
log.info "supplied csv, not looking at any supplied --reads or readPaths"
if (params.single_end) {
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row -> tuple(row.sample_id, tuple(file(row.read1)))}
.ifEmpty { exit 1, "params.csv (${params.csv}) was empty - no input files supplied" }
.dump(tag: "reads_single_end")
.into { ch_read_files_fastqc; ch_read_files_trimming; ch_read_files_translate }
} else {
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row -> tuple(row.sample_id, tuple(file(row.read1), file(row.read2)))}
.ifEmpty { exit 1, "params.csv (${params.csv}) was empty - no input files supplied" }
.dump(tag: "reads_paired_end")
.into { ch_read_files_fastqc; ch_read_files_trimming; ch_read_files_translate }
}
} else if (params.readPaths){
log.info "supplied readPaths, not looking at any supplied --reads"
if (params.single_end) {
Channel
.from(params.readPaths)
.map { row -> [ row[0], [ file(row[1][0], checkIfExists: true) ] ] }
.ifEmpty { exit 1, "params.readPaths was empty - no input files supplied" }
.dump(tag: "reads_single_end")
.into { ch_read_files_fastqc; ch_read_files_trimming; ch_read_files_translate }
} else {
Channel
.from(params.readPaths)
.map { row -> [ row[0], [ file(row[1][0], checkIfExists: true), file(row[1][1], checkIfExists: true) ] ] }
.ifEmpty { exit 1, "params.readPaths was empty - no input files supplied" }
.dump(tag: "reads_paired_end")
.into { ch_read_files_fastqc; ch_read_files_trimming; ch_read_files_translate }
}
} else {
Channel
.fromFilePairs(params.reads, size: params.single_end ? 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 --single_end on the command line." }
.dump(tag: "read_paths")
.into { ch_read_files_fastqc; ch_read_files_trimming }
}
}
if (params.hashes){
Channel.fromPath(params.hashes)
.ifEmpty { exit 1, "params.hashes was empty - no input files supplied" }
.splitText()
.map{ row -> tuple(row.replaceAll("\\s+", ""), "hash" )}
.transpose()
.into { ch_hash_to_group_for_joining_after_hash2kmer;
ch_hash_to_group_for_joining_after_hash2sig;
ch_hash_to_group_for_hash2kmer;
ch_hash_to_group_for_hash2sig
}
ch_hash_to_group_for_hash2kmer
.map{ it -> it[0] }
.set{ ch_hashes_for_hash2kmer }
}
// Utility functions for sanitizing output
def groupCleaner(group) {
return group.replaceAll(' ', '_').replaceAll('/', '-slash-').toLowerCase()
}
def hashCleaner(hash) {
return hash.replaceAll('\\n', '')
}
////////////////////////////////////////////////////
/* -- Parse gene counting -- */
////////////////////////////////////////////////////
if (params.csv_has_is_aligned) {
if (params.csv) {
Channel
.fromPath ( params.csv )
.splitCsv ( header:true )
.branch { row ->
aligned: row.is_aligned == "aligned"
unaligned: row.is_aligned == "unaligned"
}
.set { ch_csv_is_aligned }
// Create channel of signatures per group
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.filter{ row -> row.is_aligned == 'unaligned' }
.ifEmpty { exit 1, "is_aligned column can contain only aligned/unaligned values"}
.dump( tag: 'csv_unaligned' )
.map{ row -> tuple(row.group, file(row.sig, checkIfExists: true)) }
.ifEmpty { exit 1, "params.csv (${params.csv}) 'group' or 'sig' column was empty" }
.groupTuple()
.dump( tag: 'ch_per_group_unaligned_sig' )
.set{ ch_per_group_unaligned_sig }
ch_csv_is_aligned.unaligned
.dump( tag: 'ch_csv_is_aligned.unaligned' )
.map{ row -> tuple(row.group, row.sample_id, row.sig, row.fasta) }
.dump( tag: 'ch_unaligned_sig_fasta' )
.into { ch_unaligned_sig_fasta }
} else {
exit 1, "Must provide --csv when doing filtering for aligned/unaligned hashes"
}
}
////////////////////////////////////////////////////
/* -- Parse differential hash expression -- */
////////////////////////////////////////////////////
if (params.diff_hash_expression) {
if (params.csv) {
// Create metadata csv channel
ch_csv = Channel.fromPath(params.csv)
// Create channel of all signatures, but a list within a list
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row -> file(row.sig, checkIfExists: true) }
.ifEmpty { exit 1, "params.csv (${params.csv}) 'sig' column was empty" }
.collect()
.map{ it -> [it] } // Nest within a list so the combine() step keeps all the signatures together
// [DUMP: ch_all_signatures_flat_list_for_diff_hash]
// [[MACA_24m_M_BM_60__unaligned__CCACCTAAGTCCAGGA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_BM_60__unaligned__AGTTGGTCAAATCCGT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P1_14__unaligned__ACGGCCAAGCGTTGCC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_BM_58__unaligned__CTAGTGAGTCCAACTA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_SPLEEN_59__unaligned__GCGACCAGTCATCGGC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P4_2__unaligned__GACGTTACACCCATGG_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_HEPATOCYTES_58__unaligned__GCAGCCAAGTAGCGGT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_21m_F_NPC_54__unaligned__CCCAGTTTCGTAGATC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P4_2__unaligned__ATCGAGTCACCAGTTA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P5_0__unaligned__TCCACACCACATTTCT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig]]
.dump( tag: "ch_all_signatures_flat_list_for_diff_hash" )
.into{ ch_all_signatures_flat_list_for_diff_hash }
// Create channel of all signatures, completely flattened
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row -> file(row.sig, checkIfExists: true) }
.ifEmpty { exit 1, "params.csv (${params.csv}) 'sig' column was empty" }
.collect()
.into{ ch_all_signatures_flattened_for_finding_matches }
// Create channel of fastas per group
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row -> tuple(row.group, file(row.fasta, checkIfExists: true)) }
.ifEmpty { exit 1, "params.csv (${params.csv}) 'fasta' column was empty" }
.groupTuple()
.dump( tag: 'ch_group_to_fasta' )
.set{ ch_group_to_fasta }
// Create channel of signatures per group
Channel
.fromPath(params.csv)
.splitCsv(header:true)
.map{ row -> tuple(row.group) }
.unique()
.ifEmpty { exit 1, "params.csv (${params.csv}) 'group' column was empty" }
.dump(tag: 'csv_unique_groups')
// [DUMP: csv_unique_groups] ['Mostly marrow unaligned']
// [DUMP: csv_unique_groups] ['Liver unaligned']
.combine( ch_all_signatures_flat_list_for_diff_hash )
.dump(tag: 'ch_groups_with_all_signatures_for_diff_hash')
// [DUMP: ch_groups_with_all_signatures_for_diff_hash]
// ['Mostly marrow unaligned',
// [MACA_24m_M_BM_60__unaligned__CCACCTAAGTCCAGGA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_BM_60__unaligned__AGTTGGTCAAATCCGT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P1_14__unaligned__ACGGCCAAGCGTTGCC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_BM_58__unaligned__CTAGTGAGTCCAACTA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_SPLEEN_59__unaligned__GCGACCAGTCATCGGC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P4_2__unaligned__GACGTTACACCCATGG_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_HEPATOCYTES_58__unaligned__GCAGCCAAGTAGCGGT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_21m_F_NPC_54__unaligned__CCCAGTTTCGTAGATC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P4_2__unaligned__ATCGAGTCACCAGTTA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P5_0__unaligned__TCCACACCACATTTCT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig]]
// [DUMP: ch_groups_with_all_signatures_for_diff_hash]
// ['Liver unaligned',
// [MACA_24m_M_BM_60__unaligned__CCACCTAAGTCCAGGA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_BM_60__unaligned__AGTTGGTCAAATCCGT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P1_14__unaligned__ACGGCCAAGCGTTGCC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_BM_58__unaligned__CTAGTGAGTCCAACTA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_SPLEEN_59__unaligned__GCGACCAGTCATCGGC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P4_2__unaligned__GACGTTACACCCATGG_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_24m_M_HEPATOCYTES_58__unaligned__GCAGCCAAGTAGCGGT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// MACA_21m_F_NPC_54__unaligned__CCCAGTTTCGTAGATC_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P4_2__unaligned__ATCGAGTCACCAGTTA_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig,
// 10X_P5_0__unaligned__TCCACACCACATTTCT_molecule-dayhoff_ksize-45_log2sketchsize-14_trackabundance-true.sig]]
.into { ch_groups_with_all_signatures_for_diff_hash }
// exit 1, "testing"
} else {
exit 1, "--csv is required for differential hash expression!"
}
}
////////////////////////////////////////////////////
/* -- Parse reference proteomes -- */
////////////////////////////////////////////////////
// --- Parse Translate parameters ---
save_translate_csv = params.save_translate_csv
save_translate_json = params.save_translate_json
if (params.proteome_translate_fasta) {
Channel.fromPath(params.proteome_translate_fasta, checkIfExists: true)
.ifEmpty { exit 1, "Peptide fasta file not found: ${params.proteome_translate_fasta}" }
.set{ ch_proteome_translate_fasta }
}
if (params.proteome_search_fasta) {
Channel.fromPath(params.proteome_search_fasta, checkIfExists: true)
.ifEmpty { exit 1, "Reference proteome fasta file not found: ${params.proteome_search_fasta}" }
.into{ ch_diamond_reference_fasta; ch_sourmash_reference_fasta }
}
if (params.taxonmap_gz) {
Channel.fromPath(params.taxonmap_gz, checkIfExists: true)
.ifEmpty { exit 1, "Diamond Taxon map file not found: ${params.taxonmap_gz}" }
.set{ ch_diamond_taxonmap_gz }
}
if (params.taxdmp_zip) {
Channel.fromPath(params.taxdmp_zip, checkIfExists: true)
.ifEmpty { exit 1, "Diamond taxon dump file not found: ${params.taxdmp_zip}" }
.set{ ch_diamond_taxdmp_zip }
}
if (params.diamond_database){
Channel.fromPath(params.diamond_database, checkIfExists: true)
.ifEmpty { exit 1, "Diamond database file not found: ${params.diamond_database}" }
.set{ ch_diamond_db }
}
if (params.sourmash_index){
Channel.fromPath(params.sourmash_index, checkIfExists: true)
.ifEmpty { exit 1, "Sourmash SBT Index file not found: ${params.sourmash_index}" }
.set{ ch_sourmash_index }
}
if (params.search_noncoding && params.infernal_db) {
if (hasExtension(params.infernal_db, 'gz')) {
Channel.fromPath(params.infernal_db, checkIfExists: true)
.ifEmpty { exit 1, "Infernal database file not found: ${params.infernal_db}" }
.set{ ch_infernal_db_gz }
} else {
Channel.fromPath(params.infernal_db, checkIfExists: true)
.ifEmpty { exit 1, "Infernal database file not found: ${params.infernal_db}" }
.set{ ch_infernal_db }
}
}
if (params.search_noncoding && params.rfam_clan_info){
Channel.fromPath(params.rfam_clan_info, checkIfExists: true)
.ifEmpty { exit 1, "Rfam Clan Information file not found: ${params.rfam_clan_info}" }
.set{ ch_rfam_clan_info }
}
//////////////////////////////////////////////////////////////////
/* - Parse translate and diamond parameters -- */
//////////////////////////////////////////////////////////////////
ch_peptide_ksize = Channel.from(params.translate_peptide_ksize?.toString().tokenize(',')).view()
ch_peptide_molecule = Channel.from(params.translate_peptide_molecule?.toString().tokenize(',')).view()
// Make cartesian product of molecule and ksize
ch_peptide_molecule
.combine(ch_peptide_ksize)
.dump ( tag: 'ch_translate_molecule_ksize' )
.set { ch_translate_molecule_ksize }
jaccard_threshold = params.translate_jaccard_threshold
refseq_release = params.refseq_release
tablesize = params.translate_tablesize
//////////////////////////////////////////////////////////////////
/* - Parse sourmash/hash2kmer parameters -- */
//////////////////////////////////////////////////////////////////
sourmash_ksize = params.sourmash_ksize
sourmash_molecule = params.sourmash_molecule
sourmash_log2_sketch_size = params.sourmash_log2_sketch_size
//////////////////////////////////////////////////////////////////
/* - Summarize reference proteome parameters -- */
//////////////////////////////////////////////////////////////////
provided_reference_proteome = params.proteome_search_fasta || params.refseq_release
existing_reference = params.diamond_database || params.sourmash_index
need_refseq_download = !existing_reference && !params.proteome_search_fasta && params.refseq_release
//////////////////////////////////////////////////////////////////
/* - Parse differential hash expression parameters -- */
//////////////////////////////////////////////////////////////////
diff_hash_with_abundance = params.diff_hash_with_abundance
diff_hash_inverse_regularization_strength = params.diff_hash_inverse_regularization_strength
diff_hash_solver = params.diff_hash_solver
diff_hash_penalty = params.diff_hash_penalty
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- HEADER LOG INFO -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
using_hashes = params.diff_hash_expression || params.hashes
log.info nfcoreHeader()
def summary = [:]
if (workflow.revision) summary['Pipeline Release'] = workflow.revision
summary['Run Name'] = custom_runName ?: workflow.runName
// Input is sequencing reads --> need to convert to protein
if (params.csv) summary['CSV of samples'] = params.csv
if (params.bam) summary['bam'] = params.bam
if (params.bam) summary['bai'] = params.bai
if (params.bed) summary['bed'] = params.bed
if (params.reads) summary['Reads'] = params.reads
if (params.csv) summary['CSV of input reads'] = params.csv
if (!params.input_is_protein) summary['sencha translate Ref'] = params.proteome_translate_fasta
// Input is protein -- have protein sequences and hashes
summary['Diff Hash'] = params.diff_hash_expression
if (params.hashes) summary['Hashes'] = params.hashes
if (using_hashes) summary['sourmash ksize'] = params.sourmash_ksize
if (using_hashes) summary['sourmash molecule'] = params.sourmash_molecule
if (params.diff_hash_expression) summary['Diff Hash abundance?'] = params.diff_hash_with_abundance
if (params.diff_hash_expression) summary['Diff Hash C'] = params.diff_hash_inverse_regularization_strength
if (params.diff_hash_expression) summary['Diff Hash solver'] = params.diff_hash_solver
if (params.diff_hash_expression) summary['Diff Hash penalty'] = params.diff_hash_penalty
if (params.protein_fastas) summary['Input protein fastas'] = params.protein_fastas
// How the DIAMOND search database is created
if (params.proteome_search_fasta) summary['Proteome search ref'] = params.proteome_search_fasta
summary['Protein searcher'] = params.protein_searcher
if (params.hashes) summary['Hashes'] = params.hashes
if (params.hashes) summary['sourmash ksize'] = params.sourmash_ksize
if (params.hashes) summary['sourmash molecule'] = params.sourmash_molecule
if (need_refseq_download) summary['Refseq release'] = params.refseq_release
if (params.diamond_database) summary['DIAMOND pre-build database'] = params.diamond_database
if (params.protein_searcher == 'diamond') summary['Map sequences to taxon'] = params.taxonmap_gz
if (params.protein_searcher == 'diamond') summary['Taxonomy database dump'] = params.taxdmp_zip
summary['Data Type'] = params.single_end ? 'Single-End' : 'Paired-End'
summary['Max Resources'] = "$params.max_memory memory, $params.max_cpus cpus, $params.max_time time per job"
if (workflow.containerEngine) summary['Container'] = "$workflow.containerEngine - $workflow.container"
summary['Output dir'] = params.outdir
summary['Launch dir'] = workflow.launchDir
summary['Working dir'] = workflow.workDir
summary['Script dir'] = workflow.projectDir
summary['User'] = workflow.userName
if (workflow.profile.contains('awsbatch')) {
summary['AWS Region'] = params.awsregion
summary['AWS Queue'] = params.awsqueue
summary['AWS CLI'] = params.awscli
}
summary['Config Profile'] = workflow.profile
if (params.config_profile_description) summary['Config Description'] = params.config_profile_description
if (params.config_profile_contact) summary['Config Contact'] = params.config_profile_contact
if (params.config_profile_url) summary['Config URL'] = params.config_profile_url
if (params.email || params.email_on_fail) {
summary['E-mail Address'] = params.email
summary['E-mail on failure'] = params.email_on_fail
summary['MultiQC maxsize'] = params.max_multiqc_email_size
}
log.info summary.collect { k,v -> "${k.padRight(25)}: $v" }.join("\n")
log.info "-\033[2m--------------------------------------------------\033[0m-"
// Check the hostnames against configured profiles
checkHostname()
def create_workflow_summary(summary) {
def yaml_file = workDir.resolve('workflow_summary_mqc.yaml')
yaml_file.text = """
id: 'nf-core-predictorthologs-summary'
description: " - this information is collected when the pipeline is started."
section_name: 'czbiohub/nf-predictorthologs Workflow Summary'
section_href: 'https://github.com/czbiohub/predictorthologs'
plot_type: 'html'
data: |
<dl class=\"dl-horizontal\">
${summary.collect { k,v -> " <dt>$k</dt><dd><samp>${v ?: '<span style=\"color:#999999;\">N/A</a>'}</samp></dd>" }.join("\n")}
</dl>
""".stripIndent()
return yaml_file
}
/*
* Parse software version numbers
*/
process get_software_versions {
publishDir "${params.outdir}/pipeline_info", mode: 'copy',
saveAs: { filename ->
if (filename.indexOf(".csv") > 0) filename
else null
}
output:
file 'software_versions_mqc.yaml' into ch_software_versions_yaml
file "software_versions.csv"
script:
// TODO nf-core: Get all tools to print their version number here
// (base) root@aa580bfc0d2f:/# fastp --version
// fastp 0.20.0
// (base) root@aa580bfc0d2f:/# diamond version
// diamond v0.9.30.131 (C) Max Planck Society for the Advancement of Science
// Documentation, support and updates available at http://www.diamondsearch.org
//
// diamond version 0.9.30
// (base) root@aa580bfc0d2f:/# samtools --version
// samtools 1.10
// Using htslib 1.10.2
// Copyright (C) 2019 Genome Research Ltd.
"""
echo $workflow.manifest.version > v_pipeline.txt
echo $workflow.nextflow.version > v_nextflow.txt
fastqc --version > v_fastqc.txt
multiqc --version > v_multiqc.txt
fastp --version > v_fastp.txt
diamond version > v_diamond.txt
samtools --version > v_samtools.txt
sourmash -v &> v_sourmash.txt
pip show sencha &> v_sencha.txt
scrape_software_versions.py &> software_versions_mqc.yaml
"""
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- PREPROCESSING SAMBAMBA DEDUPLICATION -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
if (params.bam && !params.skip_remove_duplicates_bam && !params.bai){
process sambamba_dedup {
tag "${prefix}"
label "process_high"
publishDir "${params.outdir}/sambamba_dedup", mode: 'copy'
input:
file(bam) from ch_bam_for_dedup
output:
set val(prefix), file(bam_dedup) into ch_dedup_bam_for_index, ch_dedup_bam_for_samtools_fastq
script:
buffer_size = task.memory.toMega()
prefix = "${bam.getBaseName()}_dedup"
bam_dedup = "${prefix}.bam"
"""
sambamba markdup --remove-duplicates --sort-buffer-size ${buffer_size} --nthreads $task.cpus ${bam} ${bam_dedup}
"""
}
}
if (params.bam && !params.skip_remove_duplicates_bam && !params.bai){
process sambamba_index {
tag "${bam_name}"
label "process_medium"
publishDir "${params.outdir}/sambamba_index", mode: 'copy'
input:
set val(bam_name), file(bam_dedup) from ch_dedup_bam_for_index
output:
file(bai_dedup) into ch_dedup_bai
script:
bai_dedup = "${bam_name}.bai"
"""
sambamba index --nthreads $task.cpus ${bam_dedup} ${bai_dedup}
"""
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- SAMTOOLS VIEW GENOMIC REGION TO FASTA -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/*
* STEP 0 - samtools view
*/
if (params.bam && !params.bed && !params.bai && !params.skip_remove_duplicates_bam) {
process samtools_fastq_no_intersect {
tag "$bam_name"
label "process_low"
publishDir "${params.outdir}/intersect_fastqs", mode: 'copy'
input:
set val(bam_name), file(bam_dedup) from ch_dedup_bam_for_samtools_fastq
output:
set val(bam_name), file(fastq) into ch_intersected
script:
fastq = "${bam_name}.fastq.gz"
"""
samtools fastq -N ${bam_dedup} \\
| gzip -c > ${fastq}
"""
}
ch_intersected
// gzipped files are 20 bytes when empty
.filter{ it[1].size() > 20 }
.into { ch_read_files_fastqc; ch_read_files_trimming }
} else if (params.bam && params.bed && params.bai) {
process samtools_view_fastq {
tag "$interval_name"
label "process_low"
publishDir "${params.outdir}/intersect_fastqs", mode: 'copy'
input:
set val(interval_name), val(chrom), val(chromStart), val(chromEnd), file(bam), file(bai) from ch_bed_bam_bai
output:
set val(interval_name), file(fastq) into ch_intersected
script:
fastq = "${interval_name}.fastq.gz"
"""
samtools view -hu $bam '${chrom}:${chromStart}-${chromEnd}' \\
| samtools fastq -N - \\
| gzip -c > ${fastq}
"""
}
ch_intersected
// gzipped files are 20 bytes when empty
.filter{ it[1].size() > 20 }
.into { ch_read_files_fastqc; ch_read_files_trimming }
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- FASTQ QC -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/*
* STEP 1 - FastQC
*/
if (!params.input_is_protein && !params.skip_fastqc) {
process fastqc {
tag "$name"
label 'process_medium'
publishDir "${params.outdir}/fastqc", mode: 'copy',
saveAs: { filename ->
filename.indexOf(".zip") > 0 ? "zips/$filename" : "$filename"
}
input:
set val(name), file(reads) from ch_read_files_fastqc
output:
file "*_fastqc.{zip,html}" into ch_fastqc_results
script:
"""
fastqc --quiet --threads $task.cpus $reads
"""
}
} else {
ch_fastqc_results = Channel.empty()
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- ADAPTER TRIMMING -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/*
* STEP 2 - fastp for read trimming
*/
if (!params.skip_trimming && !(params.input_is_protein || params.protein_fastas || params.protein_fasta_paths) ){
process fastp {
label 'process_low'
tag "$name"
publishDir "${params.outdir}/fastp", mode: 'copy',
saveAs: {filename ->
if (filename.indexOf(".fastq.gz") == -1) "logs/$filename"
else if (reads[1] == null) "single_end/$filename"
else if (reads[1] != null) "paired_end/$filename"
else null
}
input:
set val(name), file(reads) from ch_read_files_trimming
output:
set val(name), file("*trimmed.fastq.gz") into ch_reads_trimmed
file "*fastp.json" into ch_fastp_results
file "*fastp.html" into ch_fastp_html
script:
// One set of reads --> single end
if (reads[1] == null) {
"""
fastp \\
--low_complexity_filter \\
--trim_poly_x \\
--in1 ${reads} \\
--out1 ${name}_R1_trimmed.fastq.gz \\
--json ${name}_fastp.json \\
--html ${name}_fastp.html
"""
} else if (reads[1] != null ){
// More than one set of reads --> paired end
"""
fastp \\
--low_complexity_filter \\
--trim_poly_x \\
--in1 ${reads[0]} \\
--in2 ${reads[1]} \\
--out1 ${name}_R1_trimmed.fastq.gz \\
--out2 ${name}_R2_trimmed.fastq.gz \\
--json ${name}_fastp.json \\
--html ${name}_fastp.html
"""
} else {
"""
echo name ${name}
echo reads: ${reads}
echo "Number of reads is not equal to 1 or 2 --> don't know how to trim non-paired-end and non-single-end reads"
"""
}
}
} else if (!params.input_is_protein) {
ch_reads_trimmed = ch_read_files_trimming
ch_fastp_results = Channel.empty()
} else {
ch_fastp_results = Channel.empty()
}
if (!(params.input_is_protein || params.protein_fastas || params.protein_fasta_paths) && params.protein_searcher == 'diamond'){
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- PREPARE PEPTIDE DATABASE TO PREDICT PROTEIN-CODING READS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/*
* STEP 2 - sencha index
*/
process make_protein_index {
tag "${peptides}__${bloom_id}"
label "process_low"
publishDir "${params.outdir}/sencha/", mode: 'copy'
input:
file(peptides) from ch_proteome_translate_fasta.collect()
set val(molecule), val(ksize) from ch_translate_molecule_ksize
output:
set val(bloom_id), val(molecule), val(ksize), file("${peptides.simpleName}__${bloom_id}.bloomfilter") into ch_sencha_bloom_filters
script:
bloom_id = "molecule-${molecule}_ksize-${ksize}"
"""
sencha index \\
--tablesize ${tablesize} \\
--molecule ${molecule} \\
--peptide-ksize ${ksize} \\
--save-as ${peptides.simpleName}__${bloom_id}.bloomfilter \\
${peptides}
"""
}
// From Paolo - how to do translate on ALL combinations of bloom filters
ch_sencha_bloom_filters
.groupTuple(by: [0, 1, 2])
.combine(ch_reads_trimmed)
.dump( tag: 'ch_sencha_bloom_filters_grouptuple' )
// [DUMP: ch_sencha_bloom_filters_grouptuple]
// [molecule-protein_ksize-12,
// 'protein',
// '12',
// [ncbi_refseq_vertebrate_mammalian_ptprc_plus__np_only__molecule-protein_ksize-12.bloomfilter],
// 'bonobo_liver_ptprc',
// bonobo_liver_ptprc_R1_trimmed.fastq.gz]
.set{ ch_sencha_bloom_filters_grouptuple }
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- PREDICT PROTEIN-CODING READS -- */
/* -- -- */
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/*
* STEP 3 - sencha translate
*/
process translate {
tag "${sample_sketch_id}"
label "process_low"
label "process_long"
publishDir "${params.outdir}/translate/${bloom_id}", mode: 'copy',
saveAs: {
filename ->
if (save_translate_csv && filename.indexOf(".csv") > 0) "$filename"
else if (save_translate_json && filename.indexOf(".json") > 0) "$filename"
else "$filename"
}
input:
tuple \
val(bloom_id), val(alphabet), val(ksize), file(bloom_filter), \
val(sample_id), file(reads) \
from ch_sencha_bloom_filters_grouptuple
output:
// TODO also extract nucleotide sequence of coding reads and do sourmash compute using only DNA on that?
set val(sample_sketch_id), file(noncoding_nucleotides) into ch_noncoding_nucleotides_potentially_empty
// Set first value to "false" so it's not treated as a differential hash, and only the sample_id is considered
set val(false), val(sample_sketch_id), file(peptides_fasta) into ch_translated_proteins_potentially_empty
set val(sample_sketch_id), file(coding_nucleotides) into ch_coding_nucleotides
set val(sample_sketch_id), file(coding_scores) into ch_coding_scores_csv
set val(sample_sketch_id), file(summary_json) into ch_coding_scores_json
script:
sample_sketch_id = "${sample_id}__${bloom_id}"
noncoding_nucleotides = "${sample_sketch_id}__noncoding_reads_nucleotides.fasta"
coding_nucleotides = "${sample_sketch_id}__coding_reads_nucleotides.fasta"
peptides_fasta = "${sample_sketch_id}__coding_reads_peptides.fasta"
coding_scores = "${sample_sketch_id}__coding_scores.csv"
summary_json = "${sample_sketch_id}__coding_summary.json"
"""
sencha translate \\
--molecule ${alphabet} \\
--peptide-ksize ${ksize} \\
--jaccard-threshold ${jaccard_threshold} \\
--noncoding-nucleotide-fasta ${noncoding_nucleotides} \\
--coding-nucleotide-fasta ${coding_nucleotides} \\
--csv ${coding_scores} \\
--json-summary ${summary_json} \\
--peptides-are-bloom-filter \\
${bloom_filter} \\
${reads} > ${peptides_fasta}
"""
}
// Remove empty files
// it[0] = sample id
// it[1] = bloom id
// it[2] = sequence fasta file
ch_translated_proteins_potentially_empty
.filter{ it[2].size() > 0 }
.dump(tag: "ch_translated_proteins_potentially_empty")
// [DUMP: ch_translated_proteins_potentially_empty]
// ['NC-033660.1-74563649-74570299-+-516-0',
// molecule-protein,
// NC-033660.1-74563649-74570299-+-516-0__molecule-protein__coding_reads_peptides.fasta]
.set{ ch_protein_seq_for_diamond }
// Remove empty files
// it[0] = sample bloom id
// it[1] = sequence fasta file
ch_noncoding_nucleotides_potentially_empty
.filter { it[1].size() > 0 }
.set { ch_noncoding_nucleotides }
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/* -- -- */
/* -- PERFORM DIFFERENTIAL HASH EXPRESSION -- */