Use point and shape layer to edit swc format in napari.
This napari plugin was generated with copier using the napari-plugin-template.
Peek.2024-12-03.16-43.mp4
- Your .swc should follow the following specs: http://www.neuronland.org/NLMorphologyConverter/MorphologyFormats/SWC/Spec.html
- the reader will create 2 napari layer:
point_layer
andshape_layer
. Onlypoint_layer
is interactive,shape_layer
is used to render path between swc points. - The raw swc can be accessed in the point layer metadata. Such as
point_layer.metadata["raw_swc"]
- A
pd.DataFrame
object is also saved in the metadata:point_layer.metadata["swc_data"]
- With the
point_layer
selected, you can use napari interface to save with.swc
extension name. - You can also do it in command line:
napari.save_layers('test.swc', [point_layer])
In swc, structure id allow to label the type of neuron structure the point belongs to. In this plugin by default, the points will follow this symbol mapping:
SWC_SYMBOL = {
0: "clobber", # undefined
1: "star", # soma
2: "disc", # axon
3: "triangle_down", # basal dendrite
4: "triangle_up", # apical dendrite
}
You can also visualize the swc data in a table using the widget under Plugin > SWC Editor Widget
When using the "Show swc table" you will have an interactive table widget:
- left-click on table: highlight + center on the corresponding point
- double-left-click on table: highlight + center on the correspongind point + zoom
- selection on the point layer: highlight the corresponding row on the table
ALL INTERACTIONS ARE ONLY BOUND TO THE point_layer
THERE IS NO CTRL-Z (please save your progress)
- Add point: You can edit the "r" and the "structure_id" using the
point_size
andsymbol
- Remove point: (Select the point and press
1
orsuppr
ordelete
) All the link pointing to this point will be removed - Add edge: Select 2 or more point(s) and press on your keyboard
l
(aka: link). - Remove edge: Select 1 or more point(s) and press on your keyboard
u
(aka: unlink).
If you want to link point as you are adding them you have two solutions:
- press "CTRL" while you add points, this will create a link with the previously selected point
- use the
Plugin > SWC Editor Widget
Checkbox ("link previous node with new node (same as using CTRL+Click)"): when selected, all new points will be selected with the previously selected point
Peek.2025-01-05.01-53.mp4
You can install napari-swc-editor
via pip:
pip install napari-swc-editor
To install latest development version :
pip install git+https://github.com/LaboratoryOpticsBiosciences/napari-swc-editor.git
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the BSD-3 license, "napari-swc-editor" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.