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

added logging #160

Merged
merged 4 commits into from
Jan 16, 2022
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
11 changes: 5 additions & 6 deletions hippunfold/workflow/rules/autotop.smk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import os
import numpy as np


def get_cmd_laplace_coords(wildcards):
def get_cmd_laplace_coords():
if config["skip_inject_template_labels"]:
cmd = "../scripts/laplace_coords.py"
else:
Expand Down Expand Up @@ -50,7 +50,6 @@ rule laplace_coords_hipp:
input:
unpack(get_inputs_laplace),
params:
cmd=get_cmd_laplace_coords,
gm_labels=lambda wildcards: config["laplace_labels"][wildcards.dir]["gm"],
src_labels=lambda wildcards: config["laplace_labels"][wildcards.dir]["src"],
sink_labels=lambda wildcards: config["laplace_labels"][wildcards.dir]["sink"],
Expand Down Expand Up @@ -81,7 +80,7 @@ rule laplace_coords_hipp:
suffix="laplace-hipp.txt"
),
script:
"{params.cmd}"
get_cmd_laplace_coords()


rule laplace_coords_dentate:
Expand Down Expand Up @@ -188,7 +187,7 @@ rule equivolume_coords:
**config["subj_wildcards"]
),
params:
src_labels=lambda wildcards: config["laplace_labels"][wildcards.dir]["src"],
script=os.path.join(workflow.basedir, "scripts/equivolume_coords.py"),
output:
coords=bids(
root=work,
Expand All @@ -215,8 +214,8 @@ rule equivolume_coords:
),
container:
config["singularity"]["autotop"]
script:
"../scripts/equivolume_coords.py"
shell:
"python {params.script} {resources.tmpdir} {input.innerbin} {input.outerbin} {output.coords} &> {log}"


rule unflip_coords:
Expand Down
2 changes: 1 addition & 1 deletion hippunfold/workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ rule archive_work_after_final:
"subj"
shell:
#exit code 0 or 1 is acceptable (2 is fatal)
"tar -cvzf {output} {params.work_dir}; "
"tar -czf {output} {params.work_dir}; "
"if [ $? -le 1 ]; then "
" rm -rf {params.work_dir}; "
"else exit 1; "
Expand Down
32 changes: 31 additions & 1 deletion hippunfold/workflow/rules/gifti.smk
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ rule constrain_surf_to_bbox:
label="{autotop}",
**config["subj_wildcards"]
),
log:
bids(
root="logs",
den="{density}",
suffix="{surfname}.txt",
desc="constrainbbox",
hemi="{hemi}",
label="{autotop}",
**config["subj_wildcards"]
),
group:
"subj"
script:
Expand Down Expand Up @@ -412,13 +422,23 @@ rule calculate_gyrification:
label="{autotop}",
**config["subj_wildcards"]
),
log:
bids(
root="logs",
den="{density}",
suffix="calcgyrification.txt",
space="{space}",
hemi="{hemi}",
label="{autotop}",
**config["subj_wildcards"]
),
container:
config["singularity"]["autotop"]
group:
"subj"
shell:
'wb_command -metric-math "nativearea/unfoldarea" {output.gii}'
" -var nativearea {input.native_surfarea} -var unfoldarea {input.unfold_surfarea}"
" -var nativearea {input.native_surfarea} -var unfoldarea {input.unfold_surfarea} &> {log}"


rule smooth_surface:
Expand Down Expand Up @@ -559,6 +579,16 @@ rule resample_bigbrain_subfield_label_gii:
label="hipp",
**config["subj_wildcards"]
),
log:
bids(
root="logs",
den="{density}",
suffix="resamplesubfieldsurf",
space="{space}",
hemi="{hemi}",
label="hipp",
**config["subj_wildcards"]
),
group:
"subj"
script:
Expand Down
29 changes: 23 additions & 6 deletions hippunfold/workflow/rules/nnunet.smk
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ rule run_inference:
space="corobl",
hemi="{hemi,Lflip|R}"
),
log:
bids(
root="logs",
**config["subj_wildcards"],
suffix="nnunet.txt",
space="corobl",
hemi="{hemi,Lflip|R}"
),
shadow:
"minimal"
threads: 16
Expand All @@ -127,12 +135,12 @@ rule run_inference:
# run inference
#copy from temp output folder to final output
"mkdir -p {params.model_dir} {params.in_folder} {params.out_folder} && "
"cp -v {input.in_img} {params.temp_img} && "
"tar -xvf {input.model_tar} -C {params.model_dir} && "
"cp {input.in_img} {params.temp_img} && "
"tar -xf {input.model_tar} -C {params.model_dir} && "
"export RESULTS_FOLDER={params.model_dir} && "
"export nnUNet_n_proc_DA={threads} && "
"nnUNet_predict -i {params.in_folder} -o {params.out_folder} -t {params.task} -chk {params.chkpnt} {params.disable_tta} && "
"cp -v {params.temp_lbl} {output.nnunet_seg}"
"nnUNet_predict -i {params.in_folder} -o {params.out_folder} -t {params.task} -chk {params.chkpnt} {params.disable_tta} &> {log} && "
"cp {params.temp_lbl} {output.nnunet_seg}"


rule unflip_nnunet_nii:
Expand Down Expand Up @@ -230,11 +238,20 @@ rule qc_nnunet_f3d:
),
container:
config["singularity"]["autotop"]
log:
bids(
root="logs",
**config["subj_wildcards"],
suffix="qcreg.txt",
desc="f3d",
space="corobl",
hemi="{hemi}"
),
group:
"subj"
shell:
"reg_f3d -flo {input.img} -ref {input.ref} -res {output.res} -cpp {output.cpp} && "
"reg_resample -flo {input.seg} -cpp {output.cpp} -ref {input.ref} -res {output.res_mask} -inter 0"
"reg_f3d -flo {input.img} -ref {input.ref} -res {output.res} -cpp {output.cpp} &> {log} && "
"reg_resample -flo {input.seg} -cpp {output.cpp} -ref {input.ref} -res {output.res_mask} -inter 0 &> {log}"


rule qc_nnunet_dice:
Expand Down
34 changes: 0 additions & 34 deletions hippunfold/workflow/rules/preproc_t1.smk
Original file line number Diff line number Diff line change
Expand Up @@ -123,40 +123,6 @@ rule reg_to_template:
"{params.cmd}"


rule qc_reg_to_template:
input:
ref=lambda wildcards: os.path.join(
workflow.basedir,
"..",
config["template_files"][config["template"]][wildcards.native_modality],
),
flo=bids(
root=work,
datatype="anat",
**config["subj_wildcards"],
suffix="{native_modality}.nii.gz",
space=config["template"],
desc="affine"
),
output:
png=report(
bids(
root=root,
datatype="qc",
**config["subj_wildcards"],
suffix="regqc.png",
from_="{native_modality}",
to=config["template"]
),
caption="../report/t1w_template_regqc.rst",
category="Registration QC",
),
group:
"subj"
script:
"../scripts/vis_regqc.py"


rule convert_template_xfm_ras2itk:
input:
bids(
Expand Down
24 changes: 22 additions & 2 deletions hippunfold/workflow/rules/preproc_t2.smk
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,22 @@ rule reg_t2_to_t1:
desc="rigid",
type_="itk"
),
log:
bids(
root="logs",
**config["subj_wildcards"],
suffix="reg.txt",
from_="T2w",
to="T1w",
desc="rigid",
type_="ras"
),
container:
config["singularity"]["autotop"]
group:
"subj"
shell:
"reg_aladin -flo {input.flo} -ref {input.ref} -res {output.warped} -aff {output.xfm_ras} -rigOnly -nac && "
"reg_aladin -flo {input.flo} -ref {input.ref} -res {output.warped} -aff {output.xfm_ras} -rigOnly -nac &> {log} && "
"c3d_affine_tool {output.xfm_ras} -oitk {output.xfm_itk}"


Expand Down Expand Up @@ -275,12 +285,22 @@ rule reg_t2_to_template:
desc="affine",
type_="ras"
),
log:
bids(
root="logs",
**config["subj_wildcards"],
suffix="reg.txt",
from_="T2w",
to=config["template"],
desc="affine",
type_="ras"
),
container:
config["singularity"]["autotop"]
group:
"subj"
shell:
"{params.cmd}"
"{params.cmd}" + " &> {log}"


def get_inputs_compose_t2_xfm_corobl(wildcards):
Expand Down
35 changes: 34 additions & 1 deletion hippunfold/workflow/rules/qc.smk
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
rule qc_reg_to_template:
input:
ref=lambda wildcards: os.path.join(
workflow.basedir,
"..",
config["template_files"][config["template"]][wildcards.native_modality],
),
flo=bids(
root=work,
datatype="anat",
**config["subj_wildcards"],
suffix="{native_modality}.nii.gz",
space=config["template"],
desc="affine"
),
output:
png=report(
bids(
root=root,
datatype="qc",
**config["subj_wildcards"],
suffix="regqc.png",
from_="{native_modality}",
to=config["template"]
),
caption="../report/t1w_template_regqc.rst",
category="Registration QC",
),
group:
"subj"
script:
"../scripts/vis_regqc.py"


rule get_subfield_vols_subj:
"""Export segmentation volume for a subject to TSV"""
Expand Down Expand Up @@ -127,7 +160,7 @@ rule qc_subfield:
output:
png=report(
bids(
root=work,
root=root,
datatype="qc",
suffix="dseg.png",
desc="subfields",
Expand Down
22 changes: 19 additions & 3 deletions hippunfold/workflow/rules/shape_inject.smk
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ rule template_shape_reg:
bids(
root="logs",
**config["subj_wildcards"],
space="corobl",
hemi="{hemi,Lflip|R}",
suffix="templateshapereg.txt"
),
Expand Down Expand Up @@ -260,13 +259,20 @@ rule template_shape_inject:
space="corobl",
hemi="{hemi,Lflip|R}"
),
log:
bids(
root="logs",
**config["subj_wildcards"],
suffix="templateshapeinject.txt",
hemi="{hemi,Lflip|R}"
),
group:
"subj"
container:
config["singularity"]["autotop"]
threads: 8
shell:
"greedy -d 3 -threads {threads} {params.interp_opt} -rf {input.subject_seg} -rm {input.template_seg} {output.inject_seg} -r {input.warp} {input.matrix}"
"greedy -d 3 -threads {threads} {params.interp_opt} -rf {input.subject_seg} -rm {input.template_seg} {output.inject_seg} -r {input.warp} {input.matrix} &> {log}"


rule inject_init_laplace_coords:
Expand Down Expand Up @@ -316,13 +322,23 @@ rule inject_init_laplace_coords:
space="corobl",
hemi="{hemi}"
),
log:
bids(
root="logs",
**config["subj_wildcards"],
dir="{dir}",
label="{autotop}",
suffix="injectcoords.txt",
desc="init",
hemi="{hemi}"
),
group:
"subj"
container:
config["singularity"]["autotop"]
threads: 8
shell:
"greedy -d 3 -threads {threads} {params.interp_opt} -rf {input.subject_seg} -rm {input.coords} {output.init_coords} -r {input.warp} {input.matrix}"
"greedy -d 3 -threads {threads} {params.interp_opt} -rf {input.subject_seg} -rm {input.coords} {output.init_coords} -r {input.warp} {input.matrix} &> {log}"


rule reinsert_subject_labels:
Expand Down
Loading