Documentation

Connectomics

How to explore published connectomic data.

27 Dec 2021
!pip install --upgrade vfb_connect
!pip install --upgrade git+git://github.com/schlegelp/navis@master
!pip install --upgrade git+git://github.com/schlegelp/pymaid@master
!pip install --upgrade ipywidgets
!pip install --upgrade jsonpath_rw
!pip install --upgrade seaborn
!pip install --upgrade neuprint-python
!pip install --upgrade flybrains
# Import libs and initialise API objects
from vfb_connect.cross_server_tools import VfbConnect
import pandas as pd
vc = VfbConnect()

import pymaid
import navis

navis.set_pbars(jupyter=False)
pymaid.set_pbars(jupyter=False)

# Connect to the VFB CATMAID server hosting the FAFB data
rm = pymaid.connect_catmaid(server="https://fafb.catmaid.virtualflybrain.org/", api_token=None, max_threads=10)

# Test call to see if connection works 
print(f'Server is running CATMAID version {rm.catmaid_version}')
WARNING: Could not load OpenGL library.
INFO  : Global CATMAID instance set. Caching is ON. (pymaid)
Server is running CATMAID version 2020.02.15-905-g93a969b37

VFB provides a simple methods for exploring connectomics data

get_connected_neurons_by_type allows queries for connections between defined upstream and downstream neuron types/classes. This supports a level of abstraction not available without VFB, where grouping of neurons by higher level classifications is limited to extraction of classification from standardised names. The following examples take advantage of the abstract clasifications on VFB to explore direct synaptic connections.

# Find all GABA-regic inputs onto descending neurons

vc.get_connected_neurons_by_type(upstream_type='GABAergic neuron',
                                 downstream_type='adult descending neuron',
                                 weight=10).sort_values('weight', ascending=False, ignore_index=True)
# Get connections between pacemaker neurons
vc.get_connected_neurons_by_type(upstream_type='pacemaker neuron',
                                 downstream_type='pacemaker neuron',
                                 weight=10).sort_values('weight', ascending=False)

upstream_neuron_idupstream_neuron_nameweightdownstream_neuron_iddownstream_neuron_nameupstream_classdownstream_classup_data_sourceup_accessiondown_sourcedown_accession
28VFB_jrchjtexDN1a_R - 26408399479VFB_jrchjzxyLNd_R - 5813069648DN1a neuronLNd neuronneuprint_JRC_Hemibrain_1point1264083994neuprint_JRC_Hemibrain_1point15813069648
26VFB_jrchjteyDN1a_R - 581302227475VFB_jrchjzxyLNd_R - 5813069648DN1a neuronLNd neuronneuprint_JRC_Hemibrain_1point15813022274neuprint_JRC_Hemibrain_1point15813069648
23VFB_jrchjteyDN1a_R - 581302227463VFB_jrchk8e05th s-LNv - 511051477DN1a neurons-LNv neuronneuprint_JRC_Hemibrain_1point15813022274neuprint_JRC_Hemibrain_1point1511051477
22VFB_jrchjtexDN1a_R - 26408399455VFB_jrchk8e05th s-LNv - 511051477DN1a neurons-LNv neuronneuprint_JRC_Hemibrain_1point1264083994neuprint_JRC_Hemibrain_1point1511051477
3VFB_jrchk089LPN_R - 48002978843VFB_jrchk08aLPN_R - 450034902LP neuronLP neuronneuprint_JRC_Hemibrain_1point1480029788neuprint_JRC_Hemibrain_1point1450034902
7VFB_jrchk8e05th s-LNv - 51105147740VFB_jrchjzxyLNd_R - 5813069648s-LNv neuronLNd neuronneuprint_JRC_Hemibrain_1point1511051477neuprint_JRC_Hemibrain_1point15813069648
1VFB_jrchjzxyLNd_R - 581306964837VFB_jrchk8e05th s-LNv - 511051477LNd neurons-LNv neuronneuprint_JRC_Hemibrain_1point15813069648neuprint_JRC_Hemibrain_1point1511051477
5VFB_jrchjtf0DN1pA_R - 32484657037VFB_jrchjzxyLNd_R - 5813069648DN1p neuronLNd neuronneuprint_JRC_Hemibrain_1point1324846570neuprint_JRC_Hemibrain_1point15813069648
16VFB_jrchjtf2DN1pA_R - 38794411834VFB_jrchjzxyLNd_R - 5813069648DN1p neuronLNd neuronneuprint_JRC_Hemibrain_1point1387944118neuprint_JRC_Hemibrain_1point15813069648
20VFB_jrchjtf1DN1pA_R - 32552923733VFB_jrchk8e05th s-LNv - 511051477DN1p neurons-LNv neuronneuprint_JRC_Hemibrain_1point1325529237neuprint_JRC_Hemibrain_1point1511051477
29VFB_jrchjtf3DN1pA_R - 38716637930VFB_jrchjzxyLNd_R - 5813069648DN1p neuronLNd neuronneuprint_JRC_Hemibrain_1point1387166379neuprint_JRC_Hemibrain_1point15813069648
11VFB_jrchjtf1DN1pA_R - 32552923730VFB_jrchjzxyLNd_R - 5813069648DN1p neuronLNd neuronneuprint_JRC_Hemibrain_1point1325529237neuprint_JRC_Hemibrain_1point15813069648
21VFB_jrchk08aLPN_R - 45003490230VFB_jrchk089LPN_R - 480029788LP neuronLP neuronneuprint_JRC_Hemibrain_1point1450034902neuprint_JRC_Hemibrain_1point1480029788
14VFB_jrchjzxyLNd_R - 581306964829VFB_jrchjzxwLNd_R - 5813056917LNd neuronLNd neuronneuprint_JRC_Hemibrain_1point15813069648neuprint_JRC_Hemibrain_1point15813056917
10VFB_jrchk8e05th s-LNv - 51105147725VFB_jrchjzxxLNd_R - 5813021192s-LNv neuronLNd neuronneuprint_JRC_Hemibrain_1point1511051477neuprint_JRC_Hemibrain_1point15813021192
8VFB_jrchjtf3DN1pA_R - 38716637925VFB_jrchk8e05th s-LNv - 511051477DN1p neurons-LNv neuronneuprint_JRC_Hemibrain_1point1387166379neuprint_JRC_Hemibrain_1point1511051477
4VFB_jrchjtf0DN1pA_R - 32484657025VFB_jrchk8e05th s-LNv - 511051477DN1p neurons-LNv neuronneuprint_JRC_Hemibrain_1point1324846570neuprint_JRC_Hemibrain_1point1511051477
12VFB_jrchjtezDN1pA_R - 581301015325VFB_jrchk8e05th s-LNv - 511051477DN1p neurons-LNv neuronneuprint_JRC_Hemibrain_1point15813010153neuprint_JRC_Hemibrain_1point1511051477
15VFB_jrchjtf2DN1pA_R - 38794411822VFB_jrchk8e05th s-LNv - 511051477DN1p neurons-LNv neuronneuprint_JRC_Hemibrain_1point1387944118neuprint_JRC_Hemibrain_1point1511051477
30VFB_jrchjzxyLNd_R - 581306964821VFB_jrchjzxxLNd_R - 5813021192LNd neuronLNd neuronneuprint_JRC_Hemibrain_1point15813069648neuprint_JRC_Hemibrain_1point15813021192
2VFB_jrchk8e05th s-LNv - 51105147717VFB_jrchjzxwLNd_R - 5813056917s-LNv neuronLNd neuronneuprint_JRC_Hemibrain_1point1511051477neuprint_JRC_Hemibrain_1point15813056917
13VFB_jrchjtezDN1pA_R - 581301015315VFB_jrchjzxyLNd_R - 5813069648DN1p neuronLNd neuronneuprint_JRC_Hemibrain_1point15813010153neuprint_JRC_Hemibrain_1point15813069648
24VFB_jrchk8e05th s-LNv - 51105147714VFB_jrchjtf3DN1pA_R - 387166379s-LNv neuronDN1p neuronneuprint_JRC_Hemibrain_1point1511051477neuprint_JRC_Hemibrain_1point1387166379
25VFB_jrchjzxyLNd_R - 581306964814VFB_jrchjtf1DN1pA_R - 325529237LNd neuronDN1p neuronneuprint_JRC_Hemibrain_1point15813069648neuprint_JRC_Hemibrain_1point1325529237
0VFB_jrchjtf0DN1pA_R - 32484657013VFB_jrchjzxxLNd_R - 5813021192DN1p neuronLNd neuronneuprint_JRC_Hemibrain_1point1324846570neuprint_JRC_Hemibrain_1point15813021192
17VFB_jrchjzxyLNd_R - 581306964813VFB_jrchjtf3DN1pA_R - 387166379LNd neuronDN1p neuronneuprint_JRC_Hemibrain_1point15813069648neuprint_JRC_Hemibrain_1point1387166379
9VFB_jrchk8e05th s-LNv - 51105147712VFB_jrchjtf1DN1pA_R - 325529237s-LNv neuronDN1p neuronneuprint_JRC_Hemibrain_1point1511051477neuprint_JRC_Hemibrain_1point1325529237
19VFB_jrchjtf5DN1pB_R - 581307131911VFB_jrchjzxyLNd_R - 5813069648DN1p neuronLNd neuronneuprint_JRC_Hemibrain_1point15813071319neuprint_JRC_Hemibrain_1point15813069648
31VFB_jrchjteyDN1a_R - 581302227411VFB_jrchjtexDN1a_R - 264083994DN1a neuronDN1a neuronneuprint_JRC_Hemibrain_1point15813022274neuprint_JRC_Hemibrain_1point1264083994
18VFB_jrchjzxyLNd_R - 581306964810VFB_jrchjtezDN1pA_R - 5813010153LNd neuronDN1p neuronneuprint_JRC_Hemibrain_1point15813069648neuprint_JRC_Hemibrain_1point15813010153
27VFB_jrchjtexDN1a_R - 26408399410VFB_jrchjteyDN1a_R - 5813022274DN1a neuronDN1a neuronneuprint_JRC_Hemibrain_1point1264083994neuprint_JRC_Hemibrain_1point15813022274
6VFB_jrchjzxyLNd_R - 581306964810VFB_jrchjtf2DN1pA_R - 387944118LNd neuronDN1p neuronneuprint_JRC_Hemibrain_1point15813069648neuprint_JRC_Hemibrain_1point1387944118
# Get connections between visual projection neurons and descending neurons
vc.get_connected_neurons_by_type(upstream_type='visual projection neuron',
                                 downstream_type='adult descending neuron',
                                 weight=10).sort_values('weight', ascending=False)

upstream_neuron_idupstream_neuron_nameweightdownstream_neuron_iddownstream_neuron_nameupstream_classdownstream_classup_data_sourceup_accessiondown_sourcedown_accession
966VFB_jrchk09jLT51(aSP29a)_R - 1282348408319VFB_jrchjtfrDNb01_R - 1566597156lobula tangential neurondescending neuron of the anterior ventral brai...neuprint_JRC_Hemibrain_1point11282348408neuprint_JRC_Hemibrain_1point11566597156
682VFB_jrchk09cLT51_R - 1444351896221VFB_jrchjtfgDNa03_R - 1139909038lobula tangential neurondescending neuron of the anterior dorsal brain...neuprint_JRC_Hemibrain_1point11444351896neuprint_JRC_Hemibrain_1point11139909038
559VFB_jrchk09jLT51(aSP29a)_R - 1282348408169VFB_jrchjthbDNp18_R - 5813068840lobula tangential neurondescending neuron of the posterior brain DNp18neuprint_JRC_Hemibrain_1point11282348408neuprint_JRC_Hemibrain_1point15813068840
744VFB_jrchk09iLT51_R - 1597493900141VFB_jrchjtfgDNa03_R - 1139909038lobula tangential neurondescending neuron of the anterior dorsal brain...neuprint_JRC_Hemibrain_1point11597493900neuprint_JRC_Hemibrain_1point11139909038
961VFB_jrchk09lLT51(aSP29a)_R - 1261229600104VFB_jrchjtfrDNb01_R - 1566597156lobula tangential neurondescending neuron of the anterior ventral brai...neuprint_JRC_Hemibrain_1point11261229600neuprint_JRC_Hemibrain_1point11566597156
....................................
284VFB_jrchjy92LC4 - 590121544610VFB_jrchjtg8DNp05_R - 1466998977lobula columnar neuron LC4descending neuron of the posterior brain DNp05neuprint_JRC_Hemibrain_1point15901215446neuprint_JRC_Hemibrain_1point11466998977
710VFB_jrchjzntLLPC1 - 581299697810VFB_jrchjthlDNp26_R - 1100404634lobula complex columnar neurondescending neuron of the posterior brain DNp26neuprint_JRC_Hemibrain_1point15812996978neuprint_JRC_Hemibrain_1point11100404634
713VFB_jrchjzx3LLPC3 - 187381161110VFB_jrchjthlDNp26_R - 1100404634lobula complex columnar neurondescending neuron of the posterior brain DNp26neuprint_JRC_Hemibrain_1point11873811611neuprint_JRC_Hemibrain_1point11100404634
953VFB_jrchjzrzLLPC2c - 581299706710VFB_jrchjtfhDNa04_R - 1262014782lobula complex columnar neurondescending neuron of the anterior dorsal brain...neuprint_JRC_Hemibrain_1point15812997067neuprint_JRC_Hemibrain_1point11262014782
0VFB_jrchk04nLPLC2_R - 581298789410VFB_jrchjtg7DNp04_R - 1405231475lobula complex columnar neuron LPLC2descending neuron of the posterior brain DNp04neuprint_JRC_Hemibrain_1point15812987894neuprint_JRC_Hemibrain_1point11405231475

1085 rows × 11 columns

Get neurons downstream/downstream of a specific neuron

Starting from an individual neuron, in this case an individual neuron from hemibrain, find all neurons upstream or downstream, restricting to edges >= some specified wieght (synaptic connections) and optionally limiting the output by neuron type/class.

# Starting point - let's take one of the individual descending neurons from
# the previous exploratory queries and look for other inputs

vc.get_neurons_upstream_of('DNp04_R - 1405231475', weight = 20)

query_neuron_idquery_neuron_nameweighttarget_neuron_idtarget_neuron_name
0VFB_jrchk4u3PVLP100_R - 137584536344VFB_jrchjtg7DNp04_R - 1405231475
1VFB_jrchjy8uLC4 - 115886499550VFB_jrchjtg7DNp04_R - 1405231475
2VFB_jrchjy9fLC4 - 581305512946VFB_jrchjtg7DNp04_R - 1405231475
3VFB_jrchjyalLC4 - 190757122278VFB_jrchjtg7DNp04_R - 1405231475
4VFB_jrchjy9tLC4 - 221516131086VFB_jrchjtg7DNp04_R - 1405231475
..................
82VFB_jrchjyakLC4 - 190793356182VFB_jrchjtg7DNp04_R - 1405231475
83VFB_jrchjy9dLC4 - 162711713446VFB_jrchjtg7DNp04_R - 1405231475
84VFB_jrchjya7LC4 - 187647122158VFB_jrchjtg7DNp04_R - 1405231475
85VFB_jrchk4tmPVLP094_R - 150373317726VFB_jrchjtg7DNp04_R - 1405231475
86VFB_jrchjya0LC4 - 581299813692VFB_jrchjtg7DNp04_R - 1405231475

87 rows × 5 columns

Let’s try a similar query from one of the LC4 neurons to see what other descending neuron types are downstream of it.

vc.get_neurons_downstream_of('LC4 - 1249932198', classification="'adult descending neuron'", weight = 20)
Running query: FBbt:00047511
Query URL: http://owl.virtualflybrain.org/kbs/vfb/instances?object=FBbt%3A00047511&prefixes=%7B%22FBbt%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FFBbt_%22%2C+%22RO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FRO_%22%2C+%22BFO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FBFO_%22%7D&direct=False
Query results: 139

query_neuron_idquery_neuron_nameweighttarget_neuron_idtarget_neuron_name
0VFB_jrchjy8yLC4 - 124993219878VFB_jrchjtg7DNp04_R - 1405231475
1VFB_jrchjy8yLC4 - 124993219830VFB_jrchjup1Giant Fiber_R - 2307027729
2VFB_jrchjy8yLC4 - 124993219865VFB_jrchjtgfDNp11_R - 1281324958

More sophisticated connectomics queries require direct queries of connectomics DB APIs

CATMAID connectivity queries

Broadly speaking, using pymaid to query CATMAID servers lets you fetch connectivity data as either lists of up- and downstream partners or as whole adjacency matrices.

These examples use the VFB FAFB server.

# Using VFB to get neurons by type
DA1 = vc.get_instances("'adult antennal lobe projection neuron DA1'", summary=True)
DA1_tab = pd.DataFrame.from_records(DA1)
len(DA1_tab)
DA1_tab
Running query: FBbt:00048096
Query URL: http://owl.virtualflybrain.org/kbs/vfb/instances?object=FBbt%3A00048096&prefixes=%7B%22FBbt%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FFBbt_%22%2C+%22RO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FRO_%22%2C+%22BFO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FBFO_%22%7D&direct=False
Query results: 31

labelsymbolidtagsparents_labelparents_iddata_sourceaccessiontemplatesdatasetlicense
0Uniglomerular mALT DA1 lPN#L3 (FAFB:2345089)VFB_0010122pEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb2345089JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
1ALv1_P02(DA1)_0_2018UVFB_00102763Entity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372Yu2013https://creativecommons.org/licenses/by-nc-sa/...
2Uniglomerular mALT DA1 lPN#R3 (FAFB:61221)VFB_00101204Entity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb61221adult brain template JFRC2|JRC2018UnisexZheng2018https://creativecommons.org/licenses/by-sa/4.0...
3Uniglomerular mALT DA1 lPN#L1 (FAFB:4207871)VFB_0010126eEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb4207871JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
4ALv1_P02(DA1)_0_2018UVFB_00103943Entity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372Yu2013https://creativecommons.org/licenses/by-nc-sa/...
5Uniglomerular mALT DA1 lPN#R1 (FAFB:57323)VFB_00101201Entity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb57323JRC2018Unisex|adult brain template JFRC2Zheng2018https://creativecommons.org/licenses/by-sa/4.0...
6DA1_lPN_R - 1734350908VFB_jrchjtdbEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363neuprint_JRC_Hemibrain_1point11734350908JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
7Uniglomerular mALT DA1 lPN#R5 (FAFB:2863104)VFB_0010124eEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb2863104JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
8Uniglomerular mALT DA1 lPN#R7 (FAFB:57353)VFB_00101202Entity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb57353JRC2018Unisex|adult brain template JFRC2Zheng2018https://creativecommons.org/licenses/by-sa/4.0...
9ALv1_P02(DA1)_0_2018UVFB_00102297Entity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372JRC2018UnisexLee2020https://creativecommons.org/licenses/by/4.0/le...
10ALv1_P02(DA1)_0_2018UVFB_00104629Entity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372JRC2018UnisexYu2013https://creativecommons.org/licenses/by-nc-sa/...
11ALv1_P02(DA1)_0_2018UVFB_00102294Entity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372Yu2013https://creativecommons.org/licenses/by-nc-sa/...
12Uniglomerular mlALT DA1 vPN#R1 (FAFB:1811442)VFB_0010121xEntity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372catmaid_fafb1811442JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
13Uniglomerular mlALT DA1 vPN#L1 (FAFB:2334841)VFB_0010122mEntity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372catmaid_fafb2334841JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
14Uniglomerular mALT DA1 lPN#L5 (FAFB:2380564)VFB_0010122zEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb2380564JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
15DA1_lPN_R - 754538881VFB_jrchjtdgEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363neuprint_JRC_Hemibrain_1point1754538881JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
16Uniglomerular mALT DA1 lPN#R6 (FAFB:27295)VFB_00101199Entity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb27295JRC2018Unisex|adult brain template JFRC2Zheng2018https://creativecommons.org/licenses/by-sa/4.0...
17Uniglomerular mALT DA1 lPN#R8 (FAFB:57381)VFB_00101203Entity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb57381adult brain template JFRC2|JRC2018UnisexZheng2018https://creativecommons.org/licenses/by-sa/4.0...
18DA1_lPN_R - 1765040289VFB_jrchjtdcEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363neuprint_JRC_Hemibrain_1point11765040289JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
19Uniglomerular mALT DA1 lPN#R2 (FAFB:57311)VFB_00101200Entity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb57311adult brain template JFRC2|JRC2018UnisexZheng2018https://creativecommons.org/licenses/by-sa/4.0...
20DA1_lPN_R - 5813039315VFB_jrchjtddEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363neuprint_JRC_Hemibrain_1point15813039315JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
21Uniglomerular mALT DA1 lPN#L6 (FAFB:2381753)VFB_0010123bEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb2381753JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
22DA1_lPN_R - 754534424VFB_jrchjtdeEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363neuprint_JRC_Hemibrain_1point1754534424JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
23DA1_lPN_R - 1734350788VFB_jrchjtdfEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363neuprint_JRC_Hemibrain_1point11734350788JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
24ALv1_P02(DA1)_0_2018UVFB_00104624Entity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372Yu2013https://creativecommons.org/licenses/by-nc-sa/...
25Uniglomerular mALT DA1 lPN#L2 (FAFB:2319457)VFB_0010122kEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb2319457JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
26Uniglomerular mALT DA1 lPN#R4 (FAFB:755022)VFB_00101205Entity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb755022adult brain template JFRC2|JRC2018UnisexZheng2018https://creativecommons.org/licenses/by-sa/4.0...
27Uniglomerular mALT DA1 lPN#L7 (FAFB:3239781)VFB_0010124lEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb3239781JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
28Uniglomerular mALT DA1 lPN#L4 (FAFB:2379517)VFB_0010122yEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363catmaid_fafb2379517JRC2018UnisexBatesSchlegel2020https://creativecommons.org/licenses/by-sa/4.0...
29DA1_vPN_R - 733316908VFB_jrchjtdhEntity|GABAergic|Adult|Anatomy|has_image|Cell|...adult antennal lobe projection neuron DA1 vPNFBbt_00067372neuprint_JRC_Hemibrain_1point1733316908JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
30DA1_lPN_R - 722817260VFB_jrchjtdaEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DA1 lPNFBbt_00067363neuprint_JRC_Hemibrain_1point1722817260JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
# Map neurons to CATMAID Skeleton IDs (skids)

da1_skids = vc.neo_query_wrapper.vfb_id_2_xrefs(DA1_tab['id'], db='catmaid_fafb', reverse_return=True)
da1_skids
{'2863104': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010124e'}],
 '57353': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_00101202'}],
 '2381753': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010123b'}],
 '1811442': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010121x'}],
 '57323': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_00101201'}],
 '57311': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_00101200'}],
 '2345089': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010122p'}],
 '27295': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_00101199'}],
 '2379517': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010122y'}],
 '2380564': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010122z'}],
 '755022': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_00101205'}],
 '61221': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_00101204'}],
 '57381': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_00101203'}],
 '3239781': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010124l'}],
 '4207871': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010126e'}],
 '2334841': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010122m'}],
 '2319457': [{'db': 'catmaid_fafb', 'vfb_id': 'VFB_0010122k'}]}
# Map neurons to CATMAID Skeleton IDs (skids)

da1_skids = vc.neo_query_wrapper.vfb_id_2_xrefs(DA1_tab['id'], db='catmaid_fafb', reverse_return=True)
da1_skids_int = list(map(int, da1_skids))
da1_skids_int
[2863104,
 57353,
 2381753,
 1811442,
 57323,
 57311,
 2345089,
 27295,
 2379517,
 2380564,
 755022,
 61221,
 57381,
 3239781,
 4207871,
 2334841,
 2319457]

Generate a connectivity table for neurons downstream of DA1 neurons

da1 = pymaid.get_neurons(da1_skids_int)
da1_ds = pymaid.get_partners(da1_skids_int,
                             threshold=3,  # anything with >= 3 synapses
                             directions=['outgoing']  # downstream partners only
                            )

# Result is a pandas DataFrame
da1_ds.head()
INFO  : Fetching connectivity table for 17 neurons (pymaid)
INFO  : Done. Found 0 pre-, 270 postsynaptic and 0 gap junction-connected neurons (pymaid)

neuron_nameskeleton_idnum_nodesrelation286310457353238175318114425732357311...2379517238056475502261221573813239781420787123348412319457total
0Uniglomerular mlALT DA1 vPN mlALTed Milk 18114...181144211769downstream303002021...00322640000151.0
1Uniglomerular mlALT DA1 vPN mlALTed Milk 23348...23348416362downstream0032000...2800002617022139.0
2LHAV4a4#1 1911125 FML PS RJVR19111246969downstream236001519...00191390000109.0
3LHAV2a3#1 1870231 RJVR AJES PS187023014820downstream5230175...00197280000105.0
4LHAV4c1#1 488056 downstream DA1 GSXEJ48805512137downstream153001117...0015150000092.0

5 rows × 22 columns

# Get an adjacency matrix between all Bates, Schlegel et al. neurons
bates = pymaid.find_neurons(annotations='Paper: Bates and Schlegel et al 2020')
adj = pymaid.adjacency_matrix(bates)
adj.head()
INFO  : Found 583 neurons matching the search parameters (pymaid)

targets28631045734957353165736115738898573654182038381339911524119...57323462436218534232842610573334624374308018357337462437857341
sources
28631040.00.00.00.00.00.00.00.00.00.0...2.00.012.00.00.00.00.00.00.00.0
573490.00.00.00.00.00.00.00.00.00.0...0.00.00.00.00.00.00.00.00.00.0
573530.00.00.00.00.00.00.00.00.00.0...0.00.05.00.00.00.00.00.00.00.0
160.00.00.01.00.00.00.00.00.01.0...0.00.00.00.00.00.00.00.00.00.0
573610.00.00.00.00.00.00.00.00.00.0...0.00.00.00.00.00.00.00.00.00.0

5 rows × 583 columns

import seaborn as sns 

ax = sns.clustermap(adj, vmax=10, cmap='Greys')
/shared-libs/python3.7/py/lib/python3.7/site-packages/seaborn/matrix.py:649: UserWarning:

Clustering large matrix with scipy. Installing `fastcluster` may give better performance.

png

# Axo-axonic connections between two different types of DA1 PNs
cn = pymaid.get_connectors_between(2863104, 1811442)
cn.head()

connector_idconnector_locnode1_idsource_neuronconfidence1creator1node1_locnode2_idtarget_neuronconfidence2creator2node2_loc
06736296[359448.44, 159319.03, 150560.0]316340828631045NaN[359487.3, 159145.66, 150600.0]673629818114425NaN[359611.9, 159541.48, 150560.0]
16795172[356041.88, 149555.53, 147920.0]679519528631045NaN[354724.44, 149284.1, 147920.0]679515318114425NaN[356366.16, 149854.86, 147920.0]
26795291[355189.5, 150232.48, 148240.0]679529328631045NaN[354595.62, 149464.8, 148240.0]679521418114425NaN[355472.28, 150294.75, 148160.0]
36795747[355030.4, 154047.86, 145800.0]679574928631045NaN[355045.38, 154180.1, 145800.0]679574518114425NaN[355024.44, 153945.73, 145760.0]
46797452[353221.4, 148570.9, 147320.0]679745628631045NaN[354213.9, 148397.44, 147320.0]679743718114425NaN[353447.6, 148704.88, 147560.0]
import numpy as np 

points = np.vstack(cn.connector_loc)

navis.plot3d([da1.idx[[1811442, 57353]],  # plot the two neurons
              points],  # plot the points of synaptic contacts as scatter 
              scatter_kws=dict(name="synaptic contacts")
              )
#neu_da1 = neu.fetch_skeletons(neu.NeuronCriteria(type='DA1_lPN.*', regex=True))
neu_da1

typenameidn_nodesn_connectorsn_branchesn_leafscable_lengthsomaunits
0navis.TreeNeuronDA1_lPN_R72281726043363132635658274910.568784NaN8 nanometer
1navis.TreeNeuronDA1_lPN_R75453888148902943626642291434.992623860.08 nanometer
.................................
5navis.TreeNeuronDA1_lPN_R176504028953803099624642324249.4030132467.08 nanometer
6navis.TreeNeuronDA1_lPN_R581303931543002954625643273403.049029NaN8 nanometer
split = navis.split_axon_dendrite(neu_da1[0])
split

typenameidn_nodesn_connectorsn_branchesn_leafscable_lengthsomaunitscompartment
0navis.TreeNeuronDA1_lPN_R72281726000000.000000None8 nanometercellbodyfiber
1navis.TreeNeuronDA1_lPN_R72281726035752505566590188806.744034None8 nanometerdendrite
2navis.TreeNeuronDA1_lPN_R722817260193140130601.319501None8 nanometerlinker
3navis.TreeNeuronDA1_lPN_R722817260474612606148872.448763None8 nanometeraxon
navis.plot3d(split, connectors=True)
WARNING : Skipping empty neuron: DA1_lPN_R (722817260) (navis)
cn = neu.fetch_synapse_connections(source_criteria=neu.NeuronCriteria(type='DA1_lPN.*', regex=True),
                                   target_criteria=neu.NeuronCriteria(type='DA1_vPN.*', regex=True))
cn.head()

bodyId_prebodyId_postroi_preroi_postx_prey_prez_prex_posty_postz_postconfidence_preconfidence_post
0754534424733316908LH(R)LH(R)50152292115043503322941150440.9720.991824
1754534424733316908AL(R)AL(R)1458835361264531458235377264440.9910.932866
2754534424733316908LH(R)LH(R)38262257414689384222576146830.9820.896622
3754534424733316908LH(R)LH(R)49242375014333492723768143240.9930.961103
4754534424733316908LH(R)LH(R)50172364214531499723622145180.9040.661779
cn.groupby(['bodyId_pre', 'bodyId_post', 'roi_pre']).size()
bodyId_pre  bodyId_post  roi_pre
722817260   733316908    AL(R)      26
                         LH(R)      28
754534424   733316908    AL(R)      13
                         LH(R)      31
754538881   733316908    AL(R)      33
                         LH(R)       5
1734350788  733316908    AL(R)      21
                         LH(R)      38
1734350908  733316908    AL(R)      24
                         LH(R)      37
1765040289  733316908    AL(R)      27
                         LH(R)       2
5813039315  733316908    AL(R)      12
                         LH(R)      33
dtype: int64

neuprint connectivity queries

To programmatically interface with neuprint, we will use neuprint-python (link). It requires an API token which you can get via the website and is bound to the Google account that you use to log into neuprint. For this workshop we provide such a token as environment variable but you will need to start using your own token after the workshop is over.

These examples use the hemibrain v1.1 dataset.

neuprint-python

First we have to initialize the connection.

import neuprint as neu
client = neu.Client('https://neuprint.janelia.org',
                    dataset='hemibrain:v1.1',
                    token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InZmYndvcmtzaG9wLm5ldXJvZmx5MjAyMEBnbWFpbC5jb20iLCJsZXZlbCI6Im5vYXV0aCIsImltYWdlLXVybCI6Imh0dHBzOi8vbGg2Lmdvb2dsZXVzZXJjb250ZW50LmNvbS8tWXFDN21NRXd3TlEvQUFBQUFBQUFBQUkvQUFBQUFBQUFBQUEvQU1adXVjbU5zaXhXZDRhM0VyTTQ0ODBMa2IzNDdvUlpfUS9zOTYtYy9waG90by5qcGc_c3o9NTA_c3o9NTAiLCJleHAiOjE3OTQwOTE4ODd9.ceg4mrj2o-aOhK0NHNGmBacg8R34PBPoLBwhCo4uOCQ')

Most functions in neuprint-python accept neu.NeuronCriteria which is effectively a filter for body IDs, types, cellbody fibers (~lineages), etc:

help(neu.NeuronCriteria)
Help on class NeuronCriteria in module neuprint.neuroncriteria:

class NeuronCriteria(builtins.object)
 |  NeuronCriteria(matchvar='n', *, bodyId=None, instance=None, type=None, regex=False, cellBodyFiber=None, status=None, cropped=None, min_pre=0, min_post=0, rois=None, inputRois=None, outputRois=None, min_roi_inputs=1, min_roi_outputs=1, label=None, roi_req='all', client=None)
 |  
 |  Specifies which fields to filter by when searching for a Neuron (or Segment).
 |  This class does not send queries itself, but you use it to specify search
 |  criteria for various query functions.
 |  
 |  Note:
 |      For simple queries involving only particular bodyId(s) or type(s)/instance(s),
 |      you can usually just pass the ``bodyId`` or ``type`` to the query function,
 |      without constructing a full ``NeuronCriteria``.
 |  
 |      .. code-block:: python
 |  
 |          from neuprint import fetch_neurons, NeuronCriteria as NC
 |  
 |          # Equivalent
 |          neuron_df, conn_df = fetch_neurons(NC(bodyId=329566174))
 |          neuron_df, conn_df = fetch_neurons(329566174)
 |  
 |          # Equivalent
 |          # (Criteria is satisfied if either type or instance matches.)
 |          neuron_df, conn_df = fetch_neurons(NC(type="OA-VPM3", instance="OA-VPM3"))
 |          neuron_df, conn_df = fetch_neurons("OA-VPM3")
 |  
 |  Methods defined here:
 |  
 |  __eq__(self, value)
 |      Implement comparison between criteria.
 |      Note: 'matchvar' is not considered during the comparison.
 |  
 |  __init__(self, matchvar='n', *, bodyId=None, instance=None, type=None, regex=False, cellBodyFiber=None, status=None, cropped=None, min_pre=0, min_post=0, rois=None, inputRois=None, outputRois=None, min_roi_inputs=1, min_roi_outputs=1, label=None, roi_req='all', client=None)
 |      Except for ``matchvar``, all parameters must be passed as keyword arguments.
 |      
 |      .. note::
 |      
 |          **Options for specifying ROI criteria**
 |      
 |          The ``rois`` argument merely matches neurons that intersect the given ROIs at all
 |          (without distinguishing between inputs and outputs).
 |      
 |          The ``inputRois`` and ``outputRois`` arguments allow you to put requirements
 |          on whether or not neurons have inputs or outputs in the listed ROIs.
 |          It results a more expensive query, but its more powerful.
 |          It also enables you to require a minimum number of connections in the given
 |          ``inputRois`` or ``outputRois`` using the ``min_roi_inputs`` and ``min_roi_outputs``
 |          criteria.
 |      
 |          In either case, use use ``roi_req`` to specify whether a neuron must match just
 |          one (``any``) of the listed ROIs, or ``all`` of them.
 |      
 |      Args:
 |          matchvar (str):
 |              An arbitrary cypher variable name to use when this
 |              ``NeuronCriteria`` is used to construct cypher queries.
 |              To help catch errors (such as accidentally passing a ``type`` or
 |              ``instance`` name in the wrong argument position), we require that
 |              ``matchvar`` begin with a lowercase letter.
 |      
 |          bodyId (int or list of ints):
 |              List of bodyId values.
 |      
 |          instance (str or list of str):
 |              If ``regex=True``, then the instance will be matched as a regular expression.
 |              Otherwise, only exact matches are found. To search for neurons with no instance
 |              at all, use ``instance=[None]``. If both ``type`` and ``instance`` criteria are
 |              supplied, any neuron that matches EITHER criteria will match the overall criteria.
 |      
 |          type (str or list of str):
 |              If ``regex=True``, then the type will be matched as a regular expression.
 |              Otherwise, only exact matches are found. To search for neurons with no type
 |              at all, use ``type=[None]``. If both ``type`` and ``instance`` criteria are
 |              supplied, any neuron that matches EITHER criteria will match the overall criteria.
 |      
 |          regex (bool):
 |              If ``True``, the ``instance`` and ``type`` arguments will be interpreted as
 |              regular expressions, rather than exact match strings.
 |      
 |          cellBodyFiber (str or list of str):
 |              Matches for the neuron ``cellBodyFiber`` field.  To search for neurons
 |              with no CBF at all, use ``cellBodyFiber=[None]``.
 |      
 |          status (str or list of str):
 |              Matches for the neuron ``status`` field.  To search for neurons with no status
 |              at all, use ``status=[None]``.
 |      
 |          cropped (bool):
 |              If given, restrict results to neurons that are cropped or not.
 |      
 |          min_pre (int):
 |              Exclude neurons that don't have at least this many t-bars (outputs) overall,
 |              regardless of how many t-bars exist in any particular ROI.
 |      
 |          min_post (int):
 |              Exclude neurons that don't have at least this many PSDs (inputs) overall,
 |              regardless of how many PSDs exist in any particular ROI.
 |      
 |          rois (str or list of str):
 |              ROIs that merely intersect the neuron, without specifying whether
 |              they're intersected by input or output synapses.
 |              If not provided, will be auto-set from ``inputRois`` and ``outputRois``.
 |      
 |          inputRois (str or list of str):
 |              Only Neurons which have inputs in EVERY one of the given ROIs will be matched.
 |              ``regex`` does not apply to this parameter.
 |      
 |          outputRois (str or list of str):
 |              Only Neurons which have outputs in EVERY one of the given ROIs will be matched.
 |              ``regex`` does not apply to this parameter.
 |      
 |          min_roi_inputs (int):
 |              How many input (post) synapses a neuron must have in each ROI to satisfy the
 |              ``inputRois`` criteria.  Can only be used if you provided ``inputRois``.
 |      
 |          min_roi_outputs (int):
 |              How many output (pre) synapses a neuron must have in each ROI to satisfy the
 |              ``outputRois`` criteria.   Can only be used if you provided ``outputRois``.
 |      
 |          roi_req (Either ``'any'`` or ``'all'``):
 |              Whether a neuron must intersect all of the listed input/output ROIs, or any of the listed input/output ROIs.
 |              When using 'any', each neuron must still match at least one input AND at least one output ROI.
 |      
 |          label (Either ``'Neuron'`` or ``'Segment'``):
 |              Which node label to match with.
 |              (In neuprint, all ``Neuron`` nodes are also ``Segment`` nodes.)
 |              By default, ``'Neuron'`` is used, unless you provided a non-empty ``bodyId`` list.
 |              In that case, ``'Segment'`` is the default. (It's assumed you're really interested
 |              in the bodies you explicitly listed, whether or not they have the ``'Neuron'`` label.)
 |      
 |          client (:py:class:`neuprint.client.Client`):
 |              Used to validate ROI names.
 |              If not provided, the global default ``Client`` will be used.
 |  
 |  __repr__(self)
 |      Return repr(self).
 |  
 |  all_conditions(self, *vars, prefix=0, comments=True)
 |  
 |  basic_conditions(self, prefix=0, comments=True)
 |      Construct a WHERE clause based on the basic conditions
 |      in this criteria (i.e. everything except for the "directed ROI" conditions.)
 |  
 |  basic_exprs(self)
 |      Return the list of expressions that correspond
 |      to the members in this NeuronCriteria object.
 |      They're intended be combined (via 'AND') in
 |      the WHERE clause of a cypher query.
 |  
 |  bodyId_expr(self)
 |  
 |  cbf_expr(self)
 |  
 |  cropped_expr(self)
 |  
 |  directed_rois_condition(self, *vars, prefix=0, comments=True)
 |      Construct the ```WITH...WHERE``` statements that apply the "directed ROI"
 |      conditions specified by this criteria's ``inputRois`` and ``outputRois``
 |      members.
 |      
 |      These conditions are expensive to evaluate, so it's usually a good
 |      idea to position them LAST in your cypher query, once the result set
 |      has already been narrowed down by eariler filters.
 |  
 |  global_vars(self)
 |  
 |  global_with(self, *vars, prefix=0)
 |  
 |  instance_expr(self)
 |  
 |  post_expr(self)
 |  
 |  pre_expr(self)
 |  
 |  rois_expr(self)
 |  
 |  status_expr(self)
 |  
 |  type_expr(self)
 |  
 |  typeinst_expr(self)
 |      Unlike all other fields, type and instance OR'd together.
 |      Either match satisfies the criteria.
 |  
 |  ----------------------------------------------------------------------
 |  Class methods defined here:
 |  
 |  combined_conditions(neuron_conditions, vars=[], prefix=0, comments=True) from builtins.type
 |      Combine the conditions from multiple NeuronCriteria into a single string,
 |      putting the "cheap" conditions first and the "expensive" conditions last.
 |      (That is, basic conditions first and the directed ROI conditions last.)
 |  
 |  combined_global_with(neuron_conditions, vars=[], prefix=0) from builtins.type
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  MAX_LITERAL_LENGTH = 3
 |  
 |  __hash__ = None

Fetching neurons

Let’s say we want to find all antennnal lobe projection neurons (PNs). Their type nomenclature adheres to {glomerulus}_{lineage}PN (e.g. DA1_lPN)for uniglomerular PNs and a M_{lineage}PN{tract}{type} (e.g. M_vPNml50 = “multiglomerular ventral lineage PN mediolateral tract type 50) for multiglomerular PNs.

To get them all, we need to use regex patterns (see this cheatsheet):

# Define the filter criteria
nc = neu.NeuronCriteria(type='.*?_.*?PN.*?', regex=True)

# Get general info for these neurons 
pns, roi_info = neu.fetch_neurons(nc)

print(f'{pns.shape[0]} PNs found.')

pns.head()
337 PNs found.

bodyIdinstancetypeprepostsizestatuscroppedstatusLabelcellBodyFibersomaRadiussomaLocationinputRoisoutputRoisroiInfo
0294792184M_vPNml53_RM_vPNml5392344420662445TracedFalseRoughly tracedAVM04336.5[18923, 34319, 35424][AL(R), AL-D(R), AL-DA2(R), AL-DA4m(R), AL-DC1...[AL(R), AL-DC1(R), LH(R), PLP(R), SIP(R), SLP(...{'SNP(R)': {'pre': 70, 'post': 155, 'downstrea...
1329599710M_lvPNm32_RM_lvPNm32247285343478957TracedFalseRoughly tracedAVM06NaNNone[AL(R), AL-DC4(R), AL-DL2v(R), AL-DM1(R), AL-D...[AL(R), AL-DL2v(R), AL-DM1(R), AL-DM4(R), AL-D...{'SNP(R)': {'pre': 180, 'post': 93, 'downstrea...
2417199910M_lvPNm36_RM_lvPNm36162347387058559TracedFalseRoughly tracedAVM06351.5[13823, 33925, 34176][AL(R), AL-DL5(R), AL-DM4(R), AL-DP1m(R), AL-V...[AL(R), AL-DL5(R), AL-DM4(R), AL-VP1d(R), AL-V...{'SNP(R)': {'pre': 156, 'post': 95, 'downstrea...
3480927537M_vPNml70_RM_vPNml7082276240153322TracedFalseRoughly tracedAVM04NaNNone[AL(R), AL-DA2(R), AL-DA4l(R), AL-DA4m(R), AL-...[LH(R), SLP(R), SNP(R)]{'SNP(R)': {'pre': 15, 'post': 18, 'downstream...
4481268653M_vPNml89_RM_vPNml8914658265085609TracedFalseRoughly tracedAVM04NaNNone[AL(R), AL-VC3l(R), AL-VC4(R), AL-VP1m(R), LH(...[LH(R), SLP(R), SNP(R)]{'SNP(R)': {'pre': 10, 'post': 2, 'downstream'...
# Check that the regex did not have any accidental by-catch
pns['type'].unique()
array(['M_vPNml53', 'M_lvPNm32', 'M_lvPNm36', 'M_vPNml70', 'M_vPNml89',
       'VP1l+_lvPN', 'M_vPNml69', 'DM1_lPN', 'DM4_vPN', 'M_vPNml79',
       'VP4+_vPN', 'DA4l_adPN', 'M_vPNml87', 'DM4_adPN', 'M_vPNml83',
       'VA5_lPN', 'DA4m_adPN', 'M_lvPNm24', 'M_vPNml85', 'VP1l+VP3_ilPN',
       'M_vPNml77', 'M_vPNml84', 'VC1_lPN', 'M_lvPNm39', 'M_vPNml50',
       'DM2_lPN', 'VC5_lvPN', 'M_vPNml88', 'M_vPNml58', 'VP4_vPN',
       'DP1m_vPN', 'DP1m_adPN', 'DM5_lPN', 'VC5_adPN', 'M_vPNml80',
       'M_lvPNm25', 'VC3m_lvPN', 'VP3+_vPN', 'VP1m+_lvPN', 'DA3_adPN',
       'V_l2PN', 'M_vPNml56', 'VC3l_adPN', 'VM7v_adPN', 'DL5_adPN',
       'VM4_adPN', 'VM2_adPN', 'M_lvPNm40', 'DC4_vPN', 'V_ilPN',
       'M_vPNml74', 'Z_lvPNm1', 'DA1_lPN', 'DP1l_adPN', 'VM4_lvPN',
       'M_vPNml71', 'DP1l_vPN', 'M_lvPNm41', 'M_spPN5t10', 'DA1_vPN',
       'VC4_adPN', 'DM3_adPN', 'M_lvPNm45', 'VL1_vPN', 'M_lvPNm44',
       'M_vPNml78', 'M_vPNml67', 'M_adPNm5', 'M_smPNm1', 'DM6_adPN',
       'DL2d_adPN', 'M_adPNm6', 'M_adPNm8', 'M_lvPNm43', 'Z_vPNml1',
       'M_vPNml59', 'DA2_lPN', 'M_lPNm11A', 'M_vPNml52', 'DL2d_vPN',
       'VL2p_vPN', 'VA1d_adPN', 'M_lPNm11B', 'M_lvPNm48', 'M_lPNm11C',
       'M_lvPNm42', 'VA1v_vPN', 'M_vPNml68', 'M_vPNml55', 'M_vPNml62',
       'VL2a_vPN', 'M_vPNml60', 'M_vPNml65', 'VM5d_adPN', 'M_l2PNm16',
       'M_vPNml61', 'M_vPNml57', 'M_vPNml64', 'M_lv2PN9t49',
       'VP2+VC5_l2PN', 'M_spPN4t9', 'M_vPNml66', 'M_vPNml75', 'M_vPNml63',
       'M_vPNml72', 'M_lvPNm38', 'D_adPN', 'M_vPNml76', 'M_vPNml54',
       'DM3_vPN', 'M_vPNml86', 'DL3_lPN', 'VA4_lPN', 'VP1d_il2PN',
       'DC1_adPN', 'M_l2PN3t18', 'M_lvPNm35', 'DL4_adPN', 'M_lvPNm28',
       'M_lvPNm27', 'M_ilPNm90', 'M_l2PNl20', 'M_lvPNm29', 'VA7l_adPN',
       'M_lPNm13', 'M_l2PNl21', 'DL1_adPN', 'M_imPNl92', 'M_vPNml73',
       'M_ilPN8t91', 'M_l2PNm14', 'VP1d+VP4_l2PN1', 'M_lvPNm26',
       'DL2v_adPN', 'VP3+VP1l_ivPN', 'M_lvPNm33', 'VA1v_adPN',
       'VP3+_l2PN', 'M_l2PN10t19', 'VP4+VL1_l2PN', 'M_l2PNl22',
       'M_l2PNm15', 'M_lPNm11D', 'MZ_lv2PN', 'DC2_adPN', 'M_lvPNm46',
       'VC2_lPN', 'VM1_lPN', 'VM3_adPN', 'VM7d_adPN', 'M_lvPNm47',
       'M_lPNm12', 'DC3_adPN', 'VP2+_adPN', 'VP1m+VP2_lvPN2',
       'VP1m+VP2_lvPN1', 'VA6_adPN', 'VA7m_lPN', 'M_adPNm7', 'M_adPNm4',
       'VA1d_vPN', 'VA3_adPN', 'VL1_ilPN', 'M_l2PNl23', 'M_lvPNm31',
       'VP1m+VP5_ilPN', 'VL2p_adPN', 'MZ_lvPN', 'VP2_adPN', 'VA2_adPN',
       'VM5v_adPN', 'VP5+VP2_l2PN', 'VP5+VP3_l2PN', 'VP5+_l2PN',
       'M_vPNml51', 'M_smPN6t2', 'M_lvPNm37', 'M_vPNml82', 'M_adPNm3',
       'VP1m_l2PN', 'DC4_adPN', 'VP5+Z_adPN', 'VL2a_adPN', 'VP2_l2PN',
       'M_lvPNm34', 'VP2+Z_lvPN', 'M_lvPNm30', 'M_l2PNm17', 'M_vPNml81',
       'VP1d+VP4_l2PN2'], dtype=object)

Find neuron types with VFB instead (this allows curated neuron classes to be used):

#This will get all ALPNs from ALL datasets on VFB
ALPNs = vc.get_instances("'adult antennal lobe projection neuron'", summary=True)
ALPNs = pd.DataFrame.from_records(ALPNs)
#Select only rows from Hemibrain1.1 dataset
ALPNs=ALPNs[ALPNs['data_source'].str.match('neuprint_JRC_Hemibrain_1point1')]
ALPNs
Running query: FBbt:00067123
Query URL: http://owl.virtualflybrain.org/kbs/vfb/instances?object=FBbt%3A00067123&prefixes=%7B%22FBbt%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FFBbt_%22%2C+%22RO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FRO_%22%2C+%22BFO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FBFO_%22%7D&direct=False
Query results: 1469

labelsymbolidtagsparents_labelparents_iddata_sourceaccessiontemplatesdatasetlicense
0M_vPNml53_R - 294792184VFB_jrchk0y5Entity|has_image|Adult|Anatomy|has_neuron_conn...adult multiglomerular antennal lobe projection...FBbt_00007414neuprint_JRC_Hemibrain_1point1294792184JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
4DC2_adPN_R - 1828206773VFB_jrchjtdtEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron DC2 adPNFBbt_00067354neuprint_JRC_Hemibrain_1point11828206773JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
8VM4_lvPN_R - 1850024931VFB_jrchk7ibEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuron VM4 lvPNFBbt_00049775neuprint_JRC_Hemibrain_1point11850024931JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
18M_vPNml81_R - 5813090752VFB_jrchk0zjEntity|has_image|Adult|Anatomy|has_neuron_conn...adult multiglomerular antennal lobe projection...FBbt_00007414neuprint_JRC_Hemibrain_1point15813090752JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
21M_lvPNm48_R - 1975187554VFB_jrchk0xtEntity|has_image|Adult|Anatomy|has_neuron_conn...adult multiglomerular antennal lobe projection...FBbt_00049779neuprint_JRC_Hemibrain_1point11975187554JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
....................................
1451Z_vPNml1(noAL+SEZ)_R - 729608317VFB_jrchk7zrEntity|has_image|Adult|Anatomy|has_neuron_conn...adult antennal lobe projection neuronFBbt_00067123neuprint_JRC_Hemibrain_1point1729608317JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
1456M_vPNml63_R - 1857143769VFB_jrchk0ylEntity|has_image|Adult|Anatomy|has_neuron_conn...adult multiglomerular antennal lobe projection...FBbt_00007414neuprint_JRC_Hemibrain_1point11857143769JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
1461M_vPNml66_R - 5813071409VFB_jrchk0yrEntity|has_image|Adult|Anatomy|has_neuron_conn...adult multiglomerular antennal lobe projection...FBbt_00007414neuprint_JRC_Hemibrain_1point15813071409JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
1465M_lPNm11A_R - 5813044177VFB_jrchk0w9Entity|has_image|Adult|Anatomy|has_neuron_conn...adult multiglomerular antennal lobe projection...FBbt_00049778neuprint_JRC_Hemibrain_1point15813044177JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
1468M_l2PNm14_R - 1723506321VFB_jrchk0w4Entity|has_image|Adult|Anatomy|has_neuron_conn...adult multiglomerular antennal lobe projection...FBbt_00049910neuprint_JRC_Hemibrain_1point11723506321JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...

339 rows × 11 columns

Fetching synaptic partners

Looks good! Next: What’s downstream of those PNs?

ds = neu.fetch_simple_connections(upstream_criteria=list(map(int, ALPNs['accession'])))
#using hemibrain regex
#ds = neu.fetch_simple_connections(upstream_criteria=neu.NeuronCriteria(bodyId=pns.bodyId.values))
ds

bodyId_prebodyId_postweighttype_pretype_postinstance_preinstance_postconn_roiInfo
06350620781671292719390DP1m_adPNlLN2T_cDP1m_adPN_RlLN2T_c(Tortuous)_R{'AL(R)': {'pre': 390, 'post': 390}, 'AL-DP1m(...
16350620781704347707326DP1m_adPNlLN2T_cDP1m_adPN_RlLN2T_c(Tortuous)_R{'AL(R)': {'pre': 324, 'post': 324}, 'AL-DP1m(...
25426348181704347707322DM1_lPNlLN2T_cDM1_lPN_RlLN2T_c(Tortuous)_R{'AL(R)': {'pre': 322, 'post': 322}, 'AL-DM1(R...
36350620781640922516320DP1m_adPNlLN2T_eDP1m_adPN_RlLN2T_e(Tortuous)_R{'AL(R)': {'pre': 317, 'post': 316}, 'AL-DP1m(...
47248161151670916819318DP1l_adPNlLN2P_aDP1l_adPN_RlLN2P_a(Patchy)_R{'AL(R)': {'pre': 318, 'post': 318}, 'AL-DP1l(...
...........................
101862590122291058130860371DM2_lPNNoneDM2_lPN_RNone{'LH(R)': {'pre': 1, 'post': 1}}
101863590122291058130959151DM2_lPNKCg-mDM2_lPN_RKCg-m_R{'MB(R)': {'pre': 1, 'post': 1}, 'CA(R)': {'pr...
101864590122291058131293161DM2_lPNLHAV6a1_bDM2_lPN_RLHAV6a1_b_R{'LH(R)': {'pre': 1, 'post': 1}}
101865590122291059011937831DM2_lPNLHAV4g4_aDM2_lPN_RLHAV4g4_a_R{'LH(R)': {'pre': 1, 'post': 1}}
101866590122291059012037801DM2_lPNLHAV4g11DM2_lPN_RLHAV4g11_R{'LH(R)': {'pre': 1, 'post': 1}}

101867 rows × 8 columns

Each row is now a connections from a single up- to a single downstream neuron. The “weight” is the number of synapses between the pre- and the postsynaptic neuron. Let’s simplify by grouping by type:

by_type = ds.groupby(['type_pre', 'type_post'], as_index=False).weight.sum()
by_type.sort_values('weight', ascending=False, inplace=True)
by_type.reset_index(drop=True, inplace=True)
by_type

type_pretype_postweight
0DC3_adPNKCg-m3670
1VM5d_adPNKCg-m3219
2DC1_adPNKCg-m3215
3VL2a_adPNKCg-m3096
4DA1_lPNKCg-m3078
............
40631M_vPNml50WEDPN41
40632M_vPNml50WEDPN121
40633M_vPNml50V_ilPN1
40634M_vPNml50VP4+VL1_l2PN1
40635Z_vPNml1mALD21

40636 rows × 3 columns

The strongest connections are between PNs and Kenyon Cells (KCs). That’s not much of a surprise since there are thousands of KCs. For the sake of the argument let’s say we want to know where these connections occur:

#First find KCs in VFB
KCs = pd.DataFrame.from_records(vc.get_instances("'adult Kenyon cell'", summary=True))
#Select only rows from Hemibrain1.1 dataset
KCs=KCs[KCs['data_source'].str.match('neuprint_JRC_Hemibrain_1point1')]
KCs
Running query: FBbt:00049825
Query URL: http://owl.virtualflybrain.org/kbs/vfb/instances?object=FBbt%3A00049825&prefixes=%7B%22FBbt%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FFBbt_%22%2C+%22RO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FRO_%22%2C+%22BFO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FBFO_%22%7D&direct=False
Query results: 5107

labelsymbolidtagsparents_labelparents_iddata_sourceaccessiontemplatesdatasetlicense
0KCg-m_R - 692810011VFB_jrchjw74Entity|has_image|Adult|Anatomy|has_neuron_conn...gamma main Kenyon cellFBbt_00111061neuprint_JRC_Hemibrain_1point1692810011JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
2KCg-m_R - 477909679VFB_jrchjw36Entity|has_image|Adult|Anatomy|has_neuron_conn...gamma main Kenyon cellFBbt_00111061neuprint_JRC_Hemibrain_1point1477909679JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
5KCab-m_R - 5812980222VFB_jrchjvqkEntity|has_image|Adult|Anatomy|has_neuron_conn...alpha/beta Kenyon cellFBbt_00100248neuprint_JRC_Hemibrain_1point15812980222JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
6KCg-m_R - 5812982832VFB_jrchjw83Entity|has_image|Adult|Anatomy|has_neuron_conn...gamma main Kenyon cellFBbt_00111061neuprint_JRC_Hemibrain_1point15812982832JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
7KCab-m_R - 5812980806VFB_jrchjvr2Entity|has_image|Adult|Anatomy|has_neuron_conn...alpha/beta Kenyon cellFBbt_00100248neuprint_JRC_Hemibrain_1point15812980806JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
....................................
5093KCg-m_R - 664184060VFB_jrchjwckEntity|has_image|Adult|Anatomy|has_neuron_conn...gamma main Kenyon cellFBbt_00111061neuprint_JRC_Hemibrain_1point1664184060JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
5096KCg-m_R - 5812982620VFB_jrchjwddEntity|has_image|Adult|Anatomy|has_neuron_conn...gamma main Kenyon cellFBbt_00111061neuprint_JRC_Hemibrain_1point15812982620JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
5100KCg-m_R - 661430179VFB_jrchjwdbEntity|has_image|Adult|Anatomy|has_neuron_conn...gamma main Kenyon cellFBbt_00111061neuprint_JRC_Hemibrain_1point1661430179JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
5101KCg-m_R - 5812982436VFB_jrchjwczEntity|has_image|Adult|Anatomy|has_neuron_conn...gamma main Kenyon cellFBbt_00111061neuprint_JRC_Hemibrain_1point15812982436JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
5102KCg-m_R - 663834152VFB_jrchjwa9Entity|has_image|Adult|Anatomy|has_neuron_conn...gamma main Kenyon cellFBbt_00111061neuprint_JRC_Hemibrain_1point1663834152JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...

1927 rows × 11 columns

adj, roi_info2 = neu.fetch_adjacencies(sources=list(map(int, ALPNs['accession'])), targets=list(map(int, KCs['accession'])))
roi_info2.head()  
  0%|          | 0/2 [00:00<?, ?it/s]

bodyId_prebodyId_postroiweight
0542634818301314208CA(R)6
1542634818331999156CA(R)1
2542634818332344592CA(R)2
3542634818332344908CA(R)9
4542634818332353106CA(R)13
# Group by region of interest (ROI)
by_roi = roi_info2.groupby('roi').weight.sum()
by_roi.head()
roi
CA(R)         181274
NotPrimary      2764
PLP(R)            11
SCL(R)           509
SLP(R)          2026
Name: weight, dtype: int64
ax = by_roi.plot.bar()
ax.set_xlabel('')
ax.set_ylabel('PN to KC synapses')
Text(0, 0.5, 'PN to KC synapses')

png

Querying paths

Let’s say we want to find out how to go from a PN (second order olfactory neurons) all the way to a descending neuron (presumably leading to motor neurons in the VNC).

#First find DNs in VFB
DNs = pd.DataFrame.from_records(vc.get_instances("'adult descending neuron'", summary=True))
#Select only rows from Hemibrain1.1 dataset
DNs=DNs[DNs['data_source'].str.match('neuprint_JRC_Hemibrain_1point1')]
DNs
Running query: FBbt:00047511
Query URL: http://owl.virtualflybrain.org/kbs/vfb/instances?object=FBbt%3A00047511&prefixes=%7B%22FBbt%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FFBbt_%22%2C+%22RO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FRO_%22%2C+%22BFO%22%3A+%22http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FBFO_%22%7D&direct=False
Query results: 139

labelsymbolidtagsparents_labelparents_iddata_sourceaccessiontemplatesdatasetlicense
2DNp27_R - 1072063538VFB_jrchjthmEntity|has_image|Adult|Anatomy|has_neuron_conn...descending neuron of the posterior brain DNp27FBbt_00047660neuprint_JRC_Hemibrain_1point11072063538JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
3DNp16/17_R - 1655626125VFB_jrchjth0Entity|has_image|Adult|Anatomy|has_neuron_conn...descending neuron of the posterior brainFBbt_00047517neuprint_JRC_Hemibrain_1point11655626125JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
7DNb04_R - 1037393225VFB_jrchjtfxEntity|has_image|Adult|Anatomy|has_neuron_conn...descending neuron of the anterior ventral brai...FBbt_00047585neuprint_JRC_Hemibrain_1point11037393225JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
9DNp32_R - 5813050455VFB_jrchjthrEntity|has_image|Adult|Anatomy|has_neuron_conn...descending neuron of the posterior brain DNp32FBbt_00047665neuprint_JRC_Hemibrain_1point15813050455JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
11NPFP1_R - 1043117106VFB_jrchk103Entity|has_image|Adult|Anatomy|has_neuron_conn...adult NPF P1 neuronFBbt_00048120neuprint_JRC_Hemibrain_1point11043117106JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
....................................
133DNp17_R - 1498383456VFB_jrchjth4Entity|has_image|Adult|Anatomy|has_neuron_conn...descending neuron of the posterior brain DNp17FBbt_00047650neuprint_JRC_Hemibrain_1point11498383456JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
134DNg30_R - 571346836VFB_jrchjtg4Entity|has_image|Adult|Anatomy|has_neuron_conn...descending neuron of the gnathal ganglion DNg30FBbt_00047622neuprint_JRC_Hemibrain_1point1571346836JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
135DNp27_L - 5813020347VFB_jrchjthnEntity|has_image|Adult|Anatomy|has_neuron_conn...descending neuron of the posterior brain DNp27FBbt_00047660neuprint_JRC_Hemibrain_1point15813020347JRC_FlyEM_Hemibrain|JRC2018UnisexXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
137MDN(PDM13)_L - 5813021079VFB_jrchk0vfEntity|has_image|Adult|Anatomy|has_neuron_conn...adult moonwalker descending neuronFBbt_00111308neuprint_JRC_Hemibrain_1point15813021079JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...
138Giant Fiber_R - 2307027729VFB_jrchjup1Entity|has_image|Adult|Anatomy|has_neuron_conn...giant fiber neuronFBbt_00004020neuprint_JRC_Hemibrain_1point12307027729JRC2018Unisex|JRC_FlyEM_HemibrainXu2020NeuronsV1point1https://creativecommons.org/licenses/by/4.0/le...

101 rows × 11 columns

# First fetch the DNs
dns, _ = neu.fetch_neurons(list(map(int, DNs['accession'])))
#with regex
#dns, _ = neu.fetch_neurons(neu.NeuronCriteria(type='(.*DN[^1]{0,}.*|Giant Fiber)', regex=True))
dns

bodyIdinstancetypeprepostsizestatuscroppedstatusLabelcellBodyFibersomaRadiussomaLocationinputRoisoutputRoisroiInfo
0451689001DNp25_RDNp25165803948309595TracedFalseRoughly tracedPDM05361.0[22185, 13374, 16352][ATL(R), CA(R), FLA(R), INP, LH(R), MB(+ACA)(R...[ATL(R), CA(R), INP, MB(+ACA)(R), MB(R), SLP(R...{'SNP(R)': {'pre': 158, 'post': 703, 'downstre...
1512851433DNp10(PDM27)_LDNp102524873010901036TracedFalseRoughly tracedNone483.5[27334, 21053, 7640][ATL(L), GC, GOR(L), IB, ICL(L), INP, SCL(L), ...[ATL(L), GC, GOR(L), ICL(L), INP, SCL(L), SMP(...{'SNP(L)': {'pre': 7, 'post': 512, 'downstream...
2519949044oviDNb_RoviDNb710891618057638TracedFalseRoughly tracedPDM15396.0[19291, 15307, 11696][AVLP(R), CA(R), CRE(-ROB,-RUB)(R), CRE(-RUB)(...[CRE(-RUB)(L), CRE(L), INP, SIP(R), SMP(L), SM...{'SNP(R)': {'pre': 2, 'post': 656, 'downstream...
3542751938DNp44_RDNp441826341674610618TracedFalseRoughly tracedPVM09321.0[18875, 11698, 13136][AL(R), AL-VL1(R), AL-VL2p(R), AL-VP1d(R), AL-...[AL(R), AL-DP1m(R), AL-VL1(R), AL-VL2p(R), AL-...{'SNP(R)': {'pre': 21, 'post': 277, 'downstrea...
4550655668oviDNa_RoviDNa3611111887226051TracedFalseRoughly tracedPDM15301.0[19199, 15756, 13456][AOTU(R), CRE(-ROB,-RUB)(R), CRE(R), EPA(R), I...[CRE(-ROB,-RUB)(R), CRE(R), INP, SCL(R), SIP(R...{'SNP(R)': {'pre': 14, 'post': 772, 'downstrea...
................................................
965813068915NPFP1(PDM12)_LNPFP11231084221447995TracedFalseRoughly tracedNone539.5[28242, 20366, 6808][ATL(L), AVLP(R), CAN(R), EPA(R), GOR(R), IB, ...[AVLP(R), CAN(R), EPA(R), GOR(R), IB, ICL(L), ...{'INP': {'pre': 34, 'post': 47, 'downstream': ...
975813077405DNd01_LDNd0121731738596888TracedFalseRoughly tracedNone342.0[25173, 33207, 14176][SMP(L), SMP(R), SNP(L), SNP(R)][SMP(L), SMP(R), SNP(L), SNP(R)]{'SNP(L)': {'pre': 13, 'post': 675, 'downstrea...
985813078134DNp15_RDNp152123101288564222TracedFalseRoughly tracedNoneNaNNone[CAN(R), GNG, IPS(R), PENP, SPS(R), VLNP(R), V...[GNG, IPS(R), VMNP]{'VMNP': {'pre': 7, 'post': 860, 'downstream':...
995813095193DNp16_RDNp1670683292910198TracedFalseRoughly tracedPVM02276.0[25941, 10730, 20000][CAN(R), GNG, IB, INP, IPS(R), PENP, SPS(R), V...[CAN(R), GNG, IPS(R), PENP, SPS(R), VMNP]{'INP': {'post': 34, 'upstream': 34}, 'IB': {'...
1005813108230DNp16/17_RDNp16/175177304268206TracedFalseRoughly tracedPVM02321.5[23677, 10111, 18544][GNG, IB, INP, IPS(R), SPS(R), VMNP][IPS(R), SPS(R), VMNP]{'INP': {'post': 2, 'upstream': 2}, 'IB': {'po...

101 rows × 15 columns

Neuprint lets you query paths from a single source to a single target. For multi-source or -target queries, your best bet is to download the entire graph and run the queries locally using networkx or igraph.

# Find all paths from A PN to A DNs 
paths = neu.fetch_shortest_paths(upstream_bodyId=list(map(int, ALPNs['accession']))[0],
                                 downstream_bodyId=list(map(int, DNs['accession']))[0],
                                 min_weight=10)
paths        

pathbodyIdtypeweight
00294792184M_vPNml530
105813057148SLP38716
20511349908SMP18319
30545501062SMP46410
40739256609CL02925
...............
343575813057148SLP38716
34457357515217SLP36512
34557479607277CL10210
34657449250041CL02622
347571072063538DNp2722

348 rows × 4 columns

So it looks like there are three separate 7-hop paths to go from M_vPNml53 to DN1a. Let’s visualize the neurons involved!

Fetching meshes & skeletons

You can fetch skeletons as SWCs directly via neuprint-python. For visualization however it’s easiest to load neuron morphologies via navis. For that navis wraps neuprint-python and adds some convenience functions (see also the tutorial):

# Import the wrapped neuprint-python 
# -> this exposes ALL base functions plus a couple navis-specific extras
import navis
import navis.interfaces.neuprint as neu 

#client = neu.Client('https://neuprint.janelia.org', dataset='hemibrain:v1.1')

# Fetch neurons in the first path
nl = neu.fetch_skeletons(paths.loc[(paths.path == 0), 'bodyId'])
nl

typenameidn_nodesn_connectorsn_branchesn_leafscable_lengthsomaunits
0navis.TreeNeuronM_vPNml53_R29479218436704361801901.877807e+0536498 nanometer
1navis.TreeNeuronSMP464_R54550106245074541831931.888869e+0548 nanometer
.................................
4navis.TreeNeuronDNp27_R1072063538471159298175018882.720497e+06258088 nanometer
5navis.TreeNeuronCL029_R739256609319537932266027091.275071e+0660338 nanometer
# Let's also get some ROI meshes
al = neu.fetch_roi('AL(R)')
lh = neu.fetch_roi('LH(R)')
ca = neu.fetch_roi('CA(R)')
# Plot
navis.plot3d([nl, lh, al, ca], width=1100)

Plotting graphs

There are various ways of plotting static graphs. In theory Jupyter notebooks lend themselves to interactive graphs too but unfortunately DeepNote does not yet support the required libraries (e.g. ipywidgets). That being said: if you want to run this locally or on Google colab, check out ipycytoscape.

There are numerous options to do this but we will use networkx to plot a static graph:

import networkx as nx 
import numpy as np

# Initialize the graph
G = nx.DiGraph()

# Generate edges from the paths
edges = []
for p in paths.path.unique():
    this_path = paths.loc[(paths.path == p)]
    this_edges = list(zip(this_path.values[:-1], this_path.values[1:]))

    for i in range(this_path.shape[0] - 1):
        edges.append([this_path.bodyId.values[i], this_path.bodyId.values[i + 1], this_path.weight.values[i + 1]])

# Add the edges 
G.add_weighted_edges_from(edges)

# Add some names to the nodes 
nx.set_node_attributes(G, paths.set_index('bodyId')['type'].to_dict(), name='name')
import matplotlib.pyplot as plt 

# Draw using a simple force-directed layout
pos = nx.kamada_kawai_layout(G)

# We could draw everything in one step but this way we have more control over the plot
fig, ax = plt.subplots(figsize=(10, 10))

# Draw nodes
nx.draw_networkx_nodes(G, pos=pos, ax=ax)

# Draw edges
weights = np.array([e[2]['weight'] for e in G.edges(data=True)])
nx.draw_networkx_edges(G, pos=pos, width=(weights / 12).tolist())

# Add node labels 
nx.draw_networkx_labels(G, pos=pos, labels=dict(G.nodes('name')), font_size=14)

# Turn axes of
ax.set_axis_off()

png

In general, I recommend exporting your graph to e.g. graphml and importing it into e.g. cytoscape if you want to explore an interactive network graph.

nx.write_gml(G, "my_graph.gml")