Skip to content

Note

Click here to download the full example code

neuPrint#

This tutorial shows how to fetch neurons from a neuPrint server.

NeuPrint is a service for presenting and analyzing connectomics data. It is used to host, for example, the Janelia EM reconstructions from a Drosophila hemibrain at https://neuprint.janelia.org/.

neuprint-python is a Python library that lets you query data directly from a neuPrint server. You can install it from PyPI:

pip3 install neuprint-python

navis.interfaces.neuprint wraps neuprint-python and adds a few new functions to fetch and convert data into NAVis objects.

# Import navis
import navis

# Import neuprint wrapper by navis
import navis.interfaces.neuprint as neu

First set up the connection: You can either pass your API token directly or store as NEUPRINT_APPLICATION_CREDENTIALS environment variable. The latter is the recommended way and we will use it here:

client = neu.Client(
    "https://neuprint.janelia.org/",
    # token="MYLONGTOKEN"  # use this to instead pass your token directly
    dataset="hemibrain:v1.2.1",
)

You can use all of neuprint's functions:

mbons, roi_info = neu.fetch_neurons(
    neu.SegmentCriteria(instance=".*MBON.*", regex=True)
)
mbons.head(3)
bodyId instance type pre post downstream upstream mito size status cropped statusLabel cellBodyFiber somaRadius somaLocation roiInfo notes inputRois outputRois
0 300972942 MBON14(a3)_R MBON14 543 13634 4336 13634 283 1566415099 Traced False Roughly traced None NaN None {'MB(R)': {'pre': 17, 'post': 13295, 'downstre... None [MB(+ACA)(R), MB(R), SIP(R), SLP(R), SMP(R), S... [MB(+ACA)(R), MB(R), SIP(R), SLP(R), SMP(R), S...
1 394225044 MBON14(a3)_L MBON14 187 5172 768 5172 142 359288547 Traced False Roughly traced None NaN None {'MB(L)': {'pre': 185, 'post': 5143, 'downstre... None [MB(L), SIP(L), SNP(L), aL(L)] [MB(L), SIP(L), SNP(L), aL(L)]
2 422725634 MBON06(B1>a)(AVM07)_L MBON06 1356 21000 9579 21000 765 3157840413 Traced False Roughly traced None NaN None {'MB(R)': {'pre': 777, 'post': 20390, 'downstr... None [CRE(-ROB,-RUB)(R), CRE(R), INP, MB(+ACA)(R), ... [CRE(-ROB,-RUB)(R), CRE(R), INP, MB(+ACA)(R), ...

NAVis has added three functions to neu:

Let's start by fetching the mesh for the right mushroom body ROI:

mb = neu.fetch_roi("MB(R)")
mb

Out:

<navis.Volume(name=MB(R), units=1 dimensionless, color=(0.85, 0.85, 0.85, 0.2), vertices.shape=(57913, 3), faces.shape=(115856, 3))>

Next, let's fetch the skeletons of all right MBONs:

mbon_skeletons = neu.fetch_skeletons(
    neu.SegmentCriteria(instance=".*MBON.*_R", regex=True), with_synapses=True
)
mbon_skeletons.head()

Out:

  0%|          | 0/1 [00:00<?, ?it/s]

100%|##########| 1/1 [00:00<00:00,  3.37it/s]
100%|##########| 1/1 [00:00<00:00,  3.36it/s]


  0%|          | 0/1 [00:00<?, ?it/s]


  0%|          | 0/1 [00:00<?, ?it/s]

100%|##########| 1/1 [00:00<00:00,  5.18it/s]
100%|##########| 1/1 [00:00<00:00,  5.17it/s]


  0%|          | 0/1 [00:00<?, ?it/s]



  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  4.89it/s]
100%|##########| 1/1 [00:00<00:00,  4.89it/s]



  0%|          | 0/1 [00:00<?, ?it/s]




  0%|          | 0/1 [00:00<?, ?it/s]





  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  3.05it/s]
100%|##########| 1/1 [00:00<00:00,  3.05it/s]


100%|##########| 1/1 [00:00<00:00,  1.21it/s]
100%|##########| 1/1 [00:00<00:00,  1.21it/s]






100%|##########| 1/1 [00:00<00:00,  1.54it/s]
100%|##########| 1/1 [00:00<00:00,  1.54it/s]




100%|##########| 1/1 [00:00<00:00,  1.02it/s]
100%|##########| 1/1 [00:00<00:00,  1.02it/s]


  0%|          | 0/1 [00:00<?, ?it/s]




100%|##########| 1/1 [00:00<00:00,  1.02it/s]
100%|##########| 1/1 [00:00<00:00,  1.02it/s]



  0%|          | 0/1 [00:00<?, ?it/s]



  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  4.88it/s]
100%|##########| 1/1 [00:00<00:00,  4.88it/s]


100%|##########| 1/1 [00:00<00:00,  1.52it/s]
100%|##########| 1/1 [00:00<00:00,  1.52it/s]


  0%|          | 0/1 [00:00<?, ?it/s]


  0%|          | 0/1 [00:00<?, ?it/s]



100%|##########| 1/1 [00:00<00:00,  1.50it/s]
100%|##########| 1/1 [00:00<00:00,  1.50it/s]


100%|##########| 1/1 [00:00<00:00,  3.49it/s]
100%|##########| 1/1 [00:00<00:00,  3.49it/s]


  0%|          | 0/1 [00:00<?, ?it/s]



  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  2.88it/s]
100%|##########| 1/1 [00:00<00:00,  2.87it/s]




100%|##########| 1/1 [00:00<00:00,  6.30it/s]
100%|##########| 1/1 [00:00<00:00,  6.29it/s]



  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  5.25it/s]
100%|##########| 1/1 [00:00<00:00,  5.25it/s]



  0%|          | 0/1 [00:00<?, ?it/s]



  0%|          | 0/1 [00:00<?, ?it/s]




  0%|          | 0/1 [00:00<?, ?it/s]





  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  4.71it/s]
100%|##########| 1/1 [00:00<00:00,  4.71it/s]






100%|##########| 1/1 [00:00<00:00,  5.37it/s]
100%|##########| 1/1 [00:00<00:00,  5.37it/s]



  0%|          | 0/1 [00:00<?, ?it/s]



100%|##########| 1/1 [00:00<00:00,  1.64it/s]
100%|##########| 1/1 [00:00<00:00,  1.64it/s]




  0%|          | 0/1 [00:00<?, ?it/s]





  0%|          | 0/1 [00:00<?, ?it/s]



100%|##########| 1/1 [00:00<00:00,  4.29it/s]
100%|##########| 1/1 [00:00<00:00,  4.29it/s]


100%|##########| 1/1 [00:01<00:00,  1.41s/it]
100%|##########| 1/1 [00:01<00:00,  1.41s/it]



100%|##########| 1/1 [00:00<00:00,  1.96it/s]
100%|##########| 1/1 [00:00<00:00,  1.96it/s]


  0%|          | 0/1 [00:00<?, ?it/s]





100%|##########| 1/1 [00:00<00:00,  2.13it/s]
100%|##########| 1/1 [00:00<00:00,  2.13it/s]





100%|##########| 1/1 [00:01<00:00,  1.37s/it]
100%|##########| 1/1 [00:01<00:00,  1.37s/it]


100%|##########| 1/1 [00:00<00:00,  3.66it/s]
100%|##########| 1/1 [00:00<00:00,  3.66it/s]


  0%|          | 0/1 [00:00<?, ?it/s]


  0%|          | 0/1 [00:00<?, ?it/s]



  0%|          | 0/1 [00:00<?, ?it/s]




  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  2.31it/s]
100%|##########| 1/1 [00:00<00:00,  2.31it/s]




100%|##########| 1/1 [00:00<00:00,  2.14it/s]
100%|##########| 1/1 [00:00<00:00,  2.14it/s]



  0%|          | 0/1 [00:00<?, ?it/s]



  0%|          | 0/1 [00:00<?, ?it/s]





  0%|          | 0/1 [00:00<?, ?it/s]

100%|##########| 1/1 [00:00<00:00,  1.03it/s]
100%|##########| 1/1 [00:00<00:00,  1.03it/s]





100%|##########| 1/1 [00:00<00:00,  1.26it/s]
100%|##########| 1/1 [00:00<00:00,  1.26it/s]




100%|##########| 1/1 [00:00<00:00,  1.83it/s]
100%|##########| 1/1 [00:00<00:00,  1.83it/s]



100%|##########| 1/1 [00:00<00:00,  1.17it/s]
100%|##########| 1/1 [00:00<00:00,  1.17it/s]


  0%|          | 0/1 [00:00<?, ?it/s]


  0%|          | 0/1 [00:00<?, ?it/s]





100%|##########| 1/1 [00:00<00:00,  1.09it/s]
100%|##########| 1/1 [00:00<00:00,  1.09it/s]




  0%|          | 0/1 [00:00<?, ?it/s]

100%|##########| 1/1 [00:00<00:00,  3.74it/s]
100%|##########| 1/1 [00:00<00:00,  3.74it/s]


  0%|          | 0/1 [00:00<?, ?it/s]



100%|##########| 1/1 [00:00<00:00,  4.11it/s]
100%|##########| 1/1 [00:00<00:00,  4.11it/s]




  0%|          | 0/1 [00:00<?, ?it/s]




  0%|          | 0/1 [00:00<?, ?it/s]





  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  1.12it/s]
100%|##########| 1/1 [00:00<00:00,  1.12it/s]



  0%|          | 0/1 [00:00<?, ?it/s]



100%|##########| 1/1 [00:00<00:00,  1.51it/s]
100%|##########| 1/1 [00:00<00:00,  1.51it/s]






100%|##########| 1/1 [00:00<00:00,  1.78it/s]
100%|##########| 1/1 [00:00<00:00,  1.78it/s]



100%|##########| 1/1 [00:00<00:00,  5.29it/s]
100%|##########| 1/1 [00:00<00:00,  5.28it/s]





100%|##########| 1/1 [00:00<00:00,  1.20it/s]
100%|##########| 1/1 [00:00<00:00,  1.20it/s]


100%|##########| 1/1 [00:01<00:00,  1.22s/it]
100%|##########| 1/1 [00:01<00:00,  1.22s/it]


  0%|          | 0/1 [00:00<?, ?it/s]


  0%|          | 0/1 [00:00<?, ?it/s]



  0%|          | 0/1 [00:00<?, ?it/s]




  0%|          | 0/1 [00:00<?, ?it/s]





  0%|          | 0/1 [00:00<?, ?it/s]


100%|##########| 1/1 [00:00<00:00,  2.36it/s]
100%|##########| 1/1 [00:00<00:00,  2.36it/s]






100%|##########| 1/1 [00:00<00:00,  2.46it/s]
100%|##########| 1/1 [00:00<00:00,  2.46it/s]





100%|##########| 1/1 [00:00<00:00,  1.54it/s]
100%|##########| 1/1 [00:00<00:00,  1.54it/s]


100%|##########| 1/1 [00:00<00:00,  1.08it/s]
100%|##########| 1/1 [00:00<00:00,  1.08it/s]




100%|##########| 1/1 [00:01<00:00,  1.45s/it]
100%|##########| 1/1 [00:01<00:00,  1.45s/it]
type name id n_nodes n_connectors n_branches n_leafs cable_length soma units
0 navis.TreeNeuron MBON23(a2sp)_R 423382015 14570 5241 1224 1253 4.588212e+05 2379 8 nanometer
1 navis.TreeNeuron MBON19(a2p3p)_R 423774471 6944 1783 549 561 2.464995e+05 1781 8 nanometer
2 navis.TreeNeuron MBON15-like(a'1a'2)_R 457175171 9523 2379 587 602 3.380105e+05 9282 8 nanometer
3 navis.TreeNeuron MBON16-like(a'3a)_R 457196643 10198 4142 933 947 4.218314e+05 6297 8 nanometer
4 navis.TreeNeuron MBON02(B2B'2a)_R 424789697 34243 20709 3040 3095 1.435912e+06 34135 8 nanometer

Co-visualize the MBONs and the MB volume:

navis.plot3d(
    [mbon_skeletons[0], mb],
    legend=False,  # Hide the legend (more space for the plot)
)

Last (but not least), let's make a 2d plot for the tutorial's thumbnail:

import matplotlib.pyplot as plt

fig, ax = navis.plot2d(
    [mbon_skeletons[0], mb],
    c=(0, 0, 0, 1),  # Make the neuron black
    method="3d",
    connectors=True,
    linewidth=0.5,  # Make neuron a bit thinner to emphasize the synapses
    view=("x", "-z"),
)

plt.tight_layout()

tutorial remote 00 neuprint

All NAVis functions for analysis & visualization should work on these neurons. If not, please open an issue on Github.

Total running time of the script: ( 0 minutes 42.944 seconds)

Download Python source code: tutorial_remote_00_neuprint.py

Download Jupyter notebook: tutorial_remote_00_neuprint.ipynb

Gallery generated by mkdocs-gallery