Skip to content

Commit

Permalink
adding t2w skullstripping
Browse files Browse the repository at this point in the history
  • Loading branch information
myousif9 committed Oct 24, 2022
1 parent 44017ed commit f2a15a5
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 228 deletions.
10 changes: 5 additions & 5 deletions anat_preproc/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ parse_args:

--grad_coef:
help: 'Provide path to gradient correction coefficient file. Gradient correction dis skipped if file is not specified.'
default: 'none'
default: false
required: false
nargs: 1

Expand All @@ -146,10 +146,10 @@ parse_args:
action: store_true


# --use_t2:
# help: 'Toggle for allowing pipeline to include T2w in fMRIprep for freesurfer reconstruction. (currently broken)'
# default: False
# required: False
--use_t2:
help: 'Toggle for allowing pipeline to include T2w in fMRIprep for freesurfer reconstruction. (currently broken)'
default: false
action: store_true


#--- workflow specific configuration -- below is just an example:
Expand Down
235 changes: 12 additions & 223 deletions anat_preproc/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,230 +23,19 @@ inputs = snakebids.generate_inputs(
wildcard_constraints: **snakebids.get_wildcard_constraints(config['pybids_inputs'])

#---- end snakebids boilerplate ------------------------------------------------
if config['grad_coef'] != 'none':
include: 'rules/gradcorrect_mprageise_mriqc.smk'
else:
if config['grad_coef'] == False:
include: 'rules/mprageise_mriqc.smk'
else:
include: 'rules/gradcorrect_mprageise_mriqc.smk'

include: 'rules/mriqc_synthstrip_t1w.smk'

rule mriqc2:
input:
mprageise_done = rules.mprageise.output.mprageised_uni,
params:
mprageise_dir = bids(
root = 'derivatives',
suffix = '3dmprageise'
),
mriqc_dir = bids(
root = 'derivatives',
suffix = 'mriqc'
),
output:
done = touch(bids(
root = 'work',
suffix = 'mriqc2.done',
**inputs.input_wildcards['uni']
))
group: 'subj'
container: config['singularity']['graham']['mriqc'] if config['graham'] else config['singularity']['docker']['mriqc']
threads: 8
resources:
mem_mb = 16000,
time = 1440,
log: bids(root='logs',suffix='mriqc2.log',**inputs.input_wildcards['uni'])
shell:
"""
mriqc {params.mprageise_dir} {params.mriqc_dir} participant --participant-label {wildcards.subject} &> {log}
"""

rule synthstrip_uni:
input:
mprageised_uni = rules.mprageise.output.mprageised_uni,
params:
container_path = config['singularity']['graham']['synthstrip'] if config['graham'] else config['singularity']['docker']['synthstrip'] ,
synthstrip_script = join(workflow.basedir,'../workflow/scripts/synthstrip-singularity')
output:
uni_skstrip = bids(
root = 'derivatives/synthstrip',
datatype = 'anat',
desc = 'synthstrip',
suffix = 'T1w.nii.gz',
**inputs.input_wildcards['uni']
),
uni_mask = bids(
root = 'derivatives/synthstrip',
datatype = 'anat',
space = 'T1w',
suffix = 'brainmask.nii.gz',
**inputs.input_wildcards['uni']
),
group: 'subj'
threads: 8
resources:
mem_mb = 16000,
time = 1440
log:
uni = bids(root='logs',suffix='synthstrip.log',**inputs.input_wildcards['uni']),
shell:
"""
python {params.synthstrip_script} {params.container_path} -i {input.mprageised_uni} -o {output.uni_skstrip} -m {output.uni_mask} &> {log}
"""

rule fmriprep:
input:
t1w = rules.synthstrip_uni.output.uni_skstrip,
# t2w = rules.synthstrip_t2w.output.t2w_skstrip,
fs_license = os.environ['FS_LICENSE'] if config['fs_license'] == False else config['fs_license'],
params:
synthstrip_dir =bids(
root = 'derivatives',
suffix = 'synthstrip'
),
fmriprep_outdir = bids(
root = 'derivatives',
suffix = 'fmriprep'
),
freesurfer_dir = bids(
root = 'derivatives',
suffix = 'freesurfer'
),
dataset_description = join(workflow.basedir,'../resources/dataset_description.json'),
work_directory = bids(
root = 'work',
suffix = 'fmriprep',
),
fmriprep_opts = config['fmriprep_opts'],
container = config['singularity']['graham']['fmriprep'] if config['graham'] else config['singularity']['docker']['fmriprep'],
output:
done = touch(bids(
root = 'work',
suffix = 'fmriprep.done',
**inputs.input_wildcards['uni']
))
group: 'subj'
threads: 8
resources:
mem_mb = 16000,
time = 1440
log: bids(root='logs',suffix='fmriprep.log',**inputs.input_wildcards['uni'])
shell:
"""
cp -n {params.dataset_description} {params.synthstrip_dir}
mkdir -p {params.work_directory}
mkdir -p {params.fmriprep_outdir}
singularity run --cleanenv \
-B {params.synthstrip_dir}:/data \
-B {params.fmriprep_outdir}:/out \
-B {params.work_directory}:/work \
-B {input.fs_license}:/opt/freesurfer/license.txt \
{params.container} /data {params.fmriprep_outdir} participant \
--participant_label {wildcards.subject} --skip_bids_validation --skull-strip-t1w skip -w /work \
{params.fmriprep_opts} &> {log}
"""

rule ciftify_recon_all:
input:
fmriprep_done = rules.fmriprep.output.done,
fs_license = os.environ['FS_LICENSE'] if config['fs_license'] == False else config['fs_license'],
params:
freesurfer_dir = bids(
root = 'derivatives/fmriprep/sourcedata',
suffix = 'freesurfer'
),
ciftify_outdir = bids(
root = 'derivatives',
suffix = 'ciftify'
),
ciftify_opts = config['ciftify_opts'],
output:
done = touch(bids(
root = 'work',
suffix = 'ciftify.done',
**inputs.input_wildcards['uni']
)),
container: config['singularity']['graham']['ciftify'] if config['graham'] else config['singularity']['docker']['ciftify']
group: 'subj'
threads: 8
resources:
mem_mb = 16000,
time = 1440
log: bids(root='logs',suffix='ciftifyreconall.log',**inputs.input_wildcards['uni'])
shell:
"""
ciftify_recon_all {params.ciftify_opts} --ciftify-work-dir '{params.ciftify_outdir}' --fs-subjects-dir '{params.freesurfer_dir}' --fs-license '{input.fs_license}' --n_cpus '{threads}' 'sub-{wildcards.subject}' &> {log}
cifti_vis_recon_all subject --ciftify-work-dir '{params.ciftify_outdir}' 'sub-{wildcards.subject}' &> {log}
cifti_vis_recon_all index --ciftify-work-dir '{params.ciftify_outdir}' &> {log}
"""

rule all_skstrip:
input:
expand(
expand(
rules.synthstrip_uni.output.uni_skstrip,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.mriqc.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.mriqc2.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
default_target: True
if config['use_t2']:
include: 'rules/synthstrip_t2w.smk'

rule all:
input:
expand(
expand(
rules.synthstrip_uni.output.uni_skstrip,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.mriqc.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.mriqc2.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.fmriprep.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.ciftify_recon_all.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
include: 'rules/fmriprep_ciftify.smk'

default_target: True
if config['use_t2']:
include: 'rules/all_T2w.smk'
else:
include: 'rules/all_noT2w.smk'
88 changes: 88 additions & 0 deletions anat_preproc/workflow/rules/all_T2w.smk
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
rule all_skstrip:
input:
expand(
expand(
rules.synthstrip_uni.output.uni_skstrip,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.synthstrip_t2w.output.t2w_skstrip,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['t2w']
),
expand(
expand(
rules.mriqc.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.mriqc2.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
default_target: True

rule all:
input:
expand(
expand(
rules.synthstrip_uni.output.uni_skstrip,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.synthstrip_t2w.output.t2w_skstrip,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['t2w']
),
expand(
expand(
rules.mriqc.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.mriqc2.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.fmriprep.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),
expand(
expand(
rules.ciftify_recon_all.output.done,
allow_missing=True,
),
zip,
**inputs.input_zip_lists['uni']
),

default_target: True
Loading

0 comments on commit f2a15a5

Please sign in to comment.