Coder Social home page Coder Social logo

Comments (8)

schlegelp avatar schlegelp commented on June 11, 2024

It looks like the file is a mix of tab and space separators. See this:

>>> # With default separator
>>> pd.read_csv('VFB_00023647_snt_skel-000.swc', header=None, skiprows=6)
                                                      0
0     1\t0\t231.908032 219.526534 88.631724 0.000000...
1     2\t0\t232.426842 219.007559 88.631724 0.000000\t1
2     3\t0\t232.945652 219.007559 88.631724 0.000000\t2
3     4\t0\t233.464462 219.007559 88.631724 0.000000\t3
4     5\t0\t233.983271 219.007559 88.631724 0.000000\t4
>>> # With tab separator
>>> pd.read_csv('VFB_00023647_snt_skel-000.swc', header=None, skiprows=6, sep='\t')
         0  1                                         2     3
0        1  0  231.908032 219.526534 88.631724 0.000000    -1
1        2  0  232.426842 219.007559 88.631724 0.000000     1
2        3  0  232.945652 219.007559 88.631724 0.000000     2
3        4  0  233.464462 219.007559 88.631724 0.000000     3
4        5  0  233.983271 219.007559 88.631724 0.000000     4

Bottom line: that's an issue with pandas (or the underlying Python csv parser) not being able to disentangle the mix of separators. Is there a way to change the output of the simple neurite tracer? Alternatively, you could write a little script to clean up the file(s). navis.read_swc has a delimiter parameter which defaults to ' ' whitespace and is passed directly to pandas.read_csc.

from navis.

schlegelp avatar schlegelp commented on June 11, 2024

Ah: a workaround is using a regex separator.

pd.read_csv('VFB_00023647_snt_skel-000.swc', header=None, skiprows=6, sep='\s+')
n = navis.read_swc('VFB_00023647_snt_skel-000.swc', delimiter='\s+')

from navis.

schlegelp avatar schlegelp commented on June 11, 2024

By-the-by: it struck me that the neuron has one one root and one end node - no branch points. Did you realize that this is one continuous line? I.e. when a neurite "ends" the skeleton just turns around, forms a loop and tracks back.

from navis.

SridharJagannathan avatar SridharJagannathan commented on June 11, 2024

Thanks, I just realised that the file seems to have arbitary number of spaces as delims and your solution to set the seperator as \s+, seems to have done the trick.
The neuron (tracing) actually looks fine when i plot it see below:
gal4line

Perhaps I need to reroot it, somehow to produce the branch points?
I was just trying to do some covisualisation of gal4line, hemibrain, flywire neuron ( ilPN) as an example here:
https://github.com/SridharJagannathan/pyroglancer/blob/master/pyroglancer/examples/gal4line2flywire.ipynb

from navis.

schlegelp avatar schlegelp commented on June 11, 2024

It will plot just fine but anything that requires correct topology will fail or produce nonsensical results.

from navis.

SridharJagannathan avatar SridharJagannathan commented on June 11, 2024

I tried to cut the neuron and then stitch them back together, that seems to have produced branches, however i can see that there are loops inside the neuron, do you know how to eliminate them, basically i'm thinking of an approach to use the pts to construct a graph, and then use the graph to construct the neuron.

vfb_neuron = navis.read_swc(swc_files, delimiter='\s+')
fragments = navis.cut_neuron(vfb_neuron, 500)
stitched = navis.stitch_neurons(fragments, method='ALL')

from navis.

schlegelp avatar schlegelp commented on June 11, 2024

With 84cfe9f I just pushed a first pass implementation for a function that resolves this (albeit not perfectly):

>>> n = navis.read_swc('VFB_00023647_snt_skel-000.swc', delimiter='\s+')
>>> fx = navis.graph.clinic.merge_duplicate_nodes(n)
>>> fx
type                     navis.TreeNeuron
name            VFB_00023647_snt_skel-000
n_nodes                              1422
n_connectors                         None
n_branches                             59
n_leafs                                61
cable_length                  1106.133057
soma                                 None
units                        1 micrometer

You can see it now has proper leafs and branches. However when co-visualizing it, you will notice that some edges got removed (red) to break up cycles after node collapse. It's better than before but not perfect.

Screenshot 2021-02-23 at 12 56 14

from navis.

schlegelp avatar schlegelp commented on June 11, 2024

I'll close this issue. Re-open if you feel this is unresolved.

from navis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.