Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spimquant/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ if config.get("analysis_level") == "group":


wildcard_constraints:
acq="[a-zA-Z0-9]+",
stain="[a-zA-Z0-9]+",
pairwise_contrast="[a-zA-Z0-9+_-]+",
n4_spline="[0-9]+",
Expand Down
4 changes: 2 additions & 2 deletions spimquant/workflow/rules/regionprops.smk
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ rule compute_filtered_regionprops:
),
threads: 64 if config["dask_scheduler"] == "distributed" else 32
resources:
mem_mb=256000,
runtime=180,
mem_mb=500000,
runtime=360,
script:
"../scripts/compute_filtered_regionprops.py"

Expand Down
2 changes: 1 addition & 1 deletion spimquant/workflow/rules/segstats.smk
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ rule merge_into_segstats_tsv:
),
threads: 1
resources:
mem_mb=1500,
mem_mb=16000,
runtime=15,
script:
"../scripts/merge_into_segstats_tsv.py"
Expand Down
38 changes: 28 additions & 10 deletions spimquant/workflow/scripts/compute_filtered_regionprops.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
"""Compute region properties from filtered segmentation masks using ZarrNii.

This script reads a segmentation mask from an OME-Zarr file, performs
connected components on chunks with overlap, applys filters based on
Comment thread
Copilot marked this conversation as resolved.
Outdated
region properties, and outputs region properties on these filtered objects
"""

import os
import shutil
import tempfile
import zipfile
Comment thread
Copilot marked this conversation as resolved.
Outdated
from dask_setup import get_dask_client
from zarrnii import ZarrNii

if __name__ == "__main__":
with get_dask_client(snakemake.config["dask_scheduler"], snakemake.threads):

znimg = ZarrNii.from_file(
snakemake.input.mask,
level=0, # input image is already downsampled to the wildcard level
)
# 1. Create a secure, temporary directory in the system default tempdir
with tempfile.TemporaryDirectory(suffix=".ome.zarr") as temp_dir:
print(f"Extracting zip archive to temporary directory: {temp_dir}")

# 2. Open and extract the entire input zip file safely
Comment thread
akhanf marked this conversation as resolved.
Outdated
with zipfile.ZipFile(snakemake.input.mask, "r") as zip_ref:
zip_ref.extractall(temp_dir)

# 3. Locate the extracted directory/file path inside the temp folder
# OME-Zarr is usually a single top-level directory inside the zip.
extracted_contents = os.listdir(temp_dir)
if not extracted_contents:
raise ValueError("The input zip file is empty.")

# Direct path to the extracted .zarr directory structure
zarr_temp_path = os.path.join(temp_dir, extracted_contents[0])

# 4. Point ZarrNii to the unzipped DirectoryStore instead of the ZipStore
znimg = ZarrNii.from_file(temp_dir)

znimg.compute_region_properties(
output_path=snakemake.output.regionprops_parquet,
region_filters=snakemake.params.region_filters,
output_properties=snakemake.params.output_properties,
)
znimg.compute_region_properties(
output_path=snakemake.output.regionprops_parquet,
region_filters=snakemake.params.region_filters,
output_properties=snakemake.params.output_properties,
)