from caveclient import CAVEclient
import numpy as np
import pandas as pd
= CAVEclient("minnie65_public")
client
# specify the materialization version, for consistency across time",
= 1300
client.version
# Example: pyramidal cell in v1300
= 864691135572530981 example_cell_id
Download Skeletons
Connected morphological representations: skeletons
Often in thinking about neurons, you want to measure things along a linear dimension of a neuron.
However, the segmentation and meshes are a full complex 3d shape that makes this non-trivial. There are methods for reducing the shape of a segmented neuron down to a linear tree like structure usually referred to as a skeleton. We have precalculated skeletons for a large number of cells in the dataset, and make the skeleton generation available on our server, on demand.
The meshes that one sees in Neuroglancer are available to download through the python client cloud-volume, and can be loaded for analysis and visualization in other tools.
The MICrONS data can be representing and rendered in multiple formats, at different levels of abstraction from the original imagery.
What is a Precomputed skeleton?
These skeletons are stored in the cloud as a bytes-IO object, which can be viewed in Neuroglancer, or downloaded with CAVEclient.skeleton module. These precomputed skeletons also contain annotations on the skeletons that have the synapses, which skeleton nodes are axon and which are dendrite, and which are likely the apical dendrite of excitatory neurons.
For more on how skeletons are generated from the mesh objects, and additional tools for generating, cacheing, and downloading meshes, see the Skeleton Service documentation
CAVEclient to download skeletons
Retrieve a skeleton using get_skeleton()
. The available output_formats (described below) are:
dict
containing vertices, edges, radius, compartment, and various metadata (default if unspecified)swc
a Pandas Dataframe in the SWC format, with ordered vertices, edges, compartment labels, and radius.
Note: if the skeleton doesn’t exist in the server cache, it may take 20-60 seconds to generate the skeleton before it is returned. This function will block during that time. Any subsequent retrieval of the same skeleton should go very quickly however.
Before using any programmatic access to the data, you first need to set up your CAVEclient token.
= client.skeleton.get_skeleton(example_cell_id, output_format='swc')
sk_df
sk_df.head()
id | type | x | y | z | radius | parent | |
---|---|---|---|---|---|---|---|
0 | 0 | 1 | 1365.120 | 763.456 | 812.60 | 3.643 | -1 |
1 | 1 | 3 | 1368.200 | 755.760 | 811.24 | 0.300 | 0 |
2 | 2 | 3 | 1368.200 | 758.552 | 811.68 | 1.915 | 1 |
3 | 3 | 3 | 1368.200 | 758.560 | 812.12 | 1.915 | 2 |
4 | 4 | 3 | 1368.192 | 758.560 | 812.44 | 2.815 | 3 |
Skeletons are “tree-like”, where every vertex (except the root vertex) has a single parent that is closer to the root than it, and any number of child vertices. Because of this, for a skeleton there are well-defined directions “away from root” and “towards root” and few types of vertices have special names:
You can see these vertices and edges represented in the alternative dict
skeleton output.
= client.skeleton.get_skeleton(example_cell_id, output_format='dict')
sk_dict
sk_dict.keys()
dict_keys(['meta', 'edges', 'mesh_to_skel_map', 'root', 'vertices', 'compartment', 'radius'])
Alternately, you can query a set of root_ids, for example all of the proofread cells in the dataset, and bulk download the skeletons
= client.materialize.tables.proofreading_status_and_strategy(
prf_root_ids ='t').query()['pt_root_id']
status_axon3) prf_root_ids.head(
0 864691135441799752
1 864691135855890478
2 864691136521831825
Name: pt_root_id, dtype: int64
= client.skeleton.get_bulk_skeletons(
all_sk_dict 3),
prf_root_ids.head(=False,
generate_missing_skeletons='dict',
output_format=4)
skeleton_version
all_sk.keys()
dict_keys(['864691135441799752', '864691135855890478', '864691136521831825'])
Download or generate skeletons with pcg_skel
pcg_skel
is a package used to rapidly build neuronal skeletons from electron microscopy data in the CAVE ecosystem. It integrates structural data, connectivity data, and local features stored across many aspects of a CAVE system, and creates objects as Meshparty meshes, skeletons, and MeshWork files for subsequent analysis.
By harnessing the way the structural data is stored, you can build skeletons for even very large neurons quickly and with little memory use.
To install pcg_skel, use pip.
pip install pcg_skel
By loading a skeleton with MeshParty, you can easily ‘rehydrate’ the mesh features of the neuron (such as synapses) and MeshParty functions (such as masking)
from pcg_skel import get_meshwork_from_client
= get_meshwork_from_client(example_cell_id,
sk_mesh =client,
client=True,
synapses# restore_graph=True,
=True,
restore_properties=4,
skeleton_version
) sk_mesh
<meshparty.meshwork.meshwork.Meshwork at 0x2175d3d13d0>
Plot with skeleton_plot
Our convenience package skeleton_plot renders the skeleton in aligned, 2D views.
pip install skeleton_plot
import skeleton_plot
=sk_mesh.skeleton,
skeleton_plot.plot_tools.plot_skel(sk=True,
invert_y=False,
pull_compartment_colors=True) plot_soma