Skip to content

Commit 8a6d819

Browse files
committed
Update measure_synapses interface
1 parent ff08ecc commit 8a6d819

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

flamingo_tools/segmentation/synapse_detection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,18 @@ def marker_detection(
175175
if os.path.exists(output_path) and prediction_key in zarr.open(output_path, "r"):
176176
skip_prediction = True
177177

178+
# skip prediction if post-processed output exists
179+
detection_path = os.path.join(output_folder, "synapse_detection.tsv")
180+
if os.path.exists(detection_path):
181+
skip_prediction = True
182+
178183
if not skip_prediction:
179184
prediction_impl(
180185
input_path, input_key, output_folder, model_path,
181186
scale=None, block_shape=block_shape, halo=halo,
182187
apply_postprocessing=False, output_channels=1,
183188
)
184189

185-
detection_path = os.path.join(output_folder, "synapse_detection.tsv")
186190
if not os.path.exists(detection_path):
187191
input_ = zarr.open(output_path, "r")[prediction_key]
188192
detections = find_local_maxima(

scripts/measurements/measure_synapses.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import argparse
12
import os
23
import json
34

@@ -8,16 +9,39 @@
89

910
OUTPUT_FOLDER = "./ihc_counts"
1011

12+
COCHLEAE = [
13+
"M_LR_000226_L",
14+
"M_LR_000226_R",
15+
"M_LR_000227_L",
16+
"M_LR_000227_R",
17+
"G_EK_000233_L",
18+
"G_LR_000233_R",
1119

12-
def check_project(plot=False, save_ihc_table=False, max_dist=None):
13-
s3 = create_s3_target()
14-
# cochleae = ["M_LR_000226_L", "M_LR_000226_R", "M_LR_000227_L", "M_LR_000227_R", "M_AMD_OTOF1_L"]
15-
cochleae = ["M_LR_000226_L", "M_LR_000226_R", "M_LR_000227_L", "M_LR_000227_R"]
20+
]
21+
22+
23+
SYNAPSE_DICT = {
24+
"M_LR_000226_L": {"synapse_table_name": "synapse_v3_ihc_v4c", "ihc_table_name": "IHC_v4c"},
25+
"M_LR_000226_R": {"synapse_table_name": "synapse_v3_ihc_v4c", "ihc_table_name": "IHC_v4c"},
26+
"M_LR_000227_L": {"synapse_table_name": "synapse_v3_ihc_v4c", "ihc_table_name": "IHC_v4c"},
27+
"M_LR_000227_R": {"synapse_table_name": "synapse_v3_ihc_v4c", "ihc_table_name": "IHC_v4c"},
28+
"G_EK_000233_L": {"synapse_table_name": "synapse_v3_ihc_v6", "ihc_table_name": "IHC_v6"},
29+
"G_LR_000233_R": {"synapse_table_name": "synapse_v3_ihc_v6", "ihc_table_name": "IHC_v6"},
30+
}
1631

32+
33+
def check_project(cochleae, output_folder, plot=False, save_ihc_table=False, max_dist=None):
34+
s3 = create_s3_target()
1735
results = {}
1836
for cochlea in cochleae:
19-
synapse_table_name = "synapse_v3_ihc_v4c"
20-
ihc_table_name = "IHC_v4c"
37+
if cochlea in SYNAPSE_DICT.keys():
38+
synapse_table_name = SYNAPSE_DICT[cochlea]["synapse_table_name"]
39+
ihc_table_name = SYNAPSE_DICT[cochlea]["ihc_table_name"]
40+
41+
else:
42+
synapse_table_name = "synapse_v3_ihc_v4c"
43+
ihc_table_name = "IHC_v4c"
44+
2145
component_id = [1]
2246

2347
if cochlea == "M_AMD_OTOF1_L":
@@ -82,8 +106,8 @@ def check_project(plot=False, save_ihc_table=False, max_dist=None):
82106
"run_length": [run_length_dict[ihc_id] for ihc_id in ihc_to_count.keys()],
83107
"frequency": [frequency_dict[ihc_id] for ihc_id in ihc_to_count.keys()]
84108
})
85-
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
86-
output_path = os.path.join(OUTPUT_FOLDER, f"ihc_count_{cochlea}.tsv")
109+
os.makedirs(output_folder, exist_ok=True)
110+
output_path = os.path.join(output_folder, f"ihc_count_{cochlea}.tsv")
87111
ihc_count_table.to_csv(output_path, sep="\t", index=False)
88112

89113
if plot:
@@ -104,7 +128,15 @@ def check_project(plot=False, save_ihc_table=False, max_dist=None):
104128

105129

106130
def main():
107-
check_project(plot=False, save_ihc_table=True, max_dist=3)
131+
parser = argparse.ArgumentParser(
132+
description="Assign each segmentation instance a marker based on annotation thresholds."
133+
)
134+
135+
parser.add_argument("-c", "--cochlea", type=str, nargs="+", default=COCHLEAE, help="Cochlea(e) to process.")
136+
parser.add_argument("-o", "--output", type=str, default=OUTPUT_FOLDER, help="Output directory.")
137+
138+
args = parser.parse_args()
139+
check_project(args.cochlea, args.output, plot=False, save_ihc_table=True, max_dist=3)
108140

109141

110142
if __name__ == "__main__":

0 commit comments

Comments
 (0)