diff --git a/examples/06_secondary_labeling/.gitignore b/examples/06_secondary_labeling/.gitignore new file mode 100644 index 000000000..92f4a577f --- /dev/null +++ b/examples/06_secondary_labeling/.gitignore @@ -0,0 +1,7 @@ +images +model +output +backup +tmp* +slurm-*.out +slurm-*.err diff --git a/examples/06_secondary_labeling/01_final_metadata.json b/examples/06_secondary_labeling/01_final_metadata.json new file mode 100644 index 000000000..f4915fc16 --- /dev/null +++ b/examples/06_secondary_labeling/01_final_metadata.json @@ -0,0 +1,22 @@ +{ + "coarsening_xy": 2, + "copy_zarr": { + "sources": { + "RS220304172545_mip": "/home/tommaso/Fractal/fractal-tasks-core/examples/06_secondary_labeling/output/RS220304172545.zarr" + }, + "suffix": "mip" + }, + "image": [ + "RS220304172545_mip.zarr/A/06/0/" + ], + "num_levels": 5, + "original_paths": [ + "images/*.tif" + ], + "plate": [ + "RS220304172545_mip.zarr" + ], + "well": [ + "RS220304172545_mip.zarr/A/06/" + ] +} diff --git a/examples/06_secondary_labeling/01_images_to_mip.py b/examples/06_secondary_labeling/01_images_to_mip.py new file mode 100644 index 000000000..d9ba87e4f --- /dev/null +++ b/examples/06_secondary_labeling/01_images_to_mip.py @@ -0,0 +1,100 @@ +import json +from pathlib import Path + +from devtools import debug + +from fractal_tasks_core.copy_ome_zarr import copy_ome_zarr +from fractal_tasks_core.create_ome_zarr import create_ome_zarr +from fractal_tasks_core.maximum_intensity_projection import ( + maximum_intensity_projection, +) +from fractal_tasks_core.yokogawa_to_ome_zarr import yokogawa_to_ome_zarr + + +allowed_channels = [ + { + "wavelength_id": "A01_C01", + "colormap": "00FFFF", + "end": 2000, + "label": "Channel 1", + "start": 110, + }, + { + "wavelength_id": "A02_C02", + "colormap": "FF00FF", + "end": 500, + "label": "Channel 2", + "start": 110, + }, + { + "wavelength_id": "A03_C03", + "colormap": "00FF00", + "end": 1600, + "label": "Channel 3", + "start": 110, + }, + { + "wavelength_id": "A04_C04", + "colormap": "FFFF00", + "end": 1600, + "label": "Channel 4", + "start": 110, + }, +] + + +num_levels = 5 +coarsening_xy = 2 + + +# Init +img_path = Path("images/*.tif") +zarr_path = Path("output/*zarr") +zarr_path_mip = Path("output/*zarr") +metadata = {} + +# Create zarr structure +metadata_update = create_ome_zarr( + input_paths=[img_path], + output_path=zarr_path, + metadata=metadata, + allowed_channels=allowed_channels, + num_levels=num_levels, + coarsening_xy=coarsening_xy, + metadata_table="mrf_mlf", +) +metadata.update(metadata_update) +debug(metadata) + +# Yokogawa to zarr +for component in metadata["image"]: + yokogawa_to_ome_zarr( + input_paths=[zarr_path], + output_path=zarr_path, + metadata=metadata, + component=component, + ) +debug(metadata) + +# Replicate +metadata_update = copy_ome_zarr( + input_paths=[zarr_path], + output_path=zarr_path_mip, + metadata=metadata, + project_to_2D=True, + suffix="mip", +) +metadata.update(metadata_update) +debug(metadata) + +# MIP +for component in metadata["image"]: + maximum_intensity_projection( + input_paths=[zarr_path_mip], + output_path=zarr_path_mip, + metadata=metadata, + component=component, + ) +debug(metadata) +with open("01_final_metadata.json", "w") as f: + json.dump(metadata, f, indent=4, sort_keys=True) diff --git a/examples/06_secondary_labeling/02_cellpose_organoids.py b/examples/06_secondary_labeling/02_cellpose_organoids.py new file mode 100644 index 000000000..1dcd73c79 --- /dev/null +++ b/examples/06_secondary_labeling/02_cellpose_organoids.py @@ -0,0 +1,44 @@ +import json +import os +import shutil +from pathlib import Path + +from devtools import debug + +from fractal_tasks_core.cellpose_segmentation import cellpose_segmentation + + +if os.path.exists("tmp"): + shutil.rmtree("tmp") +os.mkdir("tmp") +shutil.copytree( + "output/RS220304172545_mip.zarr", "tmp/RS220304172545_mip.zarr" +) + +# Init +zarr_path_mip = Path("tmp/*zarr") +with open("01_final_metadata.json", "r") as f: + metadata = json.load(f) + + +# Cellpose for organoids +for component in metadata["image"]: + cellpose_segmentation( + input_paths=[zarr_path_mip], + output_path=zarr_path_mip, + metadata=metadata, + component=component, + wavelength_id="A01_C01", + level=3, + relabeling=True, + diameter_level0=1000.0, + ROI_table_name="well_ROI_table", + cellprob_threshold=-3.0, + flow_threshold=0.4, + pretrained_model="model/Hummingbird.331986", + output_label_name="organoids", + ) + +debug(metadata) +with open("02_final_metadata.json", "w") as f: + json.dump(metadata, f, indent=4, sort_keys=True) diff --git a/examples/06_secondary_labeling/02_final_metadata.json b/examples/06_secondary_labeling/02_final_metadata.json new file mode 100644 index 000000000..f4915fc16 --- /dev/null +++ b/examples/06_secondary_labeling/02_final_metadata.json @@ -0,0 +1,22 @@ +{ + "coarsening_xy": 2, + "copy_zarr": { + "sources": { + "RS220304172545_mip": "/home/tommaso/Fractal/fractal-tasks-core/examples/06_secondary_labeling/output/RS220304172545.zarr" + }, + "suffix": "mip" + }, + "image": [ + "RS220304172545_mip.zarr/A/06/0/" + ], + "num_levels": 5, + "original_paths": [ + "images/*.tif" + ], + "plate": [ + "RS220304172545_mip.zarr" + ], + "well": [ + "RS220304172545_mip.zarr/A/06/" + ] +}