diff --git a/config/config.yml b/config/config.yml index 8da69d0..ea899ef 100644 --- a/config/config.yml +++ b/config/config.yml @@ -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 diff --git a/workflow/rules/ome_zarr.smk b/workflow/rules/ome_zarr.smk index 71ae8ea..e36e46d 100644 --- a/workflow/rules/ome_zarr.smk +++ b/workflow/rules/ome_zarr.smk @@ -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( diff --git a/workflow/scripts/zarr_to_ome_zarr.py b/workflow/scripts/zarr_to_ome_zarr.py index f7584df..0a1ab5d 100644 --- a/workflow/scripts/zarr_to_ome_zarr.py +++ b/workflow/scripts/zarr_to_ome_zarr.py @@ -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 @@ -37,9 +38,12 @@ 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) @@ -47,6 +51,15 @@ 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) @@ -63,6 +76,8 @@ scaler=scaler, coordinate_transformations=coordinate_transformations, storage_options={'dimension_separator': '/'}, - axes=axes) + axes=axes, + metadata={'omero':omero} + )