Skip to content

Commit

Permalink
Allow sorting inputs to SVDB (#6794)
Browse files Browse the repository at this point in the history
* Sort input files order

* Allow sorted inputs to SVDB

* update tests

* Update meta
  • Loading branch information
fellen31 authored Oct 18, 2024
1 parent a1a55bc commit b80931c
Show file tree
Hide file tree
Showing 5 changed files with 507 additions and 34 deletions.
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

0 comments on commit b80931c

Please sign in to comment.