pip3 install neuromorpholib
from neuromorpholib import neuromorpho
nmo = neuromorpho.NeuroMorpho()
acc1 = nmo.download_swc("martone", "ACC1")
mouse_neurons = nmo.search({"species": "mouse"})
swc_demo = nmo.download_swc(
mouse_neurons[0]
)
If you know the archive name and neuron name, you can also download the swc directly by passing archive
and neuron_name
arguments.
If you only want the SWC text and don't want it to be converted into a NeuronMorphology
object, you can pass text_only=True
.
from neuromorpholib.swc import load_swc, NeuronMorphology
my_morphology = load_swc("my_neuron.swc")
# This is a NeuronMorphology object.
branch_points = my_morphology.get_branch_points()
morphology_graph = my_morphology.smoothed()
# nx.DiGraph
Rotate, translate, or scale a geometry with NeuronMorphology
functions:
n = NeuronMorphology()
n.scale(3)
n.translate([4, 44, 10])
n.rotate([0, 0, math.pi/2])
All of the following visualization techniques assume you have a single NeuronMorphology object, downloaded perhaps like this:
from neuromorpholib import neuromorpho
nmo = neuromorpho.NeuroMorpho()
acc1 = nmo.download_swc("martone", "ACC1")
import networkx as nx
g = acc1.get_graph()
nx.draw(g, pos={n: a['xyz'][:2] for n, a in g.nodes(data=True)}, node_size=0)
Using pytri
This will return an interactive 3D turntable in a Jupyter Notebook.
from pytri import Figure
fig = Figure()
fig.graph(acc1.get_graph(), pos_attribute="xyz")
fig.show()