Open miridyson opened 2 years ago
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.
Yes I see the logic. Sorry if it's my very rusty python but I am getting these errors:
ImportError: cannot import name 'attach_synapses_to_skeleton' from 'neuprint'
ImportError: cannot import name 'attach_synapses' from 'neuprint
On Tue, 17 May 2022 at 18:37, Stuart Berg @.***> wrote:
Now that I'm thinking about this more carefully, I think the existing attach_synapses_to_skeleton() function https://connectome-neuprint.github.io/neuprint-python/docs/skeleton.html#neuprint.skeleton.attach_synapses_to_skeleton 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 = 1136399017skeleton = 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)
— Reply to this email directly, view it on GitHub https://github.com/connectome-neuprint/neuprint-python/issues/35#issuecomment-1129085341, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATLX5UM6H73T46DW34M7ITLVKPDMRANCNFSM5WFCENBQ . You are receiving this because you authored the thread.Message ID: @.***>
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
I'm still a bit stuck with plotting the synapse/mito data onto the skeleton. I can get a skeleton of a bodyID, and I have the coordinates of the mito & synapses.
Here I am just trying to add the synapses alone
body = 1136399017 skeleton = fetch_skeleton(body, heal=True) synapses = fetch_synapses(body) xx = attach_synapses_to_skeleton(skeleton, synapses)
fig = navis.plot3d([xx], color='r')
This gives me the skeleton without synapses.
I also can't change the colour this way, even though I can change the colour with the same code when I'm just plotting a skeleton and giving a bodyID.
I am following the NAVis tutorials for adding connectors, is this right? It also only shows info for plotting the connecters in 2D, not 3D and I can't see the synapses in 2D or 3D https://navis.readthedocs.io/en/latest/source/tutorials/neurons_intro.html
Thank you.
On Tue, 17 May 2022 at 20:15, Stuart Berg @.***> wrote:
That function was introduced very recently https://connectome-neuprint.github.io/neuprint-python/docs/changelog.html. 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
— Reply to this email directly, view it on GitHub https://github.com/connectome-neuprint/neuprint-python/issues/35#issuecomment-1129174599, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATLX5UNRRCG6MVVQFZFIYL3VKPO2RANCNFSM5WFCENBQ . You are receiving this because you authored the thread.Message ID: @.***>
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...
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:
Hope this is helpful. I'll have a think about how to streamline this in the future.
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.
Also quick question @stuarteberg: what is r1
, r2
, r3
in the mito table? And is there a way to get meshes for the mitochondria?
@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.
Thank you!
On Fri, 20 May 2022 at 05:16, Stuart Berg @.***> wrote:
@schlegelp https://github.com/schlegelp I fit an ellipsoid to each mito, and r1, r2, and r3 are the major, intermediate, and minor axes 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.
— Reply to this email directly, view it on GitHub https://github.com/connectome-neuprint/neuprint-python/issues/35#issuecomment-1132413657, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATLX5UPRHNDEC36TFCWLUELVK37XLANCNFSM5WFCENBQ . You are receiving this because you authored the thread.Message ID: @.***>
I would like to make skeletons of neurons that show the mitochondria as well as the synapses.