Skip to content

fix(mudata): write empty strings for null gene names - #311

Merged
ypriverol merged 1 commit into
devfrom
fix/mudata-null-gene-names
Sep 12, 2026
Merged

ypriverol merged 1 commit into
devfrom
fix/mudata-null-gene-names

Conversation

@ypriverol

Copy link
Copy Markdown
Contributor

Problem

mdata.write() fails with TypeError: Can't implicitly convert non-string objects to strings (h5py, writing key gene_name of /var) whenever every protein lacks a gene name.

_build_protein_adata reads pg.gg_names[1], which is NULL when a protein has no gene. With a few nulls the column stays object and writes fine; when all values are NULL pandas infers float64 (all NaN) and h5py refuses it.

This is the norm for TMT datasets whose consensusXML carries no GN= protein descriptions. Hit in production on MSV000085836 (TMT10, 552 raw files): all 4,891,140 protein rows had NULL gg_names, so the quantms pipeline aborted at QPX_OPENMSCONSENSUS after ~80 min — on all three attempts, and after the parquet outputs had already been written correctly. Label-free runs were unaffected (e.g. PXD000396: genes on 111,195 of 111,235 rows).

Fix

Fill missing gene names with "" and coerce to str, mirroring what _load_run_obs already does for its string columns.

Test

test_protein_var_gene_names_serialise_when_every_gene_is_null builds a pg bundle with gg_names=None and asserts the h5mu write succeeds. Verified it fails on dev with exactly the production error and passes with the fix. Full tests/unit/test_mudata.py: 23 passed.

An all-NULL gg_names column is inferred as float64, so h5py rejects var with
"Can't implicitly convert non-string objects to strings" and mdata.write()
fails. TMT datasets whose consensusXML carries no GN= descriptions hit this on
every protein row (MSV000085836: 4.89M rows, all NULL), aborting the pipeline
at the qpx conversion step after the data itself converted fine.

Fill missing gene names with "" and coerce to str, as _load_run_obs already
does for its string columns.
@coderabbitai

coderabbitai Bot commented Sep 12, 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: d6d43819-a3b2-4852-8009-96184b579202

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

Handle null protein gene names in MuData serialization

🐞 Bug fix 🧪 Tests 🕐 Less than 10 minutes

Grey Divider

AI Description

• Normalize missing protein gene names to empty strings before constructing AnnData metadata.
• Add regression coverage proving all-null gene names serialize successfully to H5MU.
Diagram

graph TD
  A["pg.parquet"] -->|reads gg_names| B["DuckDB query"] -->|returns nulls| C["String normalization"] -->|builds metadata| D["Protein AnnData"] -->|writes| E["H5MU file"]
Loading
High-Level Assessment

The localized pandas normalization is the best approach because it fixes both missing values and the inferred dtype immediately before AnnData construction. SQL COALESCE was considered, but the current approach is clearer, consistent with existing string-column handling, and independent of query result dtype behavior.

Files changed (2) +49 / -1

Bug fix (1) +8 / -1
mudata.pyNormalize missing protein gene names before AnnData construction +8/-1

Normalize missing protein gene names before AnnData construction

• Replaces null gene names with empty strings and coerces the column to strings. This prevents all-null gene metadata from becoming float64 and failing during H5MU serialization.

qpx/mudata.py

Tests (1) +41 / -0
test_mudata.pyCover H5MU serialization with entirely null gene names +41/-0

Cover H5MU serialization with entirely null gene names

• Creates a protein-only TMT fixture whose protein group has no gene names. The test verifies normalized string metadata and successful H5MU output creation.

tests/unit/test_mudata.py

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can hide the parts of a finding you never read, like the evidence or the agent prompt

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@ypriverol
ypriverol merged commit 88471f3 into dev Sep 12, 2026
9 checks passed
@ypriverol
ypriverol deleted the fix/mudata-null-gene-names 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.

1 participant