tasks.curation

Curation tasks.

Module Contents

Classes

Collect

Collect external dataset from .csv file.

ExtractMarkers

Extract marker information from the original morphology files, if any.

PlotMarkers

Plot markers on morphologies.

CheckNeurites

Detect which neurites are present in the morphology, and add soma if missing.

Sanitize

Sanitize the morphologies.

Recenter

Recenter morphologies.

Orient

Orient morphologies.

Align

Align morphologies.

EnsureNeuritesOutsideSoma

Fix radius of the soma of each morphology and cut the root section of neurites if needed.

DetectErrors

Detect and plot errors in reconstructions.

ErrorsReport

Save error report for all morphologies.

Resample

Resample morphologies.

PlotMorphologies

Plot curated morphologies.

Attributes

logger

tasks.curation.logger
class tasks.curation.Collect(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, data_validation_framework.task.ElementValidationTask

Collect external dataset from .csv file.

Original dataset has to have a ‘morph_name’ and ‘morph_path’ columns, with the name and path to the corresponding morphologies. Any other valid columns will be gathered as well. In addition, it will only collect morphologies with allowed extension: .asc, .h5, .swc.

class tasks.curation.ExtractMarkers(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(), data_validation_framework.task.ElementValidationTask

Extract marker information from the original morphology files, if any.

Markers are additional spatial information contained in some reconstructed morphologies. Some can be read by MorphIO (https://github.com/BlueBrain/MorphIO/pull/186). The markers are stored in a custom API: morphology_workflows.marker_helper.

class tasks.curation.PlotMarkers(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(), data_validation_framework.task.ElementValidationTask

Plot markers on morphologies.

Plot the markers extracted from tasks.curation.ExtractMarkers on the morphologies.

with_plotly

Use Plotly for plotting

Type:

bool

Default value:

True

class tasks.curation.CheckNeurites(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, data_validation_framework.task.ElementValidationTask

Detect which neurites are present in the morphology, and add soma if missing.

This task adds three important boolean flags:
  • has_axon

  • has_basal

  • has_apical

set to False if any are absent.

For the axon, if it only has fewer sections than axon_n_section_min, it will be considered as has_axon=False.

If soma is absent, a soma is added as a circle, with center the mean of the first points of root sections, and radius as standard deviation of these points around the center.

If the input dataset has columns use_axon or use_dendrites, our corresponding flags will match.

Todo

Set various levels, a one section neurite can be set to has_basal=False for example.

mock_soma_type

Add a soma if missing of the given type

Type:

str

Choices:

{spherical, contour}

Default value:

spherical

axon_n_section_min

Minimum number of sections in an axon to consider it valid

Type:

int

Default value:

5

ensure_stub_axon

Add a stub axon if there is no axon on the morphology

Type:

bool

Default value:

False

ensure_single_axon

Keep only largest axon if multiple are present

Type:

bool

Default value:

True

ensure_axon_at_soma

Ensure all axons are connected to the soma, and not dendrites

Type:

bool

Default value:

True

remove_dummy_neurites

Remove neurites with two equal points

Type:

bool

Default value:

True

min_length_first_section

Resize the first section to be at least of the given size (do nothing if None is given)

Type:

float

Permitted values:

float in (0, inf)

Default value:

0.0001

class tasks.curation.Sanitize(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, data_validation_framework.task.ElementValidationTask

Sanitize the morphologies.

Sanitization is done with neuror.sanitize.sanitize() and does the following:

  • 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)

Note that the tasks.curation.CheckNeurites task adds a soma if missing, so a failure here means that the soma does not have a valid type.

ensure_roots_at_soma

Reconnect root sections at soma if they are not

Type:

bool

Default value:

True

class tasks.curation.Recenter(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(), data_validation_framework.task.ElementValidationTask

Recenter morphologies.

Often, morphologies do not have a soma centered at [0, 0, 0], so we recenter and save the original location, in case it is important to know where the morphology is located in atlas.

class tasks.curation.Orient(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, data_validation_framework.task.ElementValidationTask

Orient morphologies.

Sometimes, morphologies are oriented along non-standard axis. At BBP, the standard axis is
  • y for pia direction (apical trunk, minus main axon, etc…)

  • z is the slice direction is invitro

  • x the other direction

If y is provided (default value), no oriention will be applied. One can also use minus sign, as -y to flip y axis.

pia_direction

Axis of pia direction, x, y or z

Type:

str

Default value:

y

class tasks.curation.Align(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(True), data_validation_framework.task.ElementValidationTask

Align morphologies.

Sometimes, a morphology is not aligned with any consistent direction, so we can try here to align them using a various algorithms from morph_tool.transform.align_morphology().

method can be: whole, trunk, first_segment, first_section, custom

If method is custom, one must provide external orientation direction in a json file via the parameter custom_orientation_json_path.

TODO: implement the axon_collateral method (for thalamus or example), following https://bbpgitlab.epfl.ch/cells/archive/iavarone/thalamus_pipeline/-/blob/master/notebooks/cell_alignement/Rt_TC_rotations_AxonCollaterals_Releases2019.ipynb

By default, this task is skipped.

method

Method to align morphology

Type:

str

Choices:

{custom, first_section, first_segment, trunk, whole}

Default value:

whole

neurite_type

Neurite to use to align morphology

Type:

str

Default value:

apical

direction
custom_orientation_json_path

Path to json with custom orientations

Type:

str

class tasks.curation.EnsureNeuritesOutsideSoma(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(True), data_validation_framework.task.ElementValidationTask

Fix radius of the soma of each morphology and cut the root section of neurites if needed.

class tasks.curation.DetectErrors(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(), data_validation_framework.task.ElementValidationTask

Detect and plot errors in reconstructions.

Reconstructions may contain errors, which are detected here. They are of the following type:

  • fat ends

  • z-jumps

  • narrow start

  • dangling branch

  • multifurcation

  • overlapping points

  • z-range (new error only present here, which check is the z thickness is larger than min_range)

This task uses neuror.sanitize.annotate_neurolucida(). This task creates new .asc file with error annotated so it can be red by Neurolucida, and a morphology_workflows.marker_helper.MarkerSet container of the errors, for later plotting.

min_range

Minimum z-range to be an error

Type:

float

Default value:

50

overlapping_point_tolerance

Tolerance used to detect overlapping points.

Type:

float

Default value:

1e-06

plot_errors

Plot the detected errors

Type:

bool

Default value:

True

class tasks.curation.ErrorsReport(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(), data_validation_framework.task.SetValidationTask

Save error report for all morphologies.

From the detected errors in tasks.curation.DetectErrors, create a CSV report.

error_report_path

Path to error report file in .csv

Type:

str

Default value:

error_report.csv

class tasks.curation.Resample(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(), data_validation_framework.task.ElementValidationTask

Resample morphologies.

This tasks ensures a constant sampling rate of points along all branches using the morph_tool.resampling.resample_linear_density() function.

linear_density

Density of points per micron

Type:

float

Default value:

1.0

class tasks.curation.PlotMorphologies(*args, **kwargs)

Bases: morphology_workflows.utils.StrIndexMixin, SkippableMixin(), data_validation_framework.task.ElementValidationTask

Plot curated morphologies.

This tasks creates a single pdf with all morphologies to visualise them after curation.

The PDF file is created using the neurom.view.matplotlib_impl.plot_morph() function.

with_plotly

Use Plotly for plotting

Type:

bool

Default value:

False

with_realistic_diameters

Use realistic diameters for plotting (take more time to plot)

Type:

bool

Default value:

True