-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.nf
81 lines (69 loc) · 3.31 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
process MINIMAP2_ALIGN {
tag "$meta.id"
label 'process_high'
// Note: the versions here need to match the versions used in the mulled container below and minimap2/index
conda "${moduleDir}/environment.yml"
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/mulled-v2-66534bcbb7031a148b13e2ad42583020b9cd25c4:3161f532a5ea6f1dec9be5667c9efc2afdac6104-0' :
'biocontainers/mulled-v2-66534bcbb7031a148b13e2ad42583020b9cd25c4:3161f532a5ea6f1dec9be5667c9efc2afdac6104-0' }"
input:
tuple val(meta), path(reads)
tuple val(meta2), path(reference)
val bam_format
val bam_index_extension
val cigar_paf_format
val cigar_bam
val bed_bool
output:
tuple val(meta), path("*.paf") , optional: true, emit: paf
tuple val(meta), path("*.bam") , optional: true, emit: bam
tuple val(meta), path("*.bam.${bam_index_extension}"), optional: true, emit: index
tuple val(meta), path("*.bed") , optional: true, emit: bed
path "versions.yml" , emit: versions
when:
task.ext.when == null || task.ext.when
script:
def args = task.ext.args ?: ''
def args2 = task.ext.args2 ?: ''
def args3 = task.ext.args3 ?: ''
def args4 = task.ext.args4 ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def bam_index = bam_index_extension ? "${prefix}.bam##idx##${prefix}.bam.${bam_index_extension} --write-index" : "${prefix}.bam"
def bam_output = reference.size() > 2.5e9 && bam_format ? "-a | samtools view -b -T ${reference} - > ${prefix}.bam" : reference.size() < 2.5e9 && bam_format ? "-a | samtools view -@ ${task.cpus} -b -h -o ${prefix}.bam" : bed_bool ? "| paftools.js splice2bed - > ${prefix}.bed " : "-o ${prefix}.paf"
def cigar_paf = cigar_paf_format && !bam_format ? "-c" : ''
def set_cigar_bam = cigar_bam && bam_format ? "-L" : ''
def bam_input = "${reads.extension}".matches('sam|bam|cram')
def samtools_reset_fastq = bam_input ? "samtools reset --threads ${task.cpus-1} $args3 $reads | samtools fastq --threads ${task.cpus-1} $args4 |" : ''
def query = bam_input ? "-" : reads
def target = reference ?: (bam_input ? error("BAM input requires reference") : reads)
"""
$samtools_reset_fastq \\
minimap2 \\
$args \\
-t $task.cpus \\
$target \\
$query \\
$cigar_paf \\
$set_cigar_bam \\
$bam_output
cat <<-END_VERSIONS > versions.yml
"${task.process}":
minimap2: \$(minimap2 --version 2>&1)
samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
END_VERSIONS
"""
stub:
def prefix = task.ext.prefix ?: "${meta.id}"
def output_file = bam_format ? "${prefix}.bam" : "${prefix}.paf"
def bam_index = bam_index_extension ? "touch ${prefix}.bam.${bam_index_extension}" : ""
def bam_input = "${reads.extension}".matches('sam|bam|cram')
def target = reference ?: (bam_input ? error("BAM input requires reference") : reads)
"""
touch $output_file
${bam_index}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
minimap2: \$(minimap2 --version 2>&1)
END_VERSIONS
"""
}