neuror.sanitize

Module for the sanitization of raw morphologies.

Functions

_sanitize_one

Function to be called by sanitize_all to catch all exceptions and return path if in error.

annotate_neurolucida

Annotate errors on a morphology in neurolucida format.

annotate_neurolucida_all

Annotate errors on a list of morphologies in neurolicida format.

fix_non_zero_segments

Return a neuron with zero length segments removed

fix_points_in_soma

Ensure section points are not inside the soma.

iter_morphologies

Recursively yield morphology files in folder and its sub-directories.

sanitize

Sanitize one morphology.

sanitize_all

Sanitize all morphologies in input_folder and its sub-directories.

neuror.sanitize._sanitize_one(path, input_folder, output_folder)[source]

Function to be called by sanitize_all to catch all exceptions and return path if in error.

Since multiprocessing.pool.Pool.imap_unordered() only supports one argument, the argument is a tuple: (path, input_folder, output_folder).

neuror.sanitize.annotate_neurolucida(morph_path: str, checkers: Dict | None = None)[source]

Annotate errors on a morphology in neurolucida format.

Parameters:
  • morph_path – absolute path to an ascii morphology

  • checkers – dict of checker functons from neurom with function as keys and marker data in a dict as values, if None, default checkers are used

Default checkers include:
  • fat ends

  • z-jumps

  • narrow start

  • dangling branch

  • multifurcation

Returns:

  • annotations to append to .asc file

  • dict of error summary

  • dict of error markers

neuror.sanitize.annotate_neurolucida_all(morph_paths: List[str], nprocesses: int = 1) Tuple[Dict, Dict, Dict][source]

Annotate errors on a list of morphologies in neurolicida format.

Parameters:
  • morph_paths – list of str of paths to morphologies.

  • nprocesses – number of processes to use for parallel computation

Returns:

  • dict annotations to append to .asc file (morph_path as keys)

  • dict of dict of error summary (morph_path as keys)

  • dict of dict of markers (morph_path as keys)

neuror.sanitize.fix_non_zero_segments(neuron, zero_length=0.0001)[source]

Return a neuron with zero length segments removed

Sections composed of a single zero length segment are deleted, where zero is parametrized by zero_length

Parameters:
Returns:

a fixed morphology

Return type:

morphio.mut.Morphology

neuror.sanitize.fix_points_in_soma(morph: Morphology) bool[source]

Ensure section points are not inside the soma.

Method:
  • for each root section, we check which points are inside the soma.

  • if all points of a root section are inside the soma, an exception is raised because it means that a bifurcation is located inside the soma, which is hard to automatically fix.

  • if there is at least 1 point inside the soma, a new point is defined to replace them. If this new point is too close to the first point outside the soma, the point is not added.

Parameters:

morph – the morphology

Returns:

True if at least one point was changed, else False.

neuror.sanitize.iter_morphologies(folder)[source]

Recursively yield morphology files in folder and its sub-directories.

neuror.sanitize.sanitize(input_neuron, output_path)[source]

Sanitize one morphology.

  • ensures it can be loaded with MorphIO

  • raises if the morphology has no soma or of invalid format

  • removes unifurcations

  • set negative diameters to zero

  • raises if the morphology has a neurite whose type changes along the way

  • removes segments with near zero lengths (shorter than 1e-4)

Parameters:
neuror.sanitize.sanitize_all(input_folder, output_folder, nprocesses=1)[source]

Sanitize all morphologies in input_folder and its sub-directories.

See sanitize() for more information on the sanitization process.

Parameters:

Note

The sub-directory structure is maintained.