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 stubs to behave like program #6666

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
39 changes: 24 additions & 15 deletions modules/nf-core/bcftools/annotate/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ process BCFTOOLS_ANNOTATE {
def prefix = task.ext.prefix ?: "${meta.id}"
def header_file = header_lines ? "--header-lines ${header_lines}" : ''
def annotations_file = annotations ? "--annotations ${annotations}" : ''
def extension = args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf"
def extension = getVcfExtension(args);
def index_command = !index ? "bcftools index $input" : ''

if ("$input" == "${prefix}.${extension}") error "Input and output names are the same, set prefix in module configuration to disambiguate!"
Expand All @@ -54,18 +50,12 @@ process BCFTOOLS_ANNOTATE {
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" :
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 extension = getVcfExtension(args);
def index = getVcfIndex(args, extension);
def create_cmd = extension.endsWith(".gz") ? "echo '' | gzip >" : "touch"
def create_index = extension.endsWith(".gz") && index.matches("csi|tbi") ? "touch ${prefix}.${extension}.${index}" : ""
def create_index = index ? "touch ${prefix}.${extension}.${index}" : ""

if ("$input" == "${prefix}.${extension}") error "Input and output names are the same, set prefix in module configuration to disambiguate!"
"""
${create_cmd} ${prefix}.${extension}
${create_index}
Expand All @@ -76,3 +66,22 @@ process BCFTOOLS_ANNOTATE {
END_VERSIONS
"""
}
// Custom Functions
String getVcfExtension(String args) {
return args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf";
}
String getVcfIndex(String args, String extension) {
index = ''
if (extension in ['vcf.gz', 'bcf', 'bcf.gz']) {
if (['--write-index=tbi', '-W=tbi'].any { args.contains(it) } && extension == 'vcf.gz') {
index = 'tbi'
} else if (['--write-index=tbi', '-W=tbi', '--write-index=csi', '-W=csi', '--write-index', '-W'].any { args.contains(it) }) {
index = 'csi'
}
}
return index
}
21 changes: 15 additions & 6 deletions modules/nf-core/bcftools/call/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ process BCFTOOLS_CALL {
stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
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 create_index = index.matches("csi|tbi") ? "touch ${prefix}.vcf.gz.${index}" : ""
def extension = "vcf.gz"
def index = getVcfIndex(args, extension);
def create_index = index ? "touch ${prefix}.${extension}.${index}" : ""

"""
echo "" | gzip > ${prefix}.vcf.gz
Expand All @@ -64,3 +61,15 @@ process BCFTOOLS_CALL {
END_VERSIONS
"""
}
// Custom Functions
String getVcfIndex(String args, String extension) {
index = ''
if (extension in ['vcf.gz', 'bcf', 'bcf.gz']) {
if (['--write-index=tbi', '-W=tbi'].any { args.contains(it) } && extension == 'vcf.gz') {
index = 'tbi'
} else if (['--write-index=tbi', '-W=tbi', '--write-index=csi', '-W=csi', '--write-index', '-W'].any { args.contains(it) }) {
index = 'csi'
}
}
return index
}
19 changes: 14 additions & 5 deletions modules/nf-core/bcftools/concat/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ process BCFTOOLS_CONCAT {
stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
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 create_index = index.matches("csi|tbi") ? "touch ${prefix}.vcf.gz.${index}" : ""
def extension = "vcf.gz"
def index = getVcfIndex(args, extension);
def create_index = index ? "touch ${prefix}.${extension}.${index}" : ""
"""
echo "" | gzip > ${prefix}.vcf.gz
${create_index}
Expand All @@ -53,3 +51,14 @@ process BCFTOOLS_CONCAT {
END_VERSIONS
"""
}
String getVcfIndex(String args, String extension) {
index = ''
if (extension in ['vcf.gz', 'bcf', 'bcf.gz']) {
if (['--write-index=tbi', '-W=tbi'].any { args.contains(it) } && extension == 'vcf.gz') {
index = 'tbi'
} else if (['--write-index=tbi', '-W=tbi', '--write-index=csi', '-W=csi', '--write-index', '-W'].any { args.contains(it) }) {
index = 'csi'
}
}
return index
}
40 changes: 27 additions & 13 deletions modules/nf-core/bcftools/convert/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ process BCFTOOLS_CONVERT {

def regions = bed ? "--regions-file $bed" : ""
def reference = fasta ? "--fasta-ref $fasta" : ""
def extension = args.contains("--output-type b") || args.contains("-Ob") ? "--output ${prefix}.bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "--output ${prefix}.bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "--output ${prefix}.vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "--output ${prefix}.vcf" :
args.contains("--haplegendsample") || args.contains("-h") ? "" :
"--output ${prefix}.vcf.gz"
def extension = getVcfExtension(args);

"""
bcftools convert \\
$args \\
$regions \\
$extension \\
--output ${prefix}.${extension} \\
--threads $task.cpus \\
$reference \\
$input
Expand All @@ -56,18 +51,37 @@ process BCFTOOLS_CONVERT {
stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def extension = getVcfExtension(args);
def index = getVcfIndex(args, extension);
def create_cmd = extension.endsWith(".gz") ? "echo '' | gzip >" : "touch"
def create_index = index ? "touch ${prefix}.${extension}.${index}" : ""

def extension = args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf.gz"
"""
touch ${prefix}.${extension}
${create_cmd} ${prefix}.${extension}
${create_index}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//')
END_VERSIONS
"""
}
// Custom Functions
String getVcfExtension(String args) {
return args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf.gz";
}
String getVcfIndex(String args, String extension) {
index = ''
if (extension in ['vcf.gz', 'bcf', 'bcf.gz']) {
if (['--write-index=tbi', '-W=tbi'].any { args.contains(it) } && extension == 'vcf.gz') {
index = 'tbi'
} else if (['--write-index=tbi', '-W=tbi', '--write-index=csi', '-W=csi', '--write-index', '-W'].any { args.contains(it) }) {
index = 'csi'
}
}
return index
}
19 changes: 14 additions & 5 deletions modules/nf-core/bcftools/csq/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,18 @@ process BCFTOOLS_CSQ {
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
extension = getVcfExtension(args);
index = getVcfIndex(args, extension);

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 create_cmd = extension.endsWith(".gz") ? "echo '' | gzip >" : "touch"
def create_index = extension.endsWith(".gz") && index.matches("csi|tbi") ? "touch ${prefix}.${extension}.${index}" : ""
def create_index = index ? "touch ${prefix}.${extension}.${index}" : ""

if ("$vcf" == "${prefix}.${extension}") error "Input and output names are the same, set prefix in module configuration to disambiguate!"

"""
${create_cmd} ${prefix}.${extension}
${create_index}


cat <<-END_VERSIONS > versions.yml
"${task.process}":
bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//')
Expand All @@ -79,3 +77,14 @@ String getVcfExtension(String args) {
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf";
}
String getVcfIndex(String args, String extension) {
index = ''
if (extension in ['vcf.gz', 'bcf', 'bcf.gz']) {
if (['--write-index=tbi', '-W=tbi'].any { args.contains(it) } && extension == 'vcf.gz') {
index = 'tbi'
} else if (['--write-index=tbi', '-W=tbi', '--write-index=csi', '-W=csi', '--write-index', '-W'].any { args.contains(it) }) {
index = 'csi'
}
}
return index
}
38 changes: 23 additions & 15 deletions modules/nf-core/bcftools/filter/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ process BCFTOOLS_FILTER {
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"

extension = args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf"
extension = getVcfExtension(args);

if ("$vcf" == "${prefix}.${extension}") error "Input and output names are the same, set prefix in module configuration to disambiguate!"

Expand All @@ -47,17 +43,10 @@ process BCFTOOLS_FILTER {
stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
extension = args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
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" :
""
extension = getVcfExtension(args);
def index = getVcfIndex(args, extension);
def create_cmd = extension.endsWith(".gz") ? "echo '' | gzip >" : "touch"
def create_index = extension.endsWith(".gz") && index.matches("csi|tbi") ? "touch ${prefix}.${extension}.${index}" : ""
def create_index = index ? "touch ${prefix}.${extension}.${index}" : ""

if ("$vcf" == "${prefix}.${extension}") error "Input and output names are the same, set prefix in module configuration to disambiguate!"

Expand All @@ -71,3 +60,22 @@ process BCFTOOLS_FILTER {
END_VERSIONS
"""
}
// Custom Functions
String getVcfExtension(String args) {
return args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf";
}
String getVcfIndex(String args, String extension) {
index = ''
if (extension in ['vcf.gz', 'bcf', 'bcf.gz']) {
if (['--write-index=tbi', '-W=tbi'].any { args.contains(it) } && extension == 'vcf.gz') {
index = 'tbi'
} else if (['--write-index=tbi', '-W=tbi', '--write-index=csi', '-W=csi', '--write-index', '-W'].any { args.contains(it) }) {
index = 'csi'
}
}
return index
}
8 changes: 5 additions & 3 deletions modules/nf-core/bcftools/index/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ process BCFTOOLS_INDEX {
stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def extension = args.contains("--tbi") || args.contains("-t") ? "tbi" :
"csi"
def index = (args.contains("--tbi") || args.contains("-t")) && vcf.endsWith("vcf.gz") ? "tbi" :
(args.contains("--csi") || args.contains("-c")) && !vcf.endsWith("vcf") ? "csi" :
""
def create_index = index ? "touch ${vcf}.${index}" : ""
"""
touch ${vcf}.${extension}
${create_index}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
39 changes: 23 additions & 16 deletions modules/nf-core/bcftools/merge/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ process BCFTOOLS_MERGE {

def input = (vcfs.collect().size() > 1) ? vcfs.sort{ it.name } : vcfs
def regions = bed ? "--regions-file $bed" : ""
def extension = args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf"
def extension = getVcfExtension(args);

"""
bcftools merge \\
Expand All @@ -50,18 +46,10 @@ process BCFTOOLS_MERGE {
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" :
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 extension = getVcfExtension(args);
def index = getVcfIndex(args, extension);
def create_cmd = extension.endsWith(".gz") ? "echo '' | gzip >" : "touch"
def create_index = extension.endsWith(".gz") && index.matches("csi|tbi") ? "touch ${prefix}.${extension}.${index}" : ""

def create_index = index ? "touch ${prefix}.${extension}.${index}" : ""
"""
${create_cmd} ${prefix}.${extension}
${create_index}
Expand All @@ -72,3 +60,22 @@ process BCFTOOLS_MERGE {
END_VERSIONS
"""
}
// Custom Functions
String getVcfExtension(String args) {
return args.contains("--output-type b") || args.contains("-Ob") ? "bcf.gz" :
args.contains("--output-type u") || args.contains("-Ou") ? "bcf" :
args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" :
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
"vcf";
}
String getVcfIndex(String args, String extension) {
index = ''
if (extension in ['vcf.gz', 'bcf', 'bcf.gz']) {
if (['--write-index=tbi', '-W=tbi'].any { args.contains(it) } && extension == 'vcf.gz') {
index = 'tbi'
} else if (['--write-index=tbi', '-W=tbi', '--write-index=csi', '-W=csi', '--write-index', '-W'].any { args.contains(it) }) {
index = 'csi'
}
}
return index
}
Loading
Loading