{ "cells": [ { "cell_type": "markdown", "metadata": { "cell_id": "00000-5545529d-e471-4f03-981f-5035e08c07bd", "deepnote_cell_type": "markdown", "tags": [] }, "source": [ "# VFB_connect Quickstart Guide\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "cell_id": "00000-8210ad75-dbbb-4b0a-9300-c89cfe9b9566", "deepnote_cell_type": "code", "deepnote_to_be_reexecuted": false, "execution_millis": 3868, "execution_start": 1620034838029, "source_hash": "f963f177", "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Welcome to the \u001b[36mVirtual Fly Brain\u001b[0m API\n", "See the documentation at: https://virtualflybrain.org/docs/tutorials/apis/\n", "\n", "\u001b[32mEstablishing connections to https://VirtualFlyBrain.org services...\u001b[0m\n", "\u001b[32mSession Established!\u001b[0m\n", "\n", "\u001b[33mType \u001b[35mvfb. \u001b[33mand press \u001b[35mtab\u001b[33m to see available queries. You can run help against any query e.g. \u001b[35mhelp(vfb.get_TermInfo)\u001b[0m\n" ] } ], "source": [ "!pip install -r ../../../requirements.txt --quiet\n", "!pip install ../../../ --quiet\n", "\n", "# Import lib and initialise object\n", "from vfb_connect import vfb" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00001-daa13a5a-5442-4d9e-9739-b775f0136af7", "deepnote_cell_type": "markdown", "tags": [] }, "source": [ "\n", "## VFB connect API overview\n", "\n", "The VFB connect API provides programmatic access to the databases underlying [Virtual Fly Brain](http://virtualflybrain.org). \n", "\n", "At the core of Virtual Fly Brain is a set of curated terms for Drosophila neuro-anatomy organised into a queryable classification, including terms for brain regions, e.g. [nodulus](http://virtualflybrain.org/reports/FBbt_00003680) and neurons e.g. [MBON01](http://virtualflybrain.org/reports/FBbt_00100234). These terms are used to annotate and classify individual brain regions and neurons in images and connectomics data. For example the term MBON01 is used to classify individual [neurons from sources including the CATMAID-FAFB and Neuprint-HemiBrain databases](https://v2.virtualflybrain.org/org.geppetto.frontend/geppetto?q=FBbt_00100234,ListAllAvailableImages). VFB stores both [registered 3D images](http://virtualflybrain.org/reports/VFB_00101382) and [connectomics data](https://v2-dev.virtualflybrain.org/org.geppetto.frontend/geppetto?q=VFB_00101382,ref_neuron_neuron_connectivity_query) (where available) for all of these neurons.\n", "\n", "A single VfbConnect object wraps connections and canned queries against all open VFB databases. It includes methods for retreiving metadata about anatomy, individual brain regions and neurons including IDs for these that can be used for queries against other databases (e.g. CATMAID & neuprint). It provides methods for downloading images and connectomics data. It provides access to sophisticated queries for anatomical classes and individual neurons accoring to their classification & properties. " ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00002-48f36469-c1e8-489f-8d82-28cda64901bd", "deepnote_cell_type": "markdown", "tags": [] }, "source": [ "### Locations for methods under a `VfbConnect` object.\n", "\n", "1. Directly under `vfb` are:\n", " 1. A set of methods that take lists of IDs as a primary argument and return metadata. \n", " 2. A set of methods for mapping between VFB IDs and external IDs\n", " 3. A set of methods that take the names of classes in VFB e.g. 'nodulus' or 'Kenyon cell', or simple query expressions using the names of classes and return metadata about the classes.\n", " 4. A set methods for querying connectivity and similarity\n", "2. Direct access to API queries is provided under the 'nc' and 'oc' attributes for Neo4J and OWL queries respectively. We will not cover details of how to use these here.\n", "\n", "Note: available methods and their documentation are easy to explore in DeepNote. Tab completion and type adhead can be used to help find methods. Float your cursor over a method to see its signature and docstring. " ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00003-882a178b-b8ec-499a-b737-b34a16bf5209", "deepnote_cell_type": "markdown", "tags": [] }, "source": [ "### 1. `vfb` Neo4j query methods overview\n", "\n", "**1.1** `vfb.get_TermInfo` TermInfo queries return the results of a VFB Term Information window as JSON, following the [VFB_JSON standard](https://virtualflybrain.github.io/VFB_json_schema/doc/schema_doc.html), or a summary that can be provided as a DataFrame or dictonary." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "cell_id": "00004-a903a95d-00d0-4f84-a59b-9bb8783cc403", "deepnote_cell_type": "code", "deepnote_to_be_reexecuted": false, "execution_millis": 300, "execution_start": 1620034844460, "source_hash": "c6222ca9", "tags": [] }, "outputs": [ { "data": { "text/plain": [ "dict_keys(['term', 'query', 'version', 'parents', 'relationships', 'related_individuals', 'xrefs', 'anatomy_channel_image', 'pub_syn', 'def_pubs', 'targeting_splits'])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A query for full TermInfo. This probably produces more information than you will need for most purposes.\n", "vfb.get_TermInfo(['FBbt_00003686'], summary=False)[0].keys()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "cell_id": "00005-babd24bb-f0ba-4d64-b2e7-8c290cb16c66", "deepnote_cell_type": "code", "deepnote_to_be_reexecuted": false, "execution_millis": 591, "execution_start": 1614965530699, "source_hash": "ea010a2a", "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[{'label': 'Kenyon cell',\n", " 'symbol': 'KC',\n", " 'id': 'FBbt_00003686',\n", " 'tags': ['Entity',\n", " 'Anatomy',\n", " 'Cell',\n", " 'Class',\n", " 'Nervous_system',\n", " 'Neuron',\n", " 'has_subClass',\n", " 'hasScRNAseq'],\n", " 'description': 'Intrinsic neuron of the mushroom body. They have tightly-packed cell bodies, situated in the rind above the calyx of the mushroom body (Ito et al., 1997). Four short fascicles, one per lineage, extend from the cell bodies of the Kenyon cells into the calyx (Ito et al., 1997). These 4 smaller fascicles converge in the calyx where they arborize and form pre- and post-synaptic terminals (Christiansen et al., 2011), with different Kenyon cells receiving input in different calyx regions/accessory calyces (Tanaka et al., 2008). They emerge from the calyx as a thick axon bundle referred to as the peduncle that bifurcates to innervate the dorsal and medial lobes of the mushroom body (Tanaka et al., 2008). Pre-synaptic terminals were identified using two presynaptic markers (Brp and Dsyd-1) and post-synaptic terminals by labelling a subunit of the acetylcholine receptor (Dalpha7) in genetically labelled Kenyon cells (Christiansen et al., 2011).',\n", " 'parents_label': ['anterior ectoderm derivative',\n", " 'mushroom body intrinsic neuron'],\n", " 'parents_id': ['FBbt_00025991', 'FBbt_00007484'],\n", " 'data_source': [],\n", " 'accession': [],\n", " 'xrefs': []}]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# A query for summary info\n", "summary = vfb.get_TermInfo(['FBbt_00003686'], return_dataframe=False)\n", "summary\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "cell_id": "00006-3d3a3d19-b478-4ec0-9e5c-13dc358acac9", "deepnote_cell_type": "code", "deepnote_to_be_reexecuted": false, "execution_millis": 392, "execution_start": 1614965531201, "source_hash": "b96f75cd", "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\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", "
labelsymbolidtagsdescriptionparents_labelparents_iddata_sourceaccessionxrefstemplatesdatasetlicense
05-HTPLP01_R (FlyEM-HB:1324365879)5-HTPLP01_RVFB_jrchjrch[Entity, Adult, Anatomy, Cell, Glutamatergic, ...tracing status-Roughly traced, cropped-False[adult glutamatergic neuron, adult serotonergi...[FBbt_00058208, FBbt_00110945][neuprint_JRC_Hemibrain_1point2point1][1324365879][neuronbridge:1324365879, neuprint_JRC_Hemibra...[JRC2018Unisex, JRC_FlyEM_Hemibrain][Xu2020NeuronsV1point1][https://creativecommons.org/licenses/by/4.0/l...
\n", "
" ], "text/plain": [ " label symbol id \\\n", "0 5-HTPLP01_R (FlyEM-HB:1324365879) 5-HTPLP01_R VFB_jrchjrch \n", "\n", " tags \\\n", "0 [Entity, Adult, Anatomy, Cell, Glutamatergic, ... \n", "\n", " description \\\n", "0 tracing status-Roughly traced, cropped-False \n", "\n", " parents_label \\\n", "0 [adult glutamatergic neuron, adult serotonergi... \n", "\n", " parents_id data_source \\\n", "0 [FBbt_00058208, FBbt_00110945] [neuprint_JRC_Hemibrain_1point2point1] \n", "\n", " accession xrefs \\\n", "0 [1324365879] [neuronbridge:1324365879, neuprint_JRC_Hemibra... \n", "\n", " templates dataset \\\n", "0 [JRC2018Unisex, JRC_FlyEM_Hemibrain] [Xu2020NeuronsV1point1] \n", "\n", " license \n", "0 [https://creativecommons.org/licenses/by/4.0/l... " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The same method can be used to get info about individual neurons\n", "\n", "summary = vfb.get_TermInfo(['VFB_jrchjrch'])\n", "summary\n" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00007-493e5cba-0f62-4368-85ac-25591f0ed904", "deepnote_cell_type": "markdown", "tags": [] }, "source": [ "**1.2** The `vfb` also includes methods for mapping between IDs from different sources. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "cell_id": "00008-588da430-9aca-4d42-885c-e024f0904061", "deepnote_cell_type": "code", "deepnote_to_be_reexecuted": false, "execution_millis": 1297, "execution_start": 1614965531623, "source_hash": "19280cf", "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{'1068958652': [{'db': 'neuronbridge', 'vfb_id': 'VFB_jrch06r9'},\n", " {'db': 'neuronbridge', 'vfb_id': 'VFB_jrchjwda'},\n", " {'db': 'neuprint_JRC_Hemibrain_1point0point1', 'vfb_id': 'VFB_jrch06r9'},\n", " {'db': 'neuprint_JRC_Hemibrain_1point2point1', 'vfb_id': 'VFB_jrchjwda'}],\n", " '571424748': [{'db': 'neuronbridge', 'vfb_id': 'VFB_jrch06r6'},\n", " {'db': 'neuronbridge', 'vfb_id': 'VFB_jrchjwct'},\n", " {'db': 'neuprint_JRC_Hemibrain_1point0point1', 'vfb_id': 'VFB_jrch06r6'},\n", " {'db': 'neuprint_JRC_Hemibrain_1point2point1', 'vfb_id': 'VFB_jrchjwct'}],\n", " '1141631198': [{'db': 'neuronbridge', 'vfb_id': 'VFB_jrch05uz'},\n", " {'db': 'neuronbridge', 'vfb_id': 'VFB_jrchjw8r'},\n", " {'db': 'neuprint_JRC_Hemibrain_1point0point1', 'vfb_id': 'VFB_jrch05uz'},\n", " {'db': 'neuprint_JRC_Hemibrain_1point2point1', 'vfb_id': 'VFB_jrchjw8r'}]}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Some bodyIDs of HemiBrain neurons from the neuprint DataBase:\n", "bodyIDs = [1068958652, 571424748, 1141631198]\n", "vfb.xref_2_vfb_id(map(str, bodyIDs), return_just_ids=False) # Note IDs must be strings" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_id": "00008-c3f3a1f0-9596-44e6-857c-ba8eabdba43a", "deepnote_cell_type": "code", "deepnote_to_be_reexecuted": false, "execution_millis": 358, "execution_start": 1614965532942, "source_hash": "3738587c", "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{'VFB_jrchjwct': [{'acc': '571424748',\n", " 'db': 'neuprint_JRC_Hemibrain_1point2point1'}],\n", " 'VFB_jrchjw8r': [{'acc': '1141631198',\n", " 'db': 'neuprint_JRC_Hemibrain_1point2point1'}],\n", " 'VFB_jrchjwda': [{'acc': '1068958652',\n", " 'db': 'neuprint_JRC_Hemibrain_1point2point1'}]}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# xref queries can be constrained by DB. Results can optionally be reversed\n", "\n", "vfb.xref_2_vfb_id(map(str, bodyIDs), db = 'neuprint_JRC_Hemibrain_1point2point1' , reverse_return=True, return_just_ids=False)" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00010-54619a98-fba7-40e7-9ff3-4ced3633540a", "deepnote_cell_type": "markdown", "tags": [] }, "source": [ "### 2. `vfb` OWL and Neo4j combined methods overview" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00011-f577015f-32f5-4bd6-bcea-f2274fdd9582", "deepnote_cell_type": "markdown", "tags": [] }, "source": [ "**2.1** Methods that take the names of classes in VFB e.g. 'nodulus' or 'Kenyon cell', or simple query expressions using the names of classes and return metadata about the classes or individual neurons" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "cell_id": "00009-4f6b2783-5d94-475d-88fe-f22c2302add2", "deepnote_cell_type": "code", "deepnote_to_be_reexecuted": false, "execution_millis": 2623, "execution_start": 1614965533309, "source_hash": "1ef0f13", "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\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", " \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", "
labelsymbolidtagsdata_sourceaccessionparents_labelparents_id
0Kenyon cell of main calyxFBbt_00047926[Entity, Adult, Anatomy, Cell, Cholinergic, Cl...[][][adult Kenyon cell, adult Kenyon cell, adult K...[FBbt_00049825, FBbt_00049825, FBbt_00049825, ...
1alpha/beta core Kenyon cellKCab-cFBbt_00110929[Entity, Adult, Anatomy, Cell, Cholinergic, Cl...[][][alpha/beta surface/core Kenyon cell, alpha/be...[FBbt_00049838, FBbt_00049838, FBbt_00049838, ...
2gamma main Kenyon cellKCg-mFBbt_00111061[Entity, Adult, Anatomy, Cell, Cholinergic, Cl...[][][Kenyon cell of main calyx, Kenyon cell of mai...[FBbt_00047926, FBbt_00047926, FBbt_00047926, ...
3alpha/beta inner-core Kenyon cellFBbt_00049111[Entity, Adult, Anatomy, Cell, Cholinergic, Cl...[][][alpha/beta core Kenyon cell, alpha/beta core ...[FBbt_00110929, FBbt_00110929]
4gamma Kenyon cellFBbt_00100247[Entity, Anatomy, Cell, Class, Nervous_system,...[][][Kenyon cell, Kenyon cell, Kenyon cell, Kenyon...[FBbt_00003686, FBbt_00003686, FBbt_00003686, ...
\n", "
" ], "text/plain": [ " label symbol id \\\n", "0 Kenyon cell of main calyx FBbt_00047926 \n", "1 alpha/beta core Kenyon cell KCab-c FBbt_00110929 \n", "2 gamma main Kenyon cell KCg-m FBbt_00111061 \n", "3 alpha/beta inner-core Kenyon cell FBbt_00049111 \n", "4 gamma Kenyon cell FBbt_00100247 \n", "\n", " tags data_source accession \\\n", "0 [Entity, Adult, Anatomy, Cell, Cholinergic, Cl... [] [] \n", "1 [Entity, Adult, Anatomy, Cell, Cholinergic, Cl... [] [] \n", "2 [Entity, Adult, Anatomy, Cell, Cholinergic, Cl... [] [] \n", "3 [Entity, Adult, Anatomy, Cell, Cholinergic, Cl... [] [] \n", "4 [Entity, Anatomy, Cell, Class, Nervous_system,... [] [] \n", "\n", " parents_label \\\n", "0 [adult Kenyon cell, adult Kenyon cell, adult K... \n", "1 [alpha/beta surface/core Kenyon cell, alpha/be... \n", "2 [Kenyon cell of main calyx, Kenyon cell of mai... \n", "3 [alpha/beta core Kenyon cell, alpha/beta core ... \n", "4 [Kenyon cell, Kenyon cell, Kenyon cell, Kenyon... \n", "\n", " parents_id \n", "0 [FBbt_00049825, FBbt_00049825, FBbt_00049825, ... \n", "1 [FBbt_00049838, FBbt_00049838, FBbt_00049838, ... \n", "2 [FBbt_00047926, FBbt_00047926, FBbt_00047926, ... \n", "3 [FBbt_00110929, FBbt_00110929] \n", "4 [FBbt_00003686, FBbt_00003686, FBbt_00003686, ... " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "KC_types = vfb.get_subclasses(\"Kenyon cell\")\n", "KC_types[0:5]" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00013-375d396a-7123-4921-9340-96dbbf24cf01", "deepnote_cell_type": "markdown", "tags": [] }, "source": [ "**2.2** Methods for querying connectivity\n", "\n", "Please see [Connectomics Notebook](connectomics.html) for examples" ] } ], "metadata": { "deepnote": {}, "deepnote_execution_queue": [], "deepnote_notebook_id": "923d6d41-1023-4fd0-bdc2-838346c9b7c2", "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.10.9" }, "orig_nbformat": 2 }, "nbformat": 4, "nbformat_minor": 2 }