-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First commit for examples/06_secondary_labeling
- Loading branch information
Showing
5 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
images | ||
model | ||
output | ||
backup | ||
tmp* | ||
slurm-*.out | ||
slurm-*.err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
] | ||
} |