paprica.atlaser

Submodule containing classes and functions relative to atlasing.

This submodule is essentially a wrapper to Brainreg (https://github.com/brainglobe/brainreg) for atlasing and Allen Brain Atlas for ontology analysis. It contains many convenience method for manipulating data (per region, per superpixel, etc.).

By using this code you agree to the terms of the software license agreement.

© Copyright 2020 Wyss Center for Bio and Neuro Engineering – All rights reserved

class paprica.atlaser.tileAtlaser(original_pixel_size: (<built-in function array>, <class 'list'>), downsample: int, atlas=None, merged_data=None)[source]

Bases: object

Class used for registering a dataset to the Atlas and do some post processing using the Atlas (e.g count cells per region).

It can be instantiated using a tileMerger object (for registration using Brainreg) or directly with a previously registered Atlas.

__init__(original_pixel_size: (<built-in function array>, <class 'list'>), downsample: int, atlas=None, merged_data=None)[source]
Parameters
  • original_pixel_size (array_like) – pixel size in µm on the original data

  • downsample (int) – downsampling used by APRSlicer to reconstruct the lower resolution pixel data used for registration to the Atlas.

  • atlas (ndarray, string) – atlas data or path for loading the atlas data

  • merger (tileMerger) – tileMerger object

Return type

None

classmethod from_atlas(atlas: (<built-in function array>, <class 'str'>), downsample, original_pixel_size: (<built-in function array>, <class 'list'>))[source]

Constructor from a previously computed Atlas. Typically to perform postprocessing using an Atlas (e.g. count cells per brain region).

Parameters
  • atlas (ndarray, string) – atlas data or path for loading the atlas data

  • downsample (int) – downsampling used by APRSlicer to reconstruct the lower resolution pixel data used for registration to the Atlas.

  • original_pixel_size (array_like) – pixel size in µm on the original data

Return type

tileAtlaser object

classmethod from_merger(merger: paprica.stitcher.tileMerger, original_pixel_size: (<built-in function array>, <class 'list'>))[source]

Constructor from a tileMerger object. Typically to perform the registration to the Atlas on autofluorescence data.

Parameters
  • merger (tileMerger) – tileMerger object

  • original_pixel_size (array_like) – pixel size in µm on the original data

Return type

tileAtlaser object

get_area_mask_by_acronym(acronym_list)[source]

Return the mask corresponding to brain regions given in acronym_list, brain regions referred by their Allen brain acronym.

Parameters

acronym_list (list) – list of Allen Brain region acronyms to count the mapped cells.

Returns

mask – mask containing 1 for the region in acronym_list ans 0 elsewhere.

Return type

ndarray

get_cell_number_by_acronym(acronym_list, cells_ids)[source]

Get the total number of segmented cell in different regions referenced by their acronyms.

Parameters
  • acronym_list (list) – list of acronyms (ABA)

  • cells_ids (ndarray) – cells ID (typically computed by self.get_cells_id())

Returns

cell_number – list containing the total number of cells for each asked region.

Return type

arraylike

get_cells_density(cells, kernel_size, progress_bar=True)[source]

Retuns the cell density (local average number of cell per voxel). The local average is computed using a gaussian kernel.

Parameters
  • cells (ndarray) – cell positions

  • kernel_size (int) – radius of the gaussian for local cell density estimation

Returns

_ – estimated cell density

Return type

ndarray

get_cells_density_per_region(cells_id)[source]

Retuns the cell density (number of cell per voxel) per region.

Parameters

cells_id (ndarray) – cells ID (typically computed by self.get_cells_id())

Returns

heatmap – 3D array where each brain region value is the cell density in this region.

Return type

ndarray

get_cells_id(cells)[source]

Returns the Allen Brain Atlas region ID for each cell.

Parameters

cells (ndarray) – cell positions

Returns

labels – containing the cell region ID.

Return type

ndarray

get_cells_number_per_region(cells_id)[source]

Retuns the number of cell per region.

Parameters

cells_id (ndarray) – cells ID (typically computed by self.get_cells_id())

Returns

heatmap – 3D array where each brain region value is the number of cells contained in this region.

Return type

ndarray

get_loc_id(x, y, z)[source]

Return the ID (brain region) of a given position (typically to retrieve cell position in the brain).

Parameters
  • x (int) – x position

  • y (int) – y position

  • z (int) – z position

Returns

_ – ID at the queried position.

Return type

list

get_ontology_mapping(labels, n=0)[source]

Get the mapping between area ID and name with Allen SDK.

Parameters
  • labels (ndarray) – array of labels to group by ID and fetch area name.

  • n (int) – number of parent area to group for.

Returns

area_count – area names with the counts.

Return type

dict

load_atlas(path)[source]

Function to load a previously computed atlas.

Parameters

path (string) – path to the registered atlas file.

Return type

None

register_to_atlas(output_dir='./', orientation='spr', merged_data_filename='merged_data.tif', debug=False, params=None)[source]

Function to compute the registration to the Atlas. It is just a wrapper to call brainreg.

Parameters
  • output_dir (string) – output directory to save atlas

  • orientation (string) – orientation of the input data with respect to the origin in Z,Y,X order. E.g. ‘spr’ means superior (so going from origin to z = zlim we go from superior to inferior), posterior (so going from origin to y = ylim we go from posterior to anterior part) and right (so going from origin to x = xlim we go from right to left part)

  • merged_data_filename (string) – named of the merged array (Brainreg reads data from files so we need to save the merged volume beforehand.

  • debug (bool) – add debug option for brainreg which will save intermediate steps.

  • params (dict) – dictionary with keys as brainreg options and values as parameters (see here: https://brainglobe.info/documentation/brainreg/user-guide/parameters)

Return type

None