Skip to content

Add DIAMOND blastp subworkflow for protein homology search against NCBI RefSeq - #50

Open
tracelail wants to merge 84 commits into
nf-core:devfrom
tracelail:unfinished-diamond-blastp
Open

tracelail wants to merge 84 commits into
nf-core:devfrom
tracelail:unfinished-diamond-blastp

Conversation

@tracelail

@tracelail tracelail commented Jun 2, 2025

Copy link
Copy Markdown

Protein functional annotation at scale demands efficient sequence alignment against large reference databases. BLAST, the traditional tool for this task, is computationally expensive for large datasets. [DIAMOND](https://github.com/bbuchfink/diamond) (Buchfink et al., [Nature Methods 2021](https://doi.org/10.1038/s41592-021-01101-x)) provides BLAST-compatible sensitivity with significantly higher throughput, up to 10,000× faster than BLAST on large protein databases by using a double-indexed alignment algorithm optimized for modern hardware. Adding DIAMOND blastp to proteinannotator enables users to run protein homology searches against the full NCBI RefSeq protein database as part of their functional annotation workflow, which would be impractical with BLAST at scale.

This PR adds [DIAMOND blastp](https://github.com/bbuchfink/diamond) ([Buchfink et al., Nature Methods 2021](https://doi.org/10.1038/s41592-021-01101-x)) to the pipeline, using the existing nf-core diamond/blastp and [diamond/makedb](https://nf-co.re/modules/diamond_makedb/) modules, plus two new local modules:

New local modules:

  • ncbirefseqdownload : Downloads and concatenates NCBI RefSeq protein FASTAs for a specified release category (e.g. complete, other) into a single compressed reference FASTA for use by diamond/makedb
  • diamondpreparetaxa : Extracts NCBI taxonomy files (nodes.dmp, names.dmp) required for taxonomic classification in diamond/makedb, from a local path or remote URL supplied directly to Nextflow's own file staging

New subworkflows:

  • subworkflows/local/diamond : Orchestrates the full DIAMOND pipeline: RefSeq download → taxonomy preparation → DIAMOND_MAKEDBDIAMOND_BLASTP. Supports all seven DIAMOND output formats (blast, xml, txt, daa, sam, tsv, paf) via params.diamond_outfmt and params.diamond_blast_columns
  • subworkflows/local/functional_annotation — Integrates the DIAMOND subworkflow alongside the existing InterProScan and KOfamScan logic. All three tools are independently gated by their own skip flag (params.skip_diamond, params.skip_interproscan, params.skip_kofamscan); FUNCTIONAL_ANNOTATION passes through all seven of DIAMOND's real output channels (diamond_blast, diamond_xml, diamond_txt, diamond_daa, diamond_sam, diamond_tsv, diamond_paf) rather than hardcoding a single outfmt-specific emit. Consuming these outputs downstream in proteinannotator.nf (e.g. a comparison/reporting step) is left to a follow-up PR.

New parameters (added to nextflow_schema.json and nextflow.config):

  • -skip_diamond — Skip the DIAMOND BLASTP taxonomic classification step entirely (default: false)
  • -refseq_release — NCBI RefSeq release category (default: complete)
  • -taxondmp_zip — URL to NCBI taxonomy dump archive
  • -taxonmap — URL to compressed protein accession-to-taxid map
  • -diamond_outfmt — Output format code (default: 6, tabular)
  • -diamond_blast_columns — Optional column list for tabular output

Testing:

All new local modules have nf-test test suites with both live and stub tests:

The diamond subworkflow is tested end-to-end using a miniature mini_prot.accession2taxid.gz taxon map and a small test_refseq.fasta. Tests cover five scenarios:

  • Live run with tabular output (outfmt 6, no columns)
  • Stub: outfmt 6, no columns
  • Stub: outfmt 6, with custom columns
  • Stub: outfmt 0 (pairwise BLAST format)
  • Stub: two-sample input, regression-testing a fixed channel cardinality bug (DIAMOND_MAKEDB's output now correctly broadcasts to every sample via .first(), rather than pairing positionally and silently dropping any sample beyond the first)

The functional_annotation subworkflow is tested with skip_interproscan = true and skip_diamond = false for DIAMOND-focused tests (live and stub), confirming the DIAMOND path runs correctly independently. Pre-existing InterProScan- and KOfamScan-focused tests now set skip_diamond = true, since they were previously running the full DIAMOND pipeline unconditionally despite being unrelated to what they test.

All stub tests are tagged CI for fast pipeline CI runs. Live module tests require -profile docker and are tagged accordingly. All local-module and subworkflow live tests, including the DIAMOND-focused paths in diamond and functional_annotation, have been run and verified under real -profile docker execution.

PR checklist

  • This comment contains a description of changes (with reason).
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added a new tool - have you followed the pipeline conventions in the [contribution docs](https://github.com/nf-core/proteinannotator/tree/master/.github/CONTRIBUTING.md)
  • If necessary, also make a PR on the nf-core/proteinannotator branch on the [nf-core/test-datasets](https://github.com/nf-core/test-datasets) repository.
  • Make sure your code lints (nf-core pipelines lint).
  • Ensure the test suite passes (e.g. nf-test test */local --profile=~test,docker for all new local tests).
  • Check for unexpected warnings in debug mode (nf-test test */local --profile=~test,docker,debug).
  • Usage Documentation in docs/usage.md is updated.
  • Output Documentation in docs/output.md is updated.
  • CHANGELOG.md is updated.
  • README.md is updated (including new tool citations and authors/contributors).

@nf-core-bot

nf-core-bot commented Jun 2, 2025

Copy link
Copy Markdown
Member

Warning

Newer version of the nf-core template is available.

Your pipeline is using an old version of the nf-core template: 3.3.1.
Please update your pipeline to the latest version.

For more documentation on how to update your pipeline, please see the nf-core documentation and Synchronisation documentation.

@olgabot olgabot mentioned this pull request Jun 24, 2025
11 tasks

@olgabot olgabot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out I had started this review a while ago... But here are a bunch of suggestions that will hopefully deal with the container issues.

Comment thread .vscode/settings.json Outdated
Comment thread .nf-test.log Outdated
Comment thread CITATIONS.md Outdated
Comment thread docs/output.md Outdated
Comment thread docs/output.md
Comment thread modules/local/diamondpreparetaxa/environment.yml Outdated
Comment thread modules/local/diamondpreparetaxa/main.nf Outdated
Comment thread modules/local/diamondpreparetaxa/main.nf Outdated
Comment thread modules/local/diamondpreparetaxa/main.nf Outdated
Comment thread modules/local/ncbirefseqdownload/main.nf Outdated
tracelail and others added 5 commits July 28, 2025 12:21
@tracelail

Copy link
Copy Markdown
Author

quite a few non nf-core stuff around that need to be fixed..the latest dev should be merged in this branch and conflicts should be resolved.

Non-nf-core stuff and merge conflicts: done.

I was wondring if this should stay under the functional_annotation subworkflow, or become its own derive_taxonomy subworkflow (or something like that) that is currently missing from the pipeline and this seems to fill that gap.

On functional_annotation vs its own derive_taxonomy subworkflow: keeping it under functional_annotation for now, will revisit with @olgabot since she's the one who set up this structure originally.

when finalized and before merging, the metro map should be updated accordingly (I can do that)

Metro map: good catch, you're right. Checked and DIAMOND isn't in it (neither is KOfamScan). There's also a tool for this now, nf-metro, converts Nextflow's dag output into the metro map style directly, in case that's useful. You'd mentioned you're happy to handle the update yourself, so deferring to you on that unless you'd rather I take a pass at it (haven't done this myself).

@vagkaratzas

Copy link
Copy Markdown
Collaborator

@tracelail can you resolve the last file conflict so I can hopefully go through the PR once more on Monday?

@tracelail

Copy link
Copy Markdown
Author

@tracelail can you resolve the last file conflict so I can hopefully go through the PR once more on Monday?

Resolved!

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

nf-core pipelines lint overall result: Passed ✅

Posted for pipeline commit 0ef2c8a

+| ✅ 239 tests passed       |+
#| ❔  10 tests were ignored |#
#| ❔   1 tests had warnings |#
Details

❔ Tests ignored:

  • files_exist - File is ignored: .github/workflows/ci.yml
  • files_exist - File is ignored: conf/igenomes.config
  • files_exist - File is ignored: conf/igenomes_ignored.config
  • files_exist - File is ignored: .github/workflows/linting_comment.yml
  • files_unchanged - File ignored due to lint config: .github/PULL_REQUEST_TEMPLATE.md
  • files_unchanged - File ignored due to lint config: .github/workflows/branch.yml
  • files_unchanged - File ignored due to lint config: .github/workflows/linting.yml
  • files_unchanged - File ignored due to lint config: assets/nf-core-proteinannotator_logo_light.png
  • files_unchanged - File ignored due to lint config: docs/images/nf-core-proteinannotator_logo_light.png
  • files_unchanged - File ignored due to lint config: docs/images/nf-core-proteinannotator_logo_dark.png

❔ Tests fixed:

✅ Tests passed:

Run details

  • nf-core/tools version 4.1.0
  • Run at 2026-09-07 23:36:55

@vagkaratzas

Copy link
Copy Markdown
Collaborator

@tracelail you are still not a member of the nf-core github organization. Can you request that through the github-invitations slack channel?
I started the CI workflow tests, but when you become a member they will be starting automatically so you can debug faster ;)

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

❌ nf-test failed with latest Nextflow version

Note

Tests with Nextflow's latest version failed but it will not cause a CI workflow failure.
Please check if the failure is expected with newer (edge-)releases of Nextflow or if it needs fixing.

  • docker | latest-everything | Shard 2/7

See the full run for details.

@vagkaratzas vagkaratzas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left another round of comments. These, along with the failing tests will hopefully guide you a bit better now.

Comment thread nextflow.config Outdated
when {
process {
"""
input[0] = "file://${moduleTestDir}/mini_taxdump.tar.gz"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper way to do this is to push this file at: https://github.com/nf-core/test-datasets/tree/proteinannotator/testdata

Take a look into the rest of the local subworkflows for inspiration (e.g., functional_annotation nf-tests)

process "DIAMONDPREPARETAXA"

tag "modules"
tag "modules_"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tag "modules_"

not a legit tag

Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread subworkflows/local/diamond/tests/main.nf.test Outdated
Comment on lines +25 to +27
assert process.trace.tasks().size() == 1
assert process.out.refseq_fasta.size() == 1
assert snapshot(process.out).match()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert process.trace.tasks().size() == 1
assert process.out.refseq_fasta.size() == 1
assert snapshot(process.out).match()
{ assert snapshot(sanitizeOutput(process.out)).match() }

try using sanitizeOutput instead, which is the new standard way in nf-core assertions. This also covers the tool versions, which do not show anywhere in the snapshot atm. You will have to reproduce the snapshots.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the rest of the test assertions accordingly as well


test("Should download ncbi refseq 'other' zipped protein fasta -- stub") {
tag "stub"
tag "CI"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these tag "CI" throughout

Comment on lines +7 to +11
tag "modules"
tag "modules_"
tag "ncbirefseqdownload"
tag "diamond"
tag "diamond_local"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tag "modules"
tag "modules_"
tag "ncbirefseqdownload"
tag "diamond"
tag "diamond_local"
tag "modules"
tag "ncbirefseqdownload"

no diamond tool or diamond_local is called. update like this across

tags should include:
tag "modules" by default and then a tag for each module that is executed

description: NCBI taxonomy names file containing taxon names
pattern: "names.dmp"

- versions_curl:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of sync, should contain the new topic versions channel with the proper tool (tar)

- Remove genome/igenomes_base/igenomes_ignore from nextflow.config;
  stray template params not in schema (fixes schema_params lint failures)
- Add enum constraint to refseq_release (14 valid NCBI RefSeq divisions)
- Add format: file-path to taxondmp_zip/taxonmap
- Remove redundant default: false from skip_diamond schema entry
  (matches convention of other skip_* params; default lives in nextflow.config)
- Rewrite diamondpreparetaxa meta.yml to match actual main.nf: tar (not
  untar/diamond), path input type, topic-channel versions
- Trim unused grep/lbzip2 deps from diamondpreparetaxa environment.yml
- Remove stray <h1> from README.md
- Update usage.md with refseq_release valid values
- Clean up test tags across diamondpreparetaxa, ncbirefseqdownload,
  diamond, and functional_annotation tests (remove tag "modules_",
  stray tag "CI", mismatched tool tags)
@tracelail

tracelail commented Sep 8, 2026

Copy link
Copy Markdown
Author

Shard 6/7 has failed twice now with identical No space left on device . once at 06:19:39, once at 23:36:53, both on this branch.

Looking into it, it seems structural rather than flaky: tests/default.nf.test (the full -profile test run) always lands on shard 6, since sharding splits by file and there are only 6 test files across 7 shards. That test downloads every domain + functional annotation database and container concurrently (Pfam, FunFam, metagRoot, NMPfams, InterProScan, KOfamScan, refseq, taxdump), so it's by far the heaviest job in the suite.

I don't believe have visibility into the runner's disk config or whether this is a known issue. @vagkaratzas: do you know what I should do here, or who'd be the right person to flag it to?

(Used Claude to help investigate the logs and draft this comment.)

@vagkaratzas

Copy link
Copy Markdown
Collaborator

Shard 6/7 has failed twice now with identical No space left on device . once at 06:19:39, once at 23:36:53, both on this branch.

Looking into it, it seems structural rather than flaky: tests/default.nf.test (the full -profile test run) always lands on shard 6, since sharding splits by file and there are only 6 test files across 7 shards. That test downloads every domain + functional annotation database and container concurrently (Pfam, FunFam, metagRoot, NMPfams, InterProScan, KOfamScan, refseq, taxdump), so it's by far the heaviest job in the suite.

I don't believe have visibility into the runner's disk config or whether this is a known issue. @vagkaratzas: do you know what I should do here, or who'd be the right person to flag it to?

(Used Claude to help investigate the logs and draft this comment.)

By now, I've used Claude that much, that I can feel its "watermark" in code, text, video and audio..no worries :p

The problem happens in NFCORE_PROTEINANNOTATOR:PROTEINANNOTATOR:FUNCTIONAL_ANNOTATION:DIAMOND:NCBIREFSEQDOWNLOAD (download_refseq). The best solution would be to create a subset of that database to download, that has a couple of hits for your test data.

Tests should always run with the minimal viable data possible, so try to create that subset file and host it in the test-datasets proteinannotator branch along with the rest!

Fast and accurate ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants