Skip to content

Commit

Permalink
New module: taxonkit/lineage
Browse files Browse the repository at this point in the history
  • Loading branch information
erikrikarddaniel committed Jan 14, 2025
1 parent 1c42491 commit aaeb724
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/nf-core/taxonkit/lineage/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json
channels:
- conda-forge
- bioconda
dependencies:
- "bioconda::taxonkit=0.18.0"
51 changes: 51 additions & 0 deletions modules/nf-core/taxonkit/lineage/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
process TAXONKIT_LINEAGE {
tag "$meta.id"
label 'process_low'

conda "${moduleDir}/environment.yml"
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/taxonkit:0.18.0--h9ee0642_0':
'biocontainers/taxonkit:0.18.0--h9ee0642_0' }"

input:
tuple val(meta), val(taxid), path(taxidfile)
path taxdb

output:
tuple val(meta), path("*.tsv"), emit: tsv
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}"
assert (!taxid && taxidfile) || (taxid && !taxidfile)
"""
taxonkit \\
lineage \\
$args \\
--data-dir $taxdb \\
--threads $task.cpus \\
--out-file ${prefix}.tsv \\
${taxid? "<<< '$taxid'": taxidfile}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
taxonkit: \$( taxonkit version | sed 's/.* v//' )
END_VERSIONS
"""

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch ${prefix}.tsv
cat <<-END_VERSIONS > versions.yml
"${task.process}":
taxonkit: \$( taxonkit version | sed 's/.* v//' )
END_VERSIONS
"""
}
54 changes: 54 additions & 0 deletions modules/nf-core/taxonkit/lineage/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json
name: "taxonkit_lineage"
description: Convert taxonids to taxon lineages
keywords:
- taxonomy
- taxids
- taxon name
- conversion
tools:
- "taxonkit":
description: "A Cross-platform and Efficient NCBI Taxonomy Toolkit"
homepage: "https://bioinf.shenwei.me/taxonkit/"
documentation: "https://bioinf.shenwei.me/taxonkit/usage/#name2taxid"
tool_dev_url: "https://github.com/shenwei356/taxonkit"
doi: "10.1016/j.jgg.2021.03.006"
licence: ["MIT"]
identifier: biotools:taxonkit

input:
- - meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`
- taxid:
type: string
description: Taxon id to look up (provide either this or taxidfile, not both)
- taxidfile:
type: file
description: File with taxon ids to look up, each on their own line (provide
either this or name, not both; the file can contain other information, see the tool's docs)
- - taxdb:
type: file
description: Taxonomy database unpacked from ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
output:
- tsv:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`
- "*.tsv":
type: file
description: TSV file with added taxon lineages
pattern: "*.tsv"
- versions:
- "versions.yml":
type: file
description: File containing software versions
pattern: "versions.yml"
authors:
- "@erikrikarddaniel"
maintainers:
- "@erikrikarddaniel"
101 changes: 101 additions & 0 deletions modules/nf-core/taxonkit/lineage/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
nextflow_process {

name "Test Process TAXONKIT_LINEAGE"
script "../main.nf"
process "TAXONKIT_LINEAGE"

tag "modules"
tag "modules_nfcore"
tag "untar"
tag "taxonkit"
tag "taxonkit/lineage"

setup {
run("UNTAR"){
script "modules/nf-core/untar/main.nf"
process {
"""
input[0] = [
[ id:'test' ],
file("ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz", checkIfExists: true)
]
"""
}
}
}

test("sarscov2 - taxonid") {

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
"2697049",
[]
]
input[1] = UNTAR.out.untar.map{ it[1] }
"""
}
}

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

}

test("sarscov2 - taxid list") {

when {
process {
"""
input[0] = Channel.of( [
[ id:'test', single_end:false ], // meta map
''
] ).combine( Channel.of("2697049").collectFile( name:'taxids.txt', newLine: true ) )
input[1] = UNTAR.out.untar.map{ it[1] }
"""
}
}

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

}

test("sarscov2 - taxid - stub") {

options "-stub"

when {
process {
"""
input[0] = [
[ id:'test', single_end:false ], // meta map
"2697049",
[]
]
input[1] = UNTAR.out.untar.map{ it[1] }
"""
}
}

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

}


}
107 changes: 107 additions & 0 deletions modules/nf-core/taxonkit/lineage/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"sarscov2 - taxid list": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
"test.tsv:md5,e77031f8b6f6865d9fa9525c55b7b4be"
]
],
"1": [
"versions.yml:md5,48f687591d0255bd02b4607e375a09f6"
],
"tsv": [
[
{
"id": "test",
"single_end": false
},
"test.tsv:md5,e77031f8b6f6865d9fa9525c55b7b4be"
]
],
"versions": [
"versions.yml:md5,48f687591d0255bd02b4607e375a09f6"
]
}
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.3"
},
"timestamp": "2025-01-14T15:44:11.506619"
},
"sarscov2 - taxid - stub": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
"test.tsv:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"1": [
"versions.yml:md5,48f687591d0255bd02b4607e375a09f6"
],
"tsv": [
[
{
"id": "test",
"single_end": false
},
"test.tsv:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"versions": [
"versions.yml:md5,48f687591d0255bd02b4607e375a09f6"
]
}
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.3"
},
"timestamp": "2025-01-14T15:44:41.061875"
},
"sarscov2 - taxonid": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
"test.tsv:md5,e77031f8b6f6865d9fa9525c55b7b4be"
]
],
"1": [
"versions.yml:md5,48f687591d0255bd02b4607e375a09f6"
],
"tsv": [
[
{
"id": "test",
"single_end": false
},
"test.tsv:md5,e77031f8b6f6865d9fa9525c55b7b4be"
]
],
"versions": [
"versions.yml:md5,48f687591d0255bd02b4607e375a09f6"
]
}
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.3"
},
"timestamp": "2025-01-14T15:43:31.166225"
}
}

0 comments on commit aaeb724

Please sign in to comment.