Skip to content

Commit

Permalink
made raw_tif_glob redundant for simplicity (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
akhanf authored Feb 14, 2024
1 parent 8b539e2 commit 2cac411
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
1 change: 0 additions & 1 deletion config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ targets:

import:
raw_tif_pattern: "{prefix}_Blaze[{tilex} x {tiley}]_C{channel}_xyz-Table Z{zslice}.ome.tif"
raw_tif_glob: "{prefix}_Blaze[[]{tilex} x {tiley}[]]_C{channel}_xyz-Table Z{zslice}.ome.tif"
intensity_rescaling: 0.5 #raw images seem to be at the upper end of uint16 (over-saturated) -- causes wrapping issues when adjusting with flatfield correction etc. this rescales the raw data as it imports it..


Expand Down
6 changes: 3 additions & 3 deletions workflow/rules/import.smk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rule raw_to_metadata:
input:
ome_dir=rules.get_dataset.output.ome_dir,
params:
in_tif_glob=lambda wildcards, input: os.path.join(
in_tif_pattern=lambda wildcards, input: os.path.join(
input.ome_dir,
config["import"]["raw_tif_pattern"],
),
Expand Down Expand Up @@ -85,9 +85,9 @@ rule tif_to_zarr:
ome_dir=rules.get_dataset.output.ome_dir,
metadata_json=rules.raw_to_metadata.output.metadata_json,
params:
in_tif_glob=lambda wildcards, input: os.path.join(
in_tif_pattern=lambda wildcards, input: os.path.join(
input.ome_dir,
config["import"]["raw_tif_glob"],
config["import"]["raw_tif_pattern"],
),
intensity_rescaling=config["import"]["intensity_rescaling"],
output:
Expand Down
6 changes: 3 additions & 3 deletions workflow/scripts/raw_to_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from itertools import product
from snakemake.io import glob_wildcards

in_tif_glob = snakemake.params.in_tif_glob
in_tif_pattern = snakemake.params.in_tif_pattern

#parse the filenames to get number of channels, tiles etc..
prefix, tilex, tiley, channel, zslice = glob_wildcards(in_tif_glob)
prefix, tilex, tiley, channel, zslice = glob_wildcards(in_tif_pattern)

tiles_x = sorted(list(set(tilex)))
tiles_y = sorted(list(set(tiley)))
Expand All @@ -17,7 +17,7 @@
prefixes = sorted(list(set(prefix)))

#read in series metadata from first file
in_tif = in_tif_glob.format(tilex=tiles_x[0],tiley=tiles_y[0],prefix=prefixes[0],channel=channels[0],zslice=zslices[0])
in_tif = in_tif_pattern.format(tilex=tiles_x[0],tiley=tiles_y[0],prefix=prefixes[0],channel=channels[0],zslice=zslices[0])

raw_tif = tifffile.TiffFile(in_tif)

Expand Down
18 changes: 16 additions & 2 deletions workflow/scripts/tif_to_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@
from itertools import product
from dask.diagnostics import ProgressBar

in_tif_glob = snakemake.params.in_tif_glob
def replace_square_brackets(pattern):
"""replace all [ and ] in the string (have to use
intermediate variable to avoid conflicts)"""
pattern = pattern.replace('[','##LEFTBRACKET##')
pattern = pattern.replace(']','##RIGHTBRACKET##')
pattern = pattern.replace('##LEFTBRACKET##','[[]')
pattern = pattern.replace('##RIGHTBRACKET##','[]]')
return pattern


#create function handle to tifffile.imread that sets key=0
def single_imread(*args):
"""create function handle to tifffile.imread
that sets key=0"""
return tifffile.imread(*args,key=0)


#use tif pattern but replace the [ and ] with [[] and []] so glob doesn't choke
in_tif_glob = replace_square_brackets(str(snakemake.params.in_tif_pattern))


#read metadata json
with open(snakemake.input.metadata_json) as fp:
metadata = json.load(fp)
Expand Down

0 comments on commit 2cac411

Please sign in to comment.