Note
Click here to download the full example code
H01 Dataset
In this notebook, you can learn how to work with the H01 dataset using NAVis.
The H01 dataset contains 57,000 cells and 150 million synapses from a cubic millimeter of the human temporal cortex, which is proofread using the CAVE ecoystem.
With this interface, you can access both a snapshot of the proofread dataset and the latest dataset using caveclient
:
pip install caveclient -U
Authentication
If this is your first time using CAVEclient
to access the H01
dataset, you might have to get and set your authentication token:
- Go to: https://https//global.brain-wire-test.org/auth/api/v1/create_token to create a new token.
- Log in with your Google credentials and copy the token shown afterward.
- Save it to your computer with:
from caveclient import CAVEclient
client = CAVEclient(server_address="https://global.brain-wire-test.org", datastack_name='h01_c3_flat', auth_token="PASTE_YOUR_TOKEN_HERE")
client.auth.save_token(token="PASTE_YOUR_TOKEN_HERE")
Note that the H01 dataset uses a server address that is different from the default CAVEClient
server. Also be aware that creating a new token by finishing step 2 will invalidate the previous token!
import navis
from navis.interfaces import h01
# Initialize the client
client = h01.get_cave_client()
Query Tables
client.materialize.get_versions()
Out:
[549, 527, 541, 543, 546, 548]
client.materialize.get_tables()
Out:
['cells', 'nucleus', 'synapses', 'proofreading_status_test', 'synapses_using_sample_voxel_coords']
Query Materialized Synapse Table
Query the first few rows in the table
client.materialize.synapse_query(limit=10)
Out:
201 - "Limited query to 10 rows
| id | created | superceded_id | valid | size | pre_pt_supervoxel_id | pre_pt_root_id | post_pt_supervoxel_id | post_pt_root_id | pre_pt_position | post_pt_position | ctr_pt_position |
0 | 40971523 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 134364238863925557 | 864691128621846602 | 134293870119747633 | 864691131861340864 | [453256, 225950, 1879] | [453086, 226004, 1838] | [453312, 225966, 1883] |
1 | 40971525 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 122744257927708975 | 864691132202350435 | 123448011605934094 | 864691132349699414 | [369038, 157894, 4777] | [373770, 158410, 12] | [368610, 158562, 4703] |
2 | 40971526 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 106917542483722336 | 864691132270145118 | 106776805062476142 | 864691132270173278 | [253634, 204356, 1947] | [252889, 204590, 2104] | [253668, 204394, 1970] |
3 | 40971531 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 123171415779180930 | 864691132169548413 | 123238142525309068 | 864691132434786616 | [371948, 194706, 231] | [372276, 167562, 393] | [373837, 195793, 656] |
4 | 40971532 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 112057964830916834 | 864691132186081100 | 123873454087733399 | 864691132406664067 | [291270, 230762, 692] | [376984, 182427, 422] | [291536, 230572, 743] |
5 | 40971533 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 123247282417042025 | 864691131368353049 | 123106476209209491 | 864691132146145331 | [372432, 235870, 836] | [371386, 235338, 800] | [372404, 235926, 878] |
6 | 40971543 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 111615894450340136 | 864691131150038069 | 110277925298765887 | 864691132256098281 | [288132, 82436, 4516] | [278270, 75460, 2688] | [288126, 82449, 4534] |
7 | 40971544 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 97420786213584924 | 864691132283064473 | 98476316705161844 | 864691132291684761 | [184568, 226882, 2954] | [192388, 226910, 1720] | [186353, 228578, 2425] |
8 | 40971558 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 106124452210671785 | 864691130242818215 | 106686508676678327 | 864691132254753632 | [247898, 62853, 4234] | [251917, 56124, 4088] | [247909, 62819, 4232] |
9 | 40971570 | 2024-04-12 00:14:40.110821+00:00 | NaN | t | NaN | 120781010190205127 | 864691131982166038 | 123383897072337185 | 864691132339647570 | [354624, 210728, 2843] | [373366, 204850, 1449] | [354762, 211287, 2855] |
Query specific pre- and/or postsynaptic IDs
syn = client.materialize.synapse_query(
post_ids=[864691131861340864],
# pre_ids=[ADD YOUR ROOT ID],
)
syn.head()
| id | created | superceded_id | valid | size | pre_pt_supervoxel_id | pre_pt_root_id | post_pt_supervoxel_id | post_pt_root_id | pre_pt_position | post_pt_position | ctr_pt_position |
0 | 40882209 | 2024-04-12 00:14:37.031216+00:00 | NaN | t | NaN | 134364238863925573 | 864691128621846858 | 134293870119747633 | 864691131861340864 | [453528, 225898, 1883] | [453086, 226004, 1838] | [453539, 225957, 1897] |
1 | 40899780 | 2024-04-12 00:14:37.548445+00:00 | NaN | t | NaN | 134434607608102964 | 864691130486857485 | 134293870119747633 | 864691131861340864 | [453872, 225934, 1847] | [453086, 226004, 1838] | [453854, 226063, 1851] |
2 | 40924493 | 2024-04-12 00:14:38.495865+00:00 | NaN | t | NaN | 134223432656093315 | 864691132015686175 | 134293870119747633 | 864691131861340864 | [452262, 225346, 1846] | [453086, 226004, 1838] | [453124, 225933, 1852] |
3 | 40935748 | 2024-04-12 00:14:38.723502+00:00 | NaN | t | NaN | 134434676327579728 | 864691131840536421 | 134293870119747633 | 864691131861340864 | [453838, 226378, 1849] | [453086, 226004, 1838] | [453786, 226050, 1873] |
4 | 40954321 | 2024-04-12 00:14:39.566756+00:00 | NaN | t | NaN | 134293732747903463 | 864691132191805487 | 134293870119747633 | 864691131861340864 | [453008, 224834, 1980] | [453086, 226004, 1838] | [453459, 225953, 1891] |
Out:
Live Synapse Queries
import datetime as dt
# Check if root ID is the most recent root ID
root_id = 864691131861340864
now = dt.datetime.now(dt.timezone.utc)
is_latest = client.chunkedgraph.is_latest_roots([root_id], timestamp=now)
latest_id = client.chunkedgraph.get_latest_roots(root_id, timestamp=now)
print(is_latest, latest_id)
Out:
/opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/networkx/readwrite/json_graph/node_link.py:287: FutureWarning:
The default value will be changed to `edges="edges" in NetworkX 3.6.
To make this warning go away, explicitly set the edges kwarg, e.g.:
nx.node_link_graph(data, edges="links") to preserve current behavior, or
nx.node_link_graph(data, edges="edges") for forward compatibility.
[ True] [864691131861340864]
synapse_table = client.info.get_datastack_info()["synapse_table"]
df = client.materialize.query_table(
synapse_table,
timestamp=dt.datetime.now(dt.timezone.utc),
filter_equal_dict={"post_pt_root_id": latest_id[0]},
)
df.head()
| id | created | superceded_id | valid | size | pre_pt_supervoxel_id | pre_pt_root_id | post_pt_supervoxel_id | post_pt_root_id | pre_pt_position | post_pt_position | ctr_pt_position |
0 | 40882209 | 2024-04-12 00:14:37.031216+00:00 | NaN | t | NaN | 134364238863925573 | 864691128621846858 | 134293870119747633 | 864691131861340864 | [453528, 225898, 1883] | [453086, 226004, 1838] | [453539, 225957, 1897] |
1 | 40899780 | 2024-04-12 00:14:37.548445+00:00 | NaN | t | NaN | 134434607608102964 | 864691130486857485 | 134293870119747633 | 864691131861340864 | [453872, 225934, 1847] | [453086, 226004, 1838] | [453854, 226063, 1851] |
2 | 40924493 | 2024-04-12 00:14:38.495865+00:00 | NaN | t | NaN | 134223432656093315 | 864691132015686175 | 134293870119747633 | 864691131861340864 | [452262, 225346, 1846] | [453086, 226004, 1838] | [453124, 225933, 1852] |
3 | 40935748 | 2024-04-12 00:14:38.723502+00:00 | NaN | t | NaN | 134434676327579728 | 864691131840536421 | 134293870119747633 | 864691131861340864 | [453838, 226378, 1849] | [453086, 226004, 1838] | [453786, 226050, 1873] |
4 | 40954321 | 2024-04-12 00:14:39.566756+00:00 | NaN | t | NaN | 134293732747903463 | 864691132191805487 | 134293870119747633 | 864691131861340864 | [453008, 224834, 1980] | [453086, 226004, 1838] | [453459, 225953, 1891] |
Query Cells Table
ct = client.materialize.query_table(table="cells")
ct.head()
| id | created | superceded_id | valid | classification_system | cell_type | pt_supervoxel_id | pt_root_id | pt_position |
0 | 1 | 2023-06-15 19:27:23.586264+00:00 | NaN | t | 0, 0, 0 | UNKNOWN0 | 0 | 0 | [0, 0, 0] |
1 | 2 | 2023-06-15 19:27:23.587056+00:00 | NaN | t | 0, 0, 0 | UNKNOWN0 | 0 | 0 | [0, 0, 0] |
2 | 3 | 2023-06-15 19:27:23.587786+00:00 | NaN | t | 0, 0, 0 | UNKNOWN0 | 0 | 0 | [0, 0, 0] |
3 | 4 | 2023-06-15 19:27:23.588481+00:00 | NaN | t | 0, 0, 0 | UNKNOWN0 | 0 | 0 | [0, 0, 0] |
4 | 5 | 2023-06-15 19:27:23.589166+00:00 | NaN | t | 0, 0, 0 | UNKNOWN0 | 0 | 0 | [0, 0, 0] |
Out:
array(['UNKNOWN0', 'PYRAMIDAL', 'UNCLASSIFIEDNEURON', 'UNKNOWN2', 'OLIGO',
'ASTROCYTE', 'MG_OPC', 'INTERNEURON', 'BLOODVESSELCELL',
'UNKNOWN1', 'C-SHAPEDCELL_AKA_MG_OPC'], dtype=object)
Filter by cell type
# Get the first 50 interneurons
interneuron_ids = ct[ct.cell_type == "INTERNEURON"].pt_root_id.values[:50]
# Remove 0 IDs
interneuron_ids = interneuron_ids[interneuron_ids != 0]
# What's left?
interneuron_ids
Out:
array([864691132341213351, 864691132343125732, 864691132440298746,
864691132301485893, 864691132254968355, 864691132509654349,
864691132254843391])
Fetch Neuron Meshes
interneurons = h01.fetch_neurons(interneuron_ids, lod=2, with_synapses=False)
interneurons_ds = navis.simplify_mesh(interneurons, F=1 / 3)
interneurons_ds
<class 'navis.core.neuronlist.NeuronList'> containing 7 neurons (44.1MiB)
| type | name | id | units | n_vertices | n_faces |
0 | navis.MeshNeuron | None | 864691132301485893 | 1 nanometer | 65943 | 130220 |
1 | navis.MeshNeuron | None | 864691132341213351 | 1 nanometer | 123979 | 239637 |
... | ... | ... | ... | ... | ... | ... |
5 | navis.MeshNeuron | None | 864691132254968355 | 1 nanometer | 140941 | 277315 |
6 | navis.MeshNeuron | None | 864691132254843391 | 1 nanometer | 159764 | 313186 |
# Plot
import seaborn as sns
colors = {n.id: sns.color_palette("Reds", 7)[i] for i, n in enumerate(interneurons_ds)}
navis.plot3d([interneurons_ds], color=colors)