Skip to content

Commit

Permalink
Stage input in folder
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisLeNezet committed Nov 20, 2024
1 parent a488422 commit 8e9cde6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 260 deletions.
34 changes: 8 additions & 26 deletions modules/nf-core/bcftools/pluginsplit/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ process BCFTOOLS_PLUGINSPLIT {
'biocontainers/bcftools:1.20--h8b25389_0' }"

input:
tuple val(meta), path(vcf), path(tbi)
tuple val(meta), path(vcf, stageAs: "?/*"), path(tbi, stageAs: "?/*")
path(samples)
path(groups)
path(regions)
path(targets)

output:
tuple val(meta), path("outputDir/*.{vcf,vcf.gz,bcf,bcf.gz}"), emit: vcf
tuple val(meta), path("outputDir/*.tbi") , emit: tbi, optional: true
tuple val(meta), path("outputDir/*.csi") , emit: csi, optional: true
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

script:
def args = task.ext.args ?: ''
// Here the default prefix is an empty string as the filename is created by the plugin
// and the prefix is instead added to the output files in the script
def prefix = task.ext.prefix ?: ""

def samples_arg = samples ? "--samples-file ${samples}" : ""
def groups_arg = groups ? "--groups-file ${groups}" : ""
Expand All @@ -42,13 +39,7 @@ process BCFTOOLS_PLUGINSPLIT {
${groups_arg} \\
${regions_arg} \\
${targets_arg} \\
--output outputDir
if [ -n "${prefix}" ]; then
for file in outputDir/*; do
mv \$file outputDir/${prefix}\${file##*/}
done
fi
--output .
cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand All @@ -58,7 +49,6 @@ process BCFTOOLS_PLUGINSPLIT {

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: ""

def extension = args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
Expand All @@ -72,23 +62,15 @@ process BCFTOOLS_PLUGINSPLIT {
def determination_file = samples ?: targets
def create_cmd = extension.matches("vcf|bcf") ? "touch " : "echo '' | gzip > "
"""
mkdir -p outputDir
cut -f 3 ${determination_file} | sed -e 's/\$/.${extension}/' > files.txt
while IFS= read -r filename;
do ${create_cmd} "outputDir/\$filename";
do ${create_cmd} "./\$filename";
if [ -n "${index}" ]; then
index_file=\$(sed -e 's/\$/.${index}/' <<< \$filename);
touch outputDir/\$index_file;
touch ./\$index_file;
fi;
done < files.txt
if [ -n "${prefix}" ]; then
for file in outputDir/*; do
mv \$file outputDir/${prefix}\${file##*/}
done
fi
cat <<-END_VERSIONS > versions.yml
"${task.process}":
bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//')
Expand Down
67 changes: 2 additions & 65 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 Down Expand Up @@ -99,38 +98,8 @@ nextflow_process {

}

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

config "./nextflow_prefix.config"

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

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

}

test("homo_sapiens - [ vcf, tbi ], [], [], [], [], - error no sample") {

config "./nextflow_prefix.config"
config "./nextflow.config"

when {
process {
Expand All @@ -151,7 +120,7 @@ nextflow_process {
then {
assertAll(
{ assert process.failed },
{ assert process.errorReport.contains("No samples to split: dbsnp_146.hg38.vcf.gz") }
{ assert process.errorReport.contains("No samples to split: 1/dbsnp_146.hg38.vcf.gz") }
)
}

Expand Down Expand Up @@ -244,36 +213,4 @@ nextflow_process {
}

}

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

tag "test"
config "./nextflow_prefix.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] = 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() }
)
}

}
}
Loading

0 comments on commit 8e9cde6

Please sign in to comment.