{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Examples of different co-plotting with flywire" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### This section contains several examples of different ways of manipulating flywire instances and co-plotting neurons, synapses as annotations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import neccesary library modules now" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import navis\n", "import fafbseg\n", "import pymaid" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import os\n", "from copy import deepcopy\n", "import glob" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from pyroglancer.flywire import flywireurl2dict, add_flywirelayer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 1: Add segments to empty config in flywire.." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "layer_kws = {'type': 'segments',\n", " 'segmentid': 720575940620589336,\n", " 'color': 'cyan','alpha': 0.8\n", " }" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/4557723320451072\n" ] } ], "source": [ "flywireurl = add_flywirelayer(layer_kws=layer_kws)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![alt text1](pics/flywire_example_01.png \"adding segments to empty configuration\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#add some more now..\n", "layer_kws = {'type': 'segments',\n", " 'segmentid': [720575940638461392,720575940607092337],\n", " 'color': ['yellow', 'red']}" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5112535262953472\n" ] } ], "source": [ "flywireurl = add_flywirelayer(flywireurl2dict(flywireurl), layer_kws)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![alt text2](pics/flywire_example_02.png \"adding more segments to existing configuration\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 2: Display neurons as annotations in flywire, that can be directly shared in short urls" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'/Users/sri/Documents/Python/pyroglancer'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(\"__file__\")))))\n", "BASE_DIR" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "swc_path = os.path.join(BASE_DIR, 'pyroglancer/data/swc')\n", "swc_files = glob.glob(os.path.join(swc_path, '57*.swc'))" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO - 2021-05-19 23:34:11,112 - utils - NumExpr defaulting to 8 threads.\n" ] } ], "source": [ "neuronlist = []\n", "neuronlist += [navis.read_swc(f, units='8 nm', connector_labels={'presynapse': 7, 'postsynapse': 8},\n", " id=int(os.path.splitext(os.path.basename(f))[0])) for f in swc_files]\n", "neuronlist = navis.core.NeuronList(neuronlist)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "<class 'navis.core.neuronlist.NeuronList'> containing 2 neurons (314.0KiB)
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
typenameidn_nodesn_connectorsn_branchesn_leafscable_lengthsomaunits
0navis.TreeNeuron573235732362234142562681483462.250[2579]8 nanometer
1navis.TreeNeuron573115731155433982112191364103.125[3187]8 nanometer
\n", "
" ], "text/plain": [ " containing 2 neurons (314.0KiB)\n", " type name id n_nodes n_connectors n_branches n_leafs \\\n", "0 navis.TreeNeuron 57323 57323 6223 414 256 268 \n", "1 navis.TreeNeuron 57311 57311 5543 398 211 219 \n", "\n", " cable_length soma units \n", "0 1483462.250 [2579] 8 nanometer \n", "1 1364103.125 [3187] 8 nanometer " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "neuronlist" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Transform path: FAFB14 -> FAFB14raw -> FLYWIREraw -> FLYWIRE\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bfb1aa13c13c442bba527afeba48b172", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(HTML(value='Xforming'), FloatProgress(value=0.0, max=2.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "flywire_neuron = navis.xform_brain(neuronlist, source='FAFB14', target='FLYWIRE')" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c290a8408d5145d1baa03f7ae5496099", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(HTML(value='Resampling'), FloatProgress(value=0.0, max=2.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#resample the neurons otherwise large annotations will slow down the interface..\n", "flywire_neuron = navis.resample_neuron(flywire_neuron, resample_to=1000*8, inplace=False)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "#this url has the relevant segments for the neurons..\n", "shorturl = 'https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5728630604824576'\n", "ngdict = flywireurl2dict(shorturl)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "layer_kws = {'type': 'skeletons', 'source': flywire_neuron, 'annotationstatetype': 'in-json',\n", " 'color': 'white',\n", " 'scale': [4,4,40] #scale the voxel to physical coords\n", " }" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "using voxel space with scale: [4, 4, 40]\n", "color is: ['#ffffff']\n", "color is: ['#ffffff']\n", "flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/6110186091577344\n" ] } ], "source": [ "flywireurl = add_flywirelayer(ngdict, layer_kws)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![alt text3](pics/flywire_example_03.png \"adding neurons as annotations\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example 3: Display synapses as annotations in flywire, that can be directly shared in short urls" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "ngdict = flywireurl2dict(flywireurl)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "layer_kws = {'type': 'synapses', 'source': flywire_neuron, 'annotationstatetype': 'in-json',\n", " 'color': ['red', 'blue'],\n", " 'scale': [4,4,40] #scale the voxel to physical coords\n", " }" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "using voxel space with scale: [4, 4, 40]\n", "flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5547236138156032\n" ] } ], "source": [ "flywireurl = add_flywirelayer(ngdict, layer_kws)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![alt text4](pics/flywire_example_04.png \"adding synapses as annotations\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }