Skip to content

Comments

feat: extract brain area anatomy from NWB location fields#1807

Open
bendichter wants to merge 2 commits intomasterfrom
add-brain-area-anatomy
Open

feat: extract brain area anatomy from NWB location fields#1807
bendichter wants to merge 2 commits intomasterfrom
add-brain-area-anatomy

Conversation

@bendichter
Copy link
Member

Summary

Closes #1806

  • Extracts brain location values from NWB files (ImagingPlane.location, electrodes.location, IntracellularElectrode.location)
  • Matches locations against bundled Allen Mouse Brain Atlas CCF structures (~94KB JSON, 1,327 structures)
  • Populates BioSample.anatomy within the wasDerivedFrom field using MBAO identifiers
  • Only applies to mouse species (NCBITaxon_10090); non-mouse species are skipped

New files

  • dandi/data/allen_ccf_structures.json — bundled Allen CCF structures
  • dandi/data/generate_allen_structures.py — regeneration script (python -m dandi.data.generate_allen_structures)
  • dandi/metadata/brain_areas.py — parsing and matching module
  • dandi/tests/test_brain_areas.py — 29 unit tests

Modified files

  • dandi/pynwb_utils.py_get_brain_locations() extracts location strings from NWB
  • dandi/metadata/util.pyextract_wasDerivedFrom() now adds anatomy to deepest BioSample
  • dandi/tests/test_metadata.py — 3 integration tests for anatomy in wasDerivedFrom

Test plan

  • python -m pytest dandi/tests/test_brain_areas.py -v — 29 unit tests pass
  • python -m pytest dandi/tests/test_metadata.py -v -k anatomy — 3 integration tests pass
  • pre-commit run --files <all changed files> — all hooks pass
  • CI passes

🤖 Generated with Claude Code

Extract brain location values from NWB files (ImagingPlane.location,
electrodes.location, IntracellularElectrode.location), match them
against bundled Allen Mouse Brain Atlas CCF structures, and populate
BioSample.anatomy within wasDerivedFrom.

Closes #1806

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bendichter bendichter added the minor Increment the minor version when merged label Feb 21, 2026
- Cast json.load() return to explicit type
- Use str() for AnyHttpUrl identifier comparisons
- Add None-checks before indexing wasDerivedFrom in tests
- Add explanatory comments to bare except clauses

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 85.15406% with 53 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.39%. Comparing base (da76ac3) to head (020ac76).

Files with missing lines Patch % Lines
dandi/data/generate_allen_structures.py 0.00% 23 Missing ⚠️
dandi/pynwb_utils.py 60.97% 16 Missing ⚠️
dandi/metadata/brain_areas.py 91.05% 11 Missing ⚠️
dandi/metadata/util.py 90.90% 2 Missing ⚠️
dandi/tests/test_metadata.py 98.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1807      +/-   ##
==========================================
+ Coverage   75.12%   75.39%   +0.26%     
==========================================
  Files          84       87       +3     
  Lines       11925    12282     +357     
==========================================
+ Hits         8959     9260     +301     
- Misses       2966     3022      +56     
Flag Coverage Δ
unittests 75.39% <85.15%> (+0.26%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@bendichter
Copy link
Member Author

sister PR: NeurodataWithoutBorders/nwbinspector#671

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

Labels

minor Increment the minor version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extract asset brain area from location field

1 participant