Skip to content

Commit

Permalink
Manualseg (#34)
Browse files Browse the repository at this point in the history
* BF: incidentally found bug in subfield+tissue

Was combining nnunet tissue seg with subfields, instead of
post-processed tissue seg with subfields. Probably had a
minor effect on the final dseg, but fixed now anyways

* BF: updated autotop and snakefile for man segs

autotop rule for man segs needed updating, and the
nnunet rules file is now only included if manual segs
are not used.

* added test data for seg, removed space wildcard

* BF: arguments in wrong order

Co-authored-by: jordandekraker <[email protected]>
  • Loading branch information
akhanf and jordandekraker authored Mar 7, 2021
1 parent d50354c commit 5f5b76f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
1 change: 0 additions & 1 deletion hippunfold/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pybids_inputs:
wildcards:
- subject
- session
# - space



Expand Down
12 changes: 10 additions & 2 deletions hippunfold/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ configfile: 'config/snakebids.yml'
limit_to_list = set()
limit_to_list.add('T1w') #always need T1w


for modality in config['modality']:
if modality[:3] == 'seg': #if modality is segT2w, then add seg and T2w
limit_to_list.add('seg')
Expand Down Expand Up @@ -89,9 +90,14 @@ def get_final_anat():
anat = []
for modality in config['modality']:
mod_index = get_modality_key(modality)
if mod_index == 'seg':
modality_suffix = modality[3:]
else:
modality_suffix = modality
anat = anat + \
expand(bids(root='results',datatype='seg_{modality}',desc='preproc',suffix='{modality}.nii.gz', space='cropT1w',hemi='{hemi}', **config['subj_wildcards']),
expand(bids(root='results',datatype='seg_{modality}',desc='preproc',suffix='{modality_suffix}.nii.gz', space='cropT1w',hemi='{hemi}', **config['subj_wildcards']),
modality=modality,
modality_suffix=modality_suffix,
hemi=['L','R'],
subject=config['input_lists'][mod_index]['subject'],
session=config['sessions'])
Expand Down Expand Up @@ -138,7 +144,10 @@ include: 'rules/preproc_t1.smk'
#include rules only as they are needed..
if 'segT1w' in config['modality'] or 'segT2w' in config['modality']:
include: 'rules/preproc_seg.smk'
else:
include: 'rules/nnunet.smk'

#if using manual segs, then don't use nnunet
if 'segT2w' in config['modality'] or 'T2w' in config['modality']:
include: 'rules/preproc_t2.smk'

Expand All @@ -147,6 +156,5 @@ if 'b500' in config['modality'] or 'b1000' in config['modality']:

include: 'rules/autotop.smk'
include: 'rules/gifti.smk'
include: 'rules/nnunet.smk'
include: 'rules/subfields.smk'
include: 'rules/resample_final_to_crop_t1.smk'
17 changes: 8 additions & 9 deletions hippunfold/workflow/rules/autotop.smk
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def get_autotop_input (wildcards):

return nii



rule run_autotop:
input:
nii = get_autotop_input,
Expand Down Expand Up @@ -69,7 +67,7 @@ def get_autotop_inputseg_cmd (wildcards, input, output):

if config['use_mcr'] == True:
cmd = f"AUTOTOP_DIR={autotop_dir} {autotop_dir}/mcr_v97/run_AutoTops_TransformAndRollOut.sh /opt/mcr/v97 "\
f"{input.nii} {output.out_dir} '{input.seg}' {config['cnn_model'][wildcards.modality]}"
f"{input.nii} {output.out_dir} {config['cnn_model'][wildcards.modality]} {input.seg}"
else:
singularity_cmd = f"singularity exec -B {autotop_dir}:/src -e {config['singularity']['autotop']}"
set_matlab_lic = f"SINGULARITYENV_MLM_LICENSE_FILE={config['mlm_license_file']}"
Expand All @@ -78,7 +76,7 @@ def get_autotop_inputseg_cmd (wildcards, input, output):

cmd = f"{set_matlab_lic} {set_java_home} {set_autotop_dir} {singularity_cmd} "\
f"{config['matlab_bin']} -batch \"addpath(genpath('{autotop_dir}')); "\
f"AutoTops_TransformAndRollOut('{input.nii}','{output.out_dir}','{config['cnn_model'][wildcards.modality]},'{input.seg}'')\""
f"AutoTops_TransformAndRollOut('{input.nii}','{output.out_dir}','{config['cnn_model'][wildcards.modality]}','{input.seg}')\""
return cmd

rule run_autotop_inputseg:
Expand All @@ -90,11 +88,12 @@ rule run_autotop_inputseg:
output:
out_dir = directory(bids(root='work',**config['subj_wildcards'],suffix='autotop',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='seg{modality}')),
#subfields = bids(root='work',**config['subj_wildcards'],suffix='autotop/subfields-BigBrain.nii.gz',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='seg{modality}'),
warp_unfold2native = bids(root='work',**config['subj_wildcards'],suffix='autotop/Warp_unfold2native.nii',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='{modality}'),
warp_native2unfold= bids(root='work',**config['subj_wildcards'],suffix='autotop/Warp_native2unfold.nii',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='{modality}'),
warpitk_unfold2native = bids(root='work',**config['subj_wildcards'],suffix='autotop/WarpITK_unfold2native.nii',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='{modality}'),
warpitk_native2unfold= bids(root='work',**config['subj_wildcards'],suffix='autotop/WarpITK_native2unfold.nii',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='{modality}'),
gii = expand(bids(root='work',suffix='autotop/{surfname}.unfoldedtemplate.surf.gii',desc='cropped', space='corobl',hemi='{{hemi}}',modality='seg{{modality}}', **config['subj_wildcards']),surfname=['inner','outer','midthickness'],allow_missing=True)
postproc = bids(root='work',**config['subj_wildcards'],suffix='autotop/labelmap-postProcess.nii.gz',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='seg{modality}'),
warp_unfold2native_extrap = bids(root='work',**config['subj_wildcards'],suffix='autotop/Warp_unfold2native_extrapolateNearest.nii',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='seg{modality}'),
warp_unfold2native = bids(root='work',**config['subj_wildcards'],suffix='autotop/Warp_unfold2native.nii',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='seg{modality}'),
warp_native2unfold= bids(root='work',**config['subj_wildcards'],suffix='autotop/Warp_native2unfold.nii',desc='cropped',space='corobl',hemi='{hemi,Lflip|R}',modality='seg{modality}'),
gii = expand(bids(root='work',suffix='autotop/{surfname}.unfoldedtemplate.surf.gii',desc='cropped', space='corobl',hemi='{hemi,Lflip|R}',modality='seg{modality}', **config['subj_wildcards']),surfname=['inner','outer','midthickness'],allow_missing=True),
coords = expand(bids(root='work',suffix='autotop/coords-{dir}.nii.gz',desc='cropped', space='corobl',hemi='{hemi,Lflip|R}',modality='seg{modality}', **config['subj_wildcards']),dir=['AP','PD','IO'],allow_missing=True)
threads: 8
resources:
time = 180 #3 hrs (so grouped job is set at 3hrs, since snakemake grouped resources not summed, but takes the max)
Expand Down
3 changes: 2 additions & 1 deletion hippunfold/workflow/rules/subfields.smk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

rule label_subfields_from_vol_coords_corobl:
""" Label subfields using the volumetric coords and bigbrain labels"""
input:
Expand Down Expand Up @@ -25,7 +26,7 @@ rule combine_tissue_subfield_labels_corobl:
then, we just need to add those in, using max(old,new) to override old with new in case of conflict
"""
input:
tissue = bids(root='work',datatype='seg_{modality}',suffix='dseg.nii.gz',desc='nnunet',space='corobl',hemi='{hemi}',**config['subj_wildcards']),
tissue = bids(root='work',**config['subj_wildcards'],suffix='autotop/labelmap-postProcess.nii.gz',desc='cropped',space='corobl',hemi='{hemi}',modality='{modality}'),
subfields = bids(root='work',datatype='seg_{modality}',desc='subfieldsnotissue',suffix='dseg.nii.gz', space='corobl',hemi='{hemi}', **config['subj_wildcards'])
params:
remap_dg = '-threshold 8 8 6 0 -popas dg',
Expand Down
Empty file.
Empty file.
Empty file.

0 comments on commit 5f5b76f

Please sign in to comment.