allensdk.api.queries.brain_observatory_api module

class allensdk.api.queries.brain_observatory_api.BrainObservatoryApi(base_uri=None, datacube_uri=None)[source]

Bases: allensdk.api.queries.rma_template.RmaTemplate

CELL_MAPPING_ID = 590985414
NWB_FILE_TYPE = 'NWBOphys'
OPHYS_ANALYSIS_FILE_TYPE = 'OphysExperimentCellRoiMetricsFile'
OPHYS_EVENTS_FILE_TYPE = 'ObservatoryEventsFile'
dataframe_query(self, data, filters, primary_key)[source]

Given a list of dictionary records and a list of filter dictionaries, filter the records using Pandas and return the filtered set of records.

Parameters:
data: list of dicts

List of dictionaries

filters: list of dicts

Each dictionary describes a filtering operation on a field in the dictionary. The general form is { ‘field’: <field>, ‘op’: <operation>, ‘value’: <filter_value(s)> }. For example, you can apply a threshold on the “osi_dg” column with something like this: { ‘field’: ‘osi_dg’, ‘op’: ‘>’, ‘value’: 1.0 }. See _QUERY_TEMPLATES for a full list of operators.

dataframe_query_string(self, filters)[source]

Convert a list of cell metric filter dictionaries into a Pandas query string.

filter_cell_specimens(self, cell_specimens, ids=None, experiment_container_ids=None, include_failed=False, filters=None)[source]

Filter a list of cell specimen records returned from the get_cell_metrics method according some of their properties.

Parameters:
cell_specimens: list of dicts

List of records returned by the get_cell_metrics method.

ids: list of integers

Return only records for cells with cell specimen ids in this list

experiment_container_ids: list of integers

Return only records for cells that belong to experiment container ids in this list

include_failed: bool

Whether to include cells from failed experiment containers

filters: list of dicts

Custom query used to reproduce filter sets created in the Allen Brain Observatory web application. The general form is a list of dictionaries each of which describes a filtering operation based on a metric. For more information, see dataframe_query.

filter_experiment_containers(self, containers, ids=None, targeted_structures=None, imaging_depths=None, cre_lines=None, reporter_lines=None, transgenic_lines=None, include_failed=False, simple=False)[source]
filter_experiments_and_containers(self, objs, ids=None, targeted_structures=None, imaging_depths=None, cre_lines=None, reporter_lines=None, transgenic_lines=None, include_failed=False)[source]
filter_ophys_experiments(self, experiments, ids=None, experiment_container_ids=None, targeted_structures=None, imaging_depths=None, cre_lines=None, reporter_lines=None, transgenic_lines=None, stimuli=None, session_types=None, include_failed=False, require_eye_tracking=False, simple=False)[source]
get_cell_metrics(self, cell_specimen_ids=None, *args, **kwargs)[source]

Get cell metrics by id

Parameters:
cell_metrics_ids : integer or list of integers, optional

only select specific cell metric records.

Returns:
dict : cell metric metadata
get_cell_specimen_id_mapping(self, file_name, mapping_table_id=None)[source]

Download mapping table from old to new cell specimen IDs.

The mapping table is a CSV file that maps cell specimen ids that have changed between processing runs of the Brain Observatory pipeline.

Parameters:
file_name : string

Filename to save locally.

mapping_table_id : integer

ID of the mapping table file. Defaults to the most recent mapping table.

Returns:
pandas.DataFrame

Mapping table as a DataFrame.

get_column_definitions(self, api_class_name=None)[source]

Get column definitions

Parameters:
api_class_names : string or list of strings, optional

only select specific column definition records.

Returns:
dict : column definition metadata
get_experiment_container_metrics(self, experiment_container_metric_ids=None)[source]

Get experiment container metrics by id

Parameters:
isi_experiment_ids : integer or list of integers, optional

only select specific experiments.

Returns:
dict : isi experiment metadata
get_experiment_containers(self, experiment_container_ids=None)[source]

Get experiment container by id

Parameters:
experiment_container_ids : integer or list of integers, optional

only select specific experiment containers.

Returns:
dict : experiment container metadata
get_isi_experiments(self, isi_experiment_ids=None)[source]

Get ISI Experiments by id

Parameters:
isi_experiment_ids : integer or list of integers, optional

only select specific experiments.

Returns:
dict : isi experiment metadata
get_ophys_experiments(self, ophys_experiment_ids=None)[source]

Get OPhys Experiments by id

Parameters:
ophys_experiment_ids : integer or list of integers, optional

only select specific experiments.

Returns:
dict : ophys experiment metadata
get_stimulus_mappings(self, stimulus_mapping_ids=None)[source]

Get stimulus mappings by id

Parameters:
stimulus_mapping_ids : integer or list of integers, optional

only select specific stimulus mapping records.

Returns:
dict : stimulus mapping metadata
list_column_definition_class_names(self)[source]

Get column definitions

Returns:
list : api class name strings
list_isi_experiments(self, isi_ids=None)[source]

List ISI experiments available through the Allen Institute API

Parameters:
neuronal_model_ids : integer or list of integers, optional

only select specific isi experiments.

Returns:
dict : neuronal model metadata
rma_templates = {'brain_observatory_queries': [{'name': 'list_isi_experiments', 'description': 'see name', 'model': 'IsiExperiment', 'num_rows': 'all', 'count': False, 'criteria_params': []}, {'name': 'isi_experiment_by_ids', 'description': 'see name', 'model': 'IsiExperiment', 'criteria': '[id$in{{ isi_experiment_ids }}]', 'include': 'experiment_container(ophys_experiments,targeted_structure)', 'num_rows': 'all', 'count': False, 'criteria_params': ['isi_experiment_ids']}, {'name': 'ophys_experiment_by_ids', 'description': 'see name', 'model': 'OphysExperiment', 'criteria': '{% if ophys_experiment_ids is defined %}[id$in{{ ophys_experiment_ids }}]{%endif%}', 'include': 'experiment_container,well_known_files(well_known_file_type),targeted_structure,specimen(donor(age,transgenic_lines))', 'num_rows': 'all', 'count': False, 'criteria_params': ['ophys_experiment_ids']}, {'name': 'ophys_experiment_data', 'description': 'see name', 'model': 'WellKnownFile', 'criteria': '[attachable_id$eq{{ ophys_experiment_id }}],well_known_file_type[name$eqNWBOphys]', 'num_rows': 'all', 'count': False, 'criteria_params': ['ophys_experiment_id']}, {'name': 'ophys_analysis_file', 'description': 'see name', 'model': 'WellKnownFile', 'criteria': '[attachable_id$eq{{ ophys_experiment_id }}],well_known_file_type[name$eqOphysExperimentCellRoiMetricsFile]', 'num_rows': 'all', 'count': False, 'criteria_params': ['ophys_experiment_id']}, {'name': 'ophys_events_file', 'description': 'see name', 'model': 'WellKnownFile', 'criteria': '[attachable_id$eq{{ ophys_experiment_id }}],well_known_file_type[name$eqObservatoryEventsFile]', 'num_rows': 'all', 'count': False, 'criteria_params': ['ophys_experiment_id']}, {'name': 'column_definitions', 'description': 'see name', 'model': 'ApiColumnDefinition', 'criteria': '[api_class_name$eq{{ api_class_name }}]', 'num_rows': 'all', 'count': False, 'criteria_params': ['api_class_name']}, {'name': 'column_definition_class_names', 'description': 'see name', 'model': 'ApiColumnDefinition', 'only': ['api_class_name'], 'num_rows': 'all', 'count': False}, {'name': 'stimulus_mapping', 'description': 'see name', 'model': 'ApiCamStimulusMapping', 'criteria': '{% if stimulus_mapping_ids is defined %}[id$in{{ stimulus_mapping_ids }}]{%endif%}', 'num_rows': 'all', 'count': False, 'criteria_params': ['stimulus_mapping_ids']}, {'name': 'experiment_container', 'description': 'see name', 'model': 'ExperimentContainer', 'criteria': '{% if experiment_container_ids is defined %}[id$in{{ experiment_container_ids }}]{%endif%}', 'include': 'ophys_experiments,isi_experiment,specimen(donor(conditions,age,transgenic_lines)),targeted_structure', 'num_rows': 'all', 'count': False, 'criteria_params': ['experiment_container_ids']}, {'name': 'experiment_container_metric', 'description': 'see name', 'model': 'ApiCamExperimentContainerMetric', 'criteria': '{% if experiment_container_metric_ids is defined %}[id$in{{ experiment_container_metric_ids }}]{%endif%}', 'num_rows': 'all', 'count': False, 'criteria_params': ['experiment_container_metric_ids']}, {'name': 'cell_metric', 'description': 'see name', 'model': 'ApiCamCellMetric', 'criteria': '{% if cell_specimen_ids is defined %}[cell_specimen_id$in{{ cell_specimen_ids }}]{%endif%}', 'criteria_params': ['cell_specimen_ids']}, {'name': 'cell_specimen_id_mapping_table', 'description': 'see name', 'model': 'WellKnownFile', 'criteria': '[id$eq{{ mapping_table_id }}],well_known_file_type[name$eqOphysCellSpecimenIdMapping]', 'num_rows': 'all', 'count': False, 'criteria_params': ['mapping_table_id']}, {'name': 'eye_gaze_mapping_file', 'description': 'h5 file containing mouse eye gaze mapped onto screen coordinates (as well as pupil and eye sizes)', 'model': 'WellKnownFile', 'criteria': '[attachable_id$eq{{ ophys_session_id }}],well_known_file_type[name$eqEyeDlcScreenMapping]', 'num_rows': 'all', 'count': False, 'criteria_params': ['ophys_session_id']}, {'name': 'all_eye_mapping_files', 'description': 'Get a list of dictionaries for all eye mapping wkfs', 'model': 'WellKnownFile', 'criteria': 'well_known_file_type[name$eqEyeDlcScreenMapping]', 'num_rows': 'all', 'count': False}]}
save_ophys_experiment_analysis_data(self, ophys_experiment_id, file_name)[source]
save_ophys_experiment_data(self, ophys_experiment_id, file_name)[source]
save_ophys_experiment_event_data(self, ophys_experiment_id, file_name)[source]
save_ophys_experiment_eye_gaze_data(self, ophys_experiment_id: int, ophys_session_id: int, file_name: str)[source]
simplify_experiment_containers(self, containers)[source]
simplify_ophys_experiments(self, exps)[source]
allensdk.api.queries.brain_observatory_api.find_container_tags(container)[source]

Custom logic for extracting tags from donor conditions. Filtering out tissuecyte tags.

allensdk.api.queries.brain_observatory_api.find_experiment_acquisition_age(exp)[source]
allensdk.api.queries.brain_observatory_api.find_specimen_cre_line(specimen)[source]
allensdk.api.queries.brain_observatory_api.find_specimen_reporter_line(specimen)[source]
allensdk.api.queries.brain_observatory_api.find_specimen_transgenic_lines(specimen)[source]