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.data.py
- m2m.data.download_to_cache(data_id: str, force_download: bool = False) str
Download data to cache
Parameters
- data_id
Data to download. The available are the keys of data.data_ids dictionary
- force_download
Force the download of the file if it is already in the cache
Returns
Full path to the downloaded file
m2m.streamlines.py
- class m2m.streamlines.AllenStreamLines(res, directory='./streamlines', cache=True)
Class to work with the Allen Mouse Brain Connectivity Streamlines Adapted from : https://github.com/BrancoLab/BrainRender
- download(experiment_ids, force=False)
Downloads the streamline files for a list of experiment IDs.
Parameters
- experiment_ids: list of integers
Allen experiment IDs.
- force: bool
Force download, otherwise we will check the cache first.
- download_tract(filename, file_mat, user_ref, user_vol, res)
Save the streamlines as a .trk file after aligning them on User Data Space.
Parameters
- filename: str
Full path to the output trk.
- file_mat: str
Full path to the transformation matrix.
- user_ref: str
Full path to a reference volume.
- user_vol: ndarray
User volume data
- res: int
Resolution in the Allen [25, 50, 100] Choose the one correponding to the matrix.
- make_streamline_request_url(experiment_id)
Get url of JSON file for an experiment
Parameters
- experiment_id: int
Allen experiment ID number.
Return
str: url_request
- print_info()
Print some informations about the downloaded streamlines
- remove_cache()
Remove the streamlines cache
m2m.tract.py
- m2m.tract.filter_tract_near_roi(mask, in_tract, out_tract, reference)
Save a bundle of streamlines passing through the binary mask
Parameters
- mask: ndarray
Binary mask.
- int_tract: string
Path to the input trk
- out_tract: string
Path to the output trk
- reference: string
.nii.gz file reference of the trk.
- m2m.tract.get_tract(fname, reference, check_bbox=True, check_hdr=True)
Load a tractogram
Parameters
- fname: string
Path to trk file.
- reference: string
.nii.gz file reference of the trk.
- check_bbox: bool
Check bounding box validity.
- check_hdr: bool
Check header validity.
- m2m.tract.save_tract(fname, streamlines, reference, space=None, check_bbox=True)
Save tractrogram file
Parameters
- fname: string
Path to output file.
- streamlines: array of arrays
Streamlines to save.
- reference: string
.nii.gz file reference of the trk.
- space: enum
StatefulTractogram space.
- check_bbox: bool
Check bounding box validity.
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.get_user_coords_sl(allen_coords, bbox_allen, tx, ornt_pir2user, ornt_user2pir, allen_res, user_res_um)
Overrided version of get_user_coords. Purposes: Retrieving user_coords with the maximum precision in order to right streamlines values.
Take more parameters to optimise the execution time.
Parameters
- allen_coords: list, tuple
Allen coords in voxels
- bbox_allen: list, tuple
Allen bounding box
- tx: ANTsPyX matrix
Transformation matrix
- ornt_pir2user: 3x2 matrix
nibabel orientation matrix from allen to user
- ornt_user2pir: 3x2 matrix
nibabel orientation matrix from user to allen
- allen_res: float
Allen resolution in micron
- user_res_um: float
User’s resolution in micron
Returns
- user_coords: list of floats
User coords with high precision
- 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.transform.registrate_allen_streamlines(streamlines, file_mat, user_vol, allen_res)
Align allen streamlines on the AVGT.
Parameters
- streamlines: array of arrays
Streamlines array.
- file_mat: str
Full path to transformation matrix
- user_vol: ndarray
User volume data array
- allen_res: int
Resolution in the Allen [25, 50, 100] corresponding to the matrix.
Returns
- array of arrays:
Registered streamlines
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.