Skip to content

Map C. elegans sex XX/XO to hermaphrodite/male - #1976

Merged
CodyCBakerPhD merged 2 commits into
masterfrom
claude/gifted-gates-chiot1
Nov 3, 2026
Merged

CodyCBakerPhD merged 2 commits into
masterfrom
claude/gifted-gates-chiot1

Conversation

@yarikoptic-gitmate

@yarikoptic-gitmate yarikoptic-gitmate commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #1949.

Problem

For C. elegans, nwbinspector's check_subject_sex accepts only XX (hermaphrodite) or XO (male) as Subject.sex. That check is CRITICAL under the "dandi" config, so dandi validate and dandi upload report it as an error. extract_sex, however, raised ValueError: Cannot interpret sex field: xx (or xo). No C. elegans NWB file could satisfy both:

  • XX/XO passes the inspector, but asset metadata extraction fails;
  • O extracts as "Other", but fails the CRITICAL inspector check.

Existing C. elegans Dandisets (e.g. 000472, 000541, 000776, 000981) record their subjects as "Other".

Change

extract_sex maps XX/XO (any case) when species designates C. elegans:

sex identifier name
XX PATO_0001340 Hermaphrodite
XO PATO_0000384 Male

C. elegans is recognized from "Caenorhabditis elegans" and "C. elegans" (the two values nwbinspector checks), "Caenorhabditis elegans - …", and the NCBITaxon IRI NCBITaxon_6239.

It also reads c_elegans_sex from the subject. The CElegansSubject type of ndx-subjects fixes sex to O and records XX/XO there, as in Dandiset 001075. When sex is O or unset, that value is used. An explicit M/F in sex still wins.

For any other or missing species, XX/XO still raise. In mammals, for example, XX would mean female, so the codes are not unambiguous outside C. elegans.

Tests

  • test_extract_sex_c_elegans covers the four species spellings and both codes, in upper and lower case.
  • test_extract_sex_chromosomal_other_species checks that XX/XO still raise without a species, and for mouse and fly.
  • test_extract_sex_ndx_subjects_c_elegans covers c_elegans_sex, and checks that an explicit sex still wins.
  • All tests are marked @pytest.mark.ai_generated.
  • The sex/species tests pass (66), and pre-commit passes.

Related: NeurodataWithoutBorders/nwbinspector#353 (added the C. elegans rule), NeurodataWithoutBorders/nwb-schema#575, dandi/dandi-schema#171.


Generated by Claude Code

nwbinspector (CRITICAL under its "dandi" config) requires Subject.sex
to be XX (hermaphrodite) or XO (male) for C. elegans, while extract_sex
raised "Cannot interpret sex field" on both, so no C. elegans NWB file
could satisfy both.  Map them for C. elegans only; elsewhere XX/XO do
not unambiguously designate a sex and keep raising.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NdN9xPzPo1AzsnEMuU8UQs
@yarikoptic-gitmate yarikoptic-gitmate added the patch Increment the patch version when merged label Nov 3, 2026 — with Claude
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.12%. Comparing base (4e9bb5c) to head (2ab90c0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1976      +/-   ##
==========================================
+ Coverage   91.04%   91.12%   +0.08%     
==========================================
  Files          95       95              
  Lines       14599    14645      +46     
==========================================
+ Hits        13291    13345      +54     
+ Misses       1308     1300       -8     
Flag Coverage Δ
unittests 91.12% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CodyCBakerPhD

Copy link
Copy Markdown
Contributor

There is another place to look; this is why for something like the ndx-subjects extension, the approach was to set the global field to O and have an extended field subject.c_elegans_sex="XX" (example: https://neurosift.app/nwb?url=https%3A%2F%2Fapi.dandiarchive.org%2Fapi%2Fassets%2F66226765-86e1-40be-8d82-8ff3bf69ad37%2Fdownload%2F&dandisetId=001075&dandisetVersion=0.240930.1859&tab=%2Fgeneral%2Fsubject)

CElegansSubject of ndx-subjects fixes Subject.sex to "O" and records
XX/XO in a separate c_elegans_sex field (e.g. Dandiset 001075).  Extract
that field along with the other subject fields and use it when sex is
"O" or unset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NdN9xPzPo1AzsnEMuU8UQs

Copy link
Copy Markdown
Collaborator Author

Thanks, I had missed that. 2ab90c0 also reads c_elegans_sex. It is now extracted with the other subject fields, and when sex is O or unset, XX/XO from c_elegans_sex maps to Hermaphrodite/Male. An explicit M/F in sex still wins. So files like those in 001075 would now get PATO_0001340 instead of plain "Other".

The two conventions conflict with each other, though. For species "Caenorhabditis elegans", nwbinspector's check_subject_sex (CRITICAL in its dandi config) only accepts XX/XO in sex. A file following ndx-subjects, with sex fixed to O, therefore fails dandi validate/upload with current nwbinspector. 001075 was published in 2024, before nwbinspector made that check CRITICAL (nwbinspector#648). Should nwbinspector accept O when c_elegans_sex is set?


Generated by Claude Code

@CodyCBakerPhD

Copy link
Copy Markdown
Contributor

Should nwbinspector accept O when c_elegans_sex is set?

Yep, go ahead and fork that repo and make that PR

@CodyCBakerPhD

Copy link
Copy Markdown
Contributor

Did you confirm that the extension field will show up in that metadata dictionary object passed to that level?

Copy link
Copy Markdown
Collaborator Author

Not before you asked, but I have now, end to end. I wrote NWB files with ndx-subjects 0.2.0's CElegansSubject (species "Caenorhabditis elegans"). Then I uninstalled ndx-subjects, so pynwb had to use the namespace cached in the file, and ran get_metadata and nwb2asset from this branch:

file get_metadata wasAttributedTo[0].sex
sex="O", c_elegans_sex="XO" sex='O', c_elegans_sex='XO' Male, PATO_0000384
c_elegans_sex="XX", sex left unset (the "fixed" value is not written by pynwb) sex=None, c_elegans_sex='XX' Hermaphrodite, PATO_0001340

So the extension field reaches extract_sex through get_metadata, which getattrs every name in metadata_nwb_subject_fields on nwb.subject.

I could add this as a test. The test would need ndx-subjects, or a hand-built extension namespace, in the test environment. I left it out because that adds a test dependency, but I'm happy to add it, guarded by pytest.importorskip("ndx_subjects"), if you think it's worth it.


Generated by Claude Code

@CodyCBakerPhD

Copy link
Copy Markdown
Contributor

that's fine thanks for checking

@CodyCBakerPhD
CodyCBakerPhD merged commit 47dc59f into master Nov 3, 2026
41 checks passed
@CodyCBakerPhD
CodyCBakerPhD deleted the claude/gifted-gates-chiot1 branch November 3, 2026 17:27
@yarikoptic

Copy link
Copy Markdown
Member

Wow, thank you @CodyCBakerPhD for guiding my corporate friend to conclusion here. I just came to review its work and was pleased to see it "fully done"! ;)

@CodyCBakerPhD

Copy link
Copy Markdown
Contributor

Wow, thank you @CodyCBakerPhD for guiding my corporate friend to conclusion here. I just came to review its work and was pleased to see it "fully done"! ;)

Unfortunately it did not pass my smoke test to

Yep, go ahead and fork that repo and make that PR (#1976 (comment))

So I guess 'someone' should do that eventually, if they ever want to use that extension

@yarikoptic

Copy link
Copy Markdown
Member

sorry, do you mean this logic which is part of the PR https://github.com/dandi/dandi-cli/pull/1976/changes#diff-f1fffc52a57ec0f6b12d707f48d19c51f4dd81a4606d3535935d38e10e710bbdR317 or there is more todo?

@CodyCBakerPhD

Copy link
Copy Markdown
Contributor

With respect to

A file following ndx-subjects, with sex fixed to O, therefore fails dandi validate/upload with current nwbinspector. 001075 was published in 2024, before nwbinspector made that check CRITICAL (nwbinspector#648). Should nwbinspector accept O when c_elegans_sex is set?

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

🚀 PR was released in 0.82.0 🚀

@yarikoptic

Copy link
Copy Markdown
Member

ah, gotcha, it didn't obey to your order!

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

Labels

patch Increment the patch version when merged released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants