stitch_neurons_mst: Stitch multiple fragments into single neuron using minimum...

View source: R/neuron.R

stitch_neurons_mstR Documentation

Stitch multiple fragments into single neuron using minimum spanning tree

Description

Stitch multiple fragments into single neuron using minimum spanning tree

Usage

stitch_neurons_mst(x, threshold = Inf, k = 10L)

Arguments

x

Fragments that could be a neuronlist containing multiple neurons or a single neuron with multiple unconnected subtrees.

threshold

The threshold distance above which new vertices will not be connected (default=Inf disables this feature). This parameter prevents the merging of vertices that are so far away from the main neuron that they are likely to be spurious.

k

The number of nearest neighbours to consider when trying to merge different clusters.

Details

The neurons are joined using the minimum spanning tree i.e. the tree that minimises the sum of edge weights (here, the Euclidean distance). The neuron is rooted in the largest cluster; if this cluster contained the original root of the neuron, then this should be retained.

Note that when a threshold length is used, it must be specified in the same units (microns, nm etc) as the neuron being stitched.

If you wish to process a neuronlist containing multiple neurons each of which must have all their subtrees stitched then you must use nlapply to process the list iteratively.

Value

A single neuron object containing all input fragments.

Author(s)

Sridhar Jagannathan j.sridharrajan@gmail.com

See Also

simplify_neuron, spine, ngraph, igraph::mst

Examples

n=Cell07PNs[['ECA34L']]
# find the tree with the 10 most important branches
n_main=simplify_neuron(n, n = 10)
# and the complement
n_branches=simplify_neuron(n, n = 10, invert = TRUE)

# plot the inputs
plot(n_main, col='red', WithNodes=FALSE)
plot(n_branches, col='blue', add=TRUE, WithNodes=FALSE)

# join the two fragments back together again
# first make a neuronlist containing the two fragments
nl=neuronlist(n_main, n_branches)
# and stitch those
n_stitched=stitch_neurons_mst(nl)

## Not run: 
# look at the neurons in 3D - they appear identical in this case
plot3d(n, alpha=.5, col='cyan', WithNodes=FALSE)
plot3d(n_stitched, alpha=.5, col='red', WithNodes=FALSE)

## End(Not run)

## second example neuron containing multiple sub trees
n=Cell07PNs[['ECA34L']]
# remove a single vertex, breaking the neuron in two
# note that the root (purple node) has moved 
np=prune_vertices(n, 105)
plot(np)

# now stitch the broken neuron back together again
nph=stitch_neurons_mst(np)
# note that the root remains the same as the input neuron (np)
plot(nph)

natverse/nat documentation built on Feb. 19, 2024, 7:19 a.m.