Skip to content

HERD integration: species ontology terms#1772

Open
bendichter wants to merge 5 commits into
mainfrom
add-species-herd-ontology
Open

HERD integration: species ontology terms#1772
bendichter wants to merge 5 commits into
mainfrom
add-species-herd-ontology

Conversation

@bendichter

Copy link
Copy Markdown
Contributor

Closes #1771.

What

Adds neuroconv.tools.ontology and wires it into make_nwbfile_from_metadata so that a subject's species is both recommended in a standardized form and annotated with a machine-readable NCBITaxon reference in the written file.

Two behaviors:

  1. Suggestion (non-blocking). validate_species warns with a concrete recommendation when Subject.species is a recognized common name (e.g. "mouse") or a likely typo (e.g. "Homo sapien"), pointing at the canonical Latin binomial and its NCBITaxon id (Mus musculus / NCBITaxon:10090). Valid-but-uncommon binomials pass silently.
  2. HERD annotation. add_species_external_resource attaches an external-resource reference mapping a recognized Subject.species binomial to its NCBITaxon entity, stored in-file under /general/external_resources via HDMF's HERD. This is the HERD integration the issue asked for — downstream tools (e.g. DANDI) can resolve the term without guessing.

The species table is a small curated, offline, dependency-free lookup of common neuroscience species (no network, no ontology client).

Notes

  • In-file HERD storage requires pynwb ≥ 4.0.0, already the minimum pin (Update pynwb minimum to 4.0 #1769).
  • The HERD is constructed with pynwb's type map, which is required for the Subject.species attribute spec to resolve; without it add_ref raises. The write is idempotent and extends a pre-existing external_resources HERD in place rather than replacing it.

Testing

  • tests/test_minimal/test_tools/test_ontology_species.py — table integrity, common-name/typo suggestions, get_species_term resolution, warning behavior.
  • tests/test_minimal/test_tools/test_ontology_external_resources.py — no-op cases, annotation, idempotency, extend-in-place, and a full write→read round trip confirming the reference persists in the NWB file.

🤖 Generated with Claude Code

bendichter and others added 5 commits July 1, 2026 22:13
Introduces `neuroconv.tools.ontology`, an offline, dependency-free lookup of
common neuroscience species. `make_nwbfile_from_metadata` now:

- emits a non-blocking suggestion (`validate_species`) when `Subject.species`
  is a recognized common name (e.g. "mouse") or a likely typo, pointing at the
  canonical Latin binomial and its NCBITaxon identifier; and
- attaches a machine-readable NCBITaxon external-resource reference
  (`add_species_external_resource`) for a recognized binomial, stored in-file
  under `/general/external_resources` via HDMF's HERD, so downstream tools can
  resolve the term without guessing.

The HERD is built with pynwb's type map (required for the `Subject.species`
attribute to resolve) and the write is idempotent. In-file HERD storage relies
on pynwb>=4.0.0, which is now the minimum pin.

Closes #1771

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The new neuroconv.tools.ontology submodule is attached to the tools
namespace via nwb_helpers' import of add_species_external_resource,
so test_tools' expected_structure must include it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a user guide page covering the non-blocking species suggestion and
the in-file NCBITaxon (HERD) annotation, an API reference page for
neuroconv.tools.ontology, and wire both into their toctrees.

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

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.51%. Comparing base (8457f90) to head (017f1fd).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1772      +/-   ##
==========================================
+ Coverage   82.40%   82.51%   +0.10%     
==========================================
  Files         176      179       +3     
  Lines       13992    14080      +88     
==========================================
+ Hits        11530    11618      +88     
  Misses       2462     2462              
Flag Coverage Δ
unittests 82.51% <100.00%> (+0.10%) ⬆️

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

Files with missing lines Coverage Δ
...nv/tools/nwb_helpers/_metadata_and_file_helpers.py 92.04% <100.00%> (+0.23%) ⬆️
src/neuroconv/tools/ontology/__init__.py 100.00% <100.00%> (ø)
...rc/neuroconv/tools/ontology/_external_resources.py 100.00% <100.00%> (ø)
src/neuroconv/tools/ontology/_species.py 100.00% <100.00%> (ø)
🚀 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.

[Feature]: HERD integration

1 participant