Repository navigation
Add KofamScan annotation of genome proteins - #300
Conversation
Run KofamScan once per genome on its protein FASTA (Prokka, Bakta or gffread) and store each result in `magmap_kofamscan` with `storeDir`, as for Prokka. Concatenate the per-genome results into `summary_tables/magmap.kofamscan.tsv.gz`, which also goes into the Parquet conversion with `--save_parquet`. `--skip_kofamscan` turns the step off. The vendored kofamscan module is patched to read and write gzip and to name its outputs by prefix, because a glob over the shared store directory collected other genomes' files. It also drops the versions topic emit, which `storeDir` rejects, so a local `KOFAMSCAN_VERSION` module reports the version. Only the default test runs KofamScan; the other test profiles skip it. Generated by Claude Code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH
Point the full test at S3 store directories for the KofamScan database and results, as for Prokka, so Batch does not write to a local path and download the real database on every run. Point the default test at its own store directories so that a test run does not seed the database and results of a real run in the same directory. Let `KOFAMSCAN_TABLE` succeed when no genome has a hit: `grep -v` exits 1 on header-only input and the pipeline shell uses `pipefail`. A new subworkflow test with a single no-hit genome failed before the change. Require the `tsv` output of the patched kofamscan module, so that an `ext.args` without `--format detail-tsv` fails the task instead of silently dropping the summary table. Update the module `meta.yml` and tests to the patched outputs. Add the KofamScan citation and the kofamscan version to the CHANGELOG dependencies, and drop two comments that repeated the code. Generated by Claude Code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH
Run the `hmmfiles` test with `--save_parquet` and check that `magmap.kofamscan.parquet` and `magmap.hmmrank.parquet` are written. Only the default test profile runs KofamScan, and no Parquet test covered this table or the hmmrank table. The `hmmfiles` test is used so that CI does not run another full default test. Generated by Claude Code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH
KofamScan can report several KOs for one protein, and with environmental and partial sequences the hit that reaches its own threshold is often missing. The new KOFAMSCAN_BEST module keeps one row per protein, the one with the highest score among all hits, with the lowest KO id winning a tie. No threshold is applied, so users filter on `score` and `thrshld` themselves. Scores are compared as numbers; as text "9.5" would beat "80.0". The table is published as summary_tables/magmap.kofamscan_best.tsv.gz and converted to Parquet with the other summary tables. Tests: module test with inline hits (higher score listed second, only sub-threshold hits, `-` threshold with a tie), header-only input and stub; the subworkflow and pipeline tests check that the best table has the same ORFs as the full table and that each score is the maximum. Generated by Claude Code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH
|
There was a problem hiding this comment.
Thanks for this, it's a really careful addition. The design follows the pipeline's existing patterns: storeDir caching like Prokka and Bakta, a separate *_VERSION process for the cached module, and the DuckDB heredoc style. The tests are thorough too, and the numeric-vs-text sort test case is a nice touch. The one thing to fix before merge: the KofamScan store is keyed only by accession. If a genome's proteins change between runs, for example after switching --annotator, the old hits get reused with ORF IDs that no longer match. The rest is optional.
|
|
||
| withName: KOFAMSCAN_SCAN { | ||
| ext.args = '--format detail-tsv' | ||
| ext.prefix = { "${meta.id}.kofamscan" } |
There was a problem hiding this comment.
Required: The stored file is named <accno>.kofamscan.tsv.gz whatever produced the proteins. Prokka and Bakta use separate store dirs (--prokka_store_dir, --bakta_store_dir) and give different ORF IDs: Bakta uses a hash of the accno as its locus tag (L110–123). So if one run uses --annotator prokka and a later run uses --annotator bakta_all with the same --kofamscan_store_dir, the KofamScan result is silently reused with Prokka ORF IDs. Those IDs won't join to the rest of that run's tables. Could we add the protein source to meta in workflows/magmap.nf (e.g. PROKKA.out.faa.map { m, f -> [ m + [ source: 'prokka' ], f ] }, and likewise for Bakta and gffread) and use it in the prefix?
| ext.prefix = { "${meta.id}.kofamscan" } | |
| ext.prefix = { "${meta.id}.${meta.source}.kofamscan" } |
We could also widen the warning in docs/output.md (~L210) to cover any change to a genome's proteins, such as an edited gff, not only database updates. This follows the repo's existing separate-store pattern for Prokka and Bakta (conf/modules.config L101–124).
There was a problem hiding this comment.
Good catch, fixed in d2a5ef9.
The proteins now carry meta.source (prokka, bakta or gffread) and the stored file is <accno>.<source>.kofamscan.tsv.gz, as you suggested.
A result from another source no longer matches, so switching annotator annotates the genome again.
A subworkflow test seeds the store with a Prokka result for two genomes, runs one as Bakta and one as Prokka, and checks that only the Bakta one is annotated again.
I also widened the warning in docs/output.md: it now covers a changed GFF, and says that the source in the file name is what triggers re-annotation.
| @@ -0,0 +1,184 @@ | |||
| Changes in component 'nf-core/kofamscan' | |||
There was a problem hiding this comment.
Suggestion: Most of this patch adds gzipped input and output. That seems useful upstream, and moving it there would shrink the patch here and restore the upstream tests it removes. Would you consider opening it as a PR to nf-core/modules? Then only the storeDir / versions change stays local. See nf-core module patching.
There was a problem hiding this comment.
Done in nf-core/modules#13805, which is now merged.
I updated the vendored module in 5ad5f53, and the patch is down to dropping the versions topic and keeping tsv non-optional.
storeDir needs tsv to be non-optional to tell a missing result from a stored one.
| script: | ||
| def args = task.ext.args ?: '' | ||
| prefix = task.ext.prefix ?: "${meta.id}" | ||
| extension = args.contains("--format detail-tsv") ? "tsv" : |
There was a problem hiding this comment.
Nit: Only prefix needs to be global for the output: paths. extension can stay def extension = … (same at L53).
| - conda-forge | ||
| - bioconda | ||
| dependencies: | ||
| - conda-forge::wget=1.21.4 |
There was a problem hiding this comment.
Nit: The script only uses gunzip and tar, and the comment in main.nf explains why awscli is there. Is wget still needed? Relatedly, the meta.yml description says "Downloads", but Nextflow does the download when it stages the file() inputs. Maybe "Unpacks the KOfam ko_list and HMM profiles"?
There was a problem hiding this comment.
The meta.yml description now says "Unpacks the KOfam ko_list and HMM profiles for KofamScan" (a109db5).
You are right that the script itself no longer needs wget, but I kept it for now: the image is shared with metatdenovo, and I would rather drop it in both pipelines at the next rebuild than change one image here.
| kofam_dbpath = 's3://nf-core-awsmegatests/magmap/input/databases/kofam_db' | ||
| kofamscan_store_dir = 's3://nf-core-awsmegatests/magmap/input/databases/kofamscan' |
There was a problem hiding this comment.
Question: You flagged these S3 prefixes as needing a check. Could a maintainer with access to nf-core-awsmegatests confirm magmap/input/databases/kofam_db and …/kofamscan are the right locations? I couldn't verify them from here.
There was a problem hiding this comment.
I haven't verified these prefixes, and nobody has.
Since KofamScan is on by default, the full test would have run it against them, so I set skip_kofamscan = true in conf/test_full.config and dropped the two S3 paths.
I'll add KofamScan to the full test in a later PR, once the bucket layout is decided together with metatdenovo.
The store file was named only by accession, so a result stored after a Prokka run was reused by a later run with --annotator bakta_all. Bakta and Prokka give different ORF IDs, so those hits did not join to the other tables of the run. The proteins now carry meta.source (prokka, bakta or gffread) and the file is <accno>.<source>.kofamscan.tsv.gz. A result from another source no longer matches, so the genome is annotated again. A changed GFF with the same source still reuses the stored result; the output docs now say so. Tests: a subworkflow test seeds the store with a Prokka result for two genomes, runs one of them as Bakta and one as Prokka, and checks that only the Bakta one is annotated again. The pipeline test checks the name of the stored file. Generated by Claude Code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH
Only prefix needs to be global, as the output paths use it. Declaring extension with def again makes the patch two lines shorter. The description of KOFAMSCAN_DOWNLOAD said it downloads, but Nextflow stages the files, so it now says it unpacks them. Generated by Claude Code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH
The module now reads gzipped FASTA and writes gzipped, prefix-named output (nf-core/modules#13805), so the local patch shrinks to removing the versions topic and keeping the tsv output non-optional, which storeDir needs to tell a missing result from a stored one. Generated by Claude Code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH
KofamScan runs by default, so the full test would have used the S3 prefixes for the KOfam database and the store, and nobody has checked that they exist on nf-core-awsmegatests. The full test skips KofamScan until the bucket layout is decided, together with metatdenovo. Generated by Claude Code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Thanks, this all looks good now. Each point from my earlier review is covered:
- Store keyed by protein source:
<accno>.<source>.kofamscan.tsv.gz, with a subworkflow test showing that only the genome switched to Bakta is annotated again, and the wider warning indocs/output.md. - Upstream gzip support: great to see nf-core/modules#13805 merged. The local patch is now just the
storeDir/versions change. extensionlocal again, themeta.ymlwording updated, and keepingwgetuntil the shared image is rebuilt makes sense.- Skipping KofamScan in
test_fulluntil the bucket layout is settled is sensible. Maybe open a follow-up issue so it is not forgotten.
I also checked locally (Nextflow 25.10) that a storeDir process with a remote file() input is skipped as Stored on later runs without downloading the input again, so profiles.tar.gz is fetched only once.
One optional idea for this PR or a later one: neither summary table has a genome accession column, and the best-hit table groups by orf alone. That is fine while ORF IDs are unique across genomes, but an accno column (taken from the stored file name in KOFAMSCAN_TABLE, and used in PARTITION BY accno, orf) would make the tables easier to join and protect against ID collisions between user-supplied GFFs.
LGTM!
|
Thanks @piplus2 |
PR checklist
nf-core pipelines lint).nextflow run . -profile test,docker --outdir <OUTDIR>).nextflow run . -profile debug,test,docker --outdir <OUTDIR>).docs/usage.mdis updated.docs/output.mdis updated.CHANGELOG.mdis updated.README.mdis updated (including new tool citations and authors/contributors).Description
I added KofamScan to magmap, so that the proteins of every genome get KEGG Orthology (KO) assignments (part of #164).
The pipeline already annotates genomes with Prokka or Bakta, but gave no functional KO assignment.
KofamScan runs on one genome at a time and keeps its result in a
storeDir(--kofamscan_store_dir,magmap_kofamscanby default), the same way Prokka does, so a genome is never annotated twice.The KofamScan database (
ko_listand the HMM profiles) is downloaded once into--kofam_dbpath.The hits of all genomes are collected in
summary_tables/magmap.kofamscan.tsv.gz, with one row per hit.A second table,
summary_tables/magmap.kofamscan_best.tsv.gz, has one row per protein: the hit with the highest score, with the lowest KO id winning a tie.I did not apply the score threshold (
thrshld) in the best-hit table.Environmental and partial proteins often score below it, and which threshold to use is best left to the user, who can filter on
scoreandthrshld.Both tables are also converted to Parquet when
--save_parquetis set.The step is skipped with
--skip_kofamscan.kofamscanmodule is patched to read gzipped input and write a gzipped table. The patch is inmodules/nf-core/kofamscan/kofamscan.diff.storeDir, so it does not emit its version on theversionstopic. A localKOFAMSCAN_VERSIONprocess reports it instead.storeDirdo not collide.kofam_dbpathandkofamscan_store_dir, both in.gitignore. The test data comes from the existingmetatdenovobranch of nf-core/test-datasets, so no test-datasets PR is needed.conf/test_full.configpoints to S3 paths for the database and the store. I based them on the Prokka paths and they need checking.I verified it with:
KOFAMSCAN_BEST: the higher score wins even when listed second (a text sort would pick "9.5" over "80.0"), a protein with only sub-threshold hits keeps its best hit, a-threshold with a tie, no hits, and stub;tests/default.nf.test, including the Parquet files;prek run -a,nf-core pipelines lint(0 failed) andnextflow lint .(13 warnings, all on lines already indev).nf-core modules lint kofamscanhas two known failures,correct_meta_outputsandcorrect_meta_topics, caused by the patch and thestoreDiruse.I did the work and reviewed it with Claude Code, and an independent Claude Code agent reviewed the diff.
🤖 Generated with Claude Code
https://claude.ai/code/session_01UvGYU6kuXJeVv9ffdSzdzH