Skip to content

Commit 389806f

Browse files
committed
Add more documentation; Fix LIMS query typo
This is a combination of the following two commits: 1) Add more documentation This commit adds more documentation to brain_observatory.behavior data api methods. 2) Fix a couple of LIMS query typos A set of typos where a semicolon was introduced within a single quote block resulted in a non-functional query. This commit fixes these typos.
1 parent 0374cb9 commit 389806f

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

allensdk/brain_observatory/behavior/session_apis/data_io/behavior_lims_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def from_foraging_id(cls,
7373
query = f"""
7474
SELECT id
7575
FROM behavior_sessions
76-
WHERE foraging_id = '{foraging_id};'
76+
WHERE foraging_id = '{foraging_id}';
7777
"""
7878
session_id = lims_db.fetchone(query, strict=True)
7979
return cls(session_id, lims_credentials=lims_credentials)
@@ -221,7 +221,7 @@ def get_stimulus_name(self) -> str:
221221
SELECT stages.name
222222
FROM behavior_sessions bs
223223
JOIN stages ON stages.id = bs.state_id
224-
WHERE bs.id = '{self.foraging_id};'
224+
WHERE bs.id = '{self.foraging_id}';
225225
"""
226226
return self.mtrain_db.fetchone(query, strict=True)
227227

allensdk/brain_observatory/behavior/session_apis/data_io/behavior_ophys_json_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ def get_driver_line(self) -> str:
106106
return self.data['driver_line']
107107

108108
def external_specimen_name(self) -> int:
109-
"""Get the external specimen id for the subject associated with an
110-
ophys experiment"""
109+
"""Get the external specimen id (LabTracks ID) for the subject
110+
associated with an ophys experiment"""
111111
return self.data['external_specimen_name']
112112

113113
def get_full_genotype(self) -> str:
@@ -116,6 +116,7 @@ def get_full_genotype(self) -> str:
116116
return self.data['full_genotype']
117117

118118
def get_behavior_stimulus_file(self) -> str:
119+
"""Get the filepath to the StimulusPickle file for the session"""
119120
return self.data['behavior_stimulus_file']
120121

121122
def get_dff_file(self) -> str:

allensdk/brain_observatory/behavior/session_apis/data_io/behavior_ophys_lims_api.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def get_ophys_experiment_id(self) -> int:
4949

5050
@memoize
5151
def get_ophys_session_id(self) -> int:
52+
"""Get the ophys session id associated with the ophys experiment
53+
id used to initialize the API"""
5254
query = """
5355
SELECT os.id FROM ophys_sessions os
5456
JOIN ophys_experiment oe ON oe.ophys_session_id = os.id
@@ -58,6 +60,8 @@ def get_ophys_session_id(self) -> int:
5860

5961
@memoize
6062
def get_experiment_container_id(self) -> int:
63+
"""Get the experiment container id associated with the ophys
64+
experiment id used to initialize the API"""
6165
query = """
6266
SELECT visual_behavior_experiment_container_id
6367
FROM ophys_experiments_visual_behavior_experiment_containers
@@ -67,6 +71,8 @@ def get_experiment_container_id(self) -> int:
6771

6872
@memoize
6973
def get_behavior_stimulus_file(self) -> str:
74+
"""Get the filepath to the StimulusPickle file for the session
75+
associated with the ophys experiment id used to initialize the API"""
7076
query = """
7177
SELECT wkf.storage_directory || wkf.filename AS stim_file
7278
FROM ophys_experiments oe
@@ -83,6 +89,8 @@ def get_behavior_stimulus_file(self) -> str:
8389

8490
@memoize
8591
def get_nwb_filepath(self) -> str:
92+
"""Get the filepath of the nwb file associated with the ophys
93+
experiment"""
8694
query = """
8795
SELECT wkf.storage_directory || wkf.filename AS nwb_file
8896
FROM ophys_experiments oe
@@ -96,6 +104,8 @@ def get_nwb_filepath(self) -> str:
96104

97105
@memoize
98106
def get_eye_tracking_filepath(self) -> str:
107+
"""Get the filepath of the eye tracking file (*.h5) associated with the
108+
ophys experiment"""
99109
query = """
100110
SELECT wkf.storage_directory || wkf.filename
101111
AS eye_tracking_file
@@ -112,7 +122,7 @@ def get_eye_tracking_filepath(self) -> str:
112122

113123
@staticmethod
114124
def get_ophys_experiment_df() -> pd.DataFrame:
115-
125+
"""Get a DataFrame of metadata for ophys experiments"""
116126
api = (credential_injector(LIMS_DB_CREDENTIAL_MAP)
117127
(PostgresQueryMixin)())
118128
query = """

allensdk/brain_observatory/behavior/session_apis/data_io/ophys_lims_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_plane_group_count(self) -> int:
5555
ON pg.id = oe.ophys_imaging_plane_group_id
5656
WHERE
5757
-- only 1 session for an experiment
58-
os.id = (SELECT id from sess limit 1)
58+
os.id = (SELECT id from sess limit 1);
5959
"""
6060
return self.lims_db.fetchone(query, strict=True)
6161

@@ -72,7 +72,7 @@ def get_imaging_plane_group(self) -> Optional[int]:
7272
FROM ophys_experiments oe
7373
JOIN ophys_imaging_plane_groups pg
7474
ON pg.id = oe.ophys_imaging_plane_group_id
75-
WHERE oe.id = {self.get_ophys_experiment_id()}
75+
WHERE oe.id = {self.get_ophys_experiment_id()};
7676
"""
7777
# Non-mesoscope data will not have results
7878
group_order = self.lims_db.fetchall(query)
@@ -93,7 +93,7 @@ def get_behavior_session_id(self) -> Optional[int]:
9393
JOIN ophys_sessions os ON oe.ophys_session_id = os.id
9494
-- but not every ophys_session has a behavior_session
9595
LEFT JOIN behavior_sessions bs ON os.id = bs.ophys_session_id
96-
WHERE oe.id = {self.get_ophys_experiment_id()}
96+
WHERE oe.id = {self.get_ophys_experiment_id()};
9797
"""
9898
response = self.lims_db.fetchall(query) # Can be null
9999
if not len(response):
@@ -260,8 +260,8 @@ def get_driver_line(self) -> str:
260260

261261
@memoize
262262
def get_external_specimen_name(self) -> int:
263-
"""Get the external specimen id for the subject associated with an
264-
ophys experiment"""
263+
"""Get the external specimen id (LabTracks ID) for the subject
264+
associated with an ophys experiment"""
265265
query = """
266266
SELECT sp.external_specimen_name
267267
FROM ophys_experiments oe
@@ -454,7 +454,7 @@ def get_raw_cell_specimen_table_dict(self) -> dict:
454454
query = """
455455
SELECT *
456456
FROM cell_rois cr
457-
WHERE cr.ophys_cell_segmentation_run_id = {}
457+
WHERE cr.ophys_cell_segmentation_run_id = {};
458458
""".format(ophys_cell_seg_run_id)
459459
initial_cs_table = pd.read_sql(query, self.lims_db.get_connection())
460460
cell_specimen_table = initial_cs_table.rename(

0 commit comments

Comments
 (0)