Skip to content

Commit

Permalink
add labelmerge placeholder
Browse files Browse the repository at this point in the history
- Adds in rule for labelmerge (needs updating with container and proper
command)
- Update resources with correct names and paths
- Add tsv to rule all for copying from resource to bids folders for
labelmerge
- Simplify rule all
  • Loading branch information
kaitj committed Nov 22, 2022
1 parent 2e40928 commit 46753ec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
13 changes: 7 additions & 6 deletions dbsc/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,18 @@ parse_args:
Space: MNI152NLin6Asym

zona_bb_subcortex:
tsv: 'resources/zona_bb_subcortex/desc-ZonaBBSubcor_dseg.tsv'
MNI152NLin6Asym:
dir: 'resources/MNI152NLin6Asym/'
T1w: 'resources/MNI152NLin6Asym/tpl-MNI152NLin6Asm_res-04_desc-brain_T1w.nii.gz'
seg: 'resources/MNI152NLin6Asym/sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_desc-ZonaBBSubcor_dseg.nii.gz'
dir: 'resources/zona_bb_subcortex/MNI152NLin6Asym/'
T1w: 'tpl-MNI152NLin6Asym_res-04_desc-brain_T1w.nii.gz'
seg: 'sub-SNSX32NLin2020Asym_space-MNI152NLin6Asym_desc-ZonaBBSubcor_dseg.nii.gz'
MNI152NLin2009bAsym:
dir: 'resources/MNI152NLin2009bAsym/'
seg: 'resources/MNI152NLin2009bAsym/sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_desc-ZonaBBSubcor_dseg.nii.gz'
dir: 'resources/zona_bb_subcortex/MNI152NLin2009bAsym/'
seg: 'sub-SNSX32NLin2020Asym_space-MNI152NLin2009bAsym_desc-ZonaBBSubcor_dseg.nii.gz'

# NOTE: This may not be needed with labelmerge
freesurfer:
tsv: 'resources/freesurfer/desc-Freesurfer_dseg.tsv'
tsv: 'resources/freesurfer/desc-FreesurferThal_dseg.tsv'

# Containers
# NOTE: Update from latest to use specific tags
Expand Down
18 changes: 3 additions & 15 deletions dbsc/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,8 @@ include: "rules/mrtpipelines.smk"
rule all:
input:
files=expand(
bids(
root=str(Path(config["output_dir"]) / "mrtrix"),
subject="{subject}",
datatype="tractography",
desc="filteredsubcortical",
suffix="nodeAssignment.txt",
),
rules.filtered_tck2connectome.output.sl_assignment,
subject=config["input_lists"]["dwi"]["subject"],
),
fs_tsv=str(
Path(config["output_dir"]) / "freesurfer" / config["freesurfer"]["tsv"]
),
zona_tsv=str(
Path(config["output_dir"])
/ "zona_bb_subcortex"
/ config["zona_bb_subcortex"]["tsv"]
),
fs_tsv=rules.cp_fs_tsv.output.fs_tsv,
zona_tsv=rules.cp_zona_tsv.output.zona_tsv,
19 changes: 8 additions & 11 deletions dbsc/workflow/rules/zona_bb_subcortex.smk
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ rule cp_zona_tsv:
output:
zona_tsv=f"{zona_dir}/desc-ZonaBBSubcor_dseg.tsv",
shell:
"cp -v {input.fs_tsv} {output.fs_tsv}"
"cp -v {input.zona_tsv} {output.zona_tsv}"


rule xfm2native:
"""Transform from Zona template space to subject native space"""
input:
seg=str(
Path(workflow.basedir).parent
/ Path(config["zona_bb_subcortex"][config["Space"]]["dir"])
/ Path(config["zona_bb_subcortex"][config["Space"]]["seg"])
),
seg_anat=str(
Path(workflow.basedir).parent
/ Path(config["zona_bb_subcortex"][config["Space"]]["dir"])
/ Path(config["zona_bb_subcortex"][config["Space"]]["T1w"])
),
ref=config["input_path"]["T1w"],
Expand Down Expand Up @@ -135,9 +137,6 @@ rule rm_bb_thal:
"fslmaths {output.seg} -add {output.non_thal} {output.seg}"


# NEED TO PIPE FROM rm_bb_thal with labelmerge and PIPE TO binarize
# Alternative option is to have a second target rule that performs everything
# below with participant2 and everything above with participant1
rule labelmerge:
input:
seg=expand(
Expand All @@ -154,8 +153,8 @@ rule labelmerge:
fs_dir=str(Path(config["output_dir"]) / "freesurfer"),
zona_desc="ZonaBBSubcor",
fs_desc="FreesurferThal",
output:
labelmerge_dir=directory(labelmerge_dir),
output:
seg=expand(
bids_labelmerge(
subject="{subject}",
Expand All @@ -177,10 +176,9 @@ rule labelmerge:
# ADD CONTAINER
shell:
# TO BE UPDATED WITH APPROPRIATE COMMAND
"run.py {params.zona_dir} {output.labelmerge_dir} --overlay_bids_dir {params.fs_dir} --overlay_desc {params.fs_desc} --base_desc {params.zona_desc}"
"run.py {params.zona_dir} {params.labelmerge_dir} --overlay_bids_dir {params.fs_dir} --overlay_desc {params.fs_desc} --base_desc {params.zona_desc}"


# Placeholder desc entity
rule binarize:
input:
seg=bids_labelmerge(
Expand All @@ -200,30 +198,29 @@ rule binarize:
"fslmaths {input.seg} -bin {output.mask}"


# Placeholder desc entity
rule add_brainstem:
input:
mask=rules.binarize.output.mask,
aparcaseg=rules.fs_xfm_to_native.output.aparcaseg,
output:
mask=bids_anat(
root=rules.labelmerge.output.labelmerge_dir,
root=labelmerge_dir,
space="T1w",
desc="labelmergeStem",
suffix="mask.nii.gz",
),
container:
config["singularity"]["neuroglia-core"]
shell:
"fslmaths {input.aparcaseg} -thr 16 -uthr 16 -bin -max {input.seg} {output.seg}"
"fslmaths {input.aparcaseg} -thr 16 -uthr 16 -bin -max {input.mask} {output.mask}"


rule create_convex_hull:
input:
bin_seg=rules.add_brainstem.output.mask,
output:
convex_hull=bids_anat(
root=rules.labelmerge.output.labelmerge_dir,
root=labelmerge_dir,
space="T1w",
desc="ConvexHull",
suffix="mask.nii.gz",
Expand Down

0 comments on commit 46753ec

Please sign in to comment.