Skip to content

Commit

Permalink
updates to qc scripts/rules for remote zarrs
Browse files Browse the repository at this point in the history
  • Loading branch information
akhanf committed Jul 19, 2024
1 parent 4935593 commit 200f6e2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions workflow/rules/qc.smk
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ rule generate_flatfield_qc:
rule generate_whole_slice_qc:
"Generates an html file to view whole slices from preprocessed images"
input:
**get_storage_creds(),
ome=get_input_ome_zarr_to_nii(),
params:
ws_s_start=config["report"]["whole_slice_viewer"]["slice_start"],
ws_s_step=config["report"]["whole_slice_viewer"]["slice_step"],
ws_cmap=config["report"]["whole_slice_viewer"]["colour_map"],
uri=get_output_ome_zarr_uri(),
storage_provider_settings=workflow.storage_provider_settings,
output:
html="qc/sub-{subject}_sample-{sample}_acq-{acq}/whole_slice_qc.html",
images_dir=directory("qc/sub-{subject}_sample-{sample}_acq-{acq}/images/whole"),
Expand All @@ -71,7 +74,11 @@ rule generate_whole_slice_qc:
rule generate_volume_qc:
"Generates an html file to view the volume rendered image"
input:
**get_storage_creds(),
ome=get_input_ome_zarr_to_nii(),
params:
uri=get_output_ome_zarr_uri(),
storage_provider_settings=workflow.storage_provider_settings,
output:
resources=directory(
"qc/sub-{subject}_sample-{sample}_acq-{acq}/volume_resources"
Expand Down
16 changes: 15 additions & 1 deletion workflow/scripts/generate_volume_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from pathlib import Path
from distutils.dir_util import copy_tree
from zarrnii import ZarrNii
import dask.array as da
import math
from upath import UPath as Path
from lib.cloud_io import get_fsspec, is_remote
import zarr

# directory containing the volume rendering files
resource_dir = Path(snakemake.output.resources)
Expand All @@ -17,8 +21,18 @@
copy_tree("qc/resources/volViewer", str(resource_dir))
shutil.move(resource_dir / "volRender.html", html_dest)

uri = snakemake.params.uri
if is_remote(uri):
fs_args={'storage_provider_settings':snakemake.params.storage_provider_settings,'creds':snakemake.input.creds}
else:
fs_args={}

fs = get_fsspec(uri,**fs_args)
store = zarr.storage.FSStore(Path(uri).path,fs=fs,dimension_separator='/',mode='r')
darr = da.from_zarr(store,component='/5')

# Get most downsampled ome-zarr image
ds_z = ZarrNii.from_path(ome_data,level=5, channels=[0,1])
ds_z = ZarrNii.from_darr(darr)
z_length = ds_z.darr.shape[1]

# downsample it so it has at most 100 slices and ast least 50 slices in z-direction
Expand Down
17 changes: 16 additions & 1 deletion workflow/scripts/generate_whole_slice_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import matplotlib.pyplot as plt
import numpy as np
from jinja2 import Environment, FileSystemLoader
from upath import UPath as Path
from lib.cloud_io import get_fsspec, is_remote
import zarr

# load jinja html template
file_loader = FileSystemLoader(".")
Expand All @@ -23,8 +26,20 @@
image_dir = snakemake.output.images_dir
out_html = snakemake.output.html

from ome_zarr.io import ZarrLocation

uri = snakemake.params.uri
if is_remote(uri):
fs_args={'storage_provider_settings':snakemake.params.storage_provider_settings,'creds':snakemake.input.creds}
else:
fs_args={}

fs = get_fsspec(uri,**fs_args)
store = zarr.storage.FSStore(Path(uri).path,fs=fs,dimension_separator='/',mode='r')
zarrloc = ZarrLocation(store)

# read ome-zarr data and convert to list
proc_reader= Reader(parse_url(ome))
proc_reader= Reader(zarrloc)
proc_data=list(proc_reader())[0].data

os.makedirs(image_dir, exist_ok=True)
Expand Down

0 comments on commit 200f6e2

Please sign in to comment.