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

Allow sorting inputs to SVDB #6794

Merged
merged 5 commits into from
Oct 18, 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
35 changes: 29 additions & 6 deletions modules/nf-core/svdb/merge/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,50 @@ process SVDB_MERGE {

input:
tuple val(meta), path(vcfs)
val (priority)
val(priority)
val(sort_inputs)

output:
tuple val(meta), path("*.vcf.gz"), emit: vcf
path "versions.yml" , emit: versions
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when

script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def input = "${vcfs.join(" ")}"
def prio = ""

// Ensure priority list matches the number of VCFs if priority is provided
if (priority && vcfs.collect().size() != priority.collect().size()) {
error "If priority is used, one tag per VCF is needed"
}

if (sort_inputs && vcfs.collect().size() > 1) {
if (priority) {
// make vcf-prioprity pairs and sort on VCF name, so priority is also sorted the same
def pairs = vcfs.indices.collect { [vcfs[it], priority[it]] }
pairs = pairs.sort { a, b -> a[0].name <=> b[0].name }
vcfs = pairs.collect { it[0] }
priority = pairs.collect { it[1] }
} else {
// if there's no priority input just sort the vcfs by name
vcfs = vcfs.sort { it.name }
}
}

// If there's only one input VCF the code above is not executed, and that VCF becomes the input
input = vcfs

def prio = ""
if(priority) {
prio = "--priority ${priority.join(',')}"
input = ""
for (int index = 0; index < vcfs.size(); index++) {
input += " ${vcfs[index]}:${priority[index]}"
for (int index = 0; index < vcfs.collect().size(); index++) {
input += "${vcfs[index]}:${priority[index]} "
}
}

"""
svdb \\
--merge \\
Expand Down
16 changes: 13 additions & 3 deletions modules/nf-core/svdb/merge/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ input:
e.g. [ id:'test' ]
- vcfs:
type: list
description: Two or more VCF files. Order of files should correspond to the
order of tags used for priority.
description: |
One or more VCF files. The order and number of files should correspond to
the order and number of tags in the `priority` input channel.
pattern: "*.{vcf,vcf.gz}"
- - priority:
type: list
description: prioritise the input vcf files according to this list, e.g ['tiddit','cnvnator']
description: |
Prioritize the input VCF files according to this list,
e.g ['tiddit','cnvnator']. The order and number of tags should correspond to
the order and number of VCFs in the `vcfs` input channel.
- - sort_inputs:
type: boolean
description: |
Should the input files be sorted by name. The priority tag will be sorted
together with it's corresponding VCF file.

output:
- vcf:
- meta:
Expand Down
Loading
Loading