Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bcftools plugin split #5942

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions modules/nf-core/bcftools/pluginsplit/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ process BCFTOOLS_PLUGINSPLIT {
path(targets)

output:
tuple val(meta), path("*.{vcf,vcf.gz,bcf,bcf.gz}") , emit: vcf
path "versions.yml" , emit: versions
tuple val(meta), path("*.{vcf,vcf.gz,bcf,bcf.gz}"), emit: vcf
tuple val(meta), path("*.tbi") , emit: tbi, optional: true
tuple val(meta), path("*.csi") , emit: csi, optional: true
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when
Expand All @@ -32,6 +34,7 @@ process BCFTOOLS_PLUGINSPLIT {

"""
bcftools plugin split \\
${args} \\
${vcf} \\
${samples_arg} \\
${groups_arg} \\
Expand All @@ -56,12 +59,17 @@ process BCFTOOLS_PLUGINSPLIT {
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf"

def index = args.contains("--write-index=tbi") || args.contains("-W=tbi") ? "tbi" :
args.contains("--write-index=csi") || args.contains("-W=csi") ? "csi" :
args.contains("--write-index") || args.contains("-W") ? "csi" :
""
def determination_file = samples ?: targets
def create_cmd = extension.matches("vcf|bcf") ? "touch " : "echo '' | gzip > "
def create_files = "cut -f 3 ${determination_file} | sed -e 's/\$/.${extension}/' > files.txt; while IFS= read -r filename; do ${create_cmd} \"\$filename\"; done < files.txt"
def create_index = index.matches("csi|tbi") ? "cut -f 3 ${determination_file} | sed -e 's/\$/.${extension}.${index}/' > indices.txt; touch \$(<indices.txt)" : ""
"""
cut -f 3 ${determination_file} | sed -e 's/\$/.${extension}/' > files.txt

touch \$(<files.txt)
${create_files}
${create_index}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
192 changes: 192 additions & 0 deletions modules/nf-core/bcftools/pluginsplit/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
nextflow_process {

name "Test Process BCFTOOLS_PLUGINSPLIT"
script "../main.nf"
process "BCFTOOLS_PLUGINSPLIT"

tag "modules"
tag "modules_nfcore"
tag "bcftools"
tag "bcftools/pluginsplit"

test("homo_sapiens - [ vcf, tbi ], samples, [], [], []") {

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true)
]
input[1] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour")
.collectFile(name:"samples.txt", newLine:true)
input[2] = []
input[3] = []
input[4] = []
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

test("homo_sapiens - [ vcf, tbi ], [], groups, regions, targets") {

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true)
]
input[1] = []
input[2] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour")
.collectFile(name:"samples.txt", newLine:true)
input[3] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.bed', checkIfExists: true)
input[4] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.multi_intervals.bed', checkIfExists: true)
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out.match).match() }

)
}

}

test("homo_sapiens - [ vcf, tbi ], [], groups, regions, targets - tbi") {

config "./nextflow.config"

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true)
]
input[1] = []
input[2] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour")
.collectFile(name:"samples.txt", newLine:true)
input[3] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.bed', checkIfExists: true)
input[4] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.multi_intervals.bed', checkIfExists: true)
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(
process.out.vcf,
process.out.tbi.get(0).get(1).find { file(it).name.matches("normal.vcf.gz.tbi|tumor.vcf.gz.tbi") },
) }
)
}

}

test("homo_sapiens - [ vcf, tbi ], samples, [], [], [] -stub") {

options "-stub"

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true)
]
input[1] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour")
.collectFile(name:"samples.txt", newLine:true)
input[2] = []
input[3] = []
input[4] = []
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

test("homo_sapiens - [ vcf, tbi ], [], groups, regions, targets -stub") {

options "-stub"

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true)
]
input[1] = []
input[2] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour")
.collectFile(name:"samples.txt", newLine:true)
input[3] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.bed', checkIfExists: true)
input[4] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.multi_intervals.bed', checkIfExists: true)
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

test("homo_sapiens - [ vcf, tbi ], [], groups, regions, targets - tbi -stub") {

config "./nextflow.config"
options "-stub"

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true)
]
input[1] = []
input[2] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour")
.collectFile(name:"samples.txt", newLine:true)
input[3] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.bed', checkIfExists: true)
input[4] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.multi_intervals.bed', checkIfExists: true)
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}
}
Loading
Loading