<jupyter_start><jupyter_text>Co-plotting split-gal4 line, hemibrain skeleton with flywire dataset  This section contains example of split-gal4 line, skeleton from hemibrain dataset and co-plotting with a flywire instance  Import neccesary library modules now<jupyter_code>import navis
import fafbseg
import flybrains
import os
import numpy as np
import pandas as pd
import copy
import trimesh as tm
import navis
from vfb_connect.cross_server_tools import VfbConnect
from pyroglancer.localserver import startdataserver, closedataserver
from pyroglancer.flywire import flywireurl2dict, flywiredict2url, add_flywirelayer, set_flywireviewerstate
from pyroglancer.utils import pointcloud2meshes, obj2pointcloud
import navis.interfaces.neuprint as neu
from navis.interfaces.neuprint import NeuronCriteria as NC, SynapseCriteria as SC<jupyter_output><empty_output><jupyter_text>Get the Split-Gal4 line Select the gal4 line you are interested in  for example, here I choose the line R65G01 from the neuronbridge website [here](https://neuronbridge.janelia.org/search?q=R65G01)  Convert the gal4 line to either a mesh ( a bit efficient) or to a skeleton (involves manual processing) *Using a mesh object*: Go to the virtualflybrain site like [here](https://v2.virtualflybrain.org/org.geppetto.frontend/geppetto?id=VFB_00023647&i=VFB_00101567,VFB_00023647) and get the vfb id here: VFB_00023647 *Using a skeleton object*: 1) Download the above line as *.nrrd* by following the link to the virtualflybrain site like [here](https://v2.virtualflybrain.org/org.geppetto.frontend/geppetto?id=VFB_00023647&i=VFB_00101567,VFB_00023647)  2) Use the *.nrrd* file in FiJi and skeletonise using the simple image tracer as illustrated in this video [here](https://youtu.be/xdqAb1fC91I) 3) Save the skeletonised file as *.swc* format The rest of the tutorial only involves the mesh object based co-visualisation<jupyter_code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath("__file__")))))
BASE_DIR
# vfb_neuron = navis.read_swc(swc_files, delimiter='\s+',units = 'um')
# swc_files = os.path.join(BASE_DIR, 'data/snt_tracings/VFB_00023647_snt_skel-000.swc')
# navis.health_check(vfb_neuron)
# vfb_neuron = navis.graph.clinic.merge_duplicate_nodes(vfb_neuron)
#utility function for transforming vfbids to meshes
def vfbid2mesh(vfb_id):
    vc = VfbConnect()
    vcinfo = vc.neo_query_wrapper.get_anatomical_individual_TermInfo([vfb_id])
    image_url = vcinfo[0]['channel_image'][0]['image']['image_folder'] + 'volume.obj'
    print('point cloud located at: ', image_url)
    pcd = obj2pointcloud(image_url)
    vfb_mesh = pointcloud2meshes(pcd, algorithm='rollingball')
    return vfb_mesh
vfbmeshes_dict = {}
vfbmeshes_dict['VFB_00023647'] = vfbid2mesh('VFB_00023647')
vfbmeshes_dict['VFB_00020203'] = vfbid2mesh('VFB_00020203')
jrc2018u_mesh = navis.Volume(flybrains.JRC2018U.mesh)
vfbmeshes_dict['VFB_00023647'].name = 'ilPN'
vfbmeshes_dict['VFB_00023647'].color = 'magenta'
vfbmeshes_dict['VFB_00020203'].name = 'DM5'
vfbmeshes_dict['VFB_00020203'].color = 'red'
fig, ax = navis.plot2d([vfbmeshes_dict['VFB_00023647'],jrc2018u_mesh], method='2d')
fig.gca().invert_yaxis()
fig<jupyter_output><empty_output><jupyter_text>Set configurations to fetch from data from neuprint<jupyter_code>neuprint_token = os.environ['NEUPRINT_APPLICATION_CREDENTIALS']
client = neu.Client('https://neuprint.janelia.org/', dataset='hemibrain:v1.1', token=neuprint_token)
client<jupyter_output><empty_output><jupyter_text>Get the matching skid from neuprint using the info from neuronbridge website like [here](https://neuronbridge.janelia.org/search/lines/R65G01/matches/2711776921103892491)<jupyter_code>hemibrain_skel = neu.fetch_skeletons(1912789965, heal=1000, max_threads=30)<jupyter_output>INFO - 2021-06-07 08:45:48,706 - utils - NumExpr defaulting to 8 threads.<jupyter_text>Transform them to flywire space<jupyter_code>#vfb_neuron=navis.xform_brain(vfb_neuron,source='JRC2018U', target='FLYWIRE')
vfb2flywiremeshes = {}
vfb2flywiremeshes['VFB_00023647'] = navis.xform_brain(vfbmeshes_dict['VFB_00023647'],source='JRC2018U', target='FLYWIRE')
vfb2flywiremeshes['VFB_00020203'] = navis.xform_brain(vfbmeshes_dict['VFB_00020203'],source='JRC2018U', target='FLYWIRE')
hemibrain2flywire_skel=navis.xform_brain(hemibrain_skel,source='JRCFIB2018Fraw', target='FLYWIRE')<jupyter_output>Transform path: JRCFIB2018Fraw -> JRCFIB2018F -> JRCFIB2018Fum -> JRC2018F -> FAFB14um -> FAFB14 -> FAFB14raw -> FLYWIREraw -> FLYWIRE<jupyter_text>Start the dataserver to host precomputed data<jupyter_code>startdataserver()<jupyter_output>Closing server at http://127.0.0.1:8000
Cleaning directory at /private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmpd8yw3_fb
Serving data from:  /<KEY>
Serving directory at http://127.0.0.1:8000<jupyter_text>Get the url from flywire to append data onto<jupyter_code>shorturl = 'https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5169621741076480'
#This flywire segments has some stuff similar (in blue), you will notice their closeness in the final plot<jupyter_output><empty_output><jupyter_text>Add bodyids to flywire layers<jupyter_code># vfb_neuron.id = 1234
# matchingneurons = navis.NeuronList(vfb_neuron)
# matchingneurons += hemibrain2flywire_skel
tmpviewer = add_flywirelayer(flywireurl2dict(shorturl), layer_kws = {'type': 'skeletons',
                                                                     'source': hemibrain2flywire_skel,
                                                                     'color': ['red'],
                                                                     'name':'hemibrain_1912789965'
                                                                     #'space': 'FAFBv14.1',
                                                                     #'annotationstatetype': 'precomputed'
                                                                    }) 
#'alpha': 0.3, doesn't work yet in skeleton layers..
vfb2flywiremeshes['VFB_00023647'].id = 23647
vfb2flywiremeshes['VFB_00020203'].id = 20203
vfb2flywiremeshes
tmpviewer = add_flywirelayer(flywireurl2dict(tmpviewer), layer_kws = {'type': 'volumes','name': 'vfb_' + vfbmeshes_dict['VFB_00023647'].name,
                                                        'source': vfb2flywiremeshes['VFB_00023647'],'color': 'magenta'})
# if you want to add the next vfb neuron..
tmpviewer = add_flywirelayer(flywireurl2dict(tmpviewer), layer_kws = {'type': 'volumes','name': 'vfb_' + vfbmeshes_dict['VFB_00020203'].name,
                                                        'source': vfb2flywiremeshes['VFB_00020203'],'color': 'blue'})
#tmpviewer,shorturl = set_flywireviewerstate(tmpviewer, axis_lines=False, bounding_box=False)
# # if you want to add everything in one tab (source)..
# tmpviewer = add_flywirelayer(flywireurl2dict(tmpviewer), layer_kws = {'type': 'volumes',
#                                                                       'name': 'vfb_meshes',
#                                                                       'source': list(vfb2flywiremeshes.values()),
#                                                                       'color': ['magenta','blue']})<jupyter_output><empty_output><jupyter_text>Screenshot of the flywire instance  The magenta neuron is the gal4line from vfb whereas the red neuron is the corresponding match from hemibrain according to neuronbridge and the green neuron is the corresponding flywire segment that is closest match ![alt text](pics/gal4line_hemibrain2flywire.png "hemibrain2flywire")  Close the dataserver<jupyter_code>closedataserver()<jupyter_output>Closing server at http://127.0.0.1:8000
Cleaning directory at /private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmph11kfa8u
{'fraction_non_alphanumeric': 0.10248526774276198, 'fraction_numerical': 0.0622598001537279, 'mean_word_length': 4.082682291666667, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 42, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 31, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '225877', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2929, 'n_tokens_neox': 2605, 'n_words': 520, 'path': 'docs/source/tutorials/gal4line2flywire.ipynb', 'repo_name': 'dokato/pyroglancer', 'size': '7860'}