Skip to content

New module: modkit/entropy - #11283

Open
sahuno wants to merge 3 commits into
nf-core:masterfrom
sahuno:add-modkit-entropy
Open

New module: modkit/entropy#11283
sahuno wants to merge 3 commits into
nf-core:masterfrom
sahuno:add-modkit-entropy

Conversation

@sahuno

@sahuno sahuno commented Apr 24, 2026

Copy link
Copy Markdown

PR checklist

  • This comment contains a description of changes (with reason).
  • Tests added (stub + real, both --cpg mode).
  • New tool follows module conventions.
  • Versions broadcast via topic: versions.
  • Naming/parameter/I-O conventions followed.
  • Resource label set (process_high).
  • BioConda + BioContainers used.
  • `nf-core modules lint modkit/entropy` — 50/0/0.
  • `nf-test test --profile conda` — 2/2 passed.

Summary

Adds a new nf-core module wrapping `modkit entropy`, which computes methylation entropy over genomic windows from one or more mod-BAMs. Entropy is a per-window measure of the diversity of methylation patterns across reads covering the window and is complementary to mean methylation.

The module supports modkit's file-vs-directory output dichotomy: when `--regions` is supplied (either via `ext.args` or the third input channel), modkit writes per-region BED / bedgraph / TSV into a directory (emitted via `regions_bed`, `bedgraph`, `tsv` outputs); otherwise a single genome-wide BED is produced (emitted via `bed`).

Accepts multiple input BAMs (passed as repeated `--in-bam`) for multi-sample entropy.

Why

`modkit entropy` is the canonical tool for quantifying methylation heterogeneity in ONT methylation data and is not currently in nf-core/modules. It complements the existing `modkit/pileup` (mean methylation) for heterogeneity-aware analyses.

Test data

Uses the existing `test.sorted.phased.bam` from nf-core/test-datasets (modules branch, `genomics/homo_sapiens/nanopore/bam/`). No new test data required.

🤖 Generated with Claude Code

@sahuno
sahuno force-pushed the add-modkit-entropy branch from cc8a7f2 to e0004d3 Compare April 24, 2026 02:44
@sahuno
sahuno requested review from a team as code owners April 24, 2026 02:44
@sahuno
sahuno force-pushed the add-modkit-entropy branch from e0004d3 to d95d97b Compare April 24, 2026 02:44
Add new nf-core module wrapping `modkit entropy`, which computes
methylation entropy over genomic windows from one or more mod-BAMs.
Supports an optional BED of regions for per-region descriptive
statistics; emits a genome-wide BED otherwise.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sahuno
sahuno force-pushed the add-modkit-entropy branch from d95d97b to 0978565 Compare April 24, 2026 03:02

@itrujnara itrujnara left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, thanks for the high-quality submission. I have left a handful of comments.

Comment thread modules/nf-core/modkit/entropy/main.nf Outdated
stub:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch ${prefix}.bed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we get the stub to simulate the bigger output when regions is passed?

}
}

test("homo sapiens - nanopore modbam - cpg") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need a test that uses the regions input

{ assert process.out.bed },
{ assert path(process.out.bed[0][1]).exists() },
{ assert path(process.out.bed[0][1]).size() > 0 },
// modkit entropy's BED output isn't byte-deterministic across CPU

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to check anything inside the file (e.g. header line)?

@atrigila atrigila added the awaiting-changes will be closed after 30 days label Jul 2, 2026
@github-actions

Copy link
Copy Markdown

This PR has been tagged as awaiting-changes or awaiting-feedback by an @nf-core/modules contributor. Remove stale label or add a comment if it is still useful.

@github-actions github-actions Bot added the stale Stale label Aug 16, 2026
…ions

Addresses @itrujnara's review:

- Stub now simulates the `--regions` layout. `modkit entropy --regions` writes
  a directory containing `<prefix>_regions.bed` and `<prefix>_windows.bedgraph`
  instead of the single genome-wide BED, so the stub branches on `regions`.
- Added a real and a stub test that exercise the `regions` input, asserting the
  exact output filenames and that `bed` is not emitted when `regions` is set.
- Tests now check file contents. `--header` is passed via `ext.args` so the
  header line and row structure can be asserted for all three output flavours.

Also removed the `tsv` output channel: `modkit entropy --regions` emits only
`_regions.bed` and `_windows.bedgraph` (verified against modkit 0.6.1), so the
emit never fired. The `meta.yml` description claiming a `.tsv` output was
corrected to match.

The entropy column is not byte-deterministic across thread counts, so the
non-stub tests continue to snapshot only the versions topic.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E7RSvpouxbMBdimYSwJ5ZP
@sahuno

sahuno commented Sep 6, 2026

Copy link
Copy Markdown
Author

Thanks for the review @itrujnara — all three points addressed.

1. Stub now simulates the --regions output. modkit entropy --regions
writes a directory containing <prefix>_regions.bed and
<prefix>_windows.bedgraph instead of the single genome-wide BED, so the stub
branches on whether regions is present and creates the matching layout.

While confirming the filenames against modkit 0.6.1 I found the tsv output
channel never fires — modkit entropy --regions emits only the _regions.bed
and _windows.bedgraph files, no TSV. Removed that emit and corrected the
meta.yml description, which claimed a .tsv was produced.

2. Added tests that use the regions input — one real and one stub. The
real one asserts the exact output filenames, that bed is not emitted when
regions is passed, and that the region_name column echoes the interval
from the input BED.

3. Yes — now checking file contents. modkit entropy has a --header
flag, so the test config passes --cpg --header and the tests assert on the
header line and the row structure:

  • genome-wide BED and per-window bedgraph:
    #chrom start end entropy strand num_reads
  • per-region BED: chrom start end region_name mean_entropy ...
  • every data row has all six columns and a parseable numeric entropy value

Still snapshotting only the versions topic for the non-stub tests: the entropy
column is not byte-deterministic across CPU counts (I get 0.69360054 vs
0.6936004 for the same window between runs with different thread counts), so
an md5 snapshot would be flaky in CI.

@sahuno sahuno removed the stale Stale label Sep 6, 2026
`nf-core lint` (tools@dev) checks that the string "versions" appears in each
snapshot entry via `test_snap_versions`. The two non-stub tests snapshotted
`process.out.versions_modkit` as a bare list, so the serialised content held
only the values ("MODKIT_ENTROPY", "modkit", "0.6.1") and the check failed.

Snapshotting `[versions: process.out.versions_modkit]` keeps the same content
and satisfies the check. Verified with nf-core/tools 4.1.0: 64 passed, 0 failed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E7RSvpouxbMBdimYSwJ5ZP
@sahuno sahuno mentioned this pull request Sep 7, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-changes will be closed after 30 days

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants