Skip to content

Commit

Permalink
add support for writing omero metadata (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
akhanf authored Feb 22, 2024
1 parent 6c80276 commit 342ecdb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
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}
)


0 comments on commit 342ecdb

Please sign in to comment.