BlueBrain / NeuroM

Neuronal Morphology Analysis Tool
https://neurom.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
101 stars 55 forks source link

Unsupported section type: 0 #1110

Open superwhat1 opened 5 months ago

superwhat1 commented 5 months ago

When I attempt to open a swc file from neuromorpho.org with the NEURON standard. this is what the file looks like. image

import neurom as nm

m = nm.load_morphology("C:\Users\David\Documents\NeuroComp\project\Soma_in_tectum_653519\3_mod_T_160621_F2M2_loom_02.swc")

Traceback (most recent call last):

File ~\anaconda3\envs\neurom\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec exec(code, globals, locals)

File c:\users\david\documents\neurocomp\project\morphology_function_clustering_project.py:10 m = nm.load_morphology("C:\Users\David\Documents\NeuroComp\project\Soma_in_tectum_653519\3_mod_T_160621_F2M2_loom_02.swc")

File ~\anaconda3\envs\neurom\lib\site-packages\neurom\io\utils.py:165 in load_morphology return Morphology(morph, Path(morph).name)

File ~\anaconda3\envs\neurom\lib\site-packages\neurom\core\morphology.py:435 in init super().init(filename)

RawDataError: C:\Users\David\Documents\NeuroComp\project\Soma_in_tectum_653519\3_mod_T_160621_F2M2_loom_02.swc:2:error Unsupported section type: 0

eleftherioszisis commented 5 months ago

To reproduce the error, could you please attach or provide a link to the morphology? Thanks.

xiuliren commented 1 month ago

I got the same error for several swc files.

File ~/anaconda3/envs/napari/lib/python3.11/site-packages/neurom/io/utils.py:172, in load_morphology(morph, reader, mutable, process_subtrees)
    [170](https://file+.vscode-resource.vscode-cdn.net/Users/jingpengw/projects/63_high-content-screening/~/anaconda3/envs/napari/lib/python3.11/site-packages/neurom/io/utils.py:170)     filepath = _get_file(morph, reader) if reader else morph
    [171](https://file+.vscode-resource.vscode-cdn.net/Users/jingpengw/projects/63_high-content-screening/~/anaconda3/envs/napari/lib/python3.11/site-packages/neurom/io/utils.py:171)     name = os.path.basename(filepath)
--> [172](https://file+.vscode-resource.vscode-cdn.net/Users/jingpengw/projects/63_high-content-screening/~/anaconda3/envs/napari/lib/python3.11/site-packages/neurom/io/utils.py:172)     morphio_morph = morphio.Morphology(filepath)
    [174](https://file+.vscode-resource.vscode-cdn.net/Users/jingpengw/projects/63_high-content-screening/~/anaconda3/envs/napari/lib/python3.11/site-packages/neurom/io/utils.py:174) # None does not modify existing mutability
    [175](https://file+.vscode-resource.vscode-cdn.net/Users/jingpengw/projects/63_high-content-screening/~/anaconda3/envs/napari/lib/python3.11/site-packages/neurom/io/utils.py:175) if mutable is not None:

RawDataError: 
46.swc:16:error

Unsupported section type: 0

I have attached a file. 3.swc.zip

xiuliren commented 1 month ago

I downloaded the example swc file and tested. It also has this error since the node type could be 0.

fname = os.path.expanduser('~/Downloads/undefined_type.swc')
nm.io.utils.load_morphology(fname)

It looks like this behavior is expected... https://github.com/BlueBrain/NeuroM/blob/6705714f923e81ed30750207edceda0778fc9854/tests/io/test_swc_reader.py#L149

I changed my undefined type from 0 to 4, and it works.

eleftherioszisis commented 1 month ago

Thank you @xiuliren for the detailed example, which allowed me to reproduce the error with the following minimal example extracted from your data:

from morphio import Morphology
m = Morphology(
"""
1 1 0.000000 1317316.000000 0.000000 188.000000 -1
2 0 188.000000 1317504.000000 0.000000 188.000000 1
3 0 188.000000 1317692.000000 0.000000 188.000000 2
"""
, "swc")

MorphIO SWC reader explicitly checks for "0" point type and raises if present: https://github.com/BlueBrain/MorphIO/blob/e58dd9965e6d7de4c75eb091346dbea15b61a2bc/src/readers/morphologySWC.cpp#L136

Concerning whether the behavior is expected or not, it's unclear from the specification's point of view. After a closer look, I opened an issue describing the conflict in the definition of the field "Type" and its allowed values: https://github.com/INCF/swc-specification/issues/10

I suggest we wait until an official clarification is given and then I can send a change to allow 0 types in the SWC reader.

Is a 0 type produced automatically by a reconstruction tool or do you create these morphologies on your side, having control over the types that are assigned to the points?