Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make skeletons with mitochondria #35

Open
miridyson opened this issue May 17, 2022 · 10 comments
Open

Make skeletons with mitochondria #35

miridyson opened this issue May 17, 2022 · 10 comments

Comments

@miridyson
Copy link

I would like to make skeletons of neurons that show the mitochondria as well as the synapses.

@stuarteberg
Copy link
Collaborator

stuarteberg commented May 17, 2022

Now that I'm thinking about this more carefully, I think the existing attach_synapses_to_skeleton() function should work just fine for any points you want to attach, as long as you provide the columns ['x', 'y', 'z', 'type']. Here's an example:

from neuprint import Client, fetch_skeleton, fetch_synapses, attach_synapses_to_skeleton, fetch_mitochondria

c = Client('neuprint.janelia.org', 'hemibrain:v1.2.1')

body = 1136399017
skeleton = fetch_skeleton(body, heal=True)
synapses = fetch_synapses(body)
mito = fetch_mitochondria(body)

mito['type'] = mito['mitoType'].map({'dark': 'mito-dark', 'medium': 'mito-medium', 'light': 'mito-light'})

syn_and_mito = pd.concat((synapses[[*'xyz', 'type']], mito[[*'xyz', 'type']]), ignore_index=True)

combined_skeleton = attach_synapses_to_skeleton(skeleton, syn_and_mito)

Note that you may wish to alter the radius column for the mito rows, depending on your specific use-case.

@miridyson
Copy link
Author

miridyson commented May 17, 2022 via email

@stuarteberg
Copy link
Collaborator

That function was introduced very recently. What version of neuprint-python are you using?

python -c 'import neuprint; print(neuprint.__version__)'

If you're using conda to manage your installation, try:

conda install -c flyem-forge 'neuprint-python>=0.4.21'

If you're using pip, try:

pip install --upgrade neuprint-python

@miridyson
Copy link
Author

miridyson commented May 19, 2022 via email

@stuarteberg
Copy link
Collaborator

My example code above is relatively simplistic and may not be suitable for plotting with navis. Navis has a more sophisticated model of neuron skeletons, including the Connector concept.

Maybe @schlegelp has some advice for you...

@schlegelp
Copy link
Contributor

schlegelp commented May 19, 2022

You could piggy-back on the connector table in navis but that would be a bit hackish at this point. If all you want is to co-visualise the skeleton and the mitochondria, you're better off just adding them as scatter plot:

>>> import navis
>>> # Import navis' wrapper for neuprint-python
>>> import navis.interfaces.neuprint as neu 
>>> c = Client('neuprint.janelia.org', 'hemibrain:v1.2.1')
>>> body = 1136399017
>>> # Fetch skeleton as navis neuron, including synapses (note fetch_skeleton vs fetch_skeletons)
>>> skeleton = neu.fetch_skeletons(body, heal=True, with_synapses=True)
>>> # Fetch mitochondria
>>> mito = neu.fetch_mitochondria(body)

I am assuming you're plotting in Jupyter? If so, this will do the trick:

Plot in one-go...

>>> # Plot skeleton + all mitochondria as scatterplot
>>> fig = navis.plot3d([skeleton, mito[['x', 'y', 'z']].values], scatter_kws=dict(color='magenta', size=10))

... or construct figure step-by-step (more control)

>>> fig = navis.plot3d(skeleton, inline=False)
>>> fig = navis.plot3d(mito.loc[mito.mitoType == 'medium', ['x', 'y', 'z']].values, scatter_kws=dict(color='magenta', size=10), fig=fig, inline=False)
>>> fig = navis.plot3d(mito.loc[mito.mitoType == 'dark', ['x', 'y', 'z']].values, scatter_kws=dict(color='cyan', size=10), fig=fig, inline=False)
>>> fig.show()

You can even pass the individual mito sizes as an array and get something like this:

Screenshot 2022-05-19 at 22 39 44

Hope this is helpful. I'll have a think about how to streamline this in the future.

@schlegelp
Copy link
Contributor

For reference: if you pass an (N, 3) array of x/y/z coordinates to either navis.plot2d or navis.plot3d it will plot these data as scatterplot which you can fine-tune using the scatter_kws dictionary.

@schlegelp
Copy link
Contributor

Also quick question @stuarteberg: what is r1, r2, r3 in the mito table? And is there a way to get meshes for the mitochondria?

@stuarteberg
Copy link
Collaborator

stuarteberg commented May 20, 2022

@schlegelp I fit an ellipsoid to each mito, and r0, r1, and r2 are the major, intermediate, and minor axis radii of that ellipsoid. Many mito are not well approximated by an ellipsoid, but many are. I don't know if anyone will find the ellipsoid radii useful, but it seemed like a reasonable thing to provide.

@miridyson
Copy link
Author

miridyson commented May 20, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants