iblatlas.genomics.merfish

Functions

denoise_volume

Denoise a raw MERFISH cell-type density volume.

int2rgb

One liner to convert rgba values stored as integer in dataframes

load

Reads in the Allen gene expression experiments tables

load_volume

Reads in a pre-computed MERFISH cell-type density volume and its type labels.

load(folder_cache=None)[source]

Reads in the Allen gene expression experiments tables

Parameters:

folder_cache

Returns:

df_cells: a dataframe of cells (8_879_868, 11), where each record corresponds to a single cell df_classes: a dataframe of classes (35, 3), where each record corresponds to a single class df_subclasses: a dataframe of subclasses (339, 4), where each record corresponds to a single subclass df_supertypes: a dataframe of supertypes (1202, 4), where each record corresponds to a single supertype df_clusters: a dataframe of clusters (5323, 5), where each record corresponds to a single cluster df_genes: a dataframe of genes (1672, 4), where each record corresponds to a single gene df_neurotransmitters: a dataframe of neurotransmitters (9, 2), where each record corresponds to a single

neurotransmitter

denoise_volume(volume, brain_mask, n_drop_non_neuronal=5, sigma=0.5, seed=42)[source]

Denoise a raw MERFISH cell-type density volume.

Raw volumes can contain NaN voxels with no nearby source data. Naively filling every NaN voxel with Dirichlet noise also fills the background outside the brain with random noise, which then bleeds a few voxels inward once Gaussian-smoothed. This restricts the fill/smooth/normalize steps to brain_mask and re-zeroes anything outside it after smoothing.

Parameters:
  • volume – (n_types, dim0, dim1, dim2) raw density volume, as returned by load_volume(…, label=’’)

  • brain_mask – (dim0, dim1, dim2) bool, True for voxels inside the brain (e.g. atlas_agea.label != 0)

  • n_drop_non_neuronal – number of trailing non-neuronal types to drop (Astro-Epen, OPC-Oligo, OEC, Vascular, Immune are always the last 5 rows at the ‘class’ level); set to 0 to keep all types

  • sigma – Gaussian smoothing sigma in voxels, applied per type independently; set to 0 to disable

  • seed – seed for the Dirichlet noise used to fill in-brain voxels that are NaN across every type

Returns:

a (n_types - n_drop_non_neuronal, dim0, dim1, dim2) float32 array; in-brain voxels sum to ~1 over the type axis, out-of-brain voxels are 0

load_volume(level='class', label='processed', folder_cache=None)[source]

Reads in a pre-computed MERFISH cell-type density volume and its type labels.

These are dense 4-D arrays (one 3-D volume per cell type), built by iblatlas/genomics/merfish_scrapping/02_create_volumes.py on the same 200 um grid as iblatlas.genomics.agea.load() (not the default 25 um AllenAtlas() grid).

Parameters:
  • level – taxonomy level to load, one of ‘class’, ‘subclass’, ‘supertype’, ‘cluster’

  • label

    which volume to return - ‘’: the raw, unprocessed volume (may contain NaN; returned memory-mapped) - ‘processed’: denoised via denoise_volume() (non-neuronal types dropped, NaNs filled,

    Gaussian-smoothed, renormalized to sum to 1 per in-brain voxel). Default – unlike agea.load(), which defaults to the raw (label=’’) volume.

  • folder_cache

Returns:

volume: a (n_types, ml, dv, ap) array, one density volume per cell type, on the same grid as

the expression_volumes returned by agea.load(). float16 memory-mapped if label=’’, float32 in memory if label=’processed’.

labels: a (n_types,) array of type ids for each channel of volume, matching the index of the

corresponding dataframe returned by load() (e.g. df_classes.index for level=’class’). Truncated to match volume when label=’processed’ drops non-neuronal types.

atlas_agea: a brainatlas object with the labels and coordinates matching volume (same object

as returned by agea.load() / agea.load_atlas())

int2rgb(array, dtype=None)[source]

One liner to convert rgba values stored as integer in dataframes

Parameters:
  • array – rgba column of a dataframe or slice of the column

  • dtype – optional, if int will return the uint8 view from 0-255 else will return floats from 0-1

Returns: