API
m2m.allensdk_utils.py
- m2m.allensdk_utils.download_proj_density_vol(file, id, res, nocache)
Download projection density map and store it in cache by default.
Parameters
- file:
Downloaded filename.
- id: int
Allen mouse connectiviy experiment id.
- res: int
Allen resolution [25, 50, 100]
- nocache: bool
Whether use cache of not
Returns
- ndarray:
Projection density volume.
- m2m.allensdk_utils.download_struct_mask_vol(file, id, res, nocache)
Download a structure mask and store it in cache by default.
Parameters
- file:
Downloaded filename.
- id: int
Allen mouse connectiviy experiment id.
- res: int
Allen resolution [25, 50, 100]
- nocache: bool
Whether use cache of not
Returns
- ndarray:
Structure mask volume.
- m2m.allensdk_utils.download_template_vol(file, res, nocache)
Download allen template and store it in cache by default.
Parameters
- file:
Downloaded filename.
- res: int
Allen resolution [25, 50, 100]
- nocache: bool
Whether use cache of not
Returns
- ndarray:
Allen template volume.
- m2m.allensdk_utils.get_injection_infos(allen_experiments, id)
Retrieve the injection coordinates, region and location (L/R) of an Allen experiment.
Parameters
- allen_experiments: dataframe
Allen experiments.
- id: long
Experiment id.
Returns
string: Roi acronym. list: coordinates of the injection coordinates string: Injection location (R or L).
- m2m.allensdk_utils.get_mcc(nocache, res)
Get Allen Mouse Connectivity Cache. Manifest stored in a hidden folder. Setting nocache to True reset it.
Parameters
- nocache: bool
Whether use cache of not.
Returns
mcc: MouseConnectivityCache()
- m2m.allensdk_utils.get_mcc_exps(nocache)
Get Mouse Connectivity Cache experiments. Stored in a hidden folder. Setting nocache to True reset it.
Parameters
- nocache: bool
Whether use cache of not
Return
dataframe : Allen Mouse Connectivity experiments
- m2m.allensdk_utils.get_mcc_stree(nocache)
Get allen Mouse Brain structure tree. Json stored in a hidden folder. Setting nocache to True reset it.
Parameters
- nocache: bool
Whether use cache of not
Return
dataframe : Allen Mouse Brain structure tree
- m2m.allensdk_utils.get_structure_parents_infos(structure_id)
Get the path of ids and names of the parents of a Allen Mouse Brain Atlas structure.
Parameters
- structure_id: long
Allen Mouse Brain Atlas structure id.
Returns
string: Path of parents ids’s string: Path of parents names’s
- m2m.allensdk_utils.get_unionized_list(exp_id, structs_ids)
Get the unionized structures of an Allen experiment. Experiments are cached.
Parameters
- exp_id: long
Id of Allen experiment.
- struct_ids: list
Ids of structures in Allen Mouse Brain Atlas.
Returns
dataframe: Unionized structures.
- m2m.allensdk_utils.search_experiments(injection, spatial, seed_point)
Retrieve Allen experiments from a seed point.
Using injection coordinate search or spatial search.
Parameters
- injection: bool
Using injection coordinate search.
- spatial: bool
Using spatial search.
- seed_point: list of int
Coordinate of the seed point in Allen reference space.
Return
dic: Allen experiments founded.
m2m.control.py
- m2m.control.check_file_exists(parser, args, path)
Verify that output does not exist or that if it exists, -f should be used. If not used, print parser’s usage and exit.
Parameters
- parser: argparse.ArgumentParser object
Parser.
- args: argparse namespace
Argument list.
- path: string or path to file
Required path to be checked.
- m2m.control.check_input_file(parser, path)
Assert that all inputs exist. If not, print parser’s usage and exit.
Parameters
- parser: argparse.ArgumentParser object
Parser.
- path: string or path to file
Required path to be checked.
- m2m.control.get_cache_dir()
Get the cache directory path.
Checks M2M_CACHE_DIR environment variable first, falls back to ~/.m2m This allows Docker containers to use persistent volumes for caching.
m2m.transform.py
- m2m.transform.compute_transform_matrix(moving_vol, fixed_vol, moving_res, fixed_res)
Compute an Affine transformation matrix to align Allen average template on User template. Using ANTsPyX registration.
Parameters
- moving_vol: volume
Allen volume (from nrrd.read()).
- fixed_vol: volume
Fixed volume (from nib.load()).
- moving_res: float
Allen volume resolution
- fixed_res: float
Fixed volume resolution
Return
string: Path of the transform matrix.
- m2m.transform.convert_point_to_um(point, res)
Convert a Allen point in voxels to um.
Parameters
- point: list, tuple
Coordinate in um
- res: int
Resolution in the Allen [25, 50, 100]
- m2m.transform.convert_point_to_vox(point: tuple, res: int) tuple
Convert a Allen point in um to voxels.
Parameters
- point: list, tuple
Coordinate in um
- res: int
Resolution in the Allen [25, 50, 100]
Returns
tuple: point coordinates in voxel
- m2m.transform.get_allen_coords(user_coords, res, file_mat, user_vol)
Retrieve the corresponding coordinate in the Allen of a specific location in the UserDataSpace
Parameters
- user_coords: list, tuple
User coordinate in voxels
- res: int
Resolution in the Allen [25, 50, 100]
- file_mat: str
Full path to transformation matrix
- user_vol: ndarray
User volume data array
Returns
- user_coords: list of ints
Coordinates in the Allen in um
- m2m.transform.get_ornt_PIR_UserDataSpace(user_vol)
Get the orientation transformation from Allen to User DataSpace. Using nibabel.orientations.
Parameters
- user_vol: ndarray
User volume data array
Return
- ornt: 3x2 matrix
nibabel ornt.
- m2m.transform.get_ornt_UserDataSpace_PIR(user_vol)
Get the orientation transformation from UserDataSpace to Allen. Using nibabel.orientations.
Parameters
- user_vol: ndarray
User volume data array
Return
- ornt: 3x2 matrix
nibabel ornt.
- m2m.transform.get_user_coords(allen_coords, res, file_mat, user_vol)
Retrieve the corresponding coordinate in UserDataSpace of a specific location in the Allen.
Parameters
- allen_coords: list, tuple
Allen coordinate in um
- res: int
Resolution in the Allen [25, 50, 100]
- file_mat: str
Full path to transformation matrix
- user_vol: ndarray
User volume data array
Returns
- user_coords: list of ints
Coordinates in UserDataSpace in voxels
- m2m.transform.pretransform_point_PIR_UserDataSpace(point, allen_bbox, user_vol)
Applying nibabel ornt codes to retrieve allen_coords in UserDataSpace orientation (ex: PIR->RAS)
Process: Create a fake Allen volume, place the point, reorient the volume, get the max of the array
Parameters
- point: tuple, list of ints
Coordinate in the Allen
- allen_bbox: tuple
Allen bounding box
- user_vol: ndarray
User volume data array
Returns
list: Coordinates in UserDataSpace orientation
- m2m.transform.pretransform_point_UserDataSpace_PIR(point, allen_bbox, user_vol)
Applying nibabel ornt codes to retrieve Allen coords in UserDataSpace orientation in Allen orientation (ex: RAS->PIR)
Process: Create a fake Allen volume, reorient the volume, place the point, revert the orientation of the volume, get the max of the array
Parameters
- point: tuple, list of ints
Coordinate in the Allen oriented in UserDataSpace
- allen_bbox: tuple
Allen bounding box
- user_vol: ndarray
User volume data array
Returns
list: Coordinates in PIR orientation
- m2m.transform.pretransform_vol_PIR_UserDataSpace(vol, user_vol)
Transform a PIR reference space to User Data Space.
Parameters
- vol: ndarray
PIR volume to transform.
- user_vol: volume (from nib.load())
X-oriented volume.
Return
- ndarray: vol
Transformed volume into User Data Space
- m2m.transform.pretransform_vol_UserDataSpace_PIR(user_vol, vol)
Transform a User volume to Allen Space.
Parameters
- user_vol: (from nib.load())
user volume to transform.
- vol: ndarray
PIR oriented volume.
Return
- ndarray: vol
Transformed volume into Allen Space
- m2m.transform.registrate_allen2UserDataSpace(file_mat, allen_vol, user_vol, allen_res, smooth=False)
Align a 3D allen volume on User volume. Using ANTsPyX registration.
Parameters
- file_mat: str
Path to transform matrix
- allen_vol: ndarray
Allen volume to registrate.
- user_vol: (from nib.load())
User reference volume.
- allen_res: float
Resolution of the Allen volume, in micron
- smooth: boolean
bSpline interpolation.
Return
ndarray: Warped volume.
m2m.util.py
- m2m.util.draw_spherical_mask(shape, radius, center)
Generate an n-dimensional spherical mask.
Parameters
- shape: tuple
Shape of the volume created.
- radius: int/float
Radius of the spherical mask.
- center: tuple
Position of the center of the spherical mask.
Return
ndarray: Volume containing the spherical mask.