Skip to content

Extract asset anatomy from HERD ontology links - #1980

Draft
bendichter wants to merge 1 commit into
masterfrom
herd-anatomy
Draft

bendichter wants to merge 1 commit into
masterfrom
herd-anatomy

Conversation

@bendichter

Copy link
Copy Markdown
Member

Addresses #1979.

What this does

  • pynwb_utils._get_herd_anatomy reads the file's HERD table (nwb.external_resources) and collects every entity with a UBERON: or MBA: ID, whatever object or field it is linked from. Entities linked only from Subject objects are skipped: UBERON also holds life-stage terms that may be linked from Subject.age. The result goes into the metadata dict as herd_anatomy.
  • brain_areas.herd_anatomy_to_models turns those into deduplicated Anatomy models. HERD stores no labels, so the name comes from the bundled Allen CCF table for MBA: terms, else the longest value in the file linked to the term (so trapezius muscle beats EMG), else the entity ID.
  • _extract_brain_anatomy uses HERD anatomy first, for any species, and falls back to the existing mouse-only string matching from feat: extract brain area anatomy from NWB location fields #1807. The terms land in the same place: wasDerivedFrom[BioSample].anatomy, on the synthetic brain-region-sample when there's no tissue/slice/cell ID.

The HERD tables are read directly rather than through HERD.to_dataframe(), because that call raises a pandas deprecation warning that the test config turns into an error.

Checked on DANDI:001888

On sub-GRIN2B-129/sub-GRIN2B-129_ses-2021-03-26_ecephys.nwb (rat, so #1807 extracts nothing), streamed from S3:

Identifier Name
UBERON_0008933 S1Hl_S1Fl
UBERON_0016634 M2_anterior
UBERON_0001384 M1_anterior
UBERON_0022232 V2_ML
UBERON_0002436 V1_M
UBERON_0002380 trapezius muscle
UBERON_0000956 cortex

The species, strain and genotype links in the same table are left out. Most names are lab abbreviations. Once #1825 lands, its bundled UBERON table can supply real labels through _ontology_label; I left that out to keep this PR independent of #1825.

Not done here

Tests

  • New tests: a rat file with HERD (anatomy extracted, Subject.age life-stage term skipped), a mouse file where HERD wins over Allen matching, label/dedupe rules, and HERD anatomy without a species.
  • pynwb < 4 can't store HERD in the NWB file, so the two file-writing tests skip there; I ran them under pynwb 3.1.0 / hdmf 4.1.0 (skipped, rest pass) and pynwb 4.2.0 (all pass).
  • test_metadata.py, test_pynwb_utils.py and test_brain_areas.py pass locally except three BIDS tests that need bids-validator-deno, which isn't installed here (they fail on master too). mypy and pre-commit are clean.

🤖 Generated with Claude Code

Collect UBERON and MBA entities linked in an NWB file's HERD table and
put them in wasDerivedFrom[BioSample].anatomy, for any species. HERD
links take precedence over string matching of location values. Entities
linked only from Subject objects are skipped, since UBERON also holds
life-stage terms that may be linked from Subject.age.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.98496% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.26%. Comparing base (54e842c) to head (4f911c6).

Files with missing lines Patch % Lines
dandi/pynwb_utils.py 90.24% 4 Missing ⚠️
dandi/metadata/brain_areas.py 89.28% 3 Missing ⚠️
dandi/tests/test_metadata.py 98.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1980      +/-   ##
==========================================
+ Coverage   91.18%   91.26%   +0.08%     
==========================================
  Files          95       95              
  Lines       14740    14872     +132     
==========================================
+ Hits        13440    13573     +133     
+ Misses       1300     1299       -1     
Flag Coverage Δ
unittests 91.26% <93.98%> (+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.

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