{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Co-plotting hemibrain skeleton with flywire dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### This section contains example of fetching skeleton from hemibrain dataset and co-plotting with a flywire instance" ] }, { "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 flybrains" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "127.0.0.1 - - [07/Jun/2021 09:00:19] \"GET /precomputed/hemibrain_skels/skeletons//info HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:19] \"GET /precomputed/hemibrain_neuropils/mesh/info HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:19] \"GET /precomputed/hemibrain_neuropils/mesh/200:0 HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:19] \"GET /precomputed/hemibrain_neuropils/mesh/300:0 HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:19] \"GET /precomputed/hemibrain_skels/skeletons//1734350788 HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:19] \"GET /precomputed/hemibrain_skels/skeletons//1734350908 HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:19] \"GET /precomputed/hemibrain_neuropils/mesh/200 HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:19] \"GET /precomputed/hemibrain_neuropils/mesh/300 HTTP/1.1\" 200 -\n" ] } ], "source": [ "from pyroglancer.localserver import startdataserver, closedataserver\n", "from pyroglancer.flywire import flywireurl2dict, add_flywirelayer, set_flywireviewerstate" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import navis.interfaces.neuprint as neu\n", "from navis.interfaces.neuprint import NeuronCriteria as NC, SynapseCriteria as SC" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set configurations to fetch from data from neuprint" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "client = neu.Client('https://neuprint.janelia.org/', dataset='hemibrain:v1.1')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Client(\"https://neuprint.janelia.org\", \"hemibrain:v1.1\")" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "client" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get sample skids and neuropil meshes from neuprint" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "neurons_df, roi_counts_df = neu.fetch_neurons(NC(status='Traced',type='DA1_lPN',regex=True)) #get some DA1 PNs.." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "da1pnbodyidList = neurons_df[['bodyId']]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "02c4ea30a8f74285a23323511d99310a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(HTML(value='Fetching'), FloatProgress(value=0.0, max=7.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "INFO - 2021-06-07 08:59:02,147 - utils - NumExpr defaulting to 8 threads.\n" ] } ], "source": [ "da1pn_skel = neu.fetch_skeletons(da1pnbodyidList, heal=1000, max_threads=30)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "#fetch mesh for Right Antenna lobe..\n", "al_R = neu.fetch_roi('AL(R)')" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "hemibrain_mesh = navis.Volume(flybrains.JRCFIB2018Fraw.mesh)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Transform them to Flywire space.." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO : Pre-caching deformation field(s) for transforms... (navis)\n", "INFO - 2021-06-07 08:59:09,210 - base - Pre-caching deformation field(s) for transforms...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Transform path: JRCFIB2018Fraw -> JRCFIB2018F -> JRCFIB2018Fum -> JRC2018F -> FAFB14um -> FAFB14 -> FAFB14raw -> FLYWIREraw -> FLYWIRE\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d9aa90a2ea91417fa79036b8ee00a60c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(HTML(value='Xforming'), FloatProgress(value=0.0, max=7.0), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "flywire_neuron=navis.xform_brain(da1pn_skel,source='JRCFIB2018Fraw', target='FLYWIRE')" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Transform path: JRCFIB2018Fraw -> JRCFIB2018F -> JRCFIB2018Fum -> JRC2018F -> FAFB14um -> FAFB14 -> FAFB14raw -> FLYWIREraw -> FLYWIRE\n", "Transform path: JRCFIB2018Fraw -> JRCFIB2018F -> JRCFIB2018Fum -> JRC2018F -> FAFB14um -> FAFB14 -> FAFB14raw -> FLYWIREraw -> FLYWIRE\n" ] } ], "source": [ "flywirevol = {}\n", "flywirevol['hemibrain']=navis.xform_brain(hemibrain_mesh, source='JRCFIB2018Fraw', target='FLYWIRE')\n", "flywirevol['AL_R']=navis.xform_brain(al_R, source='JRCFIB2018Fraw', target='FLYWIRE')" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'hemibrain': ,\n", " 'AL_R': }" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "flywirevol['hemibrain'].id = 200\n", "flywirevol['AL_R'].id = 300\n", "flywirevol" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Start the dataserver to host precomputed data.." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Serving data from: /var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859\n", "Serving directory at http://127.0.0.1:8000\n" ] } ], "source": [ "startdataserver()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get the url from flywire to append data onto.." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "shorturl = 'https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5644175227748352'\n", "#This flywire segments has some stuff similar to the DA1 PNs, you will notice their closeness in the final plot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add bodyids to flywire layers.." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859/precomputed/hemibrain_skels/skeletons/1734350788\n", "/private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859/precomputed/hemibrain_skels/skeletons/1734350908\n", "creating: /private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859/precomputed/hemibrain_skels/skeletons/seg_props\n", "{'1734350788': ['#ff0000'], '1734350908': ['#ff0000']}\n", "flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5341907991396352\n" ] } ], "source": [ "tmpviewer = add_flywirelayer(flywireurl2dict(shorturl), layer_kws = {'type': 'skeletons',\n", " 'source': flywire_neuron[2:4],\n", " 'name': 'hemibrain_skels',\n", " 'color': 'red'}) \n", "#'alpha': 0.3, doesn't work yet in skeleton layers.." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Add neuropil meshes to flywire layers" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "shorturl = tmpviewer" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "mesh/200\n", "Seg id is: 200\n", "Full filepath: /private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859/precomputed/hemibrain_neuropils/mesh/200\n", "mesh/300\n", "Seg id is: 300\n", "Full filepath: /private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859/precomputed/hemibrain_neuropils/mesh/300\n", "creating: /private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859/precomputed/hemibrain_neuropils/mesh/segment_properties\n", "creating: /private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859/precomputed/hemibrain_neuropils/mesh/segment_names\n", "flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5853351342243840\n" ] } ], "source": [ "tmpviewer = add_flywirelayer(flywireurl2dict(shorturl), layer_kws = {'type': 'volumes',\n", " 'source': [flywirevol['hemibrain'],\n", " flywirevol['AL_R']],\n", " 'name': 'hemibrain_neuropils',\n", " 'color': ['grey', 'magenta'], \n", " 'alpha': 0.3})" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "flywire url at: https://ngl.flywire.ai/?json_url=https://globalv1.flywire-daf.com/nglstate/5209798823903232\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "127.0.0.1 - - [07/Jun/2021 09:00:30] \"GET /precomputed/hemibrain_skels/skeletons//info HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:30] \"GET /precomputed/hemibrain_neuropils/mesh/info HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:30] \"GET /precomputed/hemibrain_neuropils/mesh/300:0 HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:30] \"GET /precomputed/hemibrain_neuropils/mesh/200:0 HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:30] \"GET /precomputed/hemibrain_skels/skeletons//1734350908 HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:30] \"GET /precomputed/hemibrain_skels/skeletons//1734350788 HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:30] \"GET /precomputed/hemibrain_neuropils/mesh/200 HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 09:00:30] \"GET /precomputed/hemibrain_neuropils/mesh/300 HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 11:19:00] \"GET /precomputed/hemibrain_skels/skeletons//info HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 11:19:00] \"GET /precomputed/hemibrain_neuropils/mesh/info HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 11:19:00] \"GET /precomputed/hemibrain_skels/skeletons//1734350908 HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 11:19:00] \"GET /precomputed/hemibrain_skels/skeletons//1734350788 HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 11:19:00] \"GET /precomputed/hemibrain_neuropils/mesh/300:0 HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 11:19:00] \"GET /precomputed/hemibrain_neuropils/mesh/200:0 HTTP/1.1\" 304 -\n", "127.0.0.1 - - [07/Jun/2021 11:19:00] \"GET /precomputed/hemibrain_neuropils/mesh/300 HTTP/1.1\" 200 -\n", "127.0.0.1 - - [07/Jun/2021 11:19:00] \"GET /precomputed/hemibrain_neuropils/mesh/200 HTTP/1.1\" 200 -\n" ] } ], "source": [ "tmpviewer,shorturl = set_flywireviewerstate(tmpviewer, axis_lines=False, bounding_box=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Screenshot of the flywire instance" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The grey mesh is the hemibrain neuropil, magenta is the Antenna lobe (Right), you can see the skeletons from hemibrain (red) plotted in the skeleton layer, and some similar neurons (meshes) of the flywire dataset plotted in green and yellow" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![alt text](pics/hemibrain2flywire.png \"hembrain2flywire\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Close the dataserver" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Closing server at http://127.0.0.1:8000\n", "Cleaning directory at /private/var/folders/_l/lrfvj_8j3ps0c37ncbr3c8dh0000gn/T/tmp4kwke859\n" ] } ], "source": [ "closedataserver()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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 }