Skip to content

Commit

Permalink
reverting adding reorient node at the very begining and passing orien…
Browse files Browse the repository at this point in the history
…tation set in config in the existing nodes for reorientations
  • Loading branch information
birajstha committed Oct 1, 2024
1 parent 99a8d4c commit 40ea22c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 59 deletions.
38 changes: 30 additions & 8 deletions CPAC/anat_preproc/anat_preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ def freesurfer_fsl_brain_connector(wf, cfg, strat_pool, pipe_num, opt):
mem_gb=0,
mem_x=(0.0115, "in_file", "t"),
)
reorient_fs_brainmask.inputs.orientation = "RPI"
reorient_fs_brainmask.inputs.orientation = cfg.pipeline_setup["desired_orientation"]
reorient_fs_brainmask.inputs.outputtype = "NIFTI_GZ"

wf.connect(
Expand All @@ -1255,7 +1255,7 @@ def freesurfer_fsl_brain_connector(wf, cfg, strat_pool, pipe_num, opt):
mem_gb=0,
mem_x=(0.0115, "in_file", "t"),
)
reorient_fs_T1.inputs.orientation = "RPI"
reorient_fs_T1.inputs.orientation = cfg.pipeline_setup["desired_orientation"]
reorient_fs_T1.inputs.outputtype = "NIFTI_GZ"

wf.connect(convert_fs_T1_to_nifti, "out_file", reorient_fs_T1, "in_file")
Expand Down Expand Up @@ -1454,10 +1454,21 @@ def anatomical_init(wf, cfg, strat_pool, pipe_num, opt=None):
node, out = strat_pool.get_data("T1w")
wf.connect(node, out, anat_deoblique, "in_file")

anat_reorient = pe.Node(
interface=afni.Resample(),
name=f"anat_reorient_{pipe_num}",
mem_gb=0,
mem_x=(0.0115, "in_file", "t"),
)
anat_reorient.inputs.orientation = cfg.pipeline_setup["desired_orientation"]
anat_reorient.inputs.outputtype = "NIFTI_GZ"

wf.connect(anat_deoblique, "out_file", anat_reorient, "in_file")

outputs = {
"desc-preproc_T1w": (anat_deoblique, "out_file"),
"desc-reorient_T1w": (anat_deoblique, "out_file"),
"desc-head_T1w": (anat_deoblique, "out_file"),
"desc-preproc_T1w": (anat_reorient, "out_file"),
"desc-reorient_T1w": (anat_reorient, "out_file"),
"desc-head_T1w": (anat_reorient, "out_file"),
}

return (wf, outputs)
Expand Down Expand Up @@ -2251,10 +2262,21 @@ def anatomical_init_T2(wf, cfg, strat_pool, pipe_num, opt=None):
node, out = strat_pool.get_data("T2w")
wf.connect(node, out, T2_deoblique, "in_file")

T2_reorient = pe.Node(
interface=afni.Resample(),
name=f"T2_reorient_{pipe_num}",
mem_gb=0,
mem_x=(0.0115, "in_file", "t"),
)
T2_reorient.inputs.orientation = cfg.pipeline_setup["desired_orientation"]
T2_reorient.inputs.outputtype = "NIFTI_GZ"

wf.connect(T2_deoblique, "out_file", T2_reorient, "in_file")

outputs = {
"desc-preproc_T2w": (T2_deoblique, "out_file"),
"desc-reorient_T2w": (T2_deoblique, "out_file"),
"desc-head_T2w": (T2_deoblique, "out_file"),
"desc-preproc_T2w": (T2_reorient, "out_file"),
"desc-reorient_T2w": (T2_reorient, "out_file"),
"desc-head_T2w": (T2_reorient, "out_file"),
}

return (wf, outputs)
Expand Down
16 changes: 14 additions & 2 deletions CPAC/func_preproc/func_preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,21 @@ def func_reorient(wf, cfg, strat_pool, pipe_num, opt=None):
node, out = strat_pool.get_data("bold")
wf.connect(node, out, func_deoblique, "in_file")

func_reorient = pe.Node(
interface=afni_utils.Resample(),
name=f"func_reorient_{pipe_num}",
mem_gb=0,
mem_x=(0.0115, "in_file", "t"),
)

func_reorient.inputs.orientation = cfg.pipeline_setup["desired_orientation"]
func_reorient.inputs.outputtype = "NIFTI_GZ"

wf.connect(func_deoblique, "out_file", func_reorient, "in_file")

outputs = {
"desc-preproc_bold": (func_deoblique, "out_file"),
"desc-reorient_bold": (func_deoblique, "out_file"),
"desc-preproc_bold": (func_reorient, "out_file"),
"desc-reorient_bold": (func_reorient, "out_file"),
}

return (wf, outputs)
Expand Down
56 changes: 7 additions & 49 deletions CPAC/pipeline/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,17 +1932,7 @@ def ingress_raw_anat_data(wf, rpool, cfg, data_paths, unique_id, part_id, ses_id
dl_dir=cfg.pipeline_setup["working_directory"]["path"],
img_type="anat",
)
reorient = pe.Node(
interface=afni.Resample(),
name=f"reorient_T1w_{part_id}_{ses_id}",
)

reorient.inputs.orientation = desired_orientation
reorient.inputs.outputtype = "NIFTI_GZ"

wf.connect(anat_flow, "outputspec.anat", reorient, "in_file")

rpool.set_data("T1w", reorient, "out_file", {}, "", "anat_ingress")
rpool.set_data("T1w", anat_flow, "outputspec.anat", {}, "", "anat_ingress")

if "T2w" in data_paths["anat"]:
anat_flow_T2 = create_anat_datasource(f"anat_T2w_gather_{part_id}_{ses_id}")
Expand All @@ -1953,17 +1943,7 @@ def ingress_raw_anat_data(wf, rpool, cfg, data_paths, unique_id, part_id, ses_id
dl_dir=cfg.pipeline_setup["working_directory"]["path"],
img_type="anat",
)
reorient = pe.Node(
interface=afni.Resample(),
name=f"reorient_T1w_{part_id}_{ses_id}",
)

reorient.inputs.orientation = desired_orientation
reorient.inputs.outputtype = "NIFTI_GZ"

wf.connect(anat_flow_T2, "outputspec.anat", reorient, "in_file")

rpool.set_data("T2w", reorient, "out_file", {}, "", "anat_ingress")
rpool.set_data("T2w", anat_flow_T2, "outputspec.anat", {}, "", "anat_ingress")

if cfg.surface_analysis["freesurfer"]["ingress_reconall"]:
rpool = ingress_freesurfer(
Expand Down Expand Up @@ -2010,28 +1990,13 @@ def ingress_freesurfer(wf, rpool, cfg, data_paths, unique_id, part_id, ses_id):
creds_path=data_paths["creds_path"],
dl_dir=cfg.pipeline_setup["working_directory"]["path"],
)
node = fs_ingress
out = "outputspec.data"
node_name = "freesurfer_config_ingress"

if fs_path.endswith(".nii.gz" or ".nii"):
reorient = pe.Node(
interface=afni.Resample(),
name=f"reorient_fs_{part_id}_{ses_id}",
)
reorient.inputs.orientation = cfg.pipeline_setup["desired_orientation"]
reorient.inputs.outputtype = "NIFTI_GZ"
wf.connect(fs_ingress, "outputspec.data", reorient, "in_file")
node = reorient
out = "out_file"
node_name = "reorient_fs"
rpool.set_data(
"freesurfer-subject-dir",
node,
out,
fs_ingress,
"outputspec.data",
{},
"",
node_name,
"freesurfer_config_ingress",
)

recon_outs = {
Expand Down Expand Up @@ -2094,15 +2059,8 @@ def ingress_raw_func_data(wf, rpool, cfg, data_paths, unique_id, part_id, ses_id
func_wf.get_node("inputnode").iterables = ("scan", list(func_paths_dct.keys()))

rpool.set_data("subject", func_wf, "outputspec.subject", {}, "", "func_ingress")
reorient = pe.Node(
interface=afni.Resample(),
name=f"reorient_func_{part_id}_{ses_id}",
)
reorient.inputs.orientation = cfg.pipeline_setup["desired_orientation"]
reorient.inputs.outputtype = "NIFTI_GZ"
wf.connect(func_wf, "outputspec.rest", reorient, "in_file")
rpool.set_data("bold", reorient, "out_file", {}, "", "func_ingress")
# rpool.set_data("bold", func_wf, "outputspec.rest", {}, "", "func_ingress")

rpool.set_data("bold", func_wf, "outputspec.rest", {}, "", "func_ingress")

rpool.set_data("scan", func_wf, "outputspec.scan", {}, "", "func_ingress")

Expand Down

0 comments on commit 40ea22c

Please sign in to comment.