From 424bb748e7371a2d4399bca80e1f3eb0e60bc5df Mon Sep 17 00:00:00 2001 From: dishalodha Date: Thu, 6 Aug 2026 13:51:51 +0100 Subject: [PATCH 1/4] new module for taxonomy classification --- modules/ensembl/taxanomy/main.nf | 65 +++++++++++++++++++++++++++ modules/ensembl/taxanomy/main.nf.test | 33 ++++++++++++++ modules/ensembl/taxanomy/meta.yml | 26 +++++++++++ 3 files changed, 124 insertions(+) create mode 100644 modules/ensembl/taxanomy/main.nf create mode 100644 modules/ensembl/taxanomy/main.nf.test create mode 100644 modules/ensembl/taxanomy/meta.yml diff --git a/modules/ensembl/taxanomy/main.nf b/modules/ensembl/taxanomy/main.nf new file mode 100644 index 0000000..2e0c1c3 --- /dev/null +++ b/modules/ensembl/taxanomy/main.nf @@ -0,0 +1,65 @@ +// See the NOTICE file distributed with this work for additional information +// regarding copyright ownership. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +nextflow.enable.types = true + +process TAXONOMY_CLASSIFICATION { + tag "${meta.id}" + label 'process_small' + + conda "${moduleDir}/environment.yml" + container 'ensemblorg/datasets-cli:latest' + + input: + record( + meta: Map, + species: String + ) + + output: + record( + meta: meta, + species: species, + json: file("classification.json") + ) + + topic: + tuple("${task.process}", 'datasets', eval('datasets --version | sed "s/^.*datasets version: //"')) >> 'versions' + + script: + """ + echo "Calling datasets-cli for ${species}" + ids=\$(datasets summary taxonomy taxon "${species}" \ + | jq -r '.reports[0].taxonomy | ((.lineage // .parents)[], .tax_id)') + + datasets summary taxonomy taxon \$ids \ + | jq -r '.reports[].taxonomy.current_scientific_name.name' \ + | awk 'NF && !seen[\$0]++' \ + | jq -Rsc 'split("\n") | map(select(length > 0))' \ + > "classification.json" + + if [ "\$(jq 'length' classification.json)" -eq 0 ]; then + echo "No classification found for ${species}" >&2 + exit 1 + fi + """ + + stub: + """ + cat <<'EOF' > classification.json + ["cellular organisms", "Eukaryota", "Viridiplantae"] + EOF + """ +} + diff --git a/modules/ensembl/taxanomy/main.nf.test b/modules/ensembl/taxanomy/main.nf.test new file mode 100644 index 0000000..af238b2 --- /dev/null +++ b/modules/ensembl/taxanomy/main.nf.test @@ -0,0 +1,33 @@ +nextflow_process { + + name "Test Process TAXONOMY_CLASSIFICATION" + script "../main.nf" + process "TAXONOMY_CLASSIFICATION" + tag "modules" + tag "modules_local" + tag "genome_classification" + + test("should create a lineage classification JSON") { + + options "-stub-run" + + when { + process { + """ + input[0] = [ + meta: [id: 'test_species'], + species: 'Arabidopsis thaliana' + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } +} + diff --git a/modules/ensembl/taxanomy/meta.yml b/modules/ensembl/taxanomy/meta.yml new file mode 100644 index 0000000..3aa2291 --- /dev/null +++ b/modules/ensembl/taxanomy/meta.yml @@ -0,0 +1,26 @@ +name: TAXONOMY_CLASSIFICATION +description: Retrieve a species lineage and write it as a JSON classification using datasets-cli. +keywords: + - taxonomy + - classification + - datasets-cli +tools: + - datasets: + description: NCBI Datasets command-line tool. + homepage: https://www.ncbi.nlm.nih.gov/datasets/ + documentation: https://www.ncbi.nlm.nih.gov/datasets/docs/v2/command-line-tools/ + licence: ["Public Domain"] +input: + - meta: + type: map + description: Sample metadata containing a unique `id`. + - species: + type: string + description: Scientific species name passed to datasets-cli. +output: + - classification: + type: record + description: Record containing sample metadata, species, and the lineage JSON file. + - versions: + type: tuple + description: Dataset version tuple published to the `versions` topic. From e7ae6a83a988dfa9bff87a0540be1eb6c40bd0e2 Mon Sep 17 00:00:00 2001 From: dishalodha Date: Thu, 6 Aug 2026 15:49:37 +0100 Subject: [PATCH 2/4] created snapshot and updated record for test --- modules/ensembl/taxanomy/main.nf.test | 33 ------------- modules/ensembl/taxanomy/tests/main.nf.test | 47 +++++++++++++++++++ .../ensembl/taxanomy/tests/main.nf.test.snap | 22 +++++++++ 3 files changed, 69 insertions(+), 33 deletions(-) delete mode 100644 modules/ensembl/taxanomy/main.nf.test create mode 100644 modules/ensembl/taxanomy/tests/main.nf.test create mode 100644 modules/ensembl/taxanomy/tests/main.nf.test.snap diff --git a/modules/ensembl/taxanomy/main.nf.test b/modules/ensembl/taxanomy/main.nf.test deleted file mode 100644 index af238b2..0000000 --- a/modules/ensembl/taxanomy/main.nf.test +++ /dev/null @@ -1,33 +0,0 @@ -nextflow_process { - - name "Test Process TAXONOMY_CLASSIFICATION" - script "../main.nf" - process "TAXONOMY_CLASSIFICATION" - tag "modules" - tag "modules_local" - tag "genome_classification" - - test("should create a lineage classification JSON") { - - options "-stub-run" - - when { - process { - """ - input[0] = [ - meta: [id: 'test_species'], - species: 'Arabidopsis thaliana' - ] - """ - } - } - - then { - assertAll( - { assert process.success }, - { assert snapshot(process.out).match() } - ) - } - } -} - diff --git a/modules/ensembl/taxanomy/tests/main.nf.test b/modules/ensembl/taxanomy/tests/main.nf.test new file mode 100644 index 0000000..e801f2d --- /dev/null +++ b/modules/ensembl/taxanomy/tests/main.nf.test @@ -0,0 +1,47 @@ +// See the NOTICE file distributed with this work for additional information +// regarding copyright ownership. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +nextflow_process { + + name "Test Process TAXONOMY_CLASSIFICATION" + script "../main.nf" + process "TAXONOMY_CLASSIFICATION" + tag "modules" + tag "modules_ensembl" + tag "genome_classification" + + test("should create a lineage classification JSON") { + + options "-stub-run" + + when { + process { + """ + input[0] = record( + meta: [id: 'test_species'], + species: 'Arabidopsis thaliana' + ) + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } +} diff --git a/modules/ensembl/taxanomy/tests/main.nf.test.snap b/modules/ensembl/taxanomy/tests/main.nf.test.snap new file mode 100644 index 0000000..f3ea752 --- /dev/null +++ b/modules/ensembl/taxanomy/tests/main.nf.test.snap @@ -0,0 +1,22 @@ +{ + "should create a lineage classification JSON": { + "content": [ + { + "0": [ + { + "json": "classification.json:md5,8a1b235fc7b2b83a658f7a9ec282b59e", + "meta": { + "id": "test_species" + }, + "species": "Arabidopsis thaliana" + } + ] + } + ], + "timestamp": "2026-08-06T15:48:40.679892238", + "meta": { + "nf-test": "0.9.5", + "nextflow": "26.04.0" + } + } +} \ No newline at end of file From ec3fd62decfa98c0a3ea35794ac697404381d2c7 Mon Sep 17 00:00:00 2001 From: dishalodha Date: Thu, 6 Aug 2026 15:54:56 +0100 Subject: [PATCH 3/4] updated the lint for main --- modules/ensembl/taxanomy/main.nf | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/ensembl/taxanomy/main.nf b/modules/ensembl/taxanomy/main.nf index 2e0c1c3..a4bce40 100644 --- a/modules/ensembl/taxanomy/main.nf +++ b/modules/ensembl/taxanomy/main.nf @@ -41,13 +41,12 @@ process TAXONOMY_CLASSIFICATION { """ echo "Calling datasets-cli for ${species}" ids=\$(datasets summary taxonomy taxon "${species}" \ - | jq -r '.reports[0].taxonomy | ((.lineage // .parents)[], .tax_id)') + | jq -r '.reports[0].taxonomy | ((.lineage // .parents)[], .tax_id)') datasets summary taxonomy taxon \$ids \ - | jq -r '.reports[].taxonomy.current_scientific_name.name' \ - | awk 'NF && !seen[\$0]++' \ - | jq -Rsc 'split("\n") | map(select(length > 0))' \ - > "classification.json" + | jq -r '.reports[].taxonomy.current_scientific_name.name' \ + | awk 'NF && !seen[\$0]++' \ + | jq -Rsc 'split("\n") | map(select(length > 0))'> classification.json if [ "\$(jq 'length' classification.json)" -eq 0 ]; then echo "No classification found for ${species}" >&2 From 332ae65bed16ebdac09bd30f87657cfbc6cae4fd Mon Sep 17 00:00:00 2001 From: dishalodha Date: Thu, 6 Aug 2026 16:09:09 +0100 Subject: [PATCH 4/4] update meta.yml --- modules/ensembl/taxanomy/environment.yml | 7 ++++ modules/ensembl/taxanomy/meta.yml | 45 +++++++++++++++++------- 2 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 modules/ensembl/taxanomy/environment.yml diff --git a/modules/ensembl/taxanomy/environment.yml b/modules/ensembl/taxanomy/environment.yml new file mode 100644 index 0000000..8411965 --- /dev/null +++ b/modules/ensembl/taxanomy/environment.yml @@ -0,0 +1,7 @@ +--- +channels: + - conda-forge + - bioconda +dependencies: + - conda-forge::ncbi-datasets-cli=18.33.1 + - conda-forge::jq=1.7.1 diff --git a/modules/ensembl/taxanomy/meta.yml b/modules/ensembl/taxanomy/meta.yml index 3aa2291..2944b95 100644 --- a/modules/ensembl/taxanomy/meta.yml +++ b/modules/ensembl/taxanomy/meta.yml @@ -4,6 +4,7 @@ keywords: - taxonomy - classification - datasets-cli + - genomics tools: - datasets: description: NCBI Datasets command-line tool. @@ -11,16 +12,36 @@ tools: documentation: https://www.ncbi.nlm.nih.gov/datasets/docs/v2/command-line-tools/ licence: ["Public Domain"] input: - - meta: - type: map - description: Sample metadata containing a unique `id`. - - species: - type: string - description: Scientific species name passed to datasets-cli. + - - meta: + type: channelMap + description: Groovy map containing sample metadata, including a unique id. + - species: + type: string + description: Scientific species name passed to datasets-cli. output: - - classification: - type: record - description: Record containing sample metadata, species, and the lineage JSON file. - - versions: - type: tuple - description: Dataset version tuple published to the `versions` topic. + classification: + - - meta: + type: channelMap + description: Sample metadata propagated from the input. + - species: + type: string + description: Species name propagated from the input. + - json: + type: file + description: JSON file containing the retrieved lineage classification. + pattern: "classification.json" +topics: + versions: + - - "${task.process}": + type: string + description: Name of the process producing the version. + - datasets: + type: string + description: Name of the tool. + - 'datasets --version | sed "s/^.*datasets version: //"': + type: eval + description: Command used to obtain the datasets version. +authors: + - "@ensembl-dev" +maintainers: + - "@ensembl-dev"