Tutorial


In [1]:
import morphopy

Loading in a morphology

MorphoPy can preprocess standard .swc format and .imx files from Imaris/Filament Tracer.

Morph() object takes two argument: filepath and preprocess. By setting preprocess=True, MorphoPy will check and remove duplicate data points in data, if they exist, and also connect all the disconnected parts to one single neuronal tree, as it always happened in messy raw data. If you are sure your data is clean and don't need any preprocessing, you can turn it off. Noted, only swc is supported without preprocessing when preprocess=False.

A short summary of data quality will return when reading data.


In [2]:
m = morphopy.Morph(filepath='data/EC3-80604.CNG.swc', preprocess=True)


INFO:root:  Data: data/EC3-80604.CNG.swc
INFO:root:  unit: um
INFO:root:  ===================  

INFO:root:  Reading data/EC3-80604.CNG.swc

INFO:root:  Checking duplicate points in data.
INFO:root:	0 duplicate points are found.

INFO:root:  Creating path arrays from voxel data points.

INFO:root:  Checking path connection.
INFO:root:	Total num of paths to check: 442

INFO:root:  No disconnected paths.

INFO:root:  ===================  
INFO:root:  Checking neurites...   

INFO:root:  Has soma (Type 1)?
INFO:root:	Yes

INFO:root:  Has axon (Type 2)?
INFO:root:	Yes

INFO:root:  Has basal dendrites (Type 3)?
INFO:root:	Yes

INFO:root:  Has apical dendrites (Type 4)?
INFO:root:	Yes

INFO:root:  Has undefined or custom types (Type 0/5)?
INFO:root:	No

Morphometric summary statistics

MorphoPy can calculate morphometric statistics about a morphology.


In [3]:
m.summarize()


INFO:root:  Calculating path statistics (e.g. real length, branching order...)
INFO:root:  Calculating summary data...
INFO:root:  Calculating density data...
INFO:root:  Calculating persistance barcode...

In [4]:
m.show_summary()


INFO:root:  Summary of the cell
INFO:root:  ======================

INFO:root:  AXON

INFO:root:    Number of arbor segments: 311
INFO:root:    Number of branch points: 156
INFO:root:    Number of irreducible nodes: 312
INFO:root:    Max branching order: 35

INFO:root:    Asymmetry: 143.052
INFO:root:    Radius: 656.817
INFO:root:    Field Area: 885.600 ×10³ um²

INFO:root:  ## Angle 

INFO:root:    Average nodal angle in degree: 111.684
INFO:root:    Average nodal angle in radian: 1.949
INFO:root:    Average local angle in degree: 114.850
INFO:root:    Average local angle in radian: 2.005 

INFO:root:  ## Average tortuosity: 1.137

INFO:root:  ## Real length (μm)

INFO:root:    Sum: 20314.797
INFO:root:    Mean: 65.321
INFO:root:    Median: 38.032
INFO:root:    Min: 0.343
INFO:root:    Max: 583.516

INFO:root:  ## Euclidean length (μm)

INFO:root:    Sum: 16817.389
INFO:root:    Mean: 54.075
INFO:root:    Median: 33.022
INFO:root:    Min: 0.343
INFO:root:    Max: 391.123

INFO:root:  ======================

INFO:root:  BASAL_DENDRITES

INFO:root:    Number of arbor segments: 51
INFO:root:    Number of branch points: 24
INFO:root:    Number of irreducible nodes: 52
INFO:root:    Max branching order: 6

INFO:root:    Asymmetry: 68.841
INFO:root:    Radius: 184.282
INFO:root:    Field Area: 89.067 ×10³ um²

INFO:root:  ## Angle 

INFO:root:    Average nodal angle in degree: 61.996
INFO:root:    Average nodal angle in radian: 1.082
INFO:root:    Average local angle in degree: 80.415
INFO:root:    Average local angle in radian: 1.404 

INFO:root:  ## Average tortuosity: 1.336

INFO:root:  ## Real length (μm)

INFO:root:    Sum: 4770.365
INFO:root:    Mean: 93.537
INFO:root:    Median: 68.106
INFO:root:    Min: 3.356
INFO:root:    Max: 438.862

INFO:root:  ## Euclidean length (μm)

INFO:root:    Sum: 3398.269
INFO:root:    Mean: 66.633
INFO:root:    Median: 52.263
INFO:root:    Min: 3.356
INFO:root:    Max: 195.778

INFO:root:  ======================

INFO:root:  APICAL_DENDRITES

INFO:root:    Number of arbor segments: 77
INFO:root:    Number of branch points: 38
INFO:root:    Number of irreducible nodes: 78
INFO:root:    Max branching order: 8

INFO:root:    Asymmetry: 217.615
INFO:root:    Radius: 210.876
INFO:root:    Field Area: 124.490 ×10³ um²

INFO:root:  ## Angle 

INFO:root:    Average nodal angle in degree: 52.457
INFO:root:    Average nodal angle in radian: 0.916
INFO:root:    Average local angle in degree: 73.126
INFO:root:    Average local angle in radian: 1.276 

INFO:root:  ## Average tortuosity: 1.308

INFO:root:  ## Real length (μm)

INFO:root:    Sum: 7243.878
INFO:root:    Mean: 94.076
INFO:root:    Median: 68.232
INFO:root:    Min: 9.065
INFO:root:    Max: 429.391

INFO:root:  ## Euclidean length (μm)

INFO:root:    Sum: 5416.765
INFO:root:    Mean: 70.348
INFO:root:    Median: 54.000
INFO:root:    Min: 8.203
INFO:root:    Max: 281.125

INFO:root:  ======================

TODO explain the different statistics

Plotting

Morph.show_morph(view) supports plotting the morphology of the cell in three different view points:

- top view: xy
- front view: xz
- side view: yz 

The cell body is depicted as a grey circle. Each branch point is marked with a circle. The color codes for branch order. The higher the branch order the brighter the color. Different neurite types are color-coded:

- axon: blue
- basal dendrites: red
- apical dendrites: purples

In [5]:
%matplotlib inline
m.show_morph(view='xy')


Out[5]:
(<matplotlib.figure.Figure at 0x7f5e396b8048>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7f5e3956a278>)

Morph.show_treeviews() will plot all three views at the same time.


In [6]:
m.show_threeviews()


Out[6]:
(<matplotlib.figure.Figure at 0x7f5eaf28acf8>,
 array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f5e394794e0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f5e2f809ef0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f5e2f7adeb8>], dtype=object))

Morph.show_animation() will generate a mp4 vedio of the cell morphology in 3D.


In [7]:
# m.show_animation()

(The example cell shown here is a pyramidal cell from enthorhinal cortex (Garden et al., 2008), taken from Neuromorpho.org http://neuromorpho.org/neuron_info.jsp?neuron_name=EC3-80604)


In [8]:
m.show_persistence_diagram()


Out[8]:
(<matplotlib.figure.Figure at 0x7f5eaf28aa58>,
 array([<matplotlib.axes._subplots.AxesSubplot object at 0x7f5e2cf40550>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f5e2cf4c940>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x7f5e2ce32940>], dtype=object))

Saving summary data and processed swc

Summary result and processed swc can be saved by calling:

  • m.save_summary(overwrite=True)
  • m.save_swc(overwrite=True)

In [ ]: