Source code for allensdk.brain_observatory.behavior.data_objects.metadata.behavior_metadata.project_code

from pynwb import NWBFile
from typing import Optional

from allensdk.core import DataObject
from allensdk.core import \
    LimsReadableInterface
from allensdk.internal.api import PostgresQueryMixin
from allensdk.core import NwbReadableInterface


[docs]class ProjectCode(DataObject, LimsReadableInterface, NwbReadableInterface): """Unique identifier for the project this BehaviorSession is associated with. Project ids can be used internally to extract a project code. If project_Code is null/None, we set the value to string 'Not Available'. """ def __init__(self, project_code: Optional[str] = None): if project_code is None: project_code = 'Not Available' super().__init__(name='project_code', value=project_code)
[docs] @classmethod def from_lims(cls, behavior_session_id: int, lims_db: PostgresQueryMixin) -> "ProjectCode": query = f""" SELECT ps.code AS project_code FROM behavior_sessions bs LEFT JOIN projects ps on bs.project_id = ps.id WHERE bs.id = {behavior_session_id} """ project_code = lims_db.fetchone(query, strict=False) return cls(project_code=project_code)
[docs] @classmethod def from_nwb(cls, nwbfile: NWBFile) -> "ProjectCode": try: metadata = nwbfile.lab_meta_data['metadata'] return cls(project_code=metadata.project_code) except AttributeError: # Return values for NWBs without the project code set/available. return cls()