2021-11-21 19:56:57 +00:00
|
|
|
process CNVKIT_BATCH {
|
2021-03-22 22:27:30 +00:00
|
|
|
tag "$meta.id"
|
|
|
|
label 'process_low'
|
|
|
|
|
2022-05-20 08:37:46 +00:00
|
|
|
conda (params.enable_conda ? 'bioconda::cnvkit=0.9.9 bioconda::samtools=1.15.1' : null)
|
2021-11-26 07:58:40 +00:00
|
|
|
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
|
2022-05-20 08:37:46 +00:00
|
|
|
'https://depot.galaxyproject.org/singularity/mulled-v2-780d630a9bb6a0ff2e7b6f730906fd703e40e98f:304d1c5ab610f216e77c61420ebe85f1e7c5968a-0' :
|
2022-05-20 07:11:45 +00:00
|
|
|
'quay.io/biocontainers/mulled-v2-780d630a9bb6a0ff2e7b6f730906fd703e40e98f:304d1c5ab610f216e77c61420ebe85f1e7c5968a-0' }"
|
2021-03-22 22:27:30 +00:00
|
|
|
|
|
|
|
input:
|
2021-11-21 19:56:57 +00:00
|
|
|
tuple val(meta), path(tumor), path(normal)
|
2021-07-01 15:13:01 +00:00
|
|
|
path fasta
|
2022-06-02 10:57:50 +00:00
|
|
|
path fasta_fai
|
2021-11-21 19:56:57 +00:00
|
|
|
path targets
|
|
|
|
path reference
|
2021-03-22 22:27:30 +00:00
|
|
|
|
|
|
|
output:
|
|
|
|
tuple val(meta), path("*.bed"), emit: bed
|
2021-11-21 19:56:57 +00:00
|
|
|
tuple val(meta), path("*.cnn"), emit: cnn, optional: true
|
|
|
|
tuple val(meta), path("*.cnr"), emit: cnr, optional: true
|
|
|
|
tuple val(meta), path("*.cns"), emit: cns, optional: true
|
2022-05-20 07:11:45 +00:00
|
|
|
tuple val(meta), path("*.pdf"), emit: pdf, optional: true
|
|
|
|
tuple val(meta), path("*.png"), emit: png, optional: true
|
2021-10-01 13:04:56 +00:00
|
|
|
path "versions.yml" , emit: versions
|
2021-03-22 22:27:30 +00:00
|
|
|
|
2022-02-04 08:53:32 +00:00
|
|
|
when:
|
|
|
|
task.ext.when == null || task.ext.when
|
|
|
|
|
2021-03-22 22:27:30 +00:00
|
|
|
script:
|
2021-11-26 07:58:40 +00:00
|
|
|
def args = task.ext.args ?: ''
|
2022-05-20 11:29:49 +00:00
|
|
|
|
2022-06-01 15:35:02 +00:00
|
|
|
def tumor_exists = tumor ? true : false
|
|
|
|
def normal_exists = normal ? true : false
|
|
|
|
|
2022-05-20 11:25:57 +00:00
|
|
|
// execute samtools only when cram files are input, cnvkit runs natively on bam but is prohibitively slow
|
2022-06-01 15:35:02 +00:00
|
|
|
def tumor_cram = tumor_exists && tumor.Extension == "cram" ? true : false
|
|
|
|
def normal_cram = normal_exists && normal.Extension == "cram" ? true : false
|
2022-06-02 10:57:50 +00:00
|
|
|
def tumor_bam = tumor_exists && tumor.Extension == "bam" ? true : false
|
|
|
|
def normal_bam = normal_exists && normal.Extension == "bam" ? true : false
|
2022-06-01 15:35:02 +00:00
|
|
|
|
|
|
|
def tumor_out = tumor_cram ? tumor.BaseName + ".bam" : "${tumor}"
|
2022-05-20 11:29:49 +00:00
|
|
|
|
2022-05-20 07:11:45 +00:00
|
|
|
// tumor_only mode does not need fasta & target
|
2022-05-20 11:08:38 +00:00
|
|
|
// instead it requires a pre-computed reference.cnn which is built from fasta & target
|
2022-05-20 11:25:57 +00:00
|
|
|
def (normal_out, normal_args, fasta_args) = ["", "", ""]
|
2022-06-02 10:57:50 +00:00
|
|
|
def fai_reference = fasta_fai ? "--fai-reference ${fasta_fai}" : ""
|
2021-11-21 19:56:57 +00:00
|
|
|
|
2022-05-20 07:11:45 +00:00
|
|
|
if (normal_exists){
|
|
|
|
def normal_prefix = normal.BaseName
|
2022-06-01 15:35:02 +00:00
|
|
|
normal_out = normal_cram ? "${normal_prefix}" + ".bam" : "${normal}"
|
2022-05-20 07:11:45 +00:00
|
|
|
fasta_args = fasta ? "--fasta $fasta" : ""
|
2022-06-01 15:35:02 +00:00
|
|
|
|
|
|
|
// germline mode
|
|
|
|
// normal samples must be input without a flag
|
2022-06-02 10:57:50 +00:00
|
|
|
// requires flag --normal to be empty []
|
2022-06-01 15:35:02 +00:00
|
|
|
if(!tumor_exists){
|
2022-06-02 10:57:50 +00:00
|
|
|
tumor_out = "${normal_prefix}" + ".bam"
|
2022-06-01 15:35:02 +00:00
|
|
|
normal_args = "--normal "
|
|
|
|
}
|
|
|
|
// somatic mode
|
|
|
|
else {
|
|
|
|
normal_args = normal_prefix ? "--normal $normal_out" : ""
|
|
|
|
}
|
2022-05-20 07:11:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 11:29:49 +00:00
|
|
|
def target_args = targets ? "--targets $targets" : ""
|
|
|
|
def reference_args = reference ? "--reference $reference" : ""
|
|
|
|
|
2022-06-02 10:57:50 +00:00
|
|
|
// somatic_mode cram_input
|
|
|
|
if (tumor_cram && normal_cram){
|
|
|
|
"""
|
|
|
|
samtools view -T $fasta $fai_reference $tumor -@ $task.cpus -o $tumor_out
|
|
|
|
samtools view -T $fasta $fai_reference $normal -@ $task.cpus -o $normal_out
|
|
|
|
|
|
|
|
cnvkit.py \\
|
|
|
|
batch \\
|
|
|
|
$tumor_out \\
|
|
|
|
$normal_args \\
|
|
|
|
$fasta_args \\
|
|
|
|
$reference_args \\
|
|
|
|
$target_args \\
|
|
|
|
--processes $task.cpus \\
|
|
|
|
$args
|
|
|
|
|
|
|
|
cat <<-END_VERSIONS > versions.yml
|
|
|
|
"${task.process}":
|
|
|
|
samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
|
|
|
|
cnvkit: \$(cnvkit.py version | sed -e "s/cnvkit v//g")
|
|
|
|
END_VERSIONS
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
// somatic_mode bam_input
|
|
|
|
else if (tumor_bam && normal_bam){
|
|
|
|
"""
|
|
|
|
cnvkit.py \\
|
|
|
|
batch \\
|
|
|
|
$tumor_out \\
|
|
|
|
$normal_args \\
|
|
|
|
$fasta_args \\
|
|
|
|
$reference_args \\
|
|
|
|
$target_args \\
|
|
|
|
--processes $task.cpus \\
|
|
|
|
$args
|
|
|
|
|
|
|
|
cat <<-END_VERSIONS > versions.yml
|
|
|
|
"${task.process}":
|
|
|
|
cnvkit: \$(cnvkit.py version | sed -e "s/cnvkit v//g")
|
|
|
|
END_VERSIONS
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
// tumor_only_mode cram_input
|
|
|
|
else if(tumor_cram && !normal_exists){
|
|
|
|
"""
|
|
|
|
samtools view -T $fasta $fai_reference $tumor -@ $task.cpus -o $tumor_out
|
|
|
|
|
|
|
|
cnvkit.py \\
|
|
|
|
batch \\
|
|
|
|
$tumor_out \\
|
|
|
|
$normal_args \\
|
|
|
|
$fasta_args \\
|
|
|
|
$reference_args \\
|
|
|
|
$target_args \\
|
|
|
|
--processes $task.cpus \\
|
|
|
|
$args
|
|
|
|
|
|
|
|
cat <<-END_VERSIONS > versions.yml
|
|
|
|
"${task.process}":
|
|
|
|
samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
|
|
|
|
cnvkit: \$(cnvkit.py version | sed -e "s/cnvkit v//g")
|
|
|
|
END_VERSIONS
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
// tumor_only bam_input
|
|
|
|
else if(tumor_bam && !normal_exists){
|
|
|
|
"""
|
|
|
|
cnvkit.py \\
|
|
|
|
batch \\
|
|
|
|
$tumor_out \\
|
|
|
|
$normal_args \\
|
|
|
|
$fasta_args \\
|
|
|
|
$reference_args \\
|
|
|
|
$target_args \\
|
|
|
|
--processes $task.cpus \\
|
|
|
|
$args
|
|
|
|
|
|
|
|
cat <<-END_VERSIONS > versions.yml
|
|
|
|
"${task.process}":
|
|
|
|
cnvkit: \$(cnvkit.py version | sed -e "s/cnvkit v//g")
|
|
|
|
END_VERSIONS
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
// germline mode cram_input
|
|
|
|
// normal_args must be --normal []
|
|
|
|
else if (normal_cram && !tumor_exists){
|
|
|
|
"""
|
|
|
|
samtools view -T $fasta $fai_reference $normal -@ $task.cpus -o $tumor_out
|
|
|
|
|
|
|
|
cnvkit.py \\
|
|
|
|
batch \\
|
|
|
|
$tumor_out \\
|
|
|
|
$normal_args \\
|
|
|
|
$fasta_args \\
|
|
|
|
$reference_args \\
|
|
|
|
$target_args \\
|
|
|
|
--processes $task.cpus \\
|
|
|
|
$args
|
|
|
|
|
|
|
|
cat <<-END_VERSIONS > versions.yml
|
|
|
|
"${task.process}":
|
|
|
|
samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
|
|
|
|
cnvkit: \$(cnvkit.py version | sed -e "s/cnvkit v//g")
|
|
|
|
END_VERSIONS
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
// germline mode bam_input
|
|
|
|
else if (normal_bam && !tumor_exists){
|
|
|
|
"""
|
|
|
|
cnvkit.py \\
|
|
|
|
batch \\
|
|
|
|
$tumor_out \\
|
|
|
|
$normal_args \\
|
|
|
|
$fasta_args \\
|
|
|
|
$reference_args \\
|
|
|
|
$target_args \\
|
|
|
|
--processes $task.cpus \\
|
|
|
|
$args
|
|
|
|
|
|
|
|
cat <<-END_VERSIONS > versions.yml
|
|
|
|
"${task.process}":
|
|
|
|
cnvkit: \$(cnvkit.py version | sed -e "s/cnvkit v//g")
|
|
|
|
END_VERSIONS
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
2021-03-22 22:27:30 +00:00
|
|
|
}
|