generated from snakemake-workflows/snakemake-workflow-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* uses zarr copy and new metadata import function to import from imaris prestitched
- Loading branch information
Showing
11 changed files
with
2,262 additions
and
1,951 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
subject sample acq stain_0 stain_1 stain_2 sample_path | ||
mouse1 brain blaze Lectin PI Abeta .test/dryrun/data | ||
lifecanvas1 brain prestitched PI Abeta n/a .test/dryrun/data | ||
brown brain imaris1x Iba1 GFAP YOPRO .test/dryrun/data |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
rule imaris_to_metadata: | ||
input: | ||
ims=get_input_sample, | ||
output: | ||
metadata_json=bids( | ||
root=root, | ||
subject="{subject}", | ||
datatype="micr", | ||
sample="{sample}", | ||
acq="{acq,[a-zA-Z0-9]*imaris[a-zA-Z0-9]*}", | ||
suffix="SPIM.json", | ||
), | ||
benchmark: | ||
bids( | ||
root="benchmarks", | ||
datatype="imaris_to_metdata", | ||
subject="{subject}", | ||
sample="{sample}", | ||
acq="{acq}", | ||
suffix="benchmark.tsv", | ||
) | ||
log: | ||
bids( | ||
root="logs", | ||
datatype="prestitched_to_metdata", | ||
subject="{subject}", | ||
sample="{sample}", | ||
acq="{acq}", | ||
suffix="log.txt", | ||
), | ||
group: | ||
"preproc" | ||
container: | ||
config["containers"]["spimprep"] | ||
script: | ||
"../scripts/imaris_to_metadata.py" | ||
|
||
|
||
rule imaris_channel_to_zarr: | ||
input: | ||
ims=get_input_sample, | ||
params: | ||
channel=lambda wildcards: get_stains(wildcards).index(wildcards.stain), | ||
output: | ||
zarr=temp( | ||
bids( | ||
root=work, | ||
subject="{subject}", | ||
datatype="micr", | ||
sample="{sample}", | ||
acq="{acq}", | ||
stain="{stain}", | ||
suffix="imaris.zarr.zip", | ||
) | ||
), | ||
log: | ||
bids( | ||
root="logs", | ||
subject="{subject}", | ||
datatype="imaris_channel_to_zarr", | ||
sample="{sample}", | ||
acq="{acq}", | ||
stain="{stain}", | ||
suffix="log.txt", | ||
), | ||
container: | ||
config["containers"]["spimprep"] | ||
group: | ||
"preproc" | ||
threads: 1 | ||
resources: | ||
runtime=360, | ||
mem_mb=1000, | ||
shadow: | ||
"minimal" | ||
script: | ||
"../scripts/imaris_channel_to_zarr.py" | ||
|
||
|
||
rule imaris_to_ome_zarr: | ||
input: | ||
zarr=lambda wildcards: expand( | ||
bids( | ||
root=work, | ||
subject="{subject}", | ||
datatype="micr", | ||
sample="{sample}", | ||
acq="{acq}", | ||
stain="{stain}", | ||
suffix="imaris.zarr.zip", | ||
), | ||
stain=get_stains(wildcards), | ||
allow_missing=True, | ||
), | ||
metadata_json=rules.prestitched_to_metadata.output.metadata_json, | ||
params: | ||
max_downsampling_layers=config["ome_zarr"]["max_downsampling_layers"], | ||
rechunk_size=config["ome_zarr"]["rechunk_size"], | ||
scaling_method=config["ome_zarr"]["scaling_method"], | ||
downsampling=config["bigstitcher"]["fuse_dataset"]["downsampling"], | ||
stains=get_stains, | ||
uri=get_output_ome_zarr_uri(), | ||
storage_provider_settings=workflow.storage_provider_settings, | ||
output: | ||
**get_output_ome_zarr("imaris"), | ||
log: | ||
bids( | ||
root="logs", | ||
subject="{subject}", | ||
datatype="imaris_to_ome_zarr", | ||
sample="{sample}", | ||
acq="{acq}", | ||
suffix="log.txt", | ||
), | ||
container: | ||
config["containers"]["spimprep"] | ||
group: | ||
"preproc" | ||
threads: config["total_cores"] | ||
resources: | ||
runtime=360, | ||
mem_mb=config["total_mem_mb"], | ||
shadow: | ||
"minimal" | ||
script: | ||
"../scripts/imaris_to_ome_zarr.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import h5py | ||
import hdf5plugin | ||
import zarr | ||
from sys import stdout #change this to log file later.. | ||
|
||
source = h5py.File(snakemake.input.ims, mode='r') | ||
|
||
store = zarr.ZipStore(snakemake.output.zarr,dimension_separator='/',mode='x') | ||
dest = zarr.group(store) | ||
|
||
zarr.copy(source['DataSet/ResolutionLevel 0/TimePoint 0/Channel {chan}/Data'.format(chan=snakemake.params.channel)], dest,log=stdout,compressor=None) | ||
source.close() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import h5py | ||
import xmltodict | ||
import json | ||
|
||
with h5py.File(snakemake.input.ims, "r") as hdf5_file: | ||
xml_data = hdf5_file['DataSetInfo/OME Image Tags/Image 0'][:] | ||
|
||
|
||
# Convert byte array to string and then to a dictionary | ||
xml_str = bytes(xml_data).decode('utf-8', errors='ignore') # Decode byte array to string | ||
|
||
try: | ||
xml_dict = xmltodict.parse(f"<root>{xml_str}</root>", namespace_separator=':') | ||
except Exception as e: | ||
print(f"Error parsing XML: {e}") | ||
|
||
|
||
metadata={} | ||
metadata['physical_size_x'] = float(xml_dict['root']['ca:CustomAttributes']['DataAxis0']['@PhysicalUnit']) | ||
metadata['physical_size_y'] = float(xml_dict['root']['ca:CustomAttributes']['DataAxis1']['@PhysicalUnit']) | ||
metadata['physical_size_z'] = abs(float(xml_dict['root']['ca:CustomAttributes']['DataAxis3']['@PhysicalUnit'])) | ||
metadata['PixelSize'] = [ metadata['physical_size_z']/1000.0, metadata['physical_size_y']/1000.0, metadata['physical_size_x']/1000.0] #zyx since OME-Zarr is ZYX | ||
metadata['PixelSizeUnits'] = 'mm' | ||
|
||
#write metadata to json | ||
with open(snakemake.output.metadata_json, 'w') as fp: | ||
json.dump(metadata, fp,indent=4) | ||
|
||
|
||
|
||
|
Oops, something went wrong.