Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch EcephysSession from SLIMS #38

Merged
merged 17 commits into from
Oct 4, 2024
Merged

Fetch EcephysSession from SLIMS #38

merged 17 commits into from
Oct 4, 2024

Conversation

mekhlakapoor
Copy link
Contributor

@mekhlakapoor mekhlakapoor commented Sep 30, 2024

closes #30

  • models for ReferenceDataRecord table: DomeModule, FiberConnections, RewardDelivery, RewardSpouts (Fetch necessary ecephys session data from ReferenceDataRecord #32)
  • models for ExperimentRunSteps and ExperimentRunStepContent tables (for Mouse Session and Group of Sessions data in a workflow)
  • operator class to collect all ecephys session data for a given subject id. Fetch_sessions iterates through the different tables and encapsulates all the data into a model "EcephysSession"
  • Makes SlimsRecordNotFound error message more specific and logs it in operator.

@mekhlakapoor mekhlakapoor marked this pull request as draft September 30, 2024 17:01
@mekhlakapoor mekhlakapoor marked this pull request as ready for review October 2, 2024 23:07
Copy link
Collaborator

@patricklatimer patricklatimer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice, feel free to take or leave my suggestions!

@@ -0,0 +1 @@
"""Init operations dir"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should include the following here so it's like models, and easier to access.

from .ecephys_session import EcephysSession, SlimsEcephysSessionOperator

__all__ = [
    "EcephysSession",
    "SlimsEcephysSessionOperator",
]

@@ -127,7 +127,7 @@ def fetch_models(
start: Optional[int] = None,
end: Optional[int] = None,
**kwargs,
) -> list[SlimsBaseModelTypeVar]:
) -> List[SlimsBaseModelTypeVar]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super trivial, and I could be wrong but isn't it now preferred to use list over typing.List?

Copy link
Contributor Author

@mekhlakapoor mekhlakapoor Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, since the slims-api requires 3.10 and up, we can use the generic types

Pydantic model encapsulating all session-related responses.
"""

session_group: Optional[SlimsExperimentRunStep]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like at least session_group (and maybe session_result?) will always be populated, should they not be Optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a (small) chance that even though there is a mouse session run step in a workflow, that session may not exist in the results table. since we don't have too many examples yet of what is/isn't possible I'll leave session_result as optional. Good catch for session_group though

stimulus_epochs: Optional[List[SlimsStimulusEpochsResult]] = []


class SlimsEcephysSessionOperator:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see the need for more methods on this class in the future? If it's just fetching the collection, I would be inclined to have that just be a public function in the module.

class EcephysSession(BaseModel):
    session_group: Optional[SlimsExperimentRunStep]
    ...

def fetch_ecephys_session(slims_client: Optional[SlimsClient], subject_id:str) -> list[EcephysSession]:
    ...

If there's the potential for more operations you'd want to do with a session, then maybe I would merge the Operator class with the EcephysSession collection object above, so that it represents a Session concept with relevant attributes and methods.

class SlimsEcephysSessionOperator:
    session_group: SlimsExperimentRunStep
    ...

    def __init__(self, slims_client: Optional[SlimsClient], subject_id: str, content_run_pk: int): ...

    def end_session(self): ...

    def add_step(self, ...): ...

def fetch_sessions(slims_client, subject_id) -> list[SlimsEcephysSessionOperator]:

I think I'm skeptical of having to instantiate an operator in addition to the client if it's not going to be a long-lasting helpful object. I know you wanted to have it inherit from SlimsClient which also solves that, though I think that has some drawbacks

@mekhlakapoor mekhlakapoor changed the title Feat 32 ecephys rdrc Fetch EcephysSession from SLIMS Oct 3, 2024
--------
>>> from aind_slims_api import SlimsClient
>>> client = SlimsClient()
>>> fetch_sessions(client=client, subject_id="000000")
Copy link
Collaborator

@mochic mochic Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an example is great. Following valid doctest syntax may provide added benefit for little cost (makes the example testable against dev). Smallest possible change would be: >>> sessions = fetch_sessions(client=client, subject_id="725804") But isn't a super necessary change.

return ecephys_sessions


def fetch_sessions(client: SlimsClient, subject_id: str) -> List[EcephysSession]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be fetch_ecephys_sessions

@mekhlakapoor mekhlakapoor merged commit c82ff9f into main Oct 4, 2024
3 checks passed
@mekhlakapoor mekhlakapoor deleted the feat-32-ecephys-rdrc branch October 4, 2024 02:20
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.

Pull ephys session metadata from SLIMS
3 participants