Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stains from ome-zarr, and Eed atlas labels #16

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 27 additions & 9 deletions spimquant/config/snakebids.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bids_dir: '/cifs/prado/Kate/AK_Pipeline_LSM/spimprep/bids/'
bids_dir: '../tests/data'
output_dir: '.'


Expand All @@ -23,8 +23,6 @@ pybids_inputs:
spim:
filters:
suffix: 'SPIM'
# acquisition: 4x #this will need to be blaze4x
subject: o28
extension: 'ome.zarr'
wildcards:
- subject
Expand All @@ -46,7 +44,6 @@ parse_args:
default: False



#--- workflow specific configuration --


Expand All @@ -70,38 +67,59 @@ ome_zarr:

template: ABAv3 #template to use



templates:
ABAv3:
anat: '{workflow.basedir}/../resources/ABAv3/P56_Atlas.nii.gz'
dseg: '{workflow.basedir}/../resources/ABAv3/P56_Annotation.nii.gz'
lut: '{workflow.basedir}/../resources/ABAv3/labelmapper_ABAv3_to_all.json'
segs:
all:
dseg: 'results/tpl-ABAv3/tpl-ABAv3_desc-LR_dseg.nii.gz'
tsv: 'results/tpl-ABAv3/tpl-ABAv3_desc-LR_dseg.tsv'
roi22:
dseg: '{workflow.basedir}/../resources/ABAv3/eed_labels/P56_annotation_22_R_L.nii.gz'
csv: '{workflow.basedir}/../resources/ABAv3/eed_labels/P56_annotation_22_R_L.csv'
roi82:
dseg: '{workflow.basedir}/../resources/ABAv3/eed_labels/P56_annotation_82_R_L.nii.gz'
csv: '{workflow.basedir}/../resources/ABAv3/eed_labels/P56_annotation_82_R_L.csv'


gubra:
anat: '{workflow.basedir}/../resources/gubra/gubra_template_olf_affine_padABAv3.nii.gz'
dseg: '{workflow.basedir}/../resources/gubra/gubra_ano_olf_affine_padABAv3_remap.nii.gz'
lut: '{workflow.basedir}/../resources/ABAv3/labelmapper_ABAv3_to_all.json'

stains:

stains_for_reg: #ordered by priority
- PI
- autof
- AutoF

stains_for_blobdetect:
- abeta
- Abeta
- BetaAmyloid
- AlphaSynuclein


templatereg:
stain: PI #set this to PI for lifecanvas data
level: 5
desc: N4brain
zooms:
# - 20
- 40

masking:
stain: PI #set this to PI for lifecanvas data
level: 5
priors_template: ABAv3
gmm_k: 9
gmm_bg_class: 1
pre_atropos_downsampling: '50%'

blobdetect:
level: 2 #downsampling level to use for blob detection
level: 4 #downsampling level to use for blob detection
dseg_level: 5 # downsampling level to use for template when assigning labels to blobs
dseg_template: ABAv3
stain: BetaAmyloid

22 changes: 22 additions & 0 deletions spimquant/resources/ABAv3/eed_labels/P56_annotation_22_R_L.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
L_OLF,L_Olfactory areas,1
R_OLF,R_Olfactory areas,2
L_Iso,L_Isocortex,3
R_ISO,R_Isocortex,4
L_HYP,L_Hippocampal formation,5
R_HYP,R_Hippocampal formation,6
L_AMY,L_Amygdala,7
R_AMY,R_Amygdala,8
L_STR,L_Striatum,9
R_STR,R_Striatum,10
L_PAL,L_Pallidum,11
R_PAL,R_Pallidum,12
L_THA,L_Thalamus,13
R_THA,R_Thalamus,14
L_HY,L_Hypothalamus,15
R_HY,R_Hypothalamus,16
L_MB,L_Midbrain,17
R_MB,R_Midbrain,18
L_HB,L_Hindbrain,19
R_HB,R_Hindbrain,20
L_CEB,L_Cerebellum,21
R_CEB,R_Cerebellum,22
Binary file not shown.
82 changes: 82 additions & 0 deletions spimquant/resources/ABAv3/eed_labels/P56_annotation_82_R_L.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
L_OLF,L_Olfactory_areas,1
R_OLF,R_Olfactory_areas,2
L_GU,L_Gustatory_areas,3
R_GU,R_Gustatory_areas,4
L_FRP,L_Frontal_pole_cerebral_cortex,5
R_FRP,R_Frontal_pole_cerebral_cortex,6
L_ECT,L_Ectorhinal_area,7
R_ECT,R_Ectorhinal_area,8
L_RSP,L_Retrosplenial_area,9
R_RSP,R_Retrosplenial_area,10
L_SS,L_Somatosensory_areas,11
R_SS,R_Somatosensory_areas,12
L_ILA,L_Infralimbic_area,13
R_ILA,R_Infralimbic_area,14
L_ACA,L_Anterior_cingulate_area,15
R_ACA,R_Anterior_cingulate_area,16
L_MO,L_Somatomotor_areas,17
R_MO,R_Somatomotor_areas,18
L_AI,L_Agranular_insular_area,19
R_AI,R_Agranular_insular_area,20
L_ORB,L_Orbital_area,21
R_ORB,R_Orbital_area,22
L_AUD,L_Auditory_areas,23
R_AUD,R_Auditory_areas,24
L_VISC,L_Visceral_area,25
R_VISC,R_Visceral_area,26
L_PERI,L_Perirhinal_area,27
R_PERI,R_Perirhinal_area,28
L_TEa,L_Temporal_association_areas,29
R_TEa,R_Temporal_association_areas,30
L_PTLp,L_Posterior_parietal_association_areas,31
R_PTLp,R_Posterior_parietal_association_areas,32
L_PL,L_Prelimbic_area,33
R_PL,R_Prelimbic_area,34
L_VIS,L_Visual_areas,35
R_VIS,R_Visual_areas,36
L_DG,L_Dentate_gyrus,37
R_DG,R_Dentate_gyrus,38
L_CA,L_Ammon's_horn,39
R_CA,R_Ammon's_horn,40
L_PAR,L_Parasubiculum,41
R_PAR,R_Parasubiculum,42
L_PRE,L_Presubiculum,43
R_PRE,R_Presubiculum,44
L_POST,L_Postsubiculum,45
R_POST,R_Postsubiculum,46
L_ProS,L_Prosubiculum,47
R_ProS,R_Prosubiculum,48
L_SUB,L_Subiculum,49
R_SUB,R_Subiculum,50
L_ENT,L_Entorhinal_area,51
R_ENT,R_Entorhinal_area,52
L_AMY,L_Amygdala,53
R_AMY,R_Amygdala,54
L_STRv,L_Striatum_ventral_region,55
R_STRv,R_Striatum_ventral_region,56
L_STRd,L_Striatum_dorsal_region,57
R_STRd,R_Striatum_dorsal_region,58
L_LSX,L_Lateral_septal_complex,59
R_LSX,R_Lateral_septal_complex,60
L_PAL,L_Pallidum,61
R_PAL,R_Pallidum,62
L_DORpm,L_Thalamus_polymodal_association_cortex_related,63
R_DORpm,R_Thalamus_polymodal_association_cortex_related,64
L_DORsm,L_Thalamus_sensory-motor_cortex_related,65
R_DORsm,R_Thalamus_sensory-motor_cortex_related,66
L_HY,L_Hypothalamus,67
R_HY,R_Hypothalamus,68
L_MBsen,L_Midbrain_sensory_related,69
R_MBsen,R_Midbrain_sensory_related,70
L_MBsta,L_Midbrain_behavioral_state_related,71
R_MBsta,R_Midbrain_behavioral_state_related,72
L_MBmot,L_Midbrain_motor_related,73
R_MBmot,R_Midbrain_motor_related,74
L_HB,L_Hindbrain,75
R_HB,R_Hindbrain,76
L_HEM,L_Hemispheric_regions,77
R_HEM,R_Hemispheric_regions,78
L_CBN,L_Cerebellar_nuclei,79
R_CBN,R_Cerebellar_nuclei,80
L_VERM,L_Vermal_regions,81
R_VERM,R_Vermal_regions,82
Binary file not shown.
38 changes: 29 additions & 9 deletions spimquant/workflow/Snakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from snakebids import bids, generate_inputs, get_wildcard_constraints, set_bids_spec
from snakemake.utils import format
import pathlib
import os
import shutil

set_bids_spec("v0_11_0")

Expand All @@ -25,8 +22,28 @@ inputs = generate_inputs(
participant_label=config.get("participant_label", None),
exclude_participant_label=config.get("exclude_participant_label", None),
validate=not config.get("plugins.validator.skip", False),
# ignore=["sourcedata"], #this is needed to correct a bug when parsing pybids datasets with fsspec, but requires updated snakebids (in akhanf fork)
)

from lib.ome_zarr import get_channel_names

# get stains from first subject (lazy - should use the correct stain for each subject, when defining target rules)
stains = get_channel_names(inputs["spim"].expand()[0])
print('stains in first subject:')
print(stains)
stain_for_reg = None
for stain in config["stains_for_reg"]:
if stain in stains:
stain_for_reg = stain
break

if stain_for_reg == None:
print("ERROR: a stain for registration was not found in the first OME zarr file")


stains_for_blobdetect = list(
set(config["stains_for_blobdetect"]).intersection(set(stains))
)
root = "results"


Expand All @@ -52,23 +69,25 @@ rule all_templatereg_deform_zooms:
**inputs["spim"].wildcards
),
template=config["template"],
stain=config["stains"],
stain=stains,
res=config["templatereg"]["zooms"],
),


rule all_blobdensity:
input:
blob_density=inputs["spim"].expand(
inputs["spim"].expand(
bids(
root=root,
datatype="micr",
seg="{seg}",
space="{template}",
stain="{stain}",
suffix="blobdensity.nii",
**inputs["spim"].wildcards
),
stain=config["blobdetect"]["stain"],
stain=stains_for_blobdetect,
seg=config["templates"][config["template"]]["segs"].keys(),
template=config["template"],
),

Expand All @@ -83,7 +102,7 @@ rule all_blobs:
suffix="blobs.npy",
**inputs["spim"].wildcards
),
stain=config["stains"],
stain=stains_for_blobdetect,
),


Expand All @@ -100,7 +119,7 @@ rule all_templatereg_deform:
**inputs["spim"].wildcards
),
template=config["template"],
stain=config["stains"],
stain=stains,
),


Expand All @@ -122,7 +141,8 @@ rule all_templatereg_lbl:
rule all:
default_target: True
input:
rules.all_templatereg_deform.input,
rules.all_templatereg_deform_zooms.input,
rules.all_blobdensity.input,


include: "rules/common.smk"
Expand Down
15 changes: 15 additions & 0 deletions spimquant/workflow/lib/ome_zarr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import zarr

def get_channel_names(path):

group = zarr.open_group(path, mode='r')

# Access the .zattrs metadata as a dictionary
metadata = dict(group.attrs)

# Retrieve channel names
return [chan['label'] for chan in metadata['multiscales'][0]['metadata']['omero']['channels']]

return channel_names


Loading