Skip to content

Commit

Permalink
Merge pull request #2650 from AllenInstitute/rc/2.15.0
Browse files Browse the repository at this point in the history
Rc/2.15.0
  • Loading branch information
aamster authored Jan 24, 2023
2 parents 9ef5214 + a8e6df0 commit d69d470
Show file tree
Hide file tree
Showing 89 changed files with 25,818 additions and 18,406 deletions.
2 changes: 1 addition & 1 deletion allensdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#
import logging

__version__ = '2.14.1'
__version__ = '2.15.0'


try:
Expand Down
977 changes: 578 additions & 399 deletions allensdk/api/queries/brain_observatory_api.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
build_in_list_selector_query, build_where_clause)
from allensdk.internal.brain_observatory.util.multi_session_utils import \
get_session_metadata_multiprocessing
from allensdk.brain_observatory.behavior.data_objects import BehaviorSessionId


class BehaviorProjectLimsApi(BehaviorProjectBase):
Expand Down Expand Up @@ -236,6 +237,7 @@ def _get_behavior_summary_table(self) -> pd.DataFrame:
query = f"""
SELECT
bs.id AS behavior_session_id,
pr.code as project_code,
equipment.name as equipment_name,
bs.date_of_acquisition,
d.id as donor_id,
Expand All @@ -257,6 +259,7 @@ def _get_behavior_summary_table(self) -> pd.DataFrame:
{self._build_line_from_donor_query("driver")}
) driver on driver.donor_id = d.id
LEFT OUTER JOIN equipment ON equipment.id = bs.equipment_id
LEFT OUTER JOIN projects pr ON pr.id = bs.project_id
"""

if self.data_release_date is not None:
Expand Down Expand Up @@ -356,7 +359,12 @@ def _get_ophys_experiment_table(self) -> pd.DataFrame:
query += where_clause

self.logger.debug(f"get_ophys_experiment_table query: \n{query}")
return self.lims_engine.select(query)
query_df = self.lims_engine.select(query)
targeted_imaging_depth = query_df[
["ophys_container_id", "imaging_depth"]
].groupby("ophys_container_id").mean()
targeted_imaging_depth.columns = ['targeted_imaging_depth']
return query_df.merge(targeted_imaging_depth, on='ophys_container_id')

def _get_ophys_cells_table(self):
"""
Expand Down Expand Up @@ -416,7 +424,7 @@ def _get_ophys_session_table(self) -> pd.DataFrame:
"""Helper function for easier testing.
Return a pd.Dataframe table with all ophys_session_ids and relevant
metadata.
Return columns: ophys_session_id, behavior_session_id,
Return columns: ophys_session_id, behavior_session_id, project_code,
ophys_experiment_id, project_code, session_name,
date_of_acquisition,
specimen_id, full_genotype, sex, age_in_days,
Expand All @@ -428,10 +436,10 @@ def _get_ophys_session_table(self) -> pd.DataFrame:
SELECT
os.id as ophys_session_id,
bs.id as behavior_session_id,
pr.code as project_code,
imaging_plane_group_count.imaging_plane_group_count,
exp_ids.experiment_ids as ophys_experiment_id,
cntr_ids.container_ids as ophys_container_id,
pr.code as project_code,
os.name as session_name,
os.date_of_acquisition,
os.specimen_id
Expand Down Expand Up @@ -528,7 +536,7 @@ def get_behavior_session_table(self, n_workers: int = 1) -> pd.DataFrame:
else:
session_metadata = [
BehaviorMetadata.from_lims(
behavior_session_id=behavior_session_id,
behavior_session_id=BehaviorSessionId(behavior_session_id),
lims_db=db_connection_creator(
fallback_credentials=LIMS_DB_CREDENTIAL_MAP
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import warnings


class OphysMixin:
"""A mixin class for ophys project data"""
def __init__(self):
Expand All @@ -11,3 +14,46 @@ def __init__(self):
self._df = self._df.drop(
['date_of_acquisition_behavior',
'date_of_acquisition_ophys'], axis=1)
self._clean_up_project_code()

def _clean_up_project_code(self):
"""Remove duplicate project_code columns from the data frames. This is
as depending on the table we get the project_code either through the
behavior_sessions or ophys_sessions tables.
Additionally test that the values in the columns are identical.
"""

if 'project_code_behavior' in self._df and \
'project_code_ophys' in self._df:

if (self._df['project_code_ophys'].isna()).sum() == 0:
# If there are no missing ophys_session_ids for the table then
# we are loading of the ophys tables and should be able to
# compare the ids directly to assure ourselves that the
# project ids are the same between ophys and behavior sessions.
if not self._df['project_code_ophys'].equals(
self._df['project_code_behavior']):
warnings.warn("BehaviorSession and OphysSession "
"project_code's do not agree. This is "
"likely due to issues with the data in "
"LIMS. Using OphysSession project_code.")
self._df['project_code'] = self._df['project_code_ophys']
else:
# If there are missing ophys_session_ids for the table then
# we are loading of the behavior table first will need to mask
# to only the sessions that have ophys_session_ids before
# comparing project_codes.
has_ophys_session_mask = ~self._df['project_code_ophys'].isna()
if not self._df['project_code_behavior'][
has_ophys_session_mask].equals(
self._df['project_code_ophys'][
has_ophys_session_mask]):
warnings.warn("BehaviorSession and OphysSession "
"project_codes do not agree. This is likely "
"due to issues with the data in LIMS. Using "
"BehaviorSession project_code.")
self._df['project_code'] = self._df['project_code_behavior']
self._df = self._df.drop(
['project_code_ophys', 'project_code_behavior'],
axis=1)
Loading

0 comments on commit d69d470

Please sign in to comment.