allensdk.api.queries package

Submodules

allensdk.api.queries.annotated_section_data_sets_api module

class allensdk.api.queries.annotated_section_data_sets_api.AnnotatedSectionDataSetsApi(base_uri=None)[source]

Bases: allensdk.api.queries.rma_api.RmaApi

See: Searching Annotated SectionDataSets

get_annotated_section_data_sets(structures, intensity_values=None, density_values=None, pattern_values=None, age_names=None)[source]

For a list of target structures, find the SectionDataSet that matches the parameters for intensity_values, density_values, pattern_values, and Age.

Parameters:

structure_graph_id : dict of integers

what to retrieve

intensity_values : array of strings, optional

‘High’,’Low’, ‘Medium’ (default)

density_values : array of strings, optional

‘High’, ‘Low’

pattern_values : array of strings, optional

‘Full’

age_names : array of strings, options

for example ‘E11.5’, ‘13.5’

Returns:

data : dict

The parsed JSON repsonse message.

Notes

This method uses the non-RMA Annotated SectionDataSet endpoint.

get_annotated_section_data_sets_via_rma(*args, **kwargs)[source]

For a list of target structures, find the SectionDataSet that matches the parameters for intensity_values, density_values, pattern_values, and Age.

Parameters:

structure_graph_id : dict of integers

what to retrieve

intensity_values : array of strings, optional

intensity values, ‘High’,’Low’, ‘Medium’ (default)

density_values : array of strings, optional

density values, ‘High’, ‘Low’

pattern_values : array of strings, optional

pattern values, ‘Full’

age_names : array of strings, options

for example ‘E11.5’, ‘13.5’

Returns:

data : dict

The parsed JSON response message.

Notes

This method uses the RMA endpoint to search annotated SectionDataSet data.

get_compound_annotated_section_data_sets(queries, fmt='json')[source]

Find the SectionDataSet that matches several annotated_section_data_sets queries linked together with a Boolean ‘and’ or ‘or’.

Parameters:

queries : array of dicts

dicts with args like build_query

fmt : string, optional

‘json’ or ‘xml’

Returns:

data : dict

The parsed JSON repsonse message.

allensdk.api.queries.biophysical_api module

class allensdk.api.queries.biophysical_api.BiophysicalApi(base_uri=None)[source]

Bases: allensdk.api.api.Api

build_rma(neuronal_model_id, fmt='json')[source]

Construct a query to find all files related to a neuronal model.

Parameters:

neuronal_model_id : integer or string representation

key of experiment to retrieve.

fmt : string, optional

json (default) or xml

Returns:

string

RMA query url.

cache_data(neuronal_model_id, working_directory=None)[source]

Take a an experiment id, query the Api RMA to get well-known-files download the files, and store them in the working directory.

Parameters:

neuronal_model_id : int or string representation

found in the neuronal_model table in the api

working_directory : string

Absolute path name where the downloaded well-known files will be stored.

create_manifest(fit_path='', model_type='', stimulus_filename='', swc_morphology_path='', marker_path='', sweeps=[])[source]

Generate a json configuration file with parameters for a a biophysical experiment.

Parameters:

fit_path : string

filename of a json configuration file with cell parameters.

stimulus_filename : string

path to an NWB file with input currents.

swc_morphology_path : string

file in SWC format.

sweeps : array of integers

which sweeps in the stimulus file are to be used.

get_well_known_file_ids(neuronal_model_id)[source]

Query the current RMA endpoint with a neuronal_model id to get the corresponding well known file ids.

Returns:

list

A list of well known file id strings.

is_well_known_file_type(wkf, name)[source]

Check if a structure has the expected name.

Parameters:

wkf : dict

A well-known-file structure with nested type information.

name : string

The expected type name

See also

read_json
where this helper function is used.
read_json(json_parsed_data)[source]

Get the list of well_known_file ids from a response body containing nested sample,microarray_slides,well_known_files.

Parameters:

json_parsed_data : dict

Response from the Allen Institute Api RMA.

Returns:

list of strings

Well known file ids.

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'
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, transgenic_lines=None, include_failed=False)[source]
filter_ophys_experiments(experiments, ids=None, experiment_container_ids=None, targeted_structures=None, imaging_depths=None, transgenic_lines=None, stimuli=None, session_types=None, include_failed=False)[source]
get_cell_metrics(*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(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(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(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(*args, **kwargs)[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(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(*args, **kwargs)[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(*args, **kwargs)[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()[source]

Get column definitions

Returns:list : api class name strings
list_isi_experiments(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': [{'count': False, 'name': 'list_isi_experiments', 'criteria_params': [], 'num_rows': 'all', 'model': 'IsiExperiment', 'description': 'see name'}, {'count': False, 'criteria_params': ['isi_experiment_ids'], 'name': 'isi_experiment_by_ids', 'criteria': '[id$in{{ isi_experiment_ids }}]', 'num_rows': 'all', 'model': 'IsiExperiment', 'include': 'experiment_container(ophys_experiments,targeted_structure)', 'description': 'see name'}, {'count': False, 'criteria_params': ['ophys_experiment_ids'], 'name': 'ophys_experiment_by_ids', 'criteria': '{% if ophys_experiment_ids is defined %}[id$in{{ ophys_experiment_ids }}]{%endif%}', 'num_rows': 'all', 'model': 'OphysExperiment', 'include': 'experiment_container,well_known_files(well_known_file_type),targeted_structure,specimen(donor(age,transgenic_lines))', 'description': 'see name'}, {'count': False, 'name': 'ophys_experiment_data', 'criteria_params': ['ophys_experiment_id'], 'criteria': '[attachable_id$eq{{ ophys_experiment_id }}],well_known_file_type[name$eqNWBOphys]', 'num_rows': 'all', 'model': 'WellKnownFile', 'description': 'see name'}, {'count': False, 'name': 'column_definitions', 'criteria_params': ['api_class_name'], 'criteria': '[api_class_name$eq{{ api_class_name }}]', 'num_rows': 'all', 'model': 'ApiColumnDefinition', 'description': 'see name'}, {'count': False, 'name': 'column_definition_class_names', 'only': ['api_class_name'], 'num_rows': 'all', 'model': 'ApiColumnDefinition', 'description': 'see name'}, {'count': False, 'name': 'stimulus_mapping', 'criteria_params': ['stimulus_mapping_ids'], 'criteria': '{% if stimulus_mapping_ids is defined %}[id$in{{ stimulus_mapping_ids }}]{%endif%}', 'num_rows': 'all', 'model': 'ApiCamStimulusMapping', 'description': 'see name'}, {'count': False, 'criteria_params': ['experiment_container_ids'], 'name': 'experiment_container', 'criteria': '{% if experiment_container_ids is defined %}[id$in{{ experiment_container_ids }}]{%endif%}', 'num_rows': 'all', 'model': 'ExperimentContainer', 'include': 'ophys_experiments,isi_experiment,specimen(donor(conditions,age,transgenic_lines)),targeted_structure', 'description': 'see name'}, {'count': False, 'name': 'experiment_container_metric', 'criteria_params': ['experiment_container_metric_ids'], 'criteria': '{% if experiment_container_metric_ids is defined %}[id$in{{ experiment_container_metric_ids }}]{%endif%}', 'num_rows': 'all', 'model': 'ApiCamExperimentContainerMetric', 'description': 'see name'}, {'model': 'ApiCamCellMetric', 'criteria': '{% if cell_specimen_ids is defined %}[cell_specimen_id$in{{ cell_specimen_ids }}]{%endif%}', 'name': 'cell_metric', 'criteria_params': ['cell_specimen_ids'], 'description': 'see name'}, {'count': False, 'name': 'cell_specimen_id_mapping_table', 'criteria_params': ['mapping_table_id'], 'criteria': '[id$eq{{ mapping_table_id }}],well_known_file_type[name$eqOphysCellSpecimenIdMapping]', 'num_rows': 'all', 'model': 'WellKnownFile', 'description': 'see name'}]}
save_ophys_experiment_data(*args, **kwargs)[source]

allensdk.api.queries.cell_types_api module

class allensdk.api.queries.cell_types_api.CellTypesApi(base_uri=None)[source]

Bases: allensdk.api.queries.rma_api.RmaApi

MARKER_FILE_TYPE = '3DNeuronMarker'
NWB_FILE_TYPE = 'NWBDownload'
SWC_FILE_TYPE = '3DNeuronReconstruction'
filter_cells(cells, require_morphology, require_reconstruction, reporter_status)[source]

Filter a list of cell specimens to those that optionally have morphologies or have morphological reconstructions.

Parameters:

cells: list

List of cell metadata dictionaries to be filtered

require_morphology: boolean

Filter out cells that have no morphological images.

require_reconstruction: boolean

Filter out cells that have no morphological reconstructions.

reporter_status: list

Filter for cells that have a particular cell reporter status

get_cell(id)[source]

Query the API for a one cells in the Cell Types Database.

Returns:

list

Meta data for one cell.

get_ephys_features(*args, **kwargs)[source]

Query the API for the full table of EphysFeatures for all cells.

get_ephys_sweeps(*args, **kwargs)[source]

Query the API for a list of sweeps for a particular cell in the Cell Types Database.

Parameters:

specimen_id: int

Specimen ID of a cell.

Returns:

list: List of sweep dictionaries belonging to a cell

get_morphology_features(*args, **kwargs)[source]

Query the API for the full table of morphology features for all cells

Notes

by default the tags column is removed because it isn’t useful

list_cells(id=None, require_morphology=False, require_reconstruction=False, reporter_status=None)[source]

Query the API for a list of all cells in the Cell Types Database.

Parameters:

id: int

ID of a cell. If not provided returns all matching cells.

require_morphology: boolean

Only return cells that have morphology images.

require_reconstruction: boolean

Only return cells that have morphological reconstructions.

reporter_status: list

Return cells that have a particular cell reporter status.

Returns:

list

Meta data for all cells.

save_ephys_data(*args, **kwargs)[source]

Save the electrophysology recordings for a cell as an NWB file.

Parameters:

specimen_id: int

ID of the specimen, from the Specimens database model in the Allen Institute API.

file_name: str

Path to save the NWB file.

save_reconstruction(specimen_id, file_name)[source]

Save the morphological reconstruction of a cell as an SWC file.

Parameters:

specimen_id: int

ID of the specimen, from the Specimens database model in the Allen Institute API.

file_name: str

Path to save the SWC file.

save_reconstruction_markers(specimen_id, file_name)[source]

Save the marker file for the morphological reconstruction of a cell. These are comma-delimited files indicating points of interest in a reconstruction (truncation points, early tracing termination, etc).

Parameters:

specimen_id: int

ID of the specimen, from the Specimens database model in the Allen Institute API.

file_name: str

Path to save the marker file.

allensdk.api.queries.connected_services module

class allensdk.api.queries.connected_services.ConnectedServices[source]

Bases: object

A class representing a schema of informatics web services.

Notes

See Connected Services and Pipes for a human-readable list of services and parameters.

The URL format is documented at Service Pipelines.

Connected Services only include API services that are accessed via the RMA endpoint using an rma::services stage.

ARRAY = 'array'
BOOLEAN = 'boolean'
FLOAT = 'float'
INTEGER = 'integer'
STRING = 'string'
build_url(service_name, kwargs)[source]

Create a single stage RMA url from a service name and parameters.

classmethod schema()

Dictionary of service names and parameters.

Notes

See Connected Services and Pipes for a human-readable list of connected services and their parameters.

allensdk.api.queries.glif_api module

class allensdk.api.queries.glif_api.GlifApi(base_uri=None)[source]

Bases: allensdk.api.queries.rma_template.RmaTemplate

NWB_FILE_TYPE = None
cache_stimulus_file(*args, **kwargs)[source]

DEPRECATED Download the NWB file for the current neuronal model and save it to a file.

Parameters:

output_file_name: string

File name to store the NWB file.

get_ephys_sweeps(*args, **kwargs)[source]

DEPRECATED Retrieve ephys sweep information out of downloaded metadata for a neuronal model

Returns:

list

A list of sweeps metadata dictionaries

get_neuron_config(*args, **kwargs)[source]

DEPRECATED Retrieve a model configuration file from the API, optionally save it to disk, and return the contents of that file as a dictionary.

Parameters:

output_file_name: string

File name to store the neuron configuration (optional).

get_neuron_configs(neuronal_model_ids=None)[source]
get_neuronal_model(*args, **kwargs)[source]

DEPRECATED Query the current RMA endpoint with a neuronal_model id to get the corresponding well known files and meta data.

Returns:

dict

A dictionary containing

get_neuronal_model_templates()[source]
get_neuronal_models(ephys_experiment_ids=None)[source]
get_neuronal_models_by_id(neuronal_model_ids=None)[source]
list_neuronal_models(*args, **kwargs)[source]

DEPRECATED Query the API for a list of all GLIF neuronal models.

Returns:

list

Meta data for all GLIF neuronal models.

rma_templates = {'glif_queries': [{'num_rows': 'all', 'count': False, 'model': 'NeuronalModelTemplate', 'name': 'neuronal_model_templates', 'description': 'see name'}, {'count': False, 'criteria_params': ['ephys_experiment_ids'], 'name': 'neuronal_models', 'criteria': '[id$in{{ ephys_experiment_ids }}]', 'num_rows': 'all', 'model': 'Specimen', 'include': 'neuronal_models(well_known_files,neuronal_model_template,neuronal_model_runs(well_known_files))', 'description': 'see name'}, {'count': False, 'criteria_params': ['neuronal_model_ids'], 'name': 'neuron_config', 'criteria': '[id$in{{ neuronal_model_ids }}]', 'num_rows': 'all', 'model': 'NeuronalModel', 'include': 'well_known_files(well_known_file_type)', 'description': 'see name'}]}

allensdk.api.queries.grid_data_api module

class allensdk.api.queries.grid_data_api.GridDataApi(resolution=None, base_uri=None)[source]

Bases: allensdk.api.queries.rma_api.RmaApi

HTTP Client for the Allen 3-D Expression Grid Data Service.

See: Downloading 3-D Expression Grid Data

DATA_MASK = 'data_mask'
DENSITY = 'density'
ENERGY = 'energy'
INJECTION_DENSITY = 'injection_density'
INJECTION_ENERGY = 'injection_energy'
INJECTION_FRACTION = 'injection_fraction'
INTENSITY = 'intensity'
PROJECTION_DENSITY = 'projection_density'
PROJECTION_ENERGY = 'projection_energy'
download_expression_grid_data(section_data_set_id, include=None, path=None)[source]

Download in NRRD format.

Parameters:

section_data_set_id : integer

What to download.

include : list of strings, optional

Image volumes. ‘energy’ (default), ‘density’, ‘intensity’.

path : string, optional

File name to save as.

i

Returns

——-

file : 3-D expression grid data packaged into a compressed archive file (.zip).

download_projection_grid_data(section_data_set_id, image=None, resolution=None, save_file_path=None)[source]

Download in NRRD format.

Parameters:

section_data_set_id : integer

What to download.

image : list of strings, optional

Image volume. ‘projection_density’, ‘projection_energy’, ‘injection_fraction’, ‘injection_density’, ‘injection_energy’, ‘data_mask’.

resolution : integer, optional

in microns. 10, 25, 50, or 100 (default).

save_file_path : string, optional

File name to save as.

Notes

See Downloading 3-D Projection Grid Data for additional documentation.

allensdk.api.queries.image_download_api module

class allensdk.api.queries.image_download_api.ImageDownloadApi(base_uri=None)[source]

Bases: allensdk.api.queries.rma_api.RmaApi

HTTP Client to download whole or partial two-dimensional images from the Allen Institute with the SectionImage, AtlasImage and ProjectionImage Download Services.

See Downloading an Image for more documentation.

COLORMAPS = {'colormap': 10, 'aba': 8, 'redtemp': 3, 'projection': 11, 'blue': 6, 'gray': 0, 'jet': 2, 'aibsmap_alt': 9, 'hotmetal': 1, 'green': 7, 'expression': 4, 'red': 5}
atlas_image_query(atlas_id, image_type_name=None)[source]

Build the URL.

Parameters:

atlas_id : integer, optional

request a certain record.

image_type_name : string, optional

if not present, the query will get it from the atlas id.

Returns:

url : string

The constructed URL

Notes

See Downloading Atlas Images and Graphics for additional documentation. The atlas id can be found with allensdk.api.queries.ontologies_api.OntologiesApi.build_atlases_query()

download_atlas_image(atlas_image_id, file_path=None, **kwargs)[source]
download_image(image_id, file_path=None, endpoint=None, **kwargs)[source]

Download whole or partial two-dimensional images from the Allen Institute with the SectionImage or AtlasImage service.

Parameters:

image_id : integer

SubImage to download.

file_path : string, optional

where to put it, defaults to image_id.jpg

downsample : int, optional

Number of times to downsample the original image.

quality : int, optional

jpeg quality of the returned image, 0 to 100 (default)

expression : boolean, optional

Request the expression mask for the SectionImage.

view : string, optional

‘expression’, ‘projection’, ‘tumor_feature_annotation’ or ‘tumor_feature_boundary’

top : int, optional

Index of the topmost row of the region of interest.

left :int, optional

Index of the leftmost column of the region of interest.

width : int, optional

Number of columns in the output image.

height : int, optional

Number of rows in the output image.

range : list of ints, optional

Filter to specify the RGB channels. low,high,low,high,low,high

colormap : list of floats, optional

Filter to specify the RGB channels. [lower_threshold,colormap] gain 0-1, colormap id is a string from ImageDownloadApi.COLORMAPS

rgb : list of floats, optional

Filter to specify the RGB channels. [red,green,blue] 0-1

contrast : list of floats, optional

Filter to specify contrast parameters. [gain,bias] 0-1

annotation : boolean, optional

Request the annotated AtlasImage

atlas : int, optional

Specify the desired Atlas’ annotations.

projection : boolean, optional

Request projection for the specified image.

downsample_dimensions : boolean, optional

Indicates if the width and height should be adjusted to account for downsampling.

Returns:

None

the file is downloaded and saved to the path.

Notes

By default, an unfiltered full-sized image with the highest quality is returned as a download if no parameters are provided.

‘downsample=1’ halves the number of pixels of the original image both horizontally and vertically. range_list = kwargs.get(‘range’, None)

Specifying ‘downsample=2’ quarters the height and width values.

Quality must be an integer from 0, for the lowest quality, up to as high as 100. If it is not specified, it defaults to the highest quality.

Top is specified in full-resolution (largest tier) pixel coordinates. SectionImage.y is the default value.

Left is specified in full-resolution (largest tier) pixel coordinates. SectionImage.x is the default value.

Width is specified in tier-resolution (desired tier) pixel coordinates. SectionImage.width is the default value. It is automatically adjusted when downsampled.

Height is specified in tier-resolution (desired tier) pixel coordinates. SectionImage.height is the default value. It is automatically adjusted when downsampled.

The range parameter consists of 6 comma delimited integers that define the lower (0) and upper (4095) bound for each channel in red-green-blue order (i.e. “range=0,1500,0,1000,0,4095”). The default range values can be determined by referring to the following fields on the Equalization model associated with the SectionDataSet: red_lower, red_uppper, green_lower, green_upper, blue_lower, blue_upper. For more information, see the Image Controls section of the Allen Mouse Brain Connectivity Atlas: Projection Dataset help topic. See: `Image Download Service `<http://help.brain-map.org/display/api/Downloading+an+Image>_

download_projection_image(projection_image_id, file_path=None, **kwargs)[source]
download_section_image(section_image_id, file_path=None, **kwargs)[source]

allensdk.api.queries.mouse_connectivity_api module

class allensdk.api.queries.mouse_connectivity_api.MouseConnectivityApi(base_uri=None)[source]

Bases: allensdk.api.queries.rma_api.RmaApi

HTTP Client for the Allen Mouse Brain Connectivity Atlas.

See: Mouse Connectivity API

ARA_NISSL = 'ara_nissl'
AVERAGE_TEMPLATE = 'average_template'
CCF_2015 = 'annotation/ccf_2015'
CCF_2016 = 'annotation/ccf_2016'
CCF_VERSION_DEFAULT = 'annotation/ccf_2016'
DEVMOUSE_2012 = 'annotation/devmouse_2012'
MOUSE_2011 = 'annotation/mouse_2011'
PRODUCT_IDS = [5, 31]
VOXEL_RESOLUTION_100_MICRONS = 100
VOXEL_RESOLUTION_10_MICRONS = 10
VOXEL_RESOLUTION_25_MICRONS = 25
VOXEL_RESOLUTION_50_MICRONS = 50
build_reference_aligned_image_channel_volumes_url(data_set_id)[source]

Construct url to download the red, green, and blue channels aligned to the 25um adult mouse brain reference space volume.

Parameters:

data_set_id : integerallensdk.api.queries

aka attachable_id

Notes

See: Reference-aligned Image Channel Volumes for additional documentation.

build_volumetric_data_download_url(data_path, file_name, voxel_resolution=None, release=None, coordinate_framework=None)[source]

Construct url to download 3D reference model in NRRD format.

Parameters:

data_path : string

‘average_template’, ‘ara_nissl’, ‘annotation/ccf_2015’, ‘annotation/mouse_2011’, or ‘annotation/devmouse_2012’

voxel_resolution : int

10, 25, 50 or 100

coordinate_framework : string

‘mouse_ccf’ (default) or ‘mouse_annotation’

Notes

See: 3-D Reference Models for additional documentation.

calculate_injection_centroid(injection_density, injection_fraction, resolution=25)[source]

Compute the centroid of an injection site.

Parameters:

injection_density: np.ndarray

The injection density volume of an experiment

injection_fraction: np.ndarray

The injection fraction volume of an experiment

download_annotation_volume(*args, **kwargs)[source]

Download the annotation volume at a particular resolution.

Parameters:

ccf_version: string

MouseConnectivityApi.CCF_2016 (default) or MouseConnectivityApi.CCF_2015

resolution: int

Desired resolution to download in microns. Must be 10, 25, 50, or 100.

file_name: string

Where to save the annotation volume.

Note: the parameters must be used as positional parameters, not keywords

download_data_mask(*args, **kwargs)[source]
download_injection_density(*args, **kwargs)[source]
download_injection_fraction(*args, **kwargs)[source]
download_projection_density(*args, **kwargs)[source]
download_reference_aligned_image_channel_volumes(data_set_id, save_file_path=None)[source]
Returns:The well known file is downloaded
download_template_volume(*args, **kwargs)[source]

Download the registration template volume at a particular resolution.

Parameters:

resolution: int

Desired resolution to download in microns. Must be 10, 25, 50, or 100.

file_name: string

Where to save the registration template volume.

download_volumetric_data(data_path, file_name, voxel_resolution=None, save_file_path=None, release=None, coordinate_framework=None)[source]

Download 3D reference model in NRRD format.

Parameters:

data_path : string

‘average_template’, ‘ara_nissl’, ‘annotation/ccf_2015’, ‘annotation/mouse_2011’, or ‘annotation/devmouse_2012’

file_name : string

server-side file name. ‘annotation_10.nrrd’ for example.

voxel_resolution : int

10, 25, 50 or 100

coordinate_framework : string

‘mouse_ccf’ (default) or ‘mouse_annotation’

Notes

See: 3-D Reference Models for additional documentation.

Select a seed experiment and a domain over which the similarity comparison is to be made.

Parameters:

row : integer

SectionDataSet.id to correlate against.

structures : list of integers or strings, optional

Integer Structure.id or String Structure.acronym.

hemisphere : string, optional

Use ‘right’ or ‘left’. Defaults to both hemispheres.

transgenic_lines : list of integers or strings, optional

Integer TransgenicLine.id or String TransgenicLine.name. Specify ID 0 to exclude all TransgenicLines.

injection_structures : list of integers or strings, optional

Integer Structure.id or String Structure.acronym.

primary_structure_only : boolean, optional

product_ids : list of integers, optional

Integer Product.id

start_row : integer, optional

For paging purposes. Defaults to 0.

num_rows : integer, optional

For paging purposes. Defaults to 2000.

Notes

See Correlation Search and service::mouse_connectivity_correlation.

User specifies a seed location within the 3D reference space. The service returns a rank list of experiments by distance of its injection site to the specified seed location.

Parameters:

seed_point : list of floats

The coordinates of a point in 3-D SectionDataSet space.

transgenic_lines : list of integers or strings, optional

Integer TransgenicLine.id or String TransgenicLine.name. Specify ID 0 to exclude all TransgenicLines.

injection_structures : list of integers or strings, optional

Integer Structure.id or String Structure.acronym.

primary_structure_only : boolean, optional

product_ids : list of integers, optional

Integer Product.id

start_row : integer, optional

For paging purposes. Defaults to 0.

num_rows : integer, optional

For paging purposes. Defaults to 2000.

Notes

See Injection Coordinate Search and service::mouse_connectivity_injection_coordinate.

Search over the whole projection signal statistics dataset to find experiments with specific projection profiles.

Parameters:

injection_structures : list of integers or strings

Integer Structure.id or String Structure.acronym.

target_domain : list of integers or strings, optional

Integer Structure.id or String Structure.acronym.

injection_hemisphere : string, optional

‘right’ or ‘left’, Defaults to both hemispheres.

target_hemisphere : string, optional

‘right’ or ‘left’, Defaults to both hemispheres.

transgenic_lines : list of integers or strings, optional

Integer TransgenicLine.id or String TransgenicLine.name. Specify ID 0 to exclude all TransgenicLines.

injection_domain : list of integers or strings, optional

Integer Structure.id or String Structure.acronym.

primary_structure_only : boolean, optional

product_ids : list of integers, optional

Integer Product.id

start_row : integer, optional

For paging purposes. Defaults to 0.

num_rows : integer, optional

For paging purposes. Defaults to 2000.

Notes

See Source Search, Target Search, and service::mouse_connectivity_injection_structure.

Displays all SectionDataSets with projection signal density >= 0.1 at the seed point. This service also returns the path along the most dense pixels from the seed point to the center of each injection site..

Parameters:

seed_point : list of floats

The coordinates of a point in 3-D SectionDataSet space.

transgenic_lines : list of integers or strings, optional

Integer TransgenicLine.id or String TransgenicLine.name. Specify ID 0 to exclude all TransgenicLines.

section_data_sets : list of integers, optional

Ids to filter the results.

injection_structures : list of integers or strings, optional

Integer Structure.id or String Structure.acronym.

primary_structure_only : boolean, optional

product_ids : list of integers, optional

Integer Product.id

start_row : integer, optional

For paging purposes. Defaults to 0.

num_rows : integer, optional

For paging purposes. Defaults to 2000.

Notes

See Spatial Search and service::mouse_connectivity_target_spatial.

get_experiment_detail(*args, **kwargs)[source]

Retrieve the experiments data.

get_experiments(*args, **kwargs)[source]

Fetch experiment metadata from the Mouse Brain Connectivity Atlas.

Parameters:

structure_ids : integer or list, optional

injection structure

Returns:

url : string

The constructed URL

get_manual_injection_summary(*args, **kwargs)[source]

Retrieve manual injection summary.

get_projection_image_info(*args, **kwargs)[source]

Fetch meta-information of one projection image.

Parameters:

experiment_id : integer

section_number : integer

Notes

See: image examples under Experimental Overview and Metadata for additional documentation. Download the image using allensdk.api.queries.image_download_api.ImageDownloadApi.download_section_image()

get_reference_aligned_image_channel_volumes_url(data_set_id)[source]

Retrieve the download link for a specific data set. Notes —– See Reference-aligned Image Channel Volumes for additional documentation.

get_structure_unionizes(*args, **kwargs)[source]

allensdk.api.queries.ontologies_api module

class allensdk.api.queries.ontologies_api.OntologiesApi(base_uri=None)[source]

Bases: allensdk.api.queries.rma_template.RmaTemplate

See: Atlas Drawings and Ontologies

get_atlases(*args, **kwargs)[source]
get_atlases_table(*args, **kwargs)[source]

List Atlases available through the API with associated ontologies and structure graphs.

Parameters:

atlas_ids : integer or list of integers, optional

only select specific atlases

brief : boolean, optional

True (default) requests only name and id fields.

Returns:

dict : atlas metadata

Notes

This query is based on the table of available Atlases. See also: Class: Atlas

get_structure_graphs(*args, **kwargs)[source]
get_structure_sets(*args, **kwargs)[source]
get_structures(*args, **kwargs)[source]

Retrieve data about anatomical structures.

Parameters:

structure_graph_ids : int or list of ints, optional

database keys to get all structures in particular graphs

structure_graph_names : string or list of strings, optional

list of graph names to narrow the query

structure_set_ids : int or list of ints, optional

database keys to get all structures in a particular set

structure_set_names : string or list of strings, optional

list of set names to narrow the query.

order : list of strings

list of RMA order clauses for sorting

num_rows : int

how many records to retrieve

Returns:

dict

the parsed json response containing data from the API

Notes

Only one of the methods of limiting the query should be used at a time.

get_structures_with_sets(*args, **kwargs)[source]

Download structures along with the sets to which they belong.

Parameters:

structure_graph_ids : int or list of int

Only fetch structure records from these graphs.

order : list of strings

list of RMA order clauses for sorting

num_rows : int

how many records to retrieve

Returns:

dict

the parsed json response containing data from the API

rma_templates = {'ontology_queries': [{'count': False, 'name': 'structures_by_graph_ids', 'criteria': '[graph_id$in{{ graph_ids }}]', 'num_rows': 'all', 'model': 'Structure', 'criteria_params': ['graph_ids'], 'order': ['structures.graph_order'], 'description': 'see name'}, {'count': False, 'name': 'structures_by_graph_names', 'criteria': 'graph[structure_graphs.name$in{{ graph_names }}]', 'num_rows': 'all', 'model': 'Structure', 'criteria_params': ['graph_names'], 'order': ['structures.graph_order'], 'description': 'see name'}, {'count': False, 'name': 'structures_by_set_ids', 'criteria': '[structure_set_id$in{{ set_ids }}]', 'num_rows': 'all', 'model': 'Structure', 'criteria_params': ['set_ids'], 'order': ['structures.graph_order'], 'description': 'see name'}, {'count': False, 'name': 'structures_by_set_names', 'criteria': 'structure_sets[name$in{{ set_names }}]', 'num_rows': 'all', 'model': 'Structure', 'criteria_params': ['set_names'], 'order': ['structures.graph_order'], 'description': 'see name'}, {'num_rows': 'all', 'count': False, 'model': 'StructureGraph', 'name': 'structure_graphs_list', 'description': 'see name'}, {'num_rows': 'all', 'count': False, 'model': 'StructureSet', 'name': 'structure_sets_list', 'description': 'see name'}, {'num_rows': 'all', 'count': False, 'model': 'Atlas', 'name': 'atlases_list', 'description': 'see name'}, {'count': False, 'only': ['atlases.id', 'atlases.name', 'atlases.image_type', 'ontologies.id', 'ontologies.name', 'structure_graphs.id', 'structure_graphs.name', 'graphic_group_labels.id', 'graphic_group_labels.name'], 'criteria_params': ['atlas_ids'], 'name': 'atlases_table', 'criteria': '{% if atlas_ids is defined %}[id$in{{ atlas_ids }}],{%endif%}structure_graph(ontology),graphic_group_labels', 'num_rows': 'all', 'model': 'Atlas', 'include': 'structure_graph(ontology),graphic_group_labels', 'description': 'see name'}, {'count': False, 'criteria_params': ['graph_ids'], 'name': 'structures_with_sets', 'criteria': '[graph_id$in{{ graph_ids }}]', 'num_rows': 'all', 'model': 'Structure', 'include': 'structure_sets', 'order': ['structures.graph_order'], 'description': 'see name'}, {'count': False, 'name': 'structure_sets_by_id', 'criteria_params': ['set_ids'], 'criteria': '[id$in{{ set_ids }}]', 'num_rows': 'all', 'model': 'StructureSet', 'description': 'see name'}]}
unpack_structure_set_ancestors(structure_dataframe)[source]

Convert a slash-separated structure_id_path field to a list.

Parameters:

structure_dataframe : DataFrame

structure data from the API

Returns:

None

A new column is added to the dataframe containing the ancestor list.

allensdk.api.queries.rma_api module

class allensdk.api.queries.rma_api.RmaApi(base_uri=None)[source]

Bases: allensdk.api.api.Api

See: RESTful Model Access (RMA)

ALL = 'all'
COUNT = 'count'
CRITERIA = 'rma::criteria'
DEBUG = 'debug'
EQ = '$eq'
EXCEPT = 'except'
EXCPT = 'excpt'
FALSE = 'false'
INCLUDE = 'rma::include'
IS = '$is'
MODEL = 'model::'
NUM_ROWS = 'num_rows'
ONLY = 'only'
OPTIONS = 'rma::options'
ORDER = 'order'
PIPE = 'pipe::'
PREVIEW = 'preview'
SERVICE = 'service::'
START_ROW = 'start_row'
TABULAR = 'tabular'
TRUE = 'true'
build_query_url(stage_clauses, fmt='json')[source]

Combine one or more RMA query stages into a single RMA query.

Parameters:

stage_clauses : list of strings

subqueries

fmt : string, optional

json (default), xml, or csv

Returns:

string

complete RMA url

build_schema_query(clazz=None, fmt='json')[source]

Build the URL that will fetch the data schema.

Parameters:

clazz : string, optional

Name of a specific class or None (default).

fmt : string, optional

json (default) or xml

Returns:

url : string

The constructed URL

Notes

If a class is specified, only the schema information for that class will be requested, otherwise the url requests the entire schema.

debug_clause(debug_value=None)[source]

Construct a debug clause for use in an rma::options clause. Parameters ———- debug_value : string or boolean

True, False, None (default) or ‘preview’
Returns:

clause : string

The query clause for inclusion in an RMA query URL.

Notes

True will request debugging information in the response. False will request no debugging information. None will return an empty clause. ‘preview’ will request debugging information without the query being run.

filter(key, value)[source]

serialize a single RMA query filter clause.

Parameters:

key : string

keys for narrowing a query.

value : string

value for narrowing a query.

Returns:

string

a single filter clause for an RMA query string.

filters(filters)[source]

serialize RMA query filter clauses.

Parameters:

filters : dict

keys and values for narrowing a query.

Returns:

string

filter clause for an RMA query string.

get_schema(clazz=None)[source]

Retrieve schema information.

model_query(*args, **kwargs)[source]

Construct and execute a model stage of an RMA query string.

Parameters:

model : string

The top level data type

filters : dict

key, value comparisons applied to the top-level model to narrow the results.

criteria : string

raw RMA criteria clause to choose what object are returned

include : string

raw RMA include clause to return associated objects

only : list of strings, optional

to be joined into an rma::options only filter to limit what data is returned

except : list of strings, optional

to be joined into an rma::options except filter to limit what data is returned

excpt : list of strings, optional

synonym for except parameter to avoid a reserved word conflict.

tabular : list of string, optional

return columns as a tabular data structure rather than a nested tree.

count : boolean, optional

False to skip the extra database count query.

debug : string, optional

‘true’, ‘false’ or ‘preview’

num_rows : int or string, optional

how many database rows are returned (may not correspond directly to JSON tree structure)

start_row : int or string, optional

which database row is start of returned data (may not correspond directly to JSON tree structure)

Notes

See RMA Path Syntax for a brief overview of the normalized RMA syntax. Normalized RMA syntax differs from the legacy syntax used in much of the RMA documentation. Using the &debug=true option with an RMA URL will include debugging information in the response, including the normalized query.

model_stage(model, **kwargs)[source]

Construct a model stage of an RMA query string.

Parameters:

model : string

The top level data type

filters : dict

key, value comparisons applied to the top-level model to narrow the results.

criteria : string

raw RMA criteria clause to choose what object are returned

include : string

raw RMA include clause to return associated objects

only : list of strings, optional

to be joined into an rma::options only filter to limit what data is returned

except : list of strings, optional

to be joined into an rma::options except filter to limit what data is returned

tabular : list of string, optional

return columns as a tabular data structure rather than a nested tree.

count : boolean, optional

False to skip the extra database count query.

debug : string, optional

‘true’, ‘false’ or ‘preview’

num_rows : int or string, optional

how many database rows are returned (may not correspond directly to JSON tree structure)

start_row : int or string, optional

which database row is start of returned data (may not correspond directly to JSON tree structure)

Notes

See RMA Path Syntax for a brief overview of the normalized RMA syntax. Normalized RMA syntax differs from the legacy syntax used in much of the RMA documentation. Using the &debug=true option with an RMA URL will include debugging information in the response, including the normalized query.

only_except_tabular_clause(filter_type, attribute_list)[source]

Construct a clause to filter which attributes are returned for use in an rma::options clause.

Parameters:

filter_type : string

‘only’, ‘except’, or ‘tabular’

attribute_list : list of strings

for example [‘acronym’, ‘products.name’, ‘structure.id’]

Returns:

clause : string

The query clause for inclusion in an RMA query URL.

Notes

The title of tabular columns can be set by adding ‘+as+<title>’ to the attribute. The tabular filter type requests a response that is row-oriented rather than a nested structure. Because of this, the tabular option can mask the lazy query behavior of an rma::include clause. The tabular option does not mask the inner-join behavior of an rma::include clause. The tabular filter is required for .csv format RMA requests.

options_clause(**kwargs)[source]

build rma:: options clause.

Parameters:

only : list of strings, optional

except : list of strings, optional

tabular : list of string, optional

count : boolean, optional

debug : string, optional

‘true’, ‘false’ or ‘preview’

num_rows : int or string, optional

start_row : int or string, optional

order_clause(order_list=None)[source]

Construct a debug clause for use in an rma::options clause.

Parameters:

order_list : list of strings

for example [‘acronym’, ‘products.name+asc’, ‘structure.id+desc’]

Returns:

clause : string

The query clause for inclusion in an RMA query URL.

Notes

Optionally adding ‘+asc’ (default) or ‘+desc’ after an attribute will change the sort order.

pipe_stage(pipe_name, parameters)[source]

Connect model and service stages via their JSON responses.

Notes

See: Service Pipelines and Connected Services and Pipes

quote_string(the_string)[source]

Wrap a clause in single quotes.

Parameters:

the_string : string

a clause to be included in an rma query that needs to be quoted

Returns:

string

input wrapped in single quotes

service_query(*args, **kwargs)[source]

Construct and Execute a single-stage RMA query to send a request to a connected service.

Parameters:

service_name : string

Name of a documented connected service.

parameters : dict

key-value pairs as in the online documentation.

Notes

See: Service Pipelines and Connected Services and Pipes

service_stage(service_name, parameters=None)[source]

Construct an RMA query fragment to send a request to a connected service.

Parameters:

service_name : string

Name of a documented connected service.

parameters : dict

key-value pairs as in the online documentation.

Notes

See: Service Pipelines and Connected Services and Pipes

tuple_filters(filters)[source]

Construct an RMA filter clause.

Notes

See RMA Path Syntax - Square Brackets for Filters for additional documentation.

allensdk.api.queries.rma_pager module

class allensdk.api.queries.rma_pager.RmaPager[source]

Bases: object

static pager(fn, *args, **kwargs)[source]
allensdk.api.queries.rma_pager.pageable(total_rows=None, num_rows=None)[source]

allensdk.api.queries.rma_template module

class allensdk.api.queries.rma_template.RmaTemplate(base_uri=None, query_manifest=None)[source]

Bases: allensdk.api.queries.rma_api.RmaApi

See: Atlas Drawings and Ontologies

template_query(template_name, entry_name, **kwargs)[source]
to_filter_rhs(rhs)[source]

allensdk.api.queries.svg_api module

class allensdk.api.queries.svg_api.SvgApi(base_uri=None)[source]

Bases: allensdk.api.api.Api

build_query(section_image_id, groups=None, download=False)[source]

Build the URL that will fetch meta data for the specified structure.

Parameters:

section_image_id : integer

Key of the object to be retrieved.

groups : array of integers

Keys of the group labels to filter the svg types that are returned.

Returns:

url : string

The constructed URL

download_svg(section_image_id, groups=None, file_path=None)[source]

Download the svg file

get_svg(section_image_id, groups=None)[source]

Get the svg document.

allensdk.api.queries.synchronization_api module

class allensdk.api.queries.synchronization_api.SynchronizationApi(base_uri=None)[source]

Bases: allensdk.api.api.Api

HTTP client for image synchronization services uses the image alignment results from the Informatics Data Processing Pipeline. Note: all locations on SectionImages are reported in pixel coordinates and all locations in 3-D ReferenceSpaces are reported in microns.

See Image to Image Synchronization for additional documentation.

get_image_to_atlas(section_image_id, x, y, atlas_id)[source]

For a specified Atlas, find the closest annotated SectionImage and (x,y) location as defined by a seed SectionImage and seed (x,y) location.

Parameters:

section_image_id : integer

Seed for spatial sync.

x : float

Pixel coordinate of the seed location in the seed SectionImage.

y : float

Pixel coordinate of the seed location in the seed SectionImage.

atlas_id : int

Target Atlas for image sync.

Returns:

dict

The parsed json response

get_image_to_image(section_image_id, x, y, section_data_set_ids)[source]

For a list of target SectionDataSets, find the closest SectionImage and (x,y) location as defined by a seed SectionImage and seed (x,y) pixel location.

Parameters:

section_image_id : integer

Seed for spatial sync.

x : float

Pixel coordinate of the seed location in the seed SectionImage.

y : float

Pixel coordinate of the seed location in the seed SectionImage.

section_data_set_ids : list of integers

Target SectionDataSet IDs for image sync.

Returns:

dict

The parsed json response

get_image_to_image_2d(section_image_id, x, y, section_image_ids)[source]

For a list of target SectionImages, find the closest (x,y) location as defined by a seed SectionImage and seed (x,y) location.

Parameters:

section_image_id : integer

Seed for image sync.

x : float

Pixel coordinate of the seed location in the seed SectionImage.

y : float

Pixel coordinate of the seed location in the seed SectionImage.

section_image_ids : list of ints

Target SectionImage IDs for image sync.

Returns:

dict

The parsed json response

get_image_to_reference(section_image_id, x, y)[source]

For a specified SectionImage and (x,y) location, return the (x,y,z) location in the ReferenceSpace of the associated SectionDataSet.

Parameters:

section_image_id : integer

Seed for image sync.

x : float

Pixel coordinate on the specified SectionImage.

y : float

Pixel coordinate on the specified SectionImage.

Returns:

dict

The parsed json response

get_reference_to_image(reference_space_id, x, y, z, section_data_set_ids)[source]

For a list of target SectionDataSets, find the closest SectionImage and (x,y) location as defined by a (x,y,z) location in a specified ReferenceSpace.

Parameters:

reference_space_id : integer

Seed for spatial sync.

x : float

Coordinate (in microns) of the seed location in the seed ReferenceSpace.

y : float

Coordinate (in microns) of the seed location in the seed ReferenceSpace.

z : float

Coordinate (in microns) of the seed location in the seed ReferenceSpace.

section_data_set_ids : list of ints

Target SectionDataSets IDs for image sync.

Returns:

dict

The parsed json response

get_structure_to_image(section_data_set_id, structure_ids)[source]

For a list of target structures, find the closest SectionImage and (x,y) location as defined by the centroid of each Structure.

Parameters:

section_data_set_id : integer

primary key

structure_ids : list of integers

primary key

Returns:

dict

The parsed json response

allensdk.api.queries.tree_search_api module

class allensdk.api.queries.tree_search_api.TreeSearchApi(base_uri=None)[source]

Bases: allensdk.api.api.Api

See Searching a Specimen or Structure Tree for additional documentation.

get_tree(kind, db_id, ancestors=None, descendants=None)[source]

Fetch meta data for the specified structure or specimen.

Parameters:

kind : string

‘Structure’ or ‘Specimen’

db_id : integer

The id of the structure or specimen to search.

ancestors : boolean, optional

whether to include ancestors in the response (defaults to False)

descendants : boolean, optional

whether to include descendants in the response (defaults to False)

Returns:

dict

parsed json response data

Module contents