allensdk.api.queries.brain_observatory_api module¶
- class allensdk.api.queries.brain_observatory_api.BrainObservatoryApi(base_uri=None, datacube_uri=None)[source]¶
Bases:
RmaTemplate- CELL_MAPPING_ID = 590985414¶
- NWB_FILE_TYPE = 'NWBOphys'¶
- OPHYS_ANALYSIS_FILE_TYPE = 'OphysExperimentCellRoiMetricsFile'¶
- OPHYS_EVENTS_FILE_TYPE = 'ObservatoryEventsFile'¶
- dataframe_query(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(filters)[source]¶
Convert a list of cell metric filter dictionaries into a Pandas query string.
- filter_cell_specimens(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(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(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(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(cell_specimen_ids=None, *args, **kwargs)[source]¶
Get cell metrics by id
- Parameters:
- cell_metrics_idsinteger or list of integers, optional
only select specific cell metric records.
- Returns:
- dictcell metric metadata
- get_cell_specimen_id_mapping(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_namestring
Filename to save locally.
- mapping_table_idinteger
ID of the mapping table file. Defaults to the most recent mapping table.
- Returns:
- pandas.DataFrame
Mapping table as a DataFrame.
- get_column_definitions(api_class_name=None)[source]¶
Get column definitions
- Parameters:
- api_class_namesstring or list of strings, optional
only select specific column definition records.
- Returns:
- dictcolumn definition metadata
- get_experiment_container_metrics(experiment_container_metric_ids=None)[source]¶
Get experiment container metrics by id
- Parameters:
- isi_experiment_idsinteger or list of integers, optional
only select specific experiments.
- Returns:
- dictisi experiment metadata
- get_experiment_containers(experiment_container_ids=None)[source]¶
Get experiment container by id
- Parameters:
- experiment_container_idsinteger or list of integers, optional
only select specific experiment containers.
- Returns:
- dictexperiment container metadata
- get_isi_experiments(isi_experiment_ids=None)[source]¶
Get ISI Experiments by id
- Parameters:
- isi_experiment_idsinteger or list of integers, optional
only select specific experiments.
- Returns:
- dictisi experiment metadata
- get_ophys_experiments(ophys_experiment_ids=None)[source]¶
Get OPhys Experiments by id
- Parameters:
- ophys_experiment_idsinteger or list of integers, optional
only select specific experiments.
- Returns:
- dictophys experiment metadata
- get_stimulus_mappings(stimulus_mapping_ids=None)[source]¶
Get stimulus mappings by id
- Parameters:
- stimulus_mapping_idsinteger or list of integers, optional
only select specific stimulus mapping records.
- Returns:
- dictstimulus mapping metadata
- list_column_definition_class_names()[source]¶
Get column definitions
- Parameters:
- Returns:
- listapi class name strings
- list_isi_experiments(isi_ids=None)[source]¶
List ISI experiments available through the Allen Institute API
- Parameters:
- neuronal_model_idsinteger or list of integers, optional
only select specific isi experiments.
- Returns:
- dictneuronal model metadata
- rma_templates = {'brain_observatory_queries': [{'count': False, 'criteria_params': [], 'description': 'see name', 'model': 'IsiExperiment', 'name': 'list_isi_experiments', 'num_rows': 'all'}, {'count': False, 'criteria': '[id$in{{ isi_experiment_ids }}]', 'criteria_params': ['isi_experiment_ids'], 'description': 'see name', 'include': 'experiment_container(ophys_experiments,targeted_structure)', 'model': 'IsiExperiment', 'name': 'isi_experiment_by_ids', 'num_rows': 'all'}, {'count': False, 'criteria': '{% if ophys_experiment_ids is defined %}[id$in{{ ophys_experiment_ids }}]{%endif%}', 'criteria_params': ['ophys_experiment_ids'], 'description': 'see name', 'include': 'experiment_container,well_known_files(well_known_file_type),targeted_structure,specimen(donor(age,transgenic_lines))', 'model': 'OphysExperiment', 'name': 'ophys_experiment_by_ids', 'num_rows': 'all'}, {'count': False, 'criteria': '[attachable_id$eq{{ ophys_experiment_id }}],well_known_file_type[name$eqNWBOphys]', 'criteria_params': ['ophys_experiment_id'], 'description': 'see name', 'model': 'WellKnownFile', 'name': 'ophys_experiment_data', 'num_rows': 'all'}, {'count': False, 'criteria': '[attachable_id$eq{{ ophys_experiment_id }}],well_known_file_type[name$eqOphysExperimentCellRoiMetricsFile]', 'criteria_params': ['ophys_experiment_id'], 'description': 'see name', 'model': 'WellKnownFile', 'name': 'ophys_analysis_file', 'num_rows': 'all'}, {'count': False, 'criteria': '[attachable_id$eq{{ ophys_experiment_id }}],well_known_file_type[name$eqObservatoryEventsFile]', 'criteria_params': ['ophys_experiment_id'], 'description': 'see name', 'model': 'WellKnownFile', 'name': 'ophys_events_file', 'num_rows': 'all'}, {'count': False, 'criteria': '[api_class_name$eq{{ api_class_name }}]', 'criteria_params': ['api_class_name'], 'description': 'see name', 'model': 'ApiColumnDefinition', 'name': 'column_definitions', 'num_rows': 'all'}, {'count': False, 'description': 'see name', 'model': 'ApiColumnDefinition', 'name': 'column_definition_class_names', 'num_rows': 'all', 'only': ['api_class_name']}, {'count': False, 'criteria': '{% if stimulus_mapping_ids is defined %}[id$in{{ stimulus_mapping_ids }}]{%endif%}', 'criteria_params': ['stimulus_mapping_ids'], 'description': 'see name', 'model': 'ApiCamStimulusMapping', 'name': 'stimulus_mapping', 'num_rows': 'all'}, {'count': False, 'criteria': '{% if experiment_container_ids is defined %}[id$in{{ experiment_container_ids }}]{%endif%}', 'criteria_params': ['experiment_container_ids'], 'description': 'see name', 'include': 'ophys_experiments,isi_experiment,specimen(donor(conditions,age,transgenic_lines)),targeted_structure', 'model': 'ExperimentContainer', 'name': 'experiment_container', 'num_rows': 'all'}, {'count': False, 'criteria': '{% if experiment_container_metric_ids is defined %}[id$in{{ experiment_container_metric_ids }}]{%endif%}', 'criteria_params': ['experiment_container_metric_ids'], 'description': 'see name', 'model': 'ApiCamExperimentContainerMetric', 'name': 'experiment_container_metric', 'num_rows': 'all'}, {'criteria': '{% if cell_specimen_ids is defined %}[cell_specimen_id$in{{ cell_specimen_ids }}]{%endif%}', 'criteria_params': ['cell_specimen_ids'], 'description': 'see name', 'model': 'ApiCamCellMetric', 'name': 'cell_metric'}, {'count': False, 'criteria': '[id$eq{{ mapping_table_id }}],well_known_file_type[name$eqOphysCellSpecimenIdMapping]', 'criteria_params': ['mapping_table_id'], 'description': 'see name', 'model': 'WellKnownFile', 'name': 'cell_specimen_id_mapping_table', 'num_rows': 'all'}, {'count': False, 'criteria': '[attachable_id$eq{{ ophys_session_id }}],well_known_file_type[name$eqEyeDlcScreenMapping]', 'criteria_params': ['ophys_session_id'], 'description': 'h5 file containing mouse eye gaze mapped onto screen coordinates (as well as pupil and eye sizes)', 'model': 'WellKnownFile', 'name': 'eye_gaze_mapping_file', 'num_rows': 'all'}, {'count': False, 'criteria': 'well_known_file_type[name$eqEyeDlcScreenMapping]', 'description': 'Get a list of dictionaries for all eye mapping wkfs', 'model': 'WellKnownFile', 'name': 'all_eye_mapping_files', 'num_rows': 'all'}]}¶
- save_ophys_experiment_eye_gaze_data(ophys_experiment_id: int, ophys_session_id: int, file_name: str)[source]¶
- static save_ophys_experiment_eye_tracking_data(ophys_experiment_id, cloud_cache: S3CloudCache) Path[source]¶
- Downloads eye tracking data for ophys_experiment_id using
S3CloudCache
S3 used instead of warehouse since the current team has stopped using warehouse in favor of S3.
- Parameters:
- ophys_experiment_id
- cloud_cache
instantiated S3CloudCache
- Returns:
- local path to eye tracking data
- Raises:
- ValueError if no eye tracking data exists for ophys_experiment_id