Source code for allensdk.brain_observatory.behavior.data_objects.metadata.subject_metadata.mouse_id
from allensdk.core import (
DataObject,
JsonReadableInterface,
LimsReadableInterface,
NwbReadableInterface,
)
from allensdk.internal.api import PostgresQueryMixin
from pynwb import NWBFile
[docs]class MouseId(
DataObject,
LimsReadableInterface,
JsonReadableInterface,
NwbReadableInterface,
):
"""the LabTracks ID"""
def __init__(self, mouse_id: str):
super().__init__(name="mouse_id", value=mouse_id)
[docs] @classmethod
def from_json(cls, dict_repr: dict) -> "MouseId":
mouse_id = dict_repr["external_specimen_name"]
# Check to make sure the dictionary value is string type and if not
# make it so.
if not isinstance(mouse_id, str):
mouse_id = str(mouse_id)
return cls(mouse_id=mouse_id)
[docs] @classmethod
def from_lims(
cls, behavior_session_id: int, lims_db: PostgresQueryMixin
) -> "MouseId":
# TODO: Should this even be included?
# Found sometimes there were entries with NONE which is
# why they are filtered out; also many entries in the table
# match the donor_id, which is why used DISTINCT
query = f"""
SELECT DISTINCT(sp.external_specimen_name)
FROM behavior_sessions bs
JOIN donors d ON bs.donor_id=d.id
JOIN specimens sp ON sp.donor_id=d.id
WHERE bs.id={behavior_session_id}
AND sp.external_specimen_name IS NOT NULL;
"""
mouse_id = lims_db.fetchone(query, strict=True)
return cls(mouse_id=mouse_id)
[docs] @classmethod
def from_nwb(cls, nwbfile: NWBFile) -> "MouseId":
return cls(mouse_id=nwbfile.subject.subject_id)