diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dcdd8c85..61c6391a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ ### Improvements * Enhanced human-readability of the return message from `check_experimenter_form`. [PR #254](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/254) +* Add check for existence of ``IntracellularElectrode.cell_id`` (#256) diff --git a/nwbinspector/__init__.py b/nwbinspector/__init__.py index d8a1c8d26..a3eb0e290 100644 --- a/nwbinspector/__init__.py +++ b/nwbinspector/__init__.py @@ -12,3 +12,4 @@ from .checks.ophys import * from .checks.tables import * from .checks.time_series import * +from .checks.icephys import * diff --git a/nwbinspector/checks/icephys.py b/nwbinspector/checks/icephys.py new file mode 100644 index 000000000..0358e6530 --- /dev/null +++ b/nwbinspector/checks/icephys.py @@ -0,0 +1,10 @@ +from pynwb.icephys import IntracellularElectrode + +from ..register_checks import register_check, Importance, InspectorMessage + + +@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=IntracellularElectrode) +def check_intracellular_electrode_cell_id_exists(intracellular_electrode: IntracellularElectrode): + """Check if the IntracellularElectrode contains a cell_id.""" + if intracellular_electrode.cell_id is None: + return InspectorMessage(message="Please include a unique cell_id associated with this IntracellularElectrode.") diff --git a/tests/unit_tests/test_icephys.py b/tests/unit_tests/test_icephys.py new file mode 100644 index 000000000..59e4ee6fa --- /dev/null +++ b/tests/unit_tests/test_icephys.py @@ -0,0 +1,23 @@ +from pynwb.icephys import IntracellularElectrode +from pynwb.device import Device + +from nwbinspector import InspectorMessage, Importance, check_intracellular_electrode_cell_id_exists + + +def test_pass_check_intracellular_electrode_cell_id_exists(): + device = Device(name="device") + ielec = IntracellularElectrode(name="ielec", cell_id="123", device=device, description="an intracellular electrode") + assert check_intracellular_electrode_cell_id_exists(ielec) is None + + +def test_fail_check_intracellular_electrode_cell_id_exists(): + device = Device(name="device") + ielec = IntracellularElectrode(name="ielec", device=device, description="an intracellular electrode") + assert check_intracellular_electrode_cell_id_exists(ielec) == InspectorMessage( + message="Please include a unique cell_id associated with this IntracellularElectrode.", + importance=Importance.BEST_PRACTICE_VIOLATION, + check_function_name="check_intracellular_electrode_cell_id_exists", + object_type="IntracellularElectrode", + object_name="ielec", + location="/", + )