Examples of different co-plotting with flywire

This section contains several examples of different ways of manipulating flywire instances and co-plotting neurons, synapses as annotations

Import neccesary library modules now

[1]:
import navis
import fafbseg
import pymaid
[2]:
import pandas as pd
import numpy as np
import os
from copy import deepcopy
import glob
[3]:
from pyroglancer.flywire import flywireurl2dict, add_flywirelayer

Example 1: Add segments to empty config in flywire..

[4]:
layer_kws = {'type': 'segments',
             'segmentid': 720575940620589336,
             'color': 'cyan','alpha': 0.8
             }
[5]:
flywireurl = add_flywirelayer(layer_kws=layer_kws)
flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/4557723320451072

alt text1

[6]:
#add some more now..
layer_kws = {'type': 'segments',
             'segmentid': [720575940638461392,720575940607092337],
             'color': ['yellow', 'red']}
[7]:
flywireurl = add_flywirelayer(flywireurl2dict(flywireurl), layer_kws)
flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5112535262953472

alt text2

Example 2: Display neurons as annotations in flywire, that can be directly shared in short urls

[8]:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath("__file__")))))
BASE_DIR
[8]:
'/Users/sri/Documents/Python/pyroglancer'
[9]:
swc_path = os.path.join(BASE_DIR, 'pyroglancer/data/swc')
swc_files = glob.glob(os.path.join(swc_path, '57*.swc'))
[10]:
neuronlist = []
neuronlist += [navis.read_swc(f, units='8 nm', connector_labels={'presynapse': 7, 'postsynapse': 8},
                              id=int(os.path.splitext(os.path.basename(f))[0])) for f in swc_files]
neuronlist = navis.core.NeuronList(neuronlist)
INFO - 2021-05-19 23:34:11,112 - utils - NumExpr defaulting to 8 threads.
[11]:
neuronlist
[11]:
<class 'navis.core.neuronlist.NeuronList'> containing 2 neurons (314.0KiB)
type name id n_nodes n_connectors n_branches n_leafs cable_length soma units
0 navis.TreeNeuron 57323 57323 6223 414 256 268 1483462.250 [2579] 8 nanometer
1 navis.TreeNeuron 57311 57311 5543 398 211 219 1364103.125 [3187] 8 nanometer
[12]:
flywire_neuron = navis.xform_brain(neuronlist, source='FAFB14', target='FLYWIRE')
Transform path: FAFB14 -> FAFB14raw -> FLYWIREraw -> FLYWIRE
[13]:
#resample the neurons otherwise large annotations will slow down the interface..
flywire_neuron = navis.resample_neuron(flywire_neuron, resample_to=1000*8, inplace=False)
[14]:
#this url has the relevant segments for the neurons..
shorturl = 'https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5728630604824576'
ngdict = flywireurl2dict(shorturl)
[15]:
layer_kws = {'type': 'skeletons', 'source': flywire_neuron, 'annotationstatetype': 'in-json',
             'color': 'white',
             'scale': [4,4,40] #scale the voxel to physical coords
            }
[16]:
flywireurl = add_flywirelayer(ngdict, layer_kws)
using  voxel space with scale:  [4, 4, 40]
color is: ['#ffffff']
color is: ['#ffffff']
flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/6110186091577344

alt text3

Example 3: Display synapses as annotations in flywire, that can be directly shared in short urls

[17]:
ngdict = flywireurl2dict(flywireurl)
[18]:
layer_kws = {'type': 'synapses', 'source': flywire_neuron, 'annotationstatetype': 'in-json',
             'color': ['red', 'blue'],
             'scale': [4,4,40] #scale the voxel to physical coords
            }
[19]:
flywireurl = add_flywirelayer(ngdict, layer_kws)
using  voxel space with scale:  [4, 4, 40]
flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5547236138156032

alt text4