dsmtools.utils.ccf_atlas

This module imported from neuro-morpho-toolbox (by Peng Xie) and only includes the necessary functions for loading CCFv3 mouse brain atlas. It can be used to retrieve brain region types of a certain location in the mouse brain template space.

It's used by importing this module, and only CCFv3 related functions are exposed. You can find them in this page.

For more information on CCFv3, you can:

 1"""
 2This module imported from [neuro-morpho-toolbox](https://github.com/pengxie-bioinfo/neuro_morpho_toolbox) (by Peng Xie)
 3and only includes the necessary functions for loading CCFv3 mouse brain atlas. It can be used to retrieve brain region
 4types of a certain location in the mouse brain template space.
 5
 6It's used by importing this module, and only CCFv3 related functions are exposed. You can find them in this page.
 7
 8For more information on CCFv3, you can:
 9
10* check this paper: [Wang Q, Ding SL, Li Y, et al. The Allen Mouse Brain Common Coordinate Framework:
11A 3D Reference Atlas. Cell. 2020;181(4):936-953.e20. doi:10.1016/j.cell.2020.04.007](https://pubmed.ncbi.nlm.nih.gov/32386544/)
12* download the [table of all annotations](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8152789/bin/NIHMS1585864-supplement-10.xlsx)
13* explore the mouse brain atlas at http://connectivity.brain-map.org.
14"""
15
16from ._annotation import id2abbr, coord2abbr, annotate_swc
17
18
19__all__ = ['id2abbr', 'coord2abbr', 'annotate_swc']
def id2abbr(region_id: int) -> str:
20def id2abbr(region_id: int) -> str:
21    """Convert a CCFv3 region ID to its region name.
22
23    :param region_id: CCFv3 structure ID.
24    :return: The abbreviation of the structure.
25    """
26    return bs_level.at[region_id, 'Abbreviation']

Convert a CCFv3 region ID to its region name.

Parameters
  • region_id: CCFv3 structure ID.
Returns

The abbreviation of the structure.

def coord2abbr(point: Sequence[float]) -> str:
29def coord2abbr(point: Sequence[float]) -> str:
30    """Given the 3D coordinate of a point, retrieve the abbreviation of the region containing the point.
31    It will locate the finest region for the location within the 25uμm template.
32
33    :param point: A 3D coordinate by xyz.
34    :return: The abbreviation of its brain region.
35    """
36    p = np.array(point, dtype=float)
37    assert p.shape == (3,)
38    p /= (annotation.space['x'], annotation.space['y'], annotation.space['z'])
39    p = p.round().astype(int)
40    if 0 <= p[0] < annotation.size['x'] and 0 <= p[1] < annotation.size['y'] and 0 <= p[2] < annotation.size['z']:
41        region_id = annotation.array[p[0], p[1], p[2]]
42        if region_id in dict_to_selected:
43            return id2abbr(dict_to_selected[region_id])
44    return 'unknown'

Given the 3D coordinate of a point, retrieve the abbreviation of the region containing the point. It will locate the finest region for the location within the 25uμm template.

Parameters
  • point: A 3D coordinate by xyz.
Returns

The abbreviation of its brain region.

def annotate_swc(swc: pandas.core.frame.DataFrame) -> pandas.core.series.Series:
47def annotate_swc(swc: pd.DataFrame) -> pd.Series:
48    """Given an SWC dataframe (with columns indicating coordinates, named by x, y, z),
49    return a series of regions mapped by node locations.
50
51    :param swc: SWC as a pandas dataframe.
52    :return: A column of region abbreviation as pandas series.
53    """
54    return swc.apply(lambda r: coord2abbr(r[['x', 'y', 'z']].values), axis=1)

Given an SWC dataframe (with columns indicating coordinates, named by x, y, z), return a series of regions mapped by node locations.

Parameters
  • swc: SWC as a pandas dataframe.
Returns

A column of region abbreviation as pandas series.