Skip to content

Commit

Permalink
First commit for examples/06_secondary_labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Feb 16, 2023
1 parent d1ab0de commit 35bb6e2
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/06_secondary_labeling/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
images
model
output
backup
tmp*
slurm-*.out
slurm-*.err
22 changes: 22 additions & 0 deletions examples/06_secondary_labeling/01_final_metadata.json
Original file line number Diff line number Diff line change
@@ -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/"
]
}
100 changes: 100 additions & 0 deletions examples/06_secondary_labeling/01_images_to_mip.py
Original file line number Diff line number Diff line change
@@ -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)
44 changes: 44 additions & 0 deletions examples/06_secondary_labeling/02_cellpose_organoids.py
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions examples/06_secondary_labeling/02_final_metadata.json
Original file line number Diff line number Diff line change
@@ -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/"
]
}

0 comments on commit 35bb6e2

Please sign in to comment.