This is the multi-page printable view of this section. Click here to print.
Application Programming Interface (API) Tutorials
- 1: VFB connect API overview
- 2: Guide to Working with Images from Virtual Fly Brain (VFB) Using the VFBConnect Library
- 3: Downloading Images from VFB Using VFBconnect
- 4: Programmatic search using SOLR
- 5: Exploring Neurons in Navis
- 6: Plotting Neurons with Navis
- 7: pymaid
- 8: NBLAST
- 9: neuprint
1 - VFB connect API overview
VFB connect API overview
The VFB connect API provides programmatic access to the databases underlying Virtual Fly Brain.
At the core of Virtual Fly Brain is a set of curated terms for Drosophila neuro-anatomy organised into a queryable classification, including terms for brain regions, e.g. nodulus and neurons e.g. MBON01. These terms are used to annotate and classify individual brain regions and neurons in images and connectomics data. For example the term MBON01 is used to classify individual neurons from sources including the CATMAID-FAFB and Neuprint-HemiBrain databases. VFB stores both registered 3D images and connectomics data (where available) for all of these neurons.
A single VfbConnect object wraps database connections and canned queries against all open VFB databases. It includes methods for retreiving metadata about anatomy, individual brain regions and neurons including IDs for these that can be used for queries against other databases (e.g. CATMAID & neuprint). It provides methods for downloading images and connectomics data. It provides access to sophisticated queries for anatomical classes and individual neurons according to their classification & properties.
Locations for methods under a VfbConnect object.
- Under
vc.neo_query_wrapperare- A set of methods that take lists of IDs as a primary argument and return metadata.
- A set of methods for mapping between VFB IDs and external IDs
- Directly under
vcare:- A set of methods that take the names of classes in VFB e.g. ’nodulus’ or ‘Kenyon cell’, or simple query expressions using the names of classes and return metadata about the classes.
- A set methods for querying connectivity and similarity
- Direct access to API queries is provided under the ’nc’ and ‘oc’ attributes for Neo4J and OWL queries respectively. We will not cover details of how to use these here.
Note: available methods and their documentation are easy to explore in DeepNote. Tab completion and type adhead can be used to help find methods. Float your cursor over a method to see its signature and docstring.
1. vc.neo_query_wrapper methods overview
1.1 vc.neo_query_wrapper TermInfo queries return the results of a VFB Term Information window as JSON, following the VFB_JSON standard, or a summary that can easily be converted into a DataFrame.
# A query for full TermInfo. This probably produces more information than you will need for most purposes.
vc.neo_query_wrapper.get_type_TermInfo(['FBbt_00003686'])
[{'term': {'core': {'iri': 'http://purl.obolibrary.org/obo/FBbt_00003686',
'symbol': '',
'types': ['Entity',
'Anatomy',
'Nervous_system',
'Cell',
'Neuron',
'Class'],
'label': 'Kenyon cell',
'short_form': 'FBbt_00003686'},
'description': ['Intrinsic neuron of the mushroom body. They have tightly-packed cell bodies, situated in the rind above the calyx of the mushroom body (Ito et al., 1997). Four short fascicles, one per lineage, extend from the cell bodies of the Kenyon cells into the calyx (Ito et al., 1997). These 4 smaller fascicles converge in the calyx where they arborize and form pre- and post-synaptic terminals (Christiansen et al., 2011), with different Kenyon cells receiving input in different calyx regions/accessory calyces (Tanaka et al., 2008). They emerge from the calyx as a thick axon bundle referred to as the peduncle that bifurcates to innervate the dorsal and medial lobes of the mushroom body (Tanaka et al., 2008).'],
'comment': ['Pre-synaptic terminals were identified using two presynaptic markers (Brp and Dsyd-1) and post-synaptic terminals by labelling a subunit of the acetylcholine receptor (Dalpha7) in genetically labelled Kenyon cells (Christiansen et al., 2011).']},
'query': 'Get JSON for Class',
'version': '44725ae',
'parents': [{'iri': 'http://purl.obolibrary.org/obo/FBbt_00001366',
'symbol': '',
'types': ['Entity',
'Anatomy',
'Nervous_system',
'Cell',
'Neuron',
'Class'],
'label': 'supraesophageal ganglion neuron',
'short_form': 'FBbt_00001366'},
{'iri': 'http://purl.obolibrary.org/obo/FBbt_00007484',
'symbol': '',
'types': ['Entity',
'Anatomy',
'Nervous_system',
'Cell',
'Neuron',
'Class'],
'label': 'mushroom body intrinsic neuron',
'short_form': 'FBbt_00007484'}],
'relationships': [{'relation': {'type': 'develops_from',
'iri': 'http://purl.obolibrary.org/obo/RO_0002202',
'label': 'develops from'},
'object': {'iri': 'http://purl.obolibrary.org/obo/FBbt_00007113',
'symbol': '',
'types': ['Entity',
'Anatomy',
'Nervous_system',
'Cell',
'Neuroblast',
'Class'],
'label': 'mushroom body neuroblast',
'short_form': 'FBbt_00007113'}},
{'relation': {'type': 'overlaps',
'iri': 'http://purl.obolibrary.org/obo/RO_0002131',
'label': 'overlaps'},
'object': {'iri': 'http://purl.obolibrary.org/obo/FBbt_00003687',
'symbol': '',
'types': ['Entity',
'Synaptic_neuropil',
'Anatomy',
'Nervous_system',
'Synaptic_neuropil_domain',
'Class'],
'label': 'mushroom body pedunculus',
'short_form': 'FBbt_00003687'}},
{'relation': {'type': 'part_of',
'iri': 'http://purl.obolibrary.org/obo/BFO_0000050',
'label': 'is part of'},
'object': {'iri': 'http://purl.obolibrary.org/obo/FBbt_00005801',
'symbol': '',
'types': ['Entity',
'Synaptic_neuropil',
'Anatomy',
'Nervous_system',
'Synaptic_neuropil_block',
'Class'],
'label': 'mushroom body',
'short_form': 'FBbt_00005801'}},
{'relation': {'type': 'receives_synaptic_input_in',
'iri': 'http://purl.obolibrary.org/obo/RO_0013002',
'label': 'receives synaptic input in'},
'object': {'iri': 'http://purl.obolibrary.org/obo/FBbt_00003685',
'symbol': '',
'types': ['Entity',
'Synaptic_neuropil',
'Anatomy',
'Nervous_system',
'Synaptic_neuropil_domain',
'Class'],
'label': 'mushroom body calyx',
'short_form': 'FBbt_00003685'}}],
'xrefs': [],
'anatomy_channel_image': [{'channel_image': {'channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_jrchjwig',
'symbol': '',
'types': ['Entity', 'Individual'],
'label': 'KCg-t_R - 5812981989_c',
'short_form': 'VFBc_jrchjwig'},
'image': {'template_channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_00101567',
'symbol': '',
'types': ['Entity', 'Individual', 'Template'],
'label': 'JRC2018Unisex_c',
'short_form': 'VFBc_00101567'},
'index': [],
'template_anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_00101567',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'Nervous_system',
'Individual',
'Template'],
'label': 'JRC2018Unisex',
'short_form': 'VFB_00101567'},
'image_folder': 'http://www.virtualflybrain.org/data/VFB/i/jrch/jwig/VFB_00101567/'},
'imaging_technique': {'iri': 'http://purl.obolibrary.org/obo/FBbi_00050000',
'symbol': 'FIB-SEM',
'types': ['Entity', 'Class'],
'label': 'focussed ion beam scanning electron microscopy (FIB-SEM)',
'short_form': 'FBbi_00050000'}},
'anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_jrchjwig',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'has_neuron_connectivity',
'Cell',
'Individual',
'has_region_connectivity',
'NBLAST',
'Nervous_system',
'Neuron'],
'label': 'KCg-t_R - 5812981989',
'short_form': 'VFB_jrchjwig'}},
{'channel_image': {'channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_jrchjwig',
'symbol': '',
'types': ['Entity', 'Individual'],
'label': 'KCg-t_R - 5812981989_c',
'short_form': 'VFBc_jrchjwig'},
'image': {'template_channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_00101384',
'symbol': '',
'types': ['Entity', 'Individual', 'Template'],
'label': 'JRC_FlyEM_Hemibrain_c',
'short_form': 'VFBc_00101384'},
'index': [],
'template_anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_00101384',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'Nervous_system',
'Individual',
'Template'],
'label': 'JRC_FlyEM_Hemibrain',
'short_form': 'VFB_00101384'},
'image_folder': 'http://www.virtualflybrain.org/data/VFB/i/jrch/jwig/VFB_00101384/'},
'imaging_technique': {'iri': 'http://purl.obolibrary.org/obo/FBbi_00050000',
'symbol': 'FIB-SEM',
'types': ['Entity', 'Class'],
'label': 'focussed ion beam scanning electron microscopy (FIB-SEM)',
'short_form': 'FBbi_00050000'}},
'anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_jrchjwig',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'has_neuron_connectivity',
'Cell',
'Individual',
'has_region_connectivity',
'NBLAST',
'Nervous_system',
'Neuron'],
'label': 'KCg-t_R - 5812981989',
'short_form': 'VFB_jrchjwig'}},
{'channel_image': {'channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_jrchjwih',
'symbol': '',
'types': ['Entity', 'Individual'],
'label': 'KCg-t_R - 1392655948_c',
'short_form': 'VFBc_jrchjwih'},
'image': {'template_channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_00101567',
'symbol': '',
'types': ['Entity', 'Individual', 'Template'],
'label': 'JRC2018Unisex_c',
'short_form': 'VFBc_00101567'},
'index': [],
'template_anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_00101567',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'Nervous_system',
'Individual',
'Template'],
'label': 'JRC2018Unisex',
'short_form': 'VFB_00101567'},
'image_folder': 'http://www.virtualflybrain.org/data/VFB/i/jrch/jwih/VFB_00101567/'},
'imaging_technique': {'iri': 'http://purl.obolibrary.org/obo/FBbi_00050000',
'symbol': 'FIB-SEM',
'types': ['Entity', 'Class'],
'label': 'focussed ion beam scanning electron microscopy (FIB-SEM)',
'short_form': 'FBbi_00050000'}},
'anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_jrchjwih',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'has_neuron_connectivity',
'Cell',
'Individual',
'has_region_connectivity',
'NBLAST',
'Nervous_system',
'Neuron'],
'label': 'KCg-t_R - 1392655948',
'short_form': 'VFB_jrchjwih'}},
{'channel_image': {'channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_jrchjwih',
'symbol': '',
'types': ['Entity', 'Individual'],
'label': 'KCg-t_R - 1392655948_c',
'short_form': 'VFBc_jrchjwih'},
'image': {'template_channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_00101384',
'symbol': '',
'types': ['Entity', 'Individual', 'Template'],
'label': 'JRC_FlyEM_Hemibrain_c',
'short_form': 'VFBc_00101384'},
'index': [],
'template_anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_00101384',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'Nervous_system',
'Individual',
'Template'],
'label': 'JRC_FlyEM_Hemibrain',
'short_form': 'VFB_00101384'},
'image_folder': 'http://www.virtualflybrain.org/data/VFB/i/jrch/jwih/VFB_00101384/'},
'imaging_technique': {'iri': 'http://purl.obolibrary.org/obo/FBbi_00050000',
'symbol': 'FIB-SEM',
'types': ['Entity', 'Class'],
'label': 'focussed ion beam scanning electron microscopy (FIB-SEM)',
'short_form': 'FBbi_00050000'}},
'anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_jrchjwih',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'has_neuron_connectivity',
'Cell',
'Individual',
'has_region_connectivity',
'NBLAST',
'Nervous_system',
'Neuron'],
'label': 'KCg-t_R - 1392655948',
'short_form': 'VFB_jrchjwih'}},
{'channel_image': {'channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_jrchjwii',
'symbol': '',
'types': ['Entity', 'Individual'],
'label': 'KCg-t_R - 785918963_c',
'short_form': 'VFBc_jrchjwii'},
'image': {'template_channel': {'iri': 'http://virtualflybrain.org/reports/VFBc_00101567',
'symbol': '',
'types': ['Entity', 'Individual', 'Template'],
'label': 'JRC2018Unisex_c',
'short_form': 'VFBc_00101567'},
'index': [],
'template_anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_00101567',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'Nervous_system',
'Individual',
'Template'],
'label': 'JRC2018Unisex',
'short_form': 'VFB_00101567'},
'image_folder': 'http://www.virtualflybrain.org/data/VFB/i/jrch/jwii/VFB_00101567/'},
'imaging_technique': {'iri': 'http://purl.obolibrary.org/obo/FBbi_00050000',
'symbol': 'FIB-SEM',
'types': ['Entity', 'Class'],
'label': 'focussed ion beam scanning electron microscopy (FIB-SEM)',
'short_form': 'FBbi_00050000'}},
'anatomy': {'iri': 'http://virtualflybrain.org/reports/VFB_jrchjwii',
'symbol': '',
'types': ['Entity',
'has_image',
'Adult',
'Anatomy',
'has_neuron_connectivity',
'Cell',
'Individual',
'has_region_connectivity',
'NBLAST',
'Nervous_system',
'Neuron'],
'label': 'KCg-t_R - 785918963',
'short_form': 'VFB_jrchjwii'}}],
'pub_syn': [{'pub': {'core': {'iri': 'http://flybase.org/reports/Unattributed',
'symbol': '',
'types': ['Entity', 'Individual', 'pub'],
'label': '',
'short_form': 'Unattributed'},
'FlyBase': '',
'PubMed': '',
'DOI': ''},
'synonym': {'type': '', 'label': 'KC', 'scope': 'has_exact_synonym'}},
{'pub': {'core': {'iri': 'http://flybase.org/reports/FBrf0236359',
'symbol': '',
'types': ['Entity', 'Individual', 'pub'],
'label': 'Eichler et al., 2017, Nature 548(7666): 175--182',
'short_form': 'FBrf0236359'},
'FlyBase': 'FBrf0236359',
'PubMed': '28796202',
'DOI': '10.1038/nature23455'},
'synonym': {'type': '',
'label': 'mature Kenyon cell',
'scope': 'has_exact_synonym'}},
{'pub': {'core': {'iri': 'http://flybase.org/reports/FBrf0111409',
'symbol': '',
'types': ['Entity', 'Individual', 'pub'],
'label': 'Lee et al., 1999, Development 126(18): 4065--4076',
'short_form': 'FBrf0111409'},
'FlyBase': '',
'PubMed': '10457015',
'DOI': ''},
'synonym': {'type': '',
'label': 'MB neuron',
'scope': 'has_narrow_synonym'}}],
'def_pubs': [{'core': {'iri': 'http://flybase.org/reports/FBrf0214059',
'symbol': '',
'types': ['Entity', 'Individual', 'pub'],
'label': 'Christiansen et al., 2011, J. Neurosci. 31(26): 9696--9707',
'short_form': 'FBrf0214059'},
'FlyBase': '',
'PubMed': '21715635',
'DOI': '10.1523/JNEUROSCI.6542-10.2011'},
{'core': {'iri': 'http://flybase.org/reports/FBrf0092568',
'symbol': '',
'types': ['Entity', 'Individual', 'pub'],
'label': 'Ito et al., 1997, Development 124(4): 761--771',
'short_form': 'FBrf0092568'},
'FlyBase': '',
'PubMed': '9043058',
'DOI': ''},
{'core': {'iri': 'http://flybase.org/reports/FBrf0205263',
'symbol': '',
'types': ['Entity', 'Individual', 'pub'],
'label': 'Tanaka et al., 2008, J. Comp. Neurol. 508(5): 711--755',
'short_form': 'FBrf0205263'},
'FlyBase': '',
'PubMed': '18395827',
'DOI': '10.1002/cne.21692'}]}]
# A query for summary info
import pandas as pd
summary = vc.neo_query_wrapper.get_type_TermInfo(['FBbt_00003686'], summary=True)
summary_tab = pd.DataFrame.from_records(summary)
summary_tab
| label | symbol | id | tags | parents_label | parents_id | |
|---|---|---|---|---|---|---|
| 0 | Kenyon cell | FBbt_00003686 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | supraesophageal ganglion neuron|mushroom body ... | FBbt_00001366|FBbt_00007484 |
# A different method is needed to get info about individual neurons
summary = vc.neo_query_wrapper.get_anatomical_individual_TermInfo(['VFB_jrchjrch'], summary=True)
summary_tab = pd.DataFrame.from_records(summary)
summary_tab
| label | symbol | id | tags | parents_label | parents_id | data_source | accession | templates | dataset | license | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 5-HTPLP01_R - 1324365879 | VFB_jrchjrch | Entity|has_image|Adult|Anatomy|has_neuron_conn... | adult serotonergic PLP neuron | FBbt_00110945 | neuprint_JRC_Hemibrain_1point1 | 1324365879 | JRC_FlyEM_Hemibrain|JRC2018Unisex | Xu2020NeuronsV1point1 | https://creativecommons.org/licenses/by/4.0/le... |
1.2 The neo_query_wrapper also includes methods for mapping between IDs from different sources.
# Some bodyIDs of HemiBrain neurons from the neuprint DataBase:
bodyIDs = [1068958652, 571424748, 1141631198]
vc.neo_query_wrapper.xref_2_vfb_id(map(str, bodyIDs)) # Note IDs must be strings
{'1068958652': [{'db': 'neuronbridge', 'vfb_id': 'VFB_jrchjwda'},
{'db': 'neuronbridge', 'vfb_id': 'VFB_jrch06r9'},
{'db': 'neuprint_JRC_Hemibrain_1point0point1', 'vfb_id': 'VFB_jrch06r9'},
{'db': 'neuprint_JRC_Hemibrain_1point1', 'vfb_id': 'VFB_jrchjwda'}],
'571424748': [{'db': 'neuronbridge', 'vfb_id': 'VFB_jrch06r6'},
{'db': 'neuronbridge', 'vfb_id': 'VFB_jrchjwct'},
{'db': 'neuprint_JRC_Hemibrain_1point0point1', 'vfb_id': 'VFB_jrch06r6'},
{'db': 'neuprint_JRC_Hemibrain_1point1', 'vfb_id': 'VFB_jrchjwct'}],
'1141631198': [{'db': 'neuronbridge', 'vfb_id': 'VFB_jrch05uz'},
{'db': 'neuronbridge', 'vfb_id': 'VFB_jrchjw8r'},
{'db': 'neuprint_JRC_Hemibrain_1point0point1', 'vfb_id': 'VFB_jrch05uz'},
{'db': 'neuprint_JRC_Hemibrain_1point1', 'vfb_id': 'VFB_jrchjw8r'}]}
# xref queries can be constrained by DB. Results can optionally be reversed
vc.neo_query_wrapper.xref_2_vfb_id(map(str, bodyIDs), db = 'neuprint_JRC_Hemibrain_1point1' , reverse_return=True)
{'VFB_jrchjw8r': [{'acc': '1141631198',
'db': 'neuprint_JRC_Hemibrain_1point1'}],
'VFB_jrchjwct': [{'acc': '571424748',
'db': 'neuprint_JRC_Hemibrain_1point1'}],
'VFB_jrchjwda': [{'acc': '1068958652',
'db': 'neuprint_JRC_Hemibrain_1point1'}]}
2. vc direct methods overview
2.1 Methods that take the names of classes in VFB e.g. ’nodulus’ or ‘Kenyon cell’, or simple query expressions using the names of classes and return metadata about the classes or individual neurons.
KC_types = vc.get_subclasses("Kenyon cell", summary=True)
pd.DataFrame.from_records(KC_types)
Running query: FBbt:00003686
Query URL: http://owl.virtualflybrain.org/kbs/vfb/subclasses?object=FBbt%3A00003686&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: 37
| label | symbol | id | tags | parents_label | parents_id | |
|---|---|---|---|---|---|---|
| 0 | adult alpha'/beta' Kenyon cell | FBbt_00049834 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | alpha'/beta' Kenyon cell|adult Kenyon cell | FBbt_00100249|FBbt_00049825 | |
| 1 | immature Kenyon cell | FBbt_00047995 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | Kenyon cell | FBbt_00003686 | |
| 2 | gamma Kenyon cell | FBbt_00100247 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | Kenyon cell | FBbt_00003686 | |
| 3 | adult Kenyon cell | FBbt_00049825 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | adult MBp lineage neuron|Kenyon cell | FBbt_00110577|FBbt_00003686 | |
| 4 | gamma main Kenyon cell | KCg-m | FBbt_00111061 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | Kenyon cell of main calyx|adult gamma Kenyon cell | FBbt_00047926|FBbt_00049828 |
| 5 | alpha'/beta' anterior-posterior type 1 Kenyon ... | FBbt_00049859 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | alpha'/beta' anterior-posterior type 1 Kenyon ... | FBbt_00049836 | |
| 6 | alpha/beta Kenyon cell | FBbt_00100248 | Entity|Neuron|Adult|Anatomy|Nervous_system|Cel... | cholinergic neuron|adult Kenyon cell | FBbt_00007173|FBbt_00049825 | |
| 7 | gamma-s4 Kenyon cell | KCg-s4 | FBbt_00049832 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | gamma-s Kenyon cell | FBbt_00049830 |
| 8 | two-claw Kenyon cell | FBbt_00047997 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | multi-claw Kenyon cell | FBbt_00047994 | |
| 9 | single-claw Kenyon cell | FBbt_00047993 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | Kenyon cell | FBbt_00003686 | |
| 10 | alpha/beta posterior Kenyon cell | KCab-p | FBbt_00110931 | Entity|Neuron|Adult|Anatomy|Nervous_system|Cel... | alpha/beta Kenyon cell | FBbt_00100248 |
| 11 | alpha'/beta' middle Kenyon cell | KCa'b'-m | FBbt_00100253 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | Kenyon cell of main calyx|adult alpha'/beta' K... | FBbt_00047926|FBbt_00049834 |
| 12 | alpha/beta surface Kenyon cell | KCab-s | FBbt_00110930 | Entity|Neuron|Adult|Anatomy|Nervous_system|Cel... | alpha/beta surface/core Kenyon cell | FBbt_00049838 |
| 13 | alpha'/beta' anterior-posterior type 1 Kenyon ... | KCa'b'-ap1 | FBbt_00049836 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | alpha'/beta' anterior-posterior Kenyon cell | FBbt_00100250 |
| 14 | larval alpha'/beta' Kenyon cell | FBbt_00049835 | Entity|Neuron|Anatomy|Nervous_system|Cell|Larv... | larval Kenyon cell|alpha'/beta' Kenyon cell | FBbt_00049826|FBbt_00100249 | |
| 15 | gamma-s1 Kenyon cell | KCg-s1 | FBbt_00049787 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | gamma-s Kenyon cell | FBbt_00049830 |
| 16 | gamma-t Kenyon cell | KCg-t | FBbt_00049833 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | adult gamma Kenyon cell | FBbt_00049828 |
| 17 | four-claw Kenyon cell | FBbt_00047999 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | multi-claw Kenyon cell | FBbt_00047994 | |
| 18 | alpha'/beta' Kenyon cell | FBbt_00100249 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | Kenyon cell | FBbt_00003686 | |
| 19 | alpha/beta surface/core Kenyon cell | FBbt_00049838 | Entity|Neuron|Adult|Anatomy|Nervous_system|Cel... | Kenyon cell of main calyx|alpha/beta Kenyon cell | FBbt_00047926|FBbt_00100248 | |
| 20 | larval Kenyon cell | FBbt_00049826 | Entity|Neuron|Anatomy|Nervous_system|Cell|Larv... | Kenyon cell|embryonic/larval neuron | FBbt_00003686|FBbt_00001446 | |
| 21 | alpha'/beta' anterior-posterior Kenyon cell | FBbt_00100250 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | adult alpha'/beta' Kenyon cell | FBbt_00049834 | |
| 22 | six-claw Kenyon cell | FBbt_00048001 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | multi-claw Kenyon cell | FBbt_00047994 | |
| 23 | Kenyon cell of main calyx | FBbt_00047926 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | adult Kenyon cell | FBbt_00049825 | |
| 24 | alpha'/beta' anterior-posterior type 2 Kenyon ... | KCa'b'-ap2 | FBbt_00049837 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | alpha'/beta' anterior-posterior Kenyon cell|Ke... | FBbt_00100250|FBbt_00047926 |
| 25 | gamma-s3 Kenyon cell | KCg-s3 | FBbt_00049831 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | gamma-s Kenyon cell | FBbt_00049830 |
| 26 | alpha/beta inner-core Kenyon cell | FBbt_00049111 | Entity|Neuron|Adult|Anatomy|Nervous_system|Cel... | alpha/beta core Kenyon cell | FBbt_00110929 | |
| 27 | gamma dorsal Kenyon cell | KCg-d | FBbt_00110932 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | adult gamma Kenyon cell | FBbt_00049828 |
| 28 | alpha/beta outer-core Kenyon cell | FBbt_00049112 | Entity|Neuron|Adult|Anatomy|Nervous_system|Cel... | alpha/beta core Kenyon cell | FBbt_00110929 | |
| 29 | five-claw Kenyon cell | FBbt_00048000 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | multi-claw Kenyon cell | FBbt_00047994 | |
| 30 | alpha/beta core Kenyon cell | KCab-c | FBbt_00110929 | Entity|Neuron|Adult|Anatomy|Nervous_system|Cel... | alpha/beta surface/core Kenyon cell | FBbt_00049838 |
| 31 | multi-claw Kenyon cell | FBbt_00047994 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | Kenyon cell | FBbt_00003686 | |
| 32 | adult gamma Kenyon cell | FBbt_00049828 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | gamma Kenyon cell|adult Kenyon cell | FBbt_00100247|FBbt_00049825 | |
| 33 | three-claw Kenyon cell | FBbt_00047998 | Entity|Anatomy|Nervous_system|Cell|Neuron|Class | multi-claw Kenyon cell | FBbt_00047994 | |
| 34 | larval gamma Kenyon cell | FBbt_00049827 | Entity|Neuron|Anatomy|Nervous_system|Cell|Larv... | larval Kenyon cell|gamma Kenyon cell | FBbt_00049826|FBbt_00100247 | |
| 35 | gamma-s2 Kenyon cell | KCg-s2 | FBbt_00049788 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | gamma-s Kenyon cell | FBbt_00049830 |
| 36 | gamma-s Kenyon cell | FBbt_00049830 | Entity|Adult|Anatomy|Nervous_system|Cell|Neuro... | adult gamma Kenyon cell | FBbt_00049828 |
2.2 Methods for querying connectivity
Please see Connectivity Notebook for examples.
2 - Guide to Working with Images from Virtual Fly Brain (VFB) Using the VFBConnect Library
Prerequisites
Before starting, ensure you have the VFBConnect library installed. The recommended Python version is 3.10.14, as this version is tested against the library.
pip install vfb-connect
Importing the VFBConnect Library
Start by importing the VFBConnect library. This library provides a simple interface to interact with neuron data from the Virtual Fly Brain.
from vfb_connect import vfb
Retrieving Neuron Data
To work with specific neurons, you can use the vfb.term() function. This function takes a unique identifier (e.g., ID, label, synonym) for the neuron.
Example: Retrieving a Single Neuron
neuron = vfb.term('5th s-LNv (FlyEM-HB:511051477)')
The neuron variable now holds data about the neuron identified by the given term.
Working with Neuron Data
The retrieved neuron object can provide different representations of neuron data, such as its skeleton, mesh, and volume. These representations can be visualized using various plotting methods.
# Access the skeleton representation
neuron_skeleton = neuron.skeleton
# Check the type of the skeleton representation
print(type(neuron_skeleton)) # Output: <class 'navis.neuron.Neuron'>
# Plot the skeleton in 2D
neuron_skeleton.plot2d()
# Access the mesh representation
neuron_mesh = neuron.mesh
# Access the volume representation
neuron_volume = neuron.volume
Retrieving Multiple Neurons
You can retrieve multiple neurons using the vfb.terms() function, which accepts a list of neuron identifiers.
Example: Retrieving Multiple Neurons
neurons = vfb.terms(['5th s-LNv', 'fru-M-300008', 'catmaid_fafb:8876600'])
This command retrieves multiple neurons, which can then be visualized or manipulated collectively.
Flexible Matching Capabilities
One of the key features of the VFBConnect library is its flexible matching capability. The vfb.terms() function can accept a variety of identifiers, such as:
- IDs: Unique identifiers assigned to each neuron.
- Xref (Cross-references): External references that relate to other datasets.
- Labels: Human-readable names for neurons.
- Symbols: Abbreviated names or symbols used to represent neurons.
- Synonyms: Alternative names by which a neuron might be known.
- Partial Matching: You can provide a partial name, and VFBConnect will attempt to find the best match.
- Case Insensitive Matching: Matching is case insensitive, so if an exact match isn’t found, ‘5th s-LNv’ and ‘5TH S-LNV’ are treated the same. This allows for more flexible querying without worrying about exact case matching.
Example: Using Flexible Matching
neurons = vfb.terms('5th s-LN')
If an exact match isn’t found, VFBConnect will provide potential matches. This feature ensures that even with partial or approximate information, you can still retrieve the relevant neuron data.
Output Example:
Notice: No exact match found, but potential matches starting with '5th s-LN':
'5th s-LNv (FlyEM-HB:511051477)': 'VFB_jrchk8e0',
'5th s-LNv': 'VFB_jrchk8e0'
This notice will help you identify the correct neuron based on the closest matches.
Visualizing Neurons
VFBConnect provides various methods to visualize neuron data, both individually and collectively.
3D Visualization
To plot neurons in 3D, use the plot3d() method. This is useful for visualizing the spatial structure of neurons.
neurons.plot3d()
2D Visualization
For 2D visualization, use the plot2d() method.
neurons.plot2d()
Viewing Merged Templates
VFBConnect also allows viewing merged templates of neurons, combining multiple neuron structures into a single view.
neurons.show()
Opening Neurons in VFB
To open the neurons directly in Virtual Fly Brain, use the open() method. This will launch a browser window displaying the neurons in the VFB interface.
neurons.open()
Summary
- Use
vfb.term()to retrieve single neuron data. - Use
vfb.terms()to retrieve multiple neurons with support for partial, case-insensitive, and flexible matching (IDs, labels, symbols, synonyms, etc.). - Access different data representations (skeleton, mesh, volume) via neuron objects.
- Visualize neuron data in 2D and 3D.
- Use the
show()method to view merged neuron templates. - Open neuron data directly in Virtual Fly Brain with the
open()method.
These examples provide a foundation for working with neuron data from Virtual Fly Brain using the VFBConnect library. By exploring different neuron representations and visualization methods, you can analyze and understand neuron structures more effectively.
3 - Downloading Images from VFB Using VFBconnect
Introduction
VFBconnect is a Python package that provides an interface to the Virtual Fly Brain (VFB) API. It allows users to query the VFB database and download data, including images.
Installation
Before you can use VFBconnect, you need to install it. You can do this using pip:
pip install vfb-connect
Downloading Images
To download images from VFB using VFBconnect, you need to first import the package and create a client:
from vfb_connect.cross_server_tools import VfbConnect
vc = VfbConnect()
Next, you can use the get_images method to download images. This method requires the dataset ID as an argument:
dataset_id = 'your_dataset_id'
images = vc.get_images(dataset_id)
This will return a list of images from the specified dataset. Each image is represented as a dictionary with information such as the image ID, title, and URL.
To download the images, you can loop through the list and use the urlretrieve function from the urllib.request module:
import urllib.request
for image in images:
url = image['image_url']
filename = image['image_id'] + '.jpg'
urllib.request.urlretrieve(url, filename)
This will download each image and save it as a JPEG file in the current directory. The filename is the image ID.
Conclusion
This guide showed you how to use VFBconnect to download images from the Virtual Fly Brain based on a dataset. With VFBconnect, you can easily access and download data from VFB for your research.
4 - Programmatic search using SOLR
SOLR python example
an example using pysolr:
install:
pip install vfb-connect pysolr
example looking for label/name match:
import pysolr
solr = pysolr.Solr('https://solr.virtualflybrain.org/solr/ontology/')
term = 'medulla'
results = solr.search('label:"' + term + '"')
print(results.docs[0])
{'iri': ['http://purl.obolibrary.org/obo/FBbt_00003748'],
'obo_id_autosuggest': ['FBbt_00003748', 'FBbt:00003748', 'FBbt 00003748'],
'label_autosuggest': ['medulla', 'medulla', 'medulla'],
'synonym_autosuggest': ['ME', 'Med', 'optic medulla', 'm'],
'label': 'medulla',
'synonym': ['ME', 'Med', 'optic medulla', 'm'],
'short_form': 'FBbt_00003748',
'autosuggest': ['medulla', 'ME', 'Med', 'optic medulla', 'm'],
'facets_annotation': ['Entity',
'Adult',
'Anatomy',
'Class',
'Nervous_system',
'Synaptic_neuropil',
'Synaptic_neuropil_domain'],
'unique_facets': ['Nervous_system', 'Adult', 'Synaptic_neuropil_domain'],
'id': 'http://purl.obolibrary.org/obo/FBbt_00003748',
'shortform_autosuggest': ['FBbt_00003748', 'FBbt:00003748', 'FBbt 00003748'],
'obo_id': ['FBbt:00003748'],
'_version_': 1734360220689235970}
Note: any of the above fields can be searched (autosuggest being a combination of both label and synonyms)
5 - Exploring Neurons in Navis
TreeNeurons using navis.Overview
navis is a Python package for analysing, manipulating and visualizing neurons. Official documentation here.
Basic datatypes: neurons and neuron lists
navis knows three types of neurons:
TreeNeurons= skeletons, e.g. from CATMAIDMeshNeurons= meshes, e.g. from the hemibrain segmentationDotprops= points + tangent vectors (typically only used for NBLAST)
Collections of neurons are typically held in a specialized container: a NeuronList.
Neurons
In this notebook we will focus on skeletons - a.k.a. TreeNeurons - since this is what you get out of CATMAID. Let’s kick things off by having a look at what neurons look like once it’s loaded:
import navis
# Load one of the example neurons shipped with navis
# (these are olfactory projection neurons from the hemibrain data set)
n = navis.example_neurons(1, kind='skeleton')
# Print some basic info
n
WARNING: Could not load OpenGL library.
| type | navis.TreeNeuron |
|---|---|
| name | 1734350788 |
| id | 1734350788 |
| n_nodes | 4465 |
| n_connectors | None |
| n_branches | 603 |
| n_leafs | 619 |
| cable_length | 266457.994591 |
| soma | [4176] |
| units | 8 nanometer |
Above summary lists a couple of (computed) properties of the neuron. Each of those can also be accessed directly like so:
n.id
1734350788
There are many more properties that you might find interesting! Typing n. and pressing TAB should give auto-complete suggestions of available properties and methods. If your notebook editor has problems with that, you can fall back to using dir().
Here is an (incomplete) list of some of the more relevant properties:
bbox: bounding box of the neuroncable_length: cable lengthid: every neuron has an IDnodes: the SWC node table underlying the neuron
And some class methods:
reroot: reroot neuronplot2d/plot3d: plot the neuron (see also plotting turorial)copy: make and return a copyprune_twigs: remove small terminal twigs
As an example: this is how you get the ID of this neuron’s root node.
# Current root node of this neuron
n.root
array([1], dtype=int32)
Some of the properties such as .root or .ends are computed on-the-fly from the underlying raw data. For TreeNeurons that’s the node table (and its graph representation). The node table is a pandas DataFrame that looks effectively like a SWC:
# `.head()` gives us the first couple rows
n.nodes.head()
| node_id | label | x | y | z | radius | parent_id | type | |
|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 15784.0 | 37250.0 | 28102.0 | 10.000000 | -1 | root |
| 1 | 2 | 0 | 15764.0 | 37230.0 | 28102.0 | 18.284300 | 1 | slab |
| 2 | 3 | 0 | 15744.0 | 37190.0 | 28142.0 | 34.721401 | 2 | slab |
| 3 | 4 | 0 | 15744.0 | 37150.0 | 28182.0 | 34.721401 | 3 | slab |
| 4 | 5 | 0 | 15704.0 | 37130.0 | 28242.0 | 34.721401 | 4 | slab |
The methods (such as .reroot) are short-hands for main navis functions:
# Reroot neuron to another node
n2 = n.reroot(new_root=2)
# Print the new root -> expect "2"
n2.root
array([2])
# Instead of calling the shorthand method, we can also do this
n3 = navis.reroot_neuron(n, new_root=2)
n3.root
array([2])
NeuronLists
In practice you will likely work with multiple neurons at a time. For that, navis has a convenient container: NeuronLists
# Get more than one example neuron
nl = navis.example_neurons(5)
# `nl` is a NeuronList
type(nl)
navis.core.neuronlist.NeuronList
# You can also create neuron lists yourself
my_nl = navis.NeuronList(n)
In many ways NeuronLists work like Python-lists with a couple of extras:
# Calling just the neuronlist produces a summary
nl
| type | name | id | n_nodes | n_connectors | n_branches | n_leafs | cable_length | soma | units | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | navis.TreeNeuron | 1734350788 | 1734350788 | 4465 | None | 603 | 619 | 266457.994591 | [4176] | 8 nanometer |
| 1 | navis.TreeNeuron | 1734350908 | 1734350908 | 4845 | None | 733 | 760 | 304277.007958 | [6] | 8 nanometer |
| 2 | navis.TreeNeuron | 722817260 | 722817260 | 4336 | None | 635 | 658 | 274910.568784 | None | 8 nanometer |
| 3 | navis.TreeNeuron | 754534424 | 754534424 | 4702 | None | 697 | 727 | 286742.998887 | [4] | 8 nanometer |
| 4 | navis.TreeNeuron | 754538881 | 754538881 | 4890 | None | 626 | 642 | 291434.992623 | [703] | 8 nanometer |
# Get a single neuron from the neuronlist
nl[1]
| type | navis.TreeNeuron |
|---|---|
| name | 1734350908 |
| id | 1734350908 |
| n_nodes | 4845 |
| n_connectors | None |
| n_branches | 733 |
| n_leafs | 760 |
| cable_length | 304277.007958 |
| soma | [6] |
| units | 8 nanometer |
neuronlists also support fancy indexing similar to numpy arrays:
# Get multiple neurons from the neuronlist
nl[[1, 2]]
| type | name | id | n_nodes | n_connectors | n_branches | n_leafs | cable_length | soma | units | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | navis.TreeNeuron | 1734350908 | 1734350908 | 4845 | None | 733 | 760 | 304277.007958 | [6] | 8 nanometer |
| 1 | navis.TreeNeuron | 722817260 | 722817260 | 4336 | None | 635 | 658 | 274910.568784 | None | 8 nanometer |
# Slicing is also supported
nl[1:3]
| type | name | id | n_nodes | n_connectors | n_branches | n_leafs | cable_length | soma | units | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | navis.TreeNeuron | 1734350908 | 1734350908 | 4845 | None | 733 | 760 | 304277.007958 | [6] | 8 nanometer |
| 1 | navis.TreeNeuron | 722817260 | 722817260 | 4336 | None | 635 | 658 | 274910.568784 | None | 8 nanometer |
Strings will be matched against the neurons’ names.
# Get neuron(s) by their name
nl['754534424']
| type | name | id | n_nodes | n_connectors | n_branches | n_leafs | cable_length | soma | units | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | navis.TreeNeuron | 754534424 | 754534424 | 4702 | None | 697 | 727 | 286742.998887 | [4] | 8 nanometer |
neuronlists have a special .idx indexer that let’s you select neurons by their ID
# Get neuron(s) by their ID
# -> note that for example neurons name == id
nl.idx[[754534424, 722817260]]
| type | name | id | n_nodes | n_connectors | n_branches | n_leafs | cable_length | soma | units | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | navis.TreeNeuron | 754534424 | 754534424 | 4702 | None | 697 | 727 | 286742.998887 | [4] | 8 nanometer |
| 1 | navis.TreeNeuron | 722817260 | 722817260 | 4336 | None | 635 | 658 | 274910.568784 | None | 8 nanometer |
# Access properties across neurons -> returns numpy arrays
nl.n_nodes
array([4465, 4845, 4336, 4702, 4890])
# Select neurons by given property
# -> this works with any boolean array
nl[nl.n_nodes >= 4500]
| type | name | id | n_nodes | n_connectors | n_branches | n_leafs | cable_length | soma | units | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | navis.TreeNeuron | 1734350908 | 1734350908 | 4845 | None | 733 | 760 | 304277.007958 | [6] | 8 nanometer |
| 1 | navis.TreeNeuron | 754534424 | 754534424 | 4702 | None | 697 | 727 | 286742.998887 | [4] | 8 nanometer |
| 2 | navis.TreeNeuron | 754538881 | 754538881 | 4890 | None | 626 | 642 | 291434.992623 | [703] | 8 nanometer |
Exercises:
- Select the first and the last neuron in the neuronlist
- Select all neurons with a soma
- Select all neurons with a soma and less than 300,000 cable length
Further reading: https://navis.readthedocs.io/en/latest/source/tutorials/neurons_intro.html
6 - Plotting Neurons with Navis
Plotting
navis lets you plot neurons in 2D using matplotlib (nice for figures), and in 3D using either plotly when in a notebook environment like Deepnote or using a vispy-based 3D viewer when using a Python terminal.
import navis
# This is relevant because Deepnote does not (yet) support fancy progress bars
navis.set_pbars(jupyter=False)
# Load one of the example neurons shipped with navis
n = navis.example_neurons(1, kind='skeleton')
WARNING: Could not load OpenGL library.
# Make a 2d plot
fig, ax = navis.plot2d(n)
# Note that this is equivalent to
# fig, ax = n.plot2d()

If you have seen an olfactory projection neuron before, you might have noticed that this neuron is upside-down. That’s because hemibrain neurons have an odd orienation in that the anterior-posterior axis is not the z- but the y-axis (they were imaged from above).
For us that just means we have to turn the camera ourselves if we want a frontal view:
# Make a 2d plot
fig, ax = navis.plot2d(n)
# Change camera (azimuth + elevation)
ax.azim, ax.elev = -90, -90

Let’s do the same in 3d:
# Get a list of neurons
nl = navis.example_neurons(5)
# Plot
navis.plot3d(nl, width=1000)
Navigation:
- left click and drag to rotate (select “Orbital rotation” above the legend to make your life easier)
- mousewheel to zoom
- middle-mouse + drag to translate
- click legend items (single or double) to hide/unhide
Above plots are very basic examples but there are a ton of ways to tweak things to your liking. For a full list of parameters check out the docs for plot2d and plot3d.
Let’s for example change the colors. In general, colors can be:
- a string - e.g.
"red"or just"r" - an rgb/rgba tuple - e.g.
(1, 0, 0)for red
# Plot all neurons in red
fig, ax = navis.plot2d(n, color='r')
ax.azim, ax.elev = -90, -90

# Plot all neurons in red (color as tuple)
fig, ax = navis.plot2d(n, color=(1, 0, 0, 1))
ax.azim, ax.elev = -90, -90

When plotting multiple neurons you can either use:
- a single color (
"r"or(1, 0, 0)) -> assigned to all neurons - a list of colors (
['r', 'yellow', (0, 0, 1)]) with a color for each neuron - a dictionary mapping neuron IDs to colors (
{1734350788: 'r', 1734350908: (1, 0, 1)}) - the name of a
matplotliborseaborncolor palette
# Plot with a specific color palette
navis.plot3d(nl, color='jet')
Exercises:
- Assign rainbow colors -
"red","orange","yellow","green"and"blue"- as list - Use a dictionary to make neurons
1734350788and1734350908green, and neurons722817260,754534424and754538881red
Volumes
plot2d and plot3d also let you plot meshes. Internally these are represented as navis.Volumes (a subclass of trimesh.Trimesh):
# navis ships with a neuropil volume (in hemibrain space)
vol = navis.example_volume('neuropil')
vol
<navis.Volume(name=neuropil, color=(0.85, 0.85, 0.85, 0.2), vertices.shape=(8997, 3), faces.shape=(18000, 3))>
To plot, simply pass it to the respective plotting function:
navis.plot3d([nl, vol])
Under the hood, Volumes are treated a bit differently from neurons. So if you want to change the color, you need to do so on the object:
# Give the neuropil a reddish color
vol.color = (1, .8, .8, .4)
navis.plot3d([nl, vol], width=800)
Scatter plots
Because scatter plots are a common way of visualizing 3D data, both plot2d and plot3d provide a quick interface: (N, 3) numpy arrays and pandas.DataFrames with x, y, and z columns are interpreted as data for a scatter plot:
# Get all branch points from the node table
bp = n.branch_points
bp.head()
| node_id | label | x | y | z | radius | parent_id | type | |
|---|---|---|---|---|---|---|---|---|
| 5 | 6 | 5 | 15678.400391 | 37086.300781 | 28349.400391 | 48.011600 | 5 | branch |
| 8 | 9 | 5 | 15159.400391 | 36641.500000 | 28392.900391 | 231.296997 | 8 | branch |
| 9 | 10 | 5 | 15144.000000 | 36710.000000 | 28142.000000 | 186.977005 | 9 | branch |
| 10 | 11 | 5 | 15246.400391 | 36812.398438 | 28005.500000 | 104.261002 | 10 | branch |
| 11 | 12 | 5 | 15284.000000 | 36850.000000 | 27882.000000 | 53.245602 | 11 | branch |
# Since `bp` contains x/y/z columns, we can pass it directly to the plotting functions
navis.plot3d([n, bp],
c='k', # make the neuron black
scatter_kws=dict(color='r') # make the markers red
)
Fine-tuning figures
plot2d and plot3d provide a high-level interface to get your neurons on/in a matplotlib or a plotly figure, respectively. You can always use lower-level matplotlib/plotly interfaces directly to add more data or manipulate the figure. Just a cheap example:
# Plot neuron on a matplotlib figure
fig, ax = navis.plot2d(n, color='r')
# Show the neuron at a slight angle
ax.azim, ax.elev = -60, -60
# Zoom out a bit more
ax.dist = 8 # default is 7
# Unhide axes
ax.set_axis_on()
# Label the axes
ax.set_xlabel('x-axis [8 nm voxels]')
ax.set_ylabel('y-axis [8 nm voxels]')
ax.set_zlabel('z-axis [8 nm voxels]')
Text(0.5, 0, 'z-axis [8 nm voxels]')

This concludes this brief introduction to plotting but just to note that plot2d and plot3d have a lot of additional functionality to customize the way neurons are plotted. If you have time on your hands, I recommend you check out and play around with the available parameters (e.g. linewidth, color_by, shade_by, linestyle).
7 - pymaid
Overview
pymaid lets you interface with a CATMAID server. It’s built on top of navis and returns data (neurons, volumes) in a way that you can plug them straight into navis to use features such as plotting.
Official documentation here.
Connecting
The VFB CATMAID servers (see here for what’s available) are public and don’t require an API token for read-only access which makes connecting simple:
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
Retrieving neurons
Let’s start with pulling a neuron based on its ID:
# Find a neuron from its ID (16) -> this is an olfactory projection neuron
n = pymaid.get_neurons(16)
n
| type | CatmaidNeuron |
|---|---|
| name | Uniglomerular mALT VA6 adPN 017 DB |
| id | 16 |
| n_nodes | 16840 |
| n_connectors | 2158 |
| n_branches | 1172 |
| n_leafs | 1230 |
| cable_length | 4003103.232861 |
| soma | [2941309] |
| units | 1 nanometer |
This neuron’s type is pymaid.CatmaidNeuron, which is a subclass of navis.TreeNeuron. The list version is pymaid.CatmaidNeuronList, which a subclass of navis.NeuronList. This adds a bit of extra functionality (such as lazy loading of data) and allows CatmaidNeuron and CatmaidNeuronList work as drop in replacements for their parent classes.
# Plot CatmaidNeuron with navis
navis.plot3d(n, width=1000, connectors=True, c='k')