Skip to content

Commit 8b5cf12

Browse files
Update example analysis pipeline and sample data
1 parent 4b3b539 commit 8b5cf12

File tree

2 files changed

+90
-9
lines changed

2 files changed

+90
-9
lines changed

examples/analysis_pipeline.py

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,88 @@
1-
# TODO implement analysis pipeline for our tomo sample data:
2-
# - segment vesicles, AZ, and compartment
3-
# - use compartment segmentation to find the presynaptic terminal
4-
# - postprocess the AZ segmentation
5-
# - measure distances between vesicles and AZ
6-
# - vesicle pool assignment into docked and non-attached terminals
7-
# - export table with distance and morphology measurements for the two pools
1+
import napari
2+
import pandas as pd
3+
4+
from synapse_net.file_utils import read_mrc
5+
from synapse_net.sample_data import get_sample_data
6+
from synapse_net.tools.util import run_segmentation, get_model, compute_scale_from_voxel_size
7+
8+
9+
def segment_structures(tomogram, voxel_size):
10+
# Segment the synaptic vesicles. The data will automatically be resized
11+
# to match the average voxel size of the training data.
12+
model_name = "vesicles_3d" # This is the name for the vesicle model for EM tomography.
13+
model = get_model(model_name) # Load the corresponding model.
14+
# Compute the scale to match the tomogram voxel size to the training data.
15+
scale = compute_scale_from_voxel_size(voxel_size, model_name)
16+
vesicles = run_segmentation(tomogram, model, model_name, scale=scale)
17+
18+
# Segment the active zone.
19+
model_name = "active_zone"
20+
model = get_model(model_name)
21+
scale = compute_scale_from_voxel_size(voxel_size, model_name)
22+
active_zone = run_segmentation(tomogram, model, model_name, scale=scale)
23+
24+
# Segment the synaptic compartments.
25+
model_name = "compartments"
26+
model = get_model(model_name)
27+
scale = compute_scale_from_voxel_size(voxel_size, model_name)
28+
compartments = run_segmentation(tomogram, model, model_name, scale=scale)
29+
30+
return {"vesicles": vesicles, "active_zone": active_zone, "compartments": compartments}
31+
32+
33+
def postprocess_segmentation(segmentations):
34+
pass
35+
36+
37+
def measure_distances(segmentations):
38+
pass
39+
40+
41+
def assign_vesicle_pools(distances):
42+
pass
43+
44+
45+
def visualize_results(tomogram, segmentations, vesicle_pools):
46+
# TODO vesicle pool visualization
47+
viewer = napari.Viewer()
48+
viewer.add_image(tomogram)
49+
for name, segmentation in segmentations.items():
50+
viewer.add_labels(segmentation, name=name)
51+
napari.run()
52+
53+
54+
def save_analysis(segmentations, distances, vesicle_pools, save_path):
55+
pass
56+
57+
58+
def main():
59+
"""This script implements an example analysis pipeline with SynapseNet and applies it to a tomogram.
60+
Here, we analyze docked and non-attached vesicles in a sample tomogram."""
61+
62+
# Load the tomogram for our sample data.
63+
mrc_path = get_sample_data("tem_tomo")
64+
tomogram, voxel_size = read_mrc(mrc_path)
65+
66+
# Segment synaptic vesicles, the active zone, and the synaptic compartment.
67+
segmentations = segment_structures(tomogram, voxel_size)
68+
69+
# Post-process the segmentations, to find the presynaptic terminal,
70+
# filter out vesicles not in the terminal, and to 'snape' the AZ to the presynaptic boundary.
71+
segmentations = postprocess_segmentation(segmentations)
72+
73+
# Measure the distances between the AZ and vesicles.
74+
distances = measure_distances(segmentations)
75+
76+
# Assign the vesicle pools, 'docked' and 'non-attached' vesicles, based on the distances.
77+
vesicle_pools = assign_vesicle_pools(distances)
78+
79+
# Visualize the results.
80+
visualize_results(tomogram, segmentations, vesicle_pools)
81+
82+
# Compute the vesicle radii and combine and save all measurements.
83+
save_path = "analysis_results.xlsx"
84+
save_analysis(segmentations, distances, vesicle_pools, save_path)
85+
86+
87+
if __name__ == "__main__":
88+
main()

synapse_net/sample_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def get_sample_data(name: str) -> str:
1515
"""
1616
registry = {
1717
"tem_2d.mrc": "3c6f9ff6d7673d9bf2fd46c09750c3c7dbb8fa1aa59dcdb3363b65cc774dcf28",
18-
"tem_tomo.mrc": "24af31a10761b59fa6ad9f0e763f8f084304e4f31c59b482dd09dde8cd443ed7",
18+
"tem_tomo.mrc": "eb790f83efb4c967c96961239ae52578d95da902fc32307629f76a26c3dc61fa",
1919
}
2020
urls = {
2121
"tem_2d.mrc": "https://owncloud.gwdg.de/index.php/s/5sAQ0U4puAspcHg/download",
22-
"tem_tomo.mrc": "https://owncloud.gwdg.de/index.php/s/NeP7gOv76Vj26lm/download",
22+
"tem_tomo.mrc": "https://owncloud.gwdg.de/index.php/s/TmLjDCXi42E49Ef/download",
2323
}
2424
key = f"{name}.mrc"
2525

0 commit comments

Comments
 (0)