Mapping

If you have a single neuron, how can you find other neurons of the same or similar type within or between data sources?
!pip install vfb-connect --upgrade
# 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}')

# Many functions return JSON-compatible nested data structures. This function coverts them to DataFrame.
def summary_2_df(summary, sort=None):
    """Convert summary to DataFrame.  Optionally specify a set of columns to sort as a list of strings"""
    if sort:
        return pd.DataFrame.from_records(summary).sort_values(sort)
    else:
        return pd.DataFrame.from_records(summary)
WARNING: Could not load OpenGL library.
INFO  : Global CATMAID instance set. Caching is ON. (pymaid)
Server is running CATMAID version 2020.02.15-925-gf56795c9c

Mapping

Use case: If I have a single neuron, how can I find other neurons of the same or similar type within or between data sources?

Mapping via common parent type

# lets take some examples from a discovery query on the previous spreadhseet
sayin_tab = pd.DataFrame.from_records(vc.get_instances_by_dataset('Sayin2019', summary=True))
sayin_tab

label symbol id tags parents_label parents_id data_source accession templates dataset license
0 OA-VPM3 (FAFB:1329078) VFB_001001dr Entity|Octopaminergic|Adult|Anatomy|has_image|... octopaminergic VPM3 neuron FBbt_00110151 catmaid_fafb 1329078 JRC2018Unisex Sayin2019 https://creativecommons.org/licenses/by-sa/4.0...
1 OA-VPM4 (FAFB:1191261) VFB_001001dq Entity|Octopaminergic|Adult|Anatomy|has_image|... octopaminergic VPM4 neuron FBbt_00110152 catmaid_fafb 1191261 JRC2018Unisex Sayin2019 https://creativecommons.org/licenses/by-sa/4.0...
oct_VPM3 = summary_2_df(vc.get_instances('octopaminergic VPM3 neuron', summary=True))
oct_VPM3

label symbol id tags parents_label parents_id data_source accession templates dataset license
0 OA-VPM3(NO2/NO3)_R - 329566174 VFB_jrchk10d Entity|Octopaminergic|Adult|Anatomy|has_image|... octopaminergic VPM3 neuron FBbt_00110151 neuprint_JRC_Hemibrain_1point1 329566174 JRC2018Unisex|JRC_FlyEM_Hemibrain Xu2020NeuronsV1point1 https://creativecommons.org/licenses/by/4.0/le...
1 OA-VPM3(NO2/NO3)_L - 5813061260 VFB_jrchk10e Entity|Octopaminergic|Adult|Anatomy|has_image|... octopaminergic VPM3 neuron FBbt_00110151 neuprint_JRC_Hemibrain_1point1 5813061260 JRC_FlyEM_Hemibrain|JRC2018Unisex Xu2020NeuronsV1point1 https://creativecommons.org/licenses/by/4.0/le...
2 OA-VPM3 (FAFB:1329078) VFB_001001dr Entity|Octopaminergic|Adult|Anatomy|has_image|... octopaminergic VPM3 neuron FBbt_00110151 catmaid_fafb 1329078 JRC2018Unisex Sayin2019 https://creativecommons.org/licenses/by-sa/4.0...
oct_VPM3_images = vc.neo_query_wrapper.get_images(oct_VPM3['id'], stomp=True, template='JRC2018Unisex', image_folder = 'oct_VPM3b')
oct_VPM3_images

label symbol id tags parents_label parents_id data_source accession templates dataset license filename
0 OA-VPM3 (FAFB:1329078) VFB_001001dr Entity|Octopaminergic|Adult|Anatomy|has_image|... octopaminergic VPM3 neuron FBbt_00110151 catmaid_fafb 1329078 JRC2018Unisex Sayin2019 https://creativecommons.org/licenses/by-sa/4.0... OA_VPM3__FAFB_1329078_.swc
1 OA-VPM3(NO2/NO3)_L - 5813061260 VFB_jrchk10e Entity|Octopaminergic|Adult|Anatomy|has_image|... octopaminergic VPM3 neuron FBbt_00110151 neuprint_JRC_Hemibrain_1point1 5813061260 JRC_FlyEM_Hemibrain|JRC2018Unisex Xu2020NeuronsV1point1 https://creativecommons.org/licenses/by/4.0/le... OA_VPM3_NO2_NO3__L___5813061260.swc
2 OA-VPM3(NO2/NO3)_R - 329566174 VFB_jrchk10d Entity|Octopaminergic|Adult|Anatomy|has_image|... octopaminergic VPM3 neuron FBbt_00110151 neuprint_JRC_Hemibrain_1point1 329566174 JRC2018Unisex|JRC_FlyEM_Hemibrain Xu2020NeuronsV1point1 https://creativecommons.org/licenses/by/4.0/le... OA_VPM3_NO2_NO3__R___329566174.swc
oct_VPM3_images = vc.get_images_by_type('octopaminergic VPM3 neuron', stomp=True, template='JRC2018Unisex', image_folder = 'oct_VPM3')
nl = navis.read_swc('./oct_VPM3')
navis.plot3d(nl)
Running query: FBbt:00110151
Query URL: http://owl.virtualflybrain.org/kbs/vfb/instances?object=FBbt%3A00110151&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: 3

Mapping via NBLAST

VFB supports image based queries that find neurons with similar morphology to a query neuron. We use a matrix of NBLAST scores for this purpose. This currently covers mapping between FAFB & Hemibrain and internal mappings within the hemibrain and FLyCircuit neurons. More mappings will be added soon, as well as support for other similarity mappings.

summary_2_df(vc.neo_query_wrapper.get_anatomical_individual_TermInfo(['VFB_001012ay'], summary=True))

label symbol id tags parents_label parents_id data_source accession templates dataset license
0 EPG-6L#1 (FAFB:676911) VFB_001012ay Entity|has_image|Adult|Anatomy|has_neuron_conn... EB-PB glomerulus 6-Vgall neuron FBbt_00111421 catmaid_fafb 676911 JRC2018Unisex Turner_Evans2020 https://creativecommons.org/licenses/by-sa/4.0...
similar_to_EPG6L1 = vc.get_similar_neurons('VFB_001012ay')
similar_to_EPG6L1 

id NBLAST_score label types source_id accession_in_source
0 VFB_jrchjtk6 0.525 EPG(PB08)_L6 - 541870397 [EB-PB 1 glomerulus-D/Vgall neuron] neuprint_JRC_Hemibrain_1point1 541870397
1 VFB_jrchjtk8 0.524 EPG(PB08)_L6 - 912601268 [EB-PB 1 glomerulus-D/Vgall neuron] neuprint_JRC_Hemibrain_1point1 912601268
2 VFB_jrchjtkb 0.504 EPG(PB08)_L6 - 788794171 [EB-PB 1 glomerulus-D/Vgall neuron] neuprint_JRC_Hemibrain_1point1 788794171
3 VFB_jrchjtji 0.481 EL(EQ5)_L - 1036753721 [EBw.AMP.s-Dga-s.b neuron] neuprint_JRC_Hemibrain_1point1 1036753721
EPG6L1_similar_images = vc.neo_query_wrapper.get_images(list(similar_to_EPG6L1['id']) + ['VFB_001012ay'], 
                                template='JRC2018Unisex',
                                image_folder='EPG6L1',
                                stomp=True) # Note - stomp allows an existing folder to be over-written


EPG6L1_similar_images

label symbol id tags parents_label parents_id data_source accession templates dataset license filename
0 EL(EQ5)_L - 1036753721 VFB_jrchjtji Entity|has_image|Adult|Anatomy|has_neuron_conn... EBw.AMP.s-Dga-s.b neuron FBbt_00049180 neuprint_JRC_Hemibrain_1point1 1036753721 JRC_FlyEM_Hemibrain|JRC2018Unisex Xu2020NeuronsV1point1 https://creativecommons.org/licenses/by/4.0/le... EL_EQ5__L___1036753721.swc
1 EPG(PB08)_L6 - 788794171 VFB_jrchjtkb Entity|has_image|Adult|Anatomy|has_neuron_conn... EB-PB 1 glomerulus-D/Vgall neuron FBbt_00047030 neuprint_JRC_Hemibrain_1point1 788794171 JRC_FlyEM_Hemibrain|JRC2018Unisex Xu2020NeuronsV1point1 https://creativecommons.org/licenses/by/4.0/le... EPG_PB08__L6___788794171.swc
2 EPG-6L#1 (FAFB:676911) VFB_001012ay Entity|has_image|Adult|Anatomy|has_neuron_conn... EB-PB glomerulus 6-Vgall neuron FBbt_00111421 catmaid_fafb 676911 JRC2018Unisex Turner_Evans2020 https://creativecommons.org/licenses/by-sa/4.0... EPG_6L_1__FAFB_676911_.swc
3 EPG(PB08)_L6 - 912601268 VFB_jrchjtk8 Entity|has_image|Adult|Anatomy|has_neuron_conn... EB-PB 1 glomerulus-D/Vgall neuron FBbt_00047030 neuprint_JRC_Hemibrain_1point1 912601268 JRC2018Unisex|JRC_FlyEM_Hemibrain Xu2020NeuronsV1point1 https://creativecommons.org/licenses/by/4.0/le... EPG_PB08__L6___912601268.swc
4 EPG(PB08)_L6 - 541870397 VFB_jrchjtk6 Entity|has_image|Adult|Anatomy|has_neuron_conn... EB-PB 1 glomerulus-D/Vgall neuron FBbt_00047030 neuprint_JRC_Hemibrain_1point1 541870397 JRC_FlyEM_Hemibrain|JRC2018Unisex Xu2020NeuronsV1point1 https://creativecommons.org/licenses/by/4.0/le... EPG_PB08__L6___541870397.swc
list(EPG6L1_similar_images['parents_label'])
['EBw.AMP.s-Dga-s.b neuron',
 'EB-PB 1 glomerulus-D/Vgall neuron',
 'EB-PB glomerulus 6-Vgall neuron',
 'EB-PB 1 glomerulus-D/Vgall neuron',
 'EB-PB 1 glomerulus-D/Vgall neuron']
import trimesh

jrc2018u = trimesh.load_remote('https://github.com/schlegelp/navis-flybrains/raw/main/flybrains/meshes/JRC2018U.ply')
jrc2018u = navis.Volume(jrc2018u, color=(.9, .9, .9, .1), name='JRC2018U')
jrc2018u
<navis.Volume(name=JRC2018U, color=(0.9, 0.9, 0.9, 0.1), vertices.shape=(11943, 3), faces.shape=(24558, 3))>
import matplotlib.pyplot as plt

# nl = navis.read_swc('./EPG6L1')
fig, ax = navis.plot2d([nl, jrc2018u], figsize=(12, 12), method='3d_complex')

ax.elev = -90
ax.azim = -90
ax.dist = 5

#plt.savefig('EPG6L1.png', transparent=True, dpi=400)

png

## Generate a link to display these neurons on VFB

print(vc.get_vfb_link(list(similar_to_EPG6L1['id']) + ['VFB_001012ay'], template='JRC2018Unisex'))
https://v2.virtualflybrain.org/org.geppetto.frontend/geppetto?id=VFB_001012ay&i=VFB_00101567,VFB_jrchjtk6,VFB_jrchjtk8,VFB_jrchjtkb,VFB_jrchjtji

Note: to clean up ‘spiky’ neurons with obvious alignment issues you can use the navis function despike


Last modified January 27, 2022: reverting to list (dd75b36)