Skip to content

feat(convert): write the MuData view from diann and openms-consensus - #332

Merged
ypriverol merged 2 commits into
devfrom
feat/convert-writes-mudata
Sep 17, 2026
Merged

ypriverol merged 2 commits into
devfrom
feat/convert-writes-mudata

Conversation

@ypriverol

Copy link
Copy Markdown
Contributor

Follow-up to the nf-modules review (bigbio/nf-modules#52): the modules carry an embedded Python heredoc to build the MuData view, because these two converters never wrote it. convert openms (the deprecated -out_qpx path) already does, via the orchestrator.

Why it matters

The first version of that heredoc called build_mudata() + mdata.write() directly, which bypasses the guard in write_dataset_mudata: build_mudata catches per-modality failures, logs them and continues, so a failed modality is simply absent. The module wrote that incomplete h5mu and the task exited 0 — on MSV000085836 an h5mu with proteins and no precursors (#316). Logic like that does not belong in a Nextflow heredoc where it cannot be tested.

Changes

  • --mudata/--no-mudata (default on) on convert diann and convert openms-consensus, writing through write_dataset_mudata: refuses a MuData missing a required quantification modality, writes via a temporary file, drops a stale view.
  • Stays best-effort: the Parquet views are the dataset's source of truth, so a view that cannot be built prints a warning and the conversion still succeeds (test included with the writer monkeypatched to fail).
  • --no-mudata skips the build for very large datasets.
  • Written after the optional --fasta step, so the view reflects the final Parquet.

Tests

Five new tests, each failing on dev: default writes the view and --no-mudata skips it (both converters), plus the best-effort failure path. Full suite 1,263 passed; pre-commit clean; pylint reports the same 3 pre-existing issues as dev.

Downstream

The nf-modules qpx modules keep their heredoc for now, since they pin 1.1.4. Once they pin a release containing this, both modules reduce to the qpxc convert … call, and the shutil.move disappears with it (the writer puts the view in the dataset folder, next to the Parquet, matching the published S3 layout).

Both converters wrote the Parquet views and stopped, so every caller had to
build the MuData view itself. The nf-modules qpx modules did that with an
embedded Python heredoc, and the first version of it called build_mudata()
+ mdata.write() directly — which skips a modality that fails to build and
writes an incomplete h5mu with exit 0 (#316, MSV000085836 shipped
proteins with no precursors).

--mudata/--no-mudata (default on) now writes it through write_dataset_mudata,
the same guarded writer convert openms already used: it refuses a MuData
missing a required quantification modality, writes via a temporary file and
drops a stale view. It stays best-effort — the Parquet views are the
dataset's source of truth — so a view that cannot be built is reported and
the conversion still succeeds. --no-mudata skips the build on very large
datasets.

The modules can drop their embedded Python once they pin a release with
this; they keep it for now, since they pin 1.1.4.

Five tests, all failing on dev.
@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: aec2e4f2-3e8e-495c-aa0f-cdefd96b6c41

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Write MuData views from DIA-NN and OpenMS consensus conversions

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Add default MuData generation to DIA-NN and OpenMS consensus conversions.
• Route writes through the guarded, atomic, best-effort writer after FASTA enrichment.
• Support --no-mudata and test success, skip, and failure behavior.
Diagram

graph TD
  D["DIA-NN Convert"] --> P["Parquet Dataset"] --> F["Optional FASTA"] --> G{"MuData enabled?"}
  O["OpenMS Consensus"] --> P
  G -->|Yes| W["Guarded Writer"] -->|Written| H["MuData View"] --> C["Conversion Success"]
  G -->|No| C
  W -->|Failed| C
Loading
High-Level Assessment

The current approach is appropriate: both commands reuse the existing guarded dataset writer instead of duplicating MuData assembly or writing directly from build_mudata(). Keeping invocation after optional FASTA enrichment ensures the view reflects final Parquet state, while best-effort handling preserves Parquet as the source of truth.

Files changed (5) +138 / -0

Enhancement (1) +43 / -0
convert.pyAdd guarded MuData writing to DIA-NN and OpenMS consensus +43/-0

Add guarded MuData writing to DIA-NN and OpenMS consensus

• Introduces a shared CLI helper and default-on '--mudata/--no-mudata' options for both converters. MuData is written after optional FASTA enrichment, with failures reported as warnings without failing conversion.

qpx/cli/convert.py

Tests (2) +92 / -0
test_diann_converter.pyTest DIA-NN MuData generation and opt-out +32/-0

Test DIA-NN MuData generation and opt-out

• Adds parameterized CLI coverage verifying that DIA-NN conversion writes H5MU by default and skips it with '--no-mudata' while retaining Parquet output.

tests/converters/test_diann_converter.py

test_openms_consensus.pyTest OpenMS consensus MuData lifecycle +60/-0

Test OpenMS consensus MuData lifecycle

• Adds shared conversion setup and tests for default H5MU generation, explicit opt-out, and non-fatal writer failure. The tests also verify user-facing status and warning messages.

tests/converters/test_openms_consensus.py

Documentation (2) +3 / -0
CHANGELOG.mdAnnounce automatic MuData generation for two converters +1/-0

Announce automatic MuData generation for two converters

• Documents the new default MuData output, guarded modality validation, opt-out flag, and removal of downstream custom build steps.

CHANGELOG.md

convert.mdDocument MuData outputs and opt-out behavior +2/-0

Document MuData outputs and opt-out behavior

• Adds H5MU output details for DIA-NN and OpenMS consensus conversions. Clarifies that generation is enabled by default, can be disabled, and remains best-effort.

docs/guide/convert.md

@codacy-production

codacy-production Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity · 2 duplication

Metric Results
Complexity 5
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@qodo-code-review

qodo-code-review Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Reruns mix prior quantification data 🐞 Bug ≡ Correctness
Description
_write_mudata discovers all same-prefix feature and protein-group Parquets, while DIA-NN leaves an
old protein-group file when its matrix option is omitted and OpenMS-consensus preserves unrequested
core views. Reusing a prefix with fewer structures or different input therefore writes a new .h5mu
that mixes current quantification with files from the prior conversion.
Code

qpx/cli/convert.py[317]

+    _write_mudata(output_folder, prefix, mudata)
Evidence
Dataset discovery registers every matching same-prefix structure, and the writer requires and builds
every discovered feature or protein-group modality. Neither conditional DIA-NN PG generation nor
OpenMS-consensus cleanup removes an unrequested prior view, so each new call site can assemble that
retained data into the new file.

qpx/cli/convert.py[301-317]
qpx/cli/convert.py[1003-1018]
qpx/converters/openms_consensus/converter.py[445-491]
qpx/dataset.py[258-278]
qpx/mudata.py[727-730]
qpx/mudata.py[925-940]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Automatic MuData rebuilding treats same-prefix core files retained from previous runs as outputs of the current conversion, mixing datasets in the resulting view.

## Fix Focus Areas
- qpx/cli/convert.py[301-317]
- qpx/cli/convert.py[1003-1018]
- qpx/converters/openms_consensus/converter.py[445-504]
- qpx/mudata.py[927-940]

## Recommended Fix
Before rebuilding MuData, make the same-prefix core output set match the current invocation: remove DIA-NN protein-group output when no matrix is supplied and remove OpenMS-consensus core views excluded from the requested structures. Add rerun tests that first create all views and then rerun with a reduced output set, asserting the old modalities are absent from both Parquet output and MuData.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Enrichment leaves exported metadata stale ✓ Resolved 🐞 Bug ≡ Correctness
Description
convert_diann_cmd calls _write_mudata before _maybe_enrich_pride, although enrichment rewrites
the same prefix's dataset Parquet. When --enrich-pride succeeds, the .h5mu retains the
pre-enrichment title, description, and publication identifier while dataset.parquet contains the
fetched values.
Code

qpx/cli/convert.py[317]

+    _write_mudata(output_folder, prefix, mudata)
Evidence
The changed call writes MuData immediately before enrichment. MuData copies every non-null dataset
metadata column into uns, while enrichment subsequently updates three fields and rewrites
dataset.parquet, so the two representations diverge.

qpx/cli/convert.py[316-318]
qpx/mudata.py[470-489]
qpx/mudata.py[925-948]
qpx/dataset.py[1345-1368]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The DIA-NN command writes MuData before PRIDE enrichment rewrites dataset metadata, leaving the exported view stale.

## Fix Focus Areas
- qpx/cli/convert.py[316-318]
- tests/converters/test_diann_converter.py[1457-1486]

## Recommended Fix
Run `_maybe_enrich_pride` before `_write_mudata` so the view is assembled from final Parquet metadata. Add a test that enables enrichment, stubs the PRIDE response, and verifies the enriched fields in both `dataset.parquet` and the resulting `.h5mu`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Skipped writes preserve stale views ✓ Resolved 🐞 Bug ≡ Correctness
Description
_write_mudata returns before write_dataset_mudata can unlink the old file when disabled, and
OpenMS-consensus places the call inside its if written branch. A same-prefix rerun with the view
disabled or with no exportable records therefore leaves the previous .h5mu even though the current
Parquet views were replaced or removed.
Code

qpx/cli/convert.py[R50-51]

+    if not enabled:
+        return
Evidence
Stale-file removal exists only inside write_dataset_mudata, after the helper's new early return.
OpenMS-consensus additionally bypasses the helper entirely for the documented empty-export path,
while its converter can remove the current core and metadata Parquets.

qpx/cli/convert.py[42-58]
qpx/cli/convert.py[1016-1019]
qpx/mudata.py[917-924]
qpx/converters/openms_consensus/converter.py[488-504]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new skip paths bypass the writer's stale-file cleanup, allowing an old MuData artifact to survive a newer conversion.

## Fix Focus Areas
- qpx/cli/convert.py[42-58]
- qpx/cli/convert.py[1016-1019]
- tests/converters/test_diann_converter.py[1457-1486]
- tests/converters/test_openms_consensus.py[1119-1138]

## Recommended Fix
Make the disabled helper path remove the same-prefix final and temporary MuData files, and ensure OpenMS-consensus performs that cleanup when `written` is empty. Extend both converters' tests by pre-seeding an old `.h5mu` before invoking `--no-mudata`, plus an empty OpenMS conversion test.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: ⚖️ Balanced: This adds runtime CLI behavior and MuData writing across two conversion paths, including best-effort failure handling and output contracts, so it warrants a complete single-pass review.

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread qpx/cli/convert.py Resolved
Comment thread qpx/cli/convert.py Resolved
Comment thread qpx/cli/convert.py Resolved
@ypriverol
ypriverol merged commit 57e7674 into dev Sep 17, 2026
9 checks passed
@ypriverol
ypriverol deleted the feat/convert-writes-mudata branch October 19, 2026 14:24
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.

2 participants