Simplify a neuron to the longest tree with n branch points

simplify_neuron(x, n = 1, invert = FALSE, ...)

## Arguments

x

A neuron to simplify

n

Required number of branch points (default=1, minimum 0)

invert

Whether to keep the simplified backbone (when invert=FALSE, the default) or its inverse.

...

## Value

The simplified neuron or the untouched original neuron for neurons that have <=n branch points.

## Details

If the neuron already contains fewer than or exactly the requested number of branches, then the original neuron is returned. The approach is to build up the new neuron starting from the longest tree including no branches all the way up to the longest tree containing n branches. The distance calculations are only carried out once so it should be reasonably efficient. Nevertheless at each iteration, the longest path from the tree so far to the newly selected leaf is calculated and it is likely that this step could be avoided. Furthermore for large values of n, pruning excess branches rather than building would presumably be more efficient.

spine

## Author

Gregory Jefferis jefferis@gmail.com

## Examples

# \donttest{
n=Cell07PNs[['ECA34L']]
n.simp=simplify_neuron(n)
n.simp4=simplify_neuron(n, n=4)

plot(n, col='green', WithNodes = FALSE) # calculate the inverse as well
n.simp4.inv=simplify_neuron(n, n=4, invert=TRUE)
plot(n.simp4, col='blue') # }

# 3D plots
if (FALSE) {
nclear3d()