diff --git a/workflow/rules/qc.smk b/workflow/rules/qc.smk index 9e0c892..b98bd7f 100644 --- a/workflow/rules/qc.smk +++ b/workflow/rules/qc.smk @@ -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"), @@ -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" diff --git a/workflow/scripts/generate_volume_qc.py b/workflow/scripts/generate_volume_qc.py index 5e0c69a..2015dd5 100644 --- a/workflow/scripts/generate_volume_qc.py +++ b/workflow/scripts/generate_volume_qc.py @@ -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) @@ -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 diff --git a/workflow/scripts/generate_whole_slice_qc.py b/workflow/scripts/generate_whole_slice_qc.py index 5967b98..c01d555 100644 --- a/workflow/scripts/generate_whole_slice_qc.py +++ b/workflow/scripts/generate_whole_slice_qc.py @@ -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(".") @@ -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)