Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for writing omero metadata #6

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ ome_zarr:
- 1024
- 1024
scaling_method: 'local_mean' #can be nearest, gaussian, local_mean, zoom (zoom uses spline interp)

omero_metadata:
channels:
default_color: 'FFFFFF'
color_mapping:
autof: 'FFFFFF'
abeta: '00FF00'
defaults:
active: True
coefficient: 1.0
inverted: False
family: linear
window:
min: 0
max: 65535
start: 0
end: 65535
defaults:
rdefs:
defaultT: 0
defaultZ: 0
model: 'color'
id: 0
name: spim
version: "0.4"

nifti:
levels: #cannot be higher than max_downsampling_layers in ome_zarr
Expand Down
1 change: 1 addition & 0 deletions workflow/rules/ome_zarr.smk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rule zarr_to_ome_zarr:
rechunk_size=config["ome_zarr"]["rechunk_size"],
scaling_method=config["ome_zarr"]["scaling_method"],
downsampling=config["bigstitcher"]["fuse_dataset"]["downsampling"],
stains=get_stains,
output:
zarr=temp(
directory(
Expand Down
19 changes: 17 additions & 2 deletions workflow/scripts/zarr_to_ome_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
max_layer=snakemake.params.max_downsampling_layers #number of downsamplings by 2 to include in zarr
rechunk_size=snakemake.params.rechunk_size
out_zarr=snakemake.output.zarr
stains=snakemake.params.stains
scaling_method=snakemake.params.scaling_method

# prepare metadata for ome-zarr
Expand All @@ -37,16 +38,28 @@
axes = [{'name': 'c', 'type': 'channel'}] + [{'name': ax, 'type': 'space', 'unit': 'micrometer'} for ax in ['z','y','x'] ]


#init omero metadata
omero={key:val for key,val in snakemake.config['ome_zarr']['omero_metadata']['defaults'].items()}
omero['channels']=[]

darr_list=[]
for zarr_i in range(len(snakemake.input.zarr)):

#open zarr to get group name
in_zarr=snakemake.input.zarr[zarr_i]
zi = zarr.open(in_zarr)
group_name = [g for g in zi.group_keys()][0]

darr_list.append(da.from_zarr(in_zarr,component=f'{group_name}/s0',chunks=rechunk_size))

#append to omero metadata
channel_metadata={key:val for key,val in snakemake.config['ome_zarr']['omero_metadata']['channels']['defaults'].items()}
channel_name=stains[zarr_i]
channel_metadata['label'] = channel_name
default_color=snakemake.config['ome_zarr']['omero_metadata']['channels']['default_color']
color=snakemake.config['ome_zarr']['omero_metadata']['channels']['color_mapping'].get(channel_name,default_color)
channel_metadata['color'] = color
omero['channels'].append(channel_metadata)


darr_channels = da.stack(darr_list)

Expand All @@ -63,6 +76,8 @@
scaler=scaler,
coordinate_transformations=coordinate_transformations,
storage_options={'dimension_separator': '/'},
axes=axes)
axes=axes,
metadata={'omero':omero}
)


Loading