Skip to content

Commit

Permalink
Modif real params (#259)
Browse files Browse the repository at this point in the history
* saving full cmd in real_params.json  + solved some bugs
  • Loading branch information
davidmeunier79 authored Apr 18, 2024
1 parent 8483483 commit 47449ae
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 46 deletions.
107 changes: 65 additions & 42 deletions macapype/pipelines/full_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ def create_full_ants_subpipes(
seg_pipe.connect(data_preparation_pipe, 'outputnode.preproc_T1',
outputnode, "stereo_T1")

seg_pipe.connect(data_preparation_pipe, 'outputnode.preproc_T1',
seg_pipe.connect(data_preparation_pipe, 'outputnode.preproc_T2',
outputnode, "stereo_T2")

seg_pipe.connect(data_preparation_pipe, "outputnode.stereo_padded_T1",
Expand Down Expand Up @@ -1103,46 +1103,54 @@ def create_full_ants_subpipes(
if mask_file is None:

# full extract brain pipeline (correct_bias, denoising, extract brain)
if "extract_pipe" not in params.keys():
return seg_pipe
if "extract_pipe" in params.keys():

# brain extraction
extract_pipe = create_extract_pipe(
params_template=params_template,
params=parse_key(params, "extract_pipe"))
# brain extraction
extract_pipe = create_extract_pipe(
params_template=params_template,
params=parse_key(params, "extract_pipe"))

seg_pipe.connect(inputnode, "indiv_params",
extract_pipe, "inputnode.indiv_params")
seg_pipe.connect(inputnode, "indiv_params",
extract_pipe, "inputnode.indiv_params")

if "correct_bias_pipe" in params:
seg_pipe.connect(correct_bias_pipe,
"outputnode.debiased_T1",
extract_pipe, "inputnode.restore_T1")
if "correct_bias_pipe" in params:
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T1",
extract_pipe, "inputnode.restore_T1")

elif "N4debias" in params.keys():
# brain extraction
seg_pipe.connect(N4debias_T1, "output_image",
extract_pipe, "inputnode.restore_T1")
elif "N4debias" in params.keys():
# brain extraction
seg_pipe.connect(
N4debias_T1, "output_image",
extract_pipe, "inputnode.restore_T1")

elif "fast" in params.keys():
elif "fast" in params.keys():

# brain extraction
seg_pipe.connect(fast_T1, ("restored_image", show_files),
extract_pipe, "inputnode.restore_T1")
else:
# brain extraction
seg_pipe.connect(
fast_T1, ("restored_image", show_files),
extract_pipe, "inputnode.restore_T1")
else:

seg_pipe.connect(data_preparation_pipe, 'outputnode.preproc_T1',
extract_pipe, "inputnode.restore_T1")
seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T1',
extract_pipe, "inputnode.restore_T1")

# outputnode
seg_pipe.connect(extract_pipe, "smooth_mask.out_file",
outputnode, "stereo_brain_mask")

if pad:
pad_back(
seg_pipe, data_preparation_pipe, inputnode,
# outputnode
seg_pipe.connect(
extract_pipe, "smooth_mask.out_file",
outputnode, "native_brain_mask", params)
outputnode, "stereo_brain_mask")

if pad:
pad_back(
seg_pipe, data_preparation_pipe, inputnode,
extract_pipe, "smooth_mask.out_file",
outputnode, "native_brain_mask", params)

# full extract brain pipeline (correct_bias, denoising, extract brain)
else:
print("no extract_brain method is defined, skipping")
return seg_pipe

else:
print("Using native external mask {}".format(mask_file))
Expand Down Expand Up @@ -1268,9 +1276,23 @@ def create_full_ants_subpipes(
debias, 't2_file')

if mask_file is None:
seg_pipe.connect(
extract_pipe, "smooth_mask.out_file",
debias, 'b')
if "extract_pipe" in params.keys():
seg_pipe.connect(
extract_pipe, "smooth_mask.out_file",
debias, 'b')
else:
debias.inputs.bet = 1

# outputnode
seg_pipe.connect(
debias, "debiased_mask_file",
outputnode, "stereo_brain_mask")

if pad:
pad_back(
seg_pipe, data_preparation_pipe, inputnode,
debias, "debiased_mask_file",
outputnode, "native_brain_mask", params)

else:
seg_pipe.connect(
Expand Down Expand Up @@ -1340,13 +1362,14 @@ def create_full_ants_subpipes(
restore_mask_T2, 'in_file')

if mask_file is None:
seg_pipe.connect(
extract_pipe, "smooth_mask.out_file",
restore_mask_T1, 'mask_file')

seg_pipe.connect(
extract_pipe, "smooth_mask.out_file",
restore_mask_T2, 'mask_file')
if "extract_pipe" in params.keys():
seg_pipe.connect(
extract_pipe, "smooth_mask.out_file",
restore_mask_T1, 'mask_file')

seg_pipe.connect(
extract_pipe, "smooth_mask.out_file",
restore_mask_T2, 'mask_file')
else:
seg_pipe.connect(
apply_crop_external_mask, "out_file",
Expand Down
2 changes: 1 addition & 1 deletion macapype/utils/subs.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"_restore_brain": "",
"_restore":"",
"_noise_corrected":"",
"_brain_corrected":"",
"_brain":"",
"_corrected":"",
"_maths":"",
"_masked":"",
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

required_packages = [
"nipype", "nilearn", "networkx",
"pybids", "scikit-image", "nibabel==3.2.2",
"numpy==1.22", "brain-slam"]
"pybids", "scikit-image", "nibabel==4.0.0",
"numpy==1.23", "brain-slam"]

verstr = "unknown"
try:
Expand Down
8 changes: 7 additions & 1 deletion workflows/segment_pnh.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
# Kepkee Loh ([email protected])
# Julien Sein ([email protected])

import sys
import os
import os.path as op

Expand Down Expand Up @@ -80,7 +81,7 @@
###############################################################################


def create_main_workflow(data_dir, process_dir, soft, species, datatypes,
def create_main_workflow(cmd, data_dir, process_dir, soft, species, datatypes,
subjects, sessions, acquisitions, reconstructions,
params_file, indiv_params_file, mask_file,
template_path, template_files, nprocs, reorient,
Expand Down Expand Up @@ -455,6 +456,8 @@ def create_main_workflow(data_dir, process_dir, soft, species, datatypes,
# saving real params.json
params["macapype_version"] = __version__

params["full_command"] = cmd

real_params_file = op.join(process_dir, wf_name, "real_params.json")
with open(real_params_file, 'w+') as fp:
json.dump(params, fp)
Expand Down Expand Up @@ -553,9 +556,12 @@ def main():

args = parser.parse_args()

cmd = " ".join(sys.argv)

# main_workflow
print("Initialising the pipeline...")
create_main_workflow(
cmd=cmd,
data_dir=args.data,
soft=args.soft,
process_dir=args.out,
Expand Down

0 comments on commit 47449ae

Please sign in to comment.