Skip to content

Commit

Permalink
update bcftools pluginsplit (#7013)
Browse files Browse the repository at this point in the history
* update bcftools pluginsplit

* Add error test

* Fix test and meta

* Fix test

* Change extension detection

* Change file renaming

* Fix renaming

* Update modules/nf-core/bcftools/pluginsplit/main.nf

Co-authored-by: Felix Lenner <[email protected]>

* Update bcftools pluginsplit

* Stage input in folder

* Fix meta.yml

* Update input

* Update error report

---------

Co-authored-by: Felix Lenner <[email protected]>
Co-authored-by: Louis Le Nezet <[email protected]>
Co-authored-by: LouisLeNezet <[email protected]>
  • Loading branch information
4 people authored Nov 21, 2024
1 parent ffd452a commit 14c910a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 32 deletions.
20 changes: 10 additions & 10 deletions modules/nf-core/bcftools/pluginsplit/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ process BCFTOOLS_PLUGINSPLIT {
'biocontainers/bcftools:1.20--h8b25389_0' }"

input:
tuple val(meta), path(vcf), path(tbi)
tuple val(meta), path(vcf, stageAs: "input/*"), path(tbi, stageAs: "input/*")
path(samples)
path(groups)
path(regions)
Expand All @@ -25,7 +25,6 @@ process BCFTOOLS_PLUGINSPLIT {

script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"

def samples_arg = samples ? "--samples-file ${samples}" : ""
def groups_arg = groups ? "--groups-file ${groups}" : ""
Expand All @@ -40,9 +39,7 @@ process BCFTOOLS_PLUGINSPLIT {
${groups_arg} \\
${regions_arg} \\
${targets_arg} \\
--output ${prefix}
mv ${prefix}/* .
--output .
cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand All @@ -52,7 +49,6 @@ process BCFTOOLS_PLUGINSPLIT {

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"

def extension = args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
Expand All @@ -65,11 +61,15 @@ process BCFTOOLS_PLUGINSPLIT {
""
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)" : ""
"""
${create_files}
${create_index}
cut -f 3 ${determination_file} | sed -e 's/\$/.${extension}/' > files.txt
while IFS= read -r filename;
do ${create_cmd} "./\$filename";
if [ -n "${index}" ]; then
index_file=\$(sed -e 's/\$/.${index}/' <<< \$filename);
touch ./\$index_file;
fi;
done < files.txt
cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
38 changes: 31 additions & 7 deletions modules/nf-core/bcftools/pluginsplit/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ nextflow_process {
}

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

config "./nextflow.config"

when {
Expand All @@ -91,16 +90,43 @@ nextflow_process {
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") },
) }
process.out.vcf.collect{ it[1].collect { file(it).name } },
process.out.tbi.collect{ it[1].collect { file(it).name } },
).match() }
)
}

}

test("homo_sapiens - [ vcf, tbi ], samples, [], [], [] -stub") {
test("homo_sapiens - [ vcf, tbi ], [], [], [], [], - error no sample") {
config "./nextflow.config"

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/vcf/dbsnp_146.hg38.vcf.gz', checkIfExists: true),
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/vcf/dbsnp_146.hg38.vcf.gz.tbi', checkIfExists: true)
]
input[1] = []
input[2] = []
input[3] = []
input[4] = []
"""
}
}

then {
assertAll(
{ assert process.failed },
{ assert process.errorReport.contains("No samples to split: input/dbsnp_146.hg38.vcf.gz") }
)
}

}

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

when {
Expand Down Expand Up @@ -130,7 +156,6 @@ nextflow_process {
}

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

options "-stub"

when {
Expand Down Expand Up @@ -160,7 +185,6 @@ nextflow_process {
}

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

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

Expand Down
51 changes: 36 additions & 15 deletions modules/nf-core/bcftools/pluginsplit/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,39 @@
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "24.04.2"
"nf-test": "0.9.2",
"nextflow": "24.10.1"
},
"timestamp": "2024-07-09T15:56:42.307673651"
"timestamp": "2024-11-20T14:56:54.383979416"
},
"homo_sapiens - [ vcf, tbi ], [], groups, regions, targets - tbi": {
"content": [
[
[
"normal.vcf.gz",
"tumour.vcf.gz"
]
],
[
[
"normal.vcf.gz.tbi",
"tumour.vcf.gz.tbi"
]
]
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.1"
},
"timestamp": "2024-11-20T14:56:44.796391578"
},
"homo_sapiens - [ vcf, tbi ], [], groups, regions, targets": {
"content": null,
"meta": {
"nf-test": "0.8.4",
"nextflow": "24.04.2"
"nf-test": "0.9.2",
"nextflow": "24.10.1"
},
"timestamp": "2024-07-09T15:56:21.498991402"
"timestamp": "2024-11-20T14:56:36.709842966"
},
"homo_sapiens - [ vcf, tbi ], [], groups, regions, targets - tbi -stub": {
"content": [
Expand Down Expand Up @@ -126,10 +147,10 @@
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "24.04.2"
"nf-test": "0.9.2",
"nextflow": "24.10.1"
},
"timestamp": "2024-07-09T15:57:04.483688966"
"timestamp": "2024-11-20T14:57:11.163588435"
},
"homo_sapiens - [ vcf, tbi ], samples, [], [], []": {
"content": [
Expand Down Expand Up @@ -179,10 +200,10 @@
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "24.04.2"
"nf-test": "0.9.2",
"nextflow": "24.10.1"
},
"timestamp": "2024-07-09T15:56:10.033818589"
"timestamp": "2024-11-20T14:56:27.978161766"
},
"homo_sapiens - [ vcf, tbi ], [], groups, regions, targets -stub": {
"content": [
Expand Down Expand Up @@ -232,9 +253,9 @@
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "24.04.2"
"nf-test": "0.9.2",
"nextflow": "24.10.1"
},
"timestamp": "2024-07-09T15:56:53.641165787"
"timestamp": "2024-11-20T14:57:02.456908152"
}
}

0 comments on commit 14c910a

Please sign in to comment.