Skip to content

Optimize DIA processing and improve MultiQC integration - #727

Merged
ypriverol merged 9 commits into
mainfrom
dev
Sep 6, 2026
Merged

Optimize DIA processing and improve MultiQC integration#727
ypriverol merged 9 commits into
mainfrom
dev

Conversation

@ypriverol

@ypriverol ypriverol commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Description

Brief description of the changes made in this PR.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Test addition/update
  • Updates to the dependencies has been done.

Summary by CodeRabbit

  • Performance

    • Improved handling of large DIA datasets to reduce memory usage and speed up peptide-length calculations and box-plot generation.
    • Large reports now use summarized box-plot statistics instead of loading all raw values into memory.
    • Avoids unnecessary MSstats file processing when tables are disabled or another data source is active.
  • Bug Fixes

    • Improved run-to-sample mapping, including handling of unmapped runs.
    • Preserved consistent DIA modification counts and peptide-length results across datasets.
  • Tests

    • Added regression coverage for large-data plots, sample mapping, peptide lengths, import stability, and conditional MSstats processing.

dia_sample_level_modifications copied the frame and merged it with the
SDRF sample table on Run: the categorical key upcast to object for every
row plus an object Sample column - the same transient already measured in
the intensity plot, and the stage (mod_plot_dict) the 72 GB run died in
after 8 minutes once everything upstream was fixed.

run_to_sample_codes maps Run->Sample through the category codes: one small
array, no strings. Used here and in the per-sample identification counts.
Run stays in the per-sample subset so drop_duplicates keeps counting a
peptidoform once per run within a sample. A test asserts the result equals
the merge-based computation, including runs absent from the SDRF.
plots.dia imported it from dia_utils, and dia_utils imports plots.dia.
MultiQC loads dia_utils first, so the partially initialised module made
the import fail and the whole QuantMS module was skipped - the report was
written without it. A test now imports dia_utils first in a fresh
interpreter.
_get_peptide_length ran .str.len() on the categorical Stripped.Sequence
column - pandas converts every row back to a Python string, 231 M on
PXD030304 - then looped value_counts over 5,798 runs. It runs right after
mod_plot_dict with no log line of its own, which is where the 72 GB run was
killed 6.5 minutes into that stage once everything before it fit.

Length is computed once per distinct sequence and broadcast through the
category codes; the per-run histogram is a single groupby size. A test
asserts the result equals the string-based implementation.
parse_msstats_input only draws the peptide/protein quantification tables;
it stores nothing else. It ran unconditionally whenever the file was
found, --disable-table or not. On PXD030304 the staged MSstats input is a
20.6 GiB, 231,620,697-row CSV with six string columns; pd.read_csv took
the process from 22 to 93 GB in three minutes and it was OOM-killed -
after every DIA stage had completed at ~43 GB - to build tables that
--disable-table then discards.

Gate the parse on tables being enabled. A test pins the gate.
…tensity std

On PXD030304 (5,798 runs) draw_dia_ms1_area passed every raw MS1 area to
box.plot and polars panicked serialising a >4 GiB buffer
(assertion failed: bytes.len() <= u32::MAX). draw_dia_intensity_std carried
42.7 M points. #718's 'switch to flat plot' changes the renderer, not the
point count (#717).

summarise_box_data already exists for exactly this and is used by the
intensity-distribution box and six other plots: above the flat threshold it
replaces each sample's list with {min,q1,median,q3,max,mean}, which
MultiQC's box plot accepts directly. Apply it at the two remaining DIA sites.
Below the threshold raw points are kept, so small reports are unchanged.
dia: the remaining #717 fixes that did not reach dev (late #722 commits + #724)
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: b885f348-d9ca-4571-9908-987a8ea94333

📥 Commits

Reviewing files that changed from the base of the PR and between 5625eeb and e277da5.

📒 Files selected for processing (7)
  • pmultiqc/modules/common/dia_utils.py
  • pmultiqc/modules/common/plots/dia.py
  • pmultiqc/modules/common/plots/general.py
  • pmultiqc/modules/quantms/quantms.py
  • tests/test_dia_box_plots.py
  • tests/test_diann_reader.py
  • tests/test_msstats_gate.py

📝 Walkthrough

Walkthrough

The change adds vectorized DIA run-to-sample and box-statistics helpers, applies size-based aggregation to DIA plots, optimizes peptide-length and modification processing, and skips MSstats parsing when tables are disabled.

Changes

DIA processing and plotting optimization

Layer / File(s) Summary
Shared vectorized helpers
pmultiqc/modules/common/plots/general.py
Adds categorical-code run-to-sample mapping and vectorized grouped box-statistics calculation.
DIA utility integration
pmultiqc/modules/common/dia_utils.py, tests/test_diann_reader.py
Replaces merge-based mappings, computes peptide lengths through categorical codes, preserves run-based deduplication, and adds regression tests.
DIA plot aggregation
pmultiqc/modules/common/plots/dia.py, tests/test_dia_box_plots.py
Uses grouped summary statistics for large datasets and raw value lists for smaller datasets. Tests cover plot payloads, statistical equivalence, and unmapped runs.

QuantMS MSstats parsing gate

Layer / File(s) Summary
Conditional MSstats parsing
pmultiqc/modules/quantms/quantms.py, tests/test_msstats_gate.py
Runs MSstats parsing only when the input is valid and tables are enabled. Adds an AST-based regression test.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: yueqixuan

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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.

@ypriverol
ypriverol merged commit 8e99d9e into main Sep 6, 2026
24 of 26 checks passed
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 20 high · 1 medium · 6 minor

Alerts:
⚠ 27 issues (≤ 0 issues of at least minor severity)

Results:
27 new issues

Category Results
Documentation 5 minor
Security 1 medium
1 minor
20 high

View in Codacy

🟢 Metrics 52 complexity

Metric Results
Complexity 52

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.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant