diff --git a/flamingo_tools/segmentation/synapse_detection.py b/flamingo_tools/segmentation/synapse_detection.py index ef27db1..4a12e8d 100644 --- a/flamingo_tools/segmentation/synapse_detection.py +++ b/flamingo_tools/segmentation/synapse_detection.py @@ -175,6 +175,11 @@ def marker_detection( if os.path.exists(output_path) and prediction_key in zarr.open(output_path, "r"): skip_prediction = True + # skip prediction if post-processed output exists + detection_path = os.path.join(output_folder, "synapse_detection.tsv") + if os.path.exists(detection_path): + skip_prediction = True + if not skip_prediction: prediction_impl( input_path, input_key, output_folder, model_path, @@ -182,7 +187,6 @@ def marker_detection( apply_postprocessing=False, output_channels=1, ) - detection_path = os.path.join(output_folder, "synapse_detection.tsv") if not os.path.exists(detection_path): input_ = zarr.open(output_path, "r")[prediction_key] detections = find_local_maxima( diff --git a/reproducibility/block_extraction/GEK233L_IHC.json b/reproducibility/block_extraction/GEK233L_IHC.json new file mode 100644 index 0000000..0ec9aab --- /dev/null +++ b/reproducibility/block_extraction/GEK233L_IHC.json @@ -0,0 +1,41 @@ +[ + { + "cochlea": "G_EK_000233_L", + "image_channel": [ + "Vglut3", + "IHC_v6" + ], + "halo_size": [ + 196, + 196, + 80 + ], + "crop_centers": [ + [ + 593, + 1018, + 276 + ], + [ + 674, + 1048, + 1574 + ], + [ + 788, + 937, + 255 + ], + [ + 950, + 1450, + 380 + ], + [ + 1120, + 875, + 360 + ] + ] + } +] diff --git a/reproducibility/block_extraction/GLR233R_SGN_DA.json b/reproducibility/block_extraction/GLR233R_SGN_DA.json new file mode 100644 index 0000000..b996e32 --- /dev/null +++ b/reproducibility/block_extraction/GLR233R_SGN_DA.json @@ -0,0 +1,50 @@ +[ + { + "cochlea": "G_LR_000233_R", + "image_channel": [ + "PV" + ], + "halo_size": [ + 196, + 196, + 196 + ], + "crop_centers": [ + [ + 620, + 1060, + 1050 + ], + [ + 1555, + 1170, + 1230 + ], + [ + 1600, + 1075, + 1090 + ], + [ + 1390, + 1430, + 1375 + ], + [ + 650, + 1130, + 1000 + ], + [ + 800, + 1230, + 710 + ], + [ + 600, + 1100, + 1055 + ] + ] + } +] diff --git a/reproducibility/block_extraction/GLR233R_SGN_train.json b/reproducibility/block_extraction/GLR233R_SGN_train.json new file mode 100644 index 0000000..e594322 --- /dev/null +++ b/reproducibility/block_extraction/GLR233R_SGN_train.json @@ -0,0 +1,36 @@ +[ + { + "cochlea": "G_LR_000233_R", + "image_channel": [ + "PV", + "SGN_v2-DA" + ], + "halo_size": [ + 196, + 196, + 48 + ], + "crop_centers": [ + [ + 1584, + 1570, + 958 + ], + [ + 1474, + 1655, + 730 + ], + [ + 1275, + 1604, + 1324 + ], + [ + 1603, + 1240, + 1279 + ] + ] + } +] diff --git a/reproducibility/block_extraction/LaVision-M04_SGN.json b/reproducibility/block_extraction/LaVision-M04_SGN.json new file mode 100644 index 0000000..222f06b --- /dev/null +++ b/reproducibility/block_extraction/LaVision-M04_SGN.json @@ -0,0 +1,25 @@ +[ + { + "cochlea": "LaVision-M04", + "image_channel": [ + "PV" + ], + "resolution" : [ + 1.887779, + 1.887779, + 3.0 + ], + "halo_size": [ + 128, + 128, + 64 + ], + "crop_centers": [ + [ + 2550, + 2340, + 440 + ] + ] + } +] diff --git a/reproducibility/block_extraction/LaVision_IHC_M04.json b/reproducibility/block_extraction/LaVision_IHC_M04.json new file mode 100644 index 0000000..f1df999 --- /dev/null +++ b/reproducibility/block_extraction/LaVision_IHC_M04.json @@ -0,0 +1,41 @@ +[ + { + "cochlea": "LaVision-M04", + "image_channel": [ + "MYO", + "IHC_LOWRES-v1" + ], + "resolution" : [ + 1.887779, + 1.887779, + 3.0 + ], + "halo_size": [ + 128, + 128, + 32 + ], + "crop_centers": [ + [ + 3118, + 2840, + 500 + ], + [ + 1540, + 2075, + 924 + ], + [ + 2135, + 835, + 627 + ], + [ + 2025, + 1332, + 221 + ] + ] + } +] diff --git a/reproducibility/block_extraction/LaVision_OTOF_IHC.json b/reproducibility/block_extraction/LaVision_OTOF_IHC.json new file mode 100644 index 0000000..c660aa4 --- /dev/null +++ b/reproducibility/block_extraction/LaVision_OTOF_IHC.json @@ -0,0 +1,84 @@ +[ + { + "cochlea": "LaVision-OTOF23R", + "image_channel": [ + "CR", + "IHC_LOWRES-v2" + ], + "resolution" : [ + 1.887779, + 1.887779, + 3.0 + ], + "halo_size": [ + 128, + 128, + 48 + ], + "crop_centers": [ + [ + 1360, + 3450, + 732 + ], + [ + 2408, + 913, + 688 + ], + [ + 2700, + 3220, + 620 + ] + ] + }, + { + "cochlea": "LaVision-OTOF25R", + "image_channel": [ + "CR", + "IHC_LOWRES-v2" + ], + "resolution" : [ + 1.887779, + 1.887779, + 3.0 + ], + "halo_size": [ + 128, + 128, + 48 + ], + "crop_centers": [ + [ + 2490, + 3460, + 875 + ] + ] + }, + { + "cochlea": "LaVision-OTOF36R", + "image_channel": [ + "CR", + "IHC_LOWRES-v2" + ], + "resolution" : [ + 1.887779, + 1.887779, + 3.0 + ], + "halo_size": [ + 128, + 128, + 48 + ], + "crop_centers": [ + [ + 2558, + 3415, + 871 + ] + ] + } +] diff --git a/reproducibility/block_extraction/LaVision_SGN_empty.json b/reproducibility/block_extraction/LaVision_SGN_empty.json new file mode 100644 index 0000000..631d838 --- /dev/null +++ b/reproducibility/block_extraction/LaVision_SGN_empty.json @@ -0,0 +1,93 @@ +[ + { + "cochlea": "LaVision-M04", + "image_channel": [ + "PV" + ], + "resolution" : [ + 1.887779, + 1.887779, + 3.0 + ], + "halo_size": [ + 128, + 128, + 64 + ], + "crop_centers": [ + [ + 396, + 1906, + 383 + ], + [ + 830, + 3390, + 670 + ], + [ + 3520, + 1525, + 310 + ], + [ + 1867, + 2538, + 390 + ], + [ + 400, + 2500, + 840 + ] + ] + }, + { + "cochlea": "LaVision-Mar05", + "image_channel": [ + "PV" + ], + "resolution" : [ + 1.887779, + 1.887779, + 3.0 + ], + "halo_size": [ + 128, + 128, + 64 + ], + "crop_centers": [ + [ + 2247, + 2434, + 1660 + ], + [ + 1182, + 2920, + 726 + ], + [ + 2530, + 1660, + 1840 + ], + [ + 620, + 1900, + 1825 + ], + [ + 1330, + 3375, + 1114 + ], + [ + 3442, + 2950, + 1000 + ] + ] + } +] diff --git a/reproducibility/block_extraction/repro_block_extraction.py b/reproducibility/block_extraction/repro_block_extraction.py index e6458c0..22943cf 100644 --- a/reproducibility/block_extraction/repro_block_extraction.py +++ b/reproducibility/block_extraction/repro_block_extraction.py @@ -16,6 +16,7 @@ def repro_block_extraction( s3_flag = True tif_flag = True input_key = "s0" + default_resolution = 0.38 with open(json_file, 'r') as myfile: data = myfile.read() @@ -28,9 +29,11 @@ def repro_block_extraction( input_path = os.path.join(dic["cochlea"], "images", "ome-zarr", image_channel + ".ome.zarr") roi_halo = dic["halo_size"] crop_centers = dic["crop_centers"] + resolution = tuple(dic["resolution"]) if "resolution" in dic else default_resolution for coord in crop_centers: extract_block(input_path, coord, output_dir, input_key=input_key, roi_halo=roi_halo.copy(), tif=tif_flag, + resolution=resolution, s3=s3_flag, s3_credentials=s3_credentials, s3_bucket_name=s3_bucket_name, s3_service_endpoint=s3_service_endpoint) diff --git a/scripts/figures/plot_fig3.py b/scripts/figures/plot_fig3.py index aec623a..373f43f 100644 --- a/scripts/figures/plot_fig3.py +++ b/scripts/figures/plot_fig3.py @@ -16,7 +16,9 @@ from flamingo_tools.s3_utils import BUCKET_NAME, create_s3_target from util import sliding_runlength_sum, frequency_mapping, SYNAPSE_DIR_ROOT, to_alias -INPUT_ROOT = "/home/pape/Work/my_projects/flamingo-tools/scripts/M_LR_000227_R/scale3" +# INPUT_ROOT = "/home/pape/Work/my_projects/flamingo-tools/scripts/M_LR_000227_R/scale3" +INPUT_ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/frequency_mapping/M_LR_000227_R/scale3" +FILE_EXTENSION = "png" TYPE_TO_CHANNEL = { "Type-Ia": "CR", diff --git a/scripts/measurements/evaluate_marker_annotations.py b/scripts/measurements/evaluate_marker_annotations.py index d8f2b49..6fc72a7 100644 --- a/scripts/measurements/evaluate_marker_annotations.py +++ b/scripts/measurements/evaluate_marker_annotations.py @@ -24,6 +24,8 @@ "M_LR_000153_R", "M_LR_000155_R", "M_LR_000189_R", + "G_EK_000049_L", + "G_EK_000049_R", ] diff --git a/scripts/measurements/measure_synapses.py b/scripts/measurements/measure_synapses.py index 38fdcda..826f021 100644 --- a/scripts/measurements/measure_synapses.py +++ b/scripts/measurements/measure_synapses.py @@ -1,3 +1,4 @@ +import argparse import os import json @@ -8,16 +9,39 @@ OUTPUT_FOLDER = "./ihc_counts" +COCHLEAE = [ + "M_LR_000226_L", + "M_LR_000226_R", + "M_LR_000227_L", + "M_LR_000227_R", + "G_EK_000233_L", + "G_LR_000233_R", -def check_project(plot=False, save_ihc_table=False, max_dist=None): - s3 = create_s3_target() - # cochleae = ["M_LR_000226_L", "M_LR_000226_R", "M_LR_000227_L", "M_LR_000227_R", "M_AMD_OTOF1_L"] - cochleae = ["M_LR_000226_L", "M_LR_000226_R", "M_LR_000227_L", "M_LR_000227_R"] +] + + +SYNAPSE_DICT = { + "M_LR_000226_L": {"synapse_table_name": "synapse_v3_ihc_v4c", "ihc_table_name": "IHC_v4c"}, + "M_LR_000226_R": {"synapse_table_name": "synapse_v3_ihc_v4c", "ihc_table_name": "IHC_v4c"}, + "M_LR_000227_L": {"synapse_table_name": "synapse_v3_ihc_v4c", "ihc_table_name": "IHC_v4c"}, + "M_LR_000227_R": {"synapse_table_name": "synapse_v3_ihc_v4c", "ihc_table_name": "IHC_v4c"}, + "G_EK_000233_L": {"synapse_table_name": "synapse_v3_ihc_v6", "ihc_table_name": "IHC_v6"}, + "G_LR_000233_R": {"synapse_table_name": "synapse_v3_ihc_v6", "ihc_table_name": "IHC_v6"}, +} + +def check_project(cochleae, output_folder, plot=False, save_ihc_table=False, max_dist=None): + s3 = create_s3_target() results = {} for cochlea in cochleae: - synapse_table_name = "synapse_v3_ihc_v4c" - ihc_table_name = "IHC_v4c" + if cochlea in SYNAPSE_DICT.keys(): + synapse_table_name = SYNAPSE_DICT[cochlea]["synapse_table_name"] + ihc_table_name = SYNAPSE_DICT[cochlea]["ihc_table_name"] + + else: + synapse_table_name = "synapse_v3_ihc_v4c" + ihc_table_name = "IHC_v4c" + component_id = [1] if cochlea == "M_AMD_OTOF1_L": @@ -82,8 +106,8 @@ def check_project(plot=False, save_ihc_table=False, max_dist=None): "run_length": [run_length_dict[ihc_id] for ihc_id in ihc_to_count.keys()], "frequency": [frequency_dict[ihc_id] for ihc_id in ihc_to_count.keys()] }) - os.makedirs(OUTPUT_FOLDER, exist_ok=True) - output_path = os.path.join(OUTPUT_FOLDER, f"ihc_count_{cochlea}.tsv") + os.makedirs(output_folder, exist_ok=True) + output_path = os.path.join(output_folder, f"ihc_count_{cochlea}.tsv") ihc_count_table.to_csv(output_path, sep="\t", index=False) if plot: @@ -104,7 +128,15 @@ def check_project(plot=False, save_ihc_table=False, max_dist=None): def main(): - check_project(plot=False, save_ihc_table=True, max_dist=3) + parser = argparse.ArgumentParser( + description="Assign each segmentation instance a marker based on annotation thresholds." + ) + + parser.add_argument("-c", "--cochlea", type=str, nargs="+", default=COCHLEAE, help="Cochlea(e) to process.") + parser.add_argument("-o", "--output", type=str, default=OUTPUT_FOLDER, help="Output directory.") + + args = parser.parse_args() + check_project(args.cochlea, args.output, plot=False, save_ihc_table=True, max_dist=3) if __name__ == "__main__": diff --git a/scripts/training/sgn_domain_adaptation_gerbil_PV.py b/scripts/training/sgn_domain_adaptation_gerbil_PV.py index fba2097..192de1a 100644 --- a/scripts/training/sgn_domain_adaptation_gerbil_PV.py +++ b/scripts/training/sgn_domain_adaptation_gerbil_PV.py @@ -8,7 +8,7 @@ def get_paths(): root = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/training_data/SGN" - folders = ["2025-06-SGN_domain_gerbil_PV"] + folders = ["2025-09-SGN_domain_gerbil_GLR233R"] train_paths = [] val_paths = [] for folder in folders: @@ -49,7 +49,7 @@ def main(): parser = argparse.ArgumentParser() parser.add_argument("--export_path") args = parser.parse_args() - name = "sgn-adapted-model_gerbil_PV" + name = "sgn-adapted-model_GLR233R_PV" if args.export_path is None: run_training(name) else: