forked from CDCgov/mycosnp-nf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbwa-reference.nf
109 lines (89 loc) · 4.01 KB
/
bwa-reference.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
/*
========================================================================================
BWA Reference Sub-Workflow
========================================================================================
*/
include { NUCMER } from '../../modules/nf-core/modules/nucmer/main'
include { COORDSTOBED } from '../../modules/local/coordstobed.nf'
include { BEDTOOLS_MASKFASTA } from '../../modules/nf-core/modules/bedtools/maskfasta/main'
include { BWA_INDEX } from '../../modules/nf-core/modules/bwa/index/main'
include { PICARD_CREATESEQUENCEDICTIONARY } from '../../modules/nf-core/modules/picard/createsequencedictionary/main'
include { SAMTOOLS_FAIDX } from '../../modules/nf-core/modules/samtools/faidx/main'
process INPUT_PROC {
conda (params.enable_conda ? "conda-forge::sed=4.7" : null)
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/python:3.8.3' :
'quay.io/biocontainers/python:3.8.3' }"
input:
path(fasta)
output:
tuple val(meta), path("reference.fasta", includeInputs: true), path("reference.copy.fasta"), emit: ref_fasta
script:
meta = [
"id": 'reference'
]
def is_compressed = false
if(fasta.getName().endsWith(".gz"))
{
is_compressed = true
}
"""
echo ${meta.id}
if [[ ${is_compressed} == "true" ]]; then
gunzip -c $fasta > reference.fasta
else
mv ${fasta} reference.fasta
fi
cp reference.fasta reference.copy.fasta
"""
}
workflow BWA_REFERENCE {
take:
fasta // channel: fasta
main:
ch_use_fasta = Channel.empty()
ch_masked_fasta = Channel.empty()
ch_samtools_index = Channel.empty()
ch_bwa_index = Channel.empty()
ch_dict = Channel.empty()
ch_reference_combined = Channel.empty()
ch_versions = Channel.empty()
INPUT_PROC( fasta )
NUCMER( INPUT_PROC.out )
COORDSTOBED( NUCMER.out.delta )
BEDTOOLS_MASKFASTA( COORDSTOBED.out.bed, INPUT_PROC.out.map{ meta, fa, fa2->[ fa]} )
if(params.mask)
{
// else use nucmer masked fasta input
ch_use_fasta = BEDTOOLS_MASKFASTA.out.fasta
} else
{
// If no_mask is set, use original fasta input
ch_use_fasta = INPUT_PROC.out.map{meta, fa1, fa2 -> [ meta, fa1 ] }
}
BWA_INDEX(ch_use_fasta.map{meta, fa -> fa})
SAMTOOLS_FAIDX(ch_use_fasta)
PICARD_CREATESEQUENCEDICTIONARY(ch_use_fasta)
// reference_fasta, samtools_faidx, bwa_index, dict
ch_use_fasta.combine(SAMTOOLS_FAIDX.out.fai)
.combine(BWA_INDEX.out.index)
.combine(PICARD_CREATESEQUENCEDICTIONARY.out.reference_dict)
.map{meta, fa1, meta2, fai, bai, meta4, dict -> [meta, fa1, fai, bai, dict] }
.set{ch_reference_combined}
// Collect versions information
ch_versions = ch_versions.mix( NUCMER.out.versions,
BWA_INDEX.out.versions,
SAMTOOLS_FAIDX.out.versions,
PICARD_CREATESEQUENCEDICTIONARY.out.versions )
ch_masked_fasta = ch_use_fasta
ch_samtools_index = SAMTOOLS_FAIDX.out.fai
ch_bwa_index = BWA_INDEX.out.index
ch_dict = PICARD_CREATESEQUENCEDICTIONARY.out.reference_dict
emit:
masked_fasta = ch_masked_fasta // channel: [ val(meta), fas ]
samtools_index = ch_samtools_index // channel: [ val(meta), fai ]
bwa_index = ch_bwa_index // channel: [ val(meta), bwa ]
dict = ch_dict // channel: [ val(meta), dict ]
reference_combined = ch_reference_combined // channel: [ val(meta), fa, fai, bai, dict ]
versions = ch_versions // channel: [ ch_versions ]
}