Skip to content

Commit 088784e

Browse files
committed
FIX: Syntax errors, connections, everything really
1 parent 73987c1 commit 088784e

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

nibabies/workflows/bold/alignment.py

+24-20
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
)
2020

2121

22-
def gen_subcortical_alignment_wf(repetition_time, name='subcortical_alignment_wf'):
22+
def init_subcortical_mni_alignment_wf(*, repetition_time, name='subcortical_mni_alignment_wf'):
2323
"""
2424
Align individual subcortical structures into MNI space.
2525
2626
This is a nipype workflow port of the DCAN infant pipeline.
27-
https://github.com/DCAN-Labs/dcan-infant-pipeline/blob/247e19/fMRISurface/scripts/SubcorticalAlign_ROIs.sh
27+
https://github.com/DCAN-Labs/dcan-infant-pipeline/ \
28+
blob/247e19/fMRISurface/scripts/SubcorticalAlign_ROIs.sh
2829
2930
3031
Parameters
@@ -67,7 +68,7 @@ def gen_subcortical_alignment_wf(repetition_time, name='subcortical_alignment_wf
6768
split_atlas_rois = pe.Node(fsl.Split(dimension="t"), name="split_atlas_rois")
6869
atlas_labels = pe.Node(VolumeLabelExportTable(label_map=1), name="atlas_labels")
6970
parse_labels = pe.Node(
70-
niu.Function(function=parse_roi_labels, output_names=["structures", "label_id"]),
71+
niu.Function(function=parse_roi_labels, output_names=["structures", "label_ids"]),
7172
name="parse_labels",
7273
)
7374

@@ -85,22 +86,22 @@ def gen_subcortical_alignment_wf(repetition_time, name='subcortical_alignment_wf
8586
)
8687
applyxfm_roi = pe.MapNode(
8788
fsl.ApplyXFM(interp="spline"),
88-
iterfield=["reference"],
89+
iterfield=["reference", "in_matrix_file"],
8990
name='applyxfm_roi',
9091
)
9192
bold_mask_roi = pe.MapNode(
9293
fsl.ApplyMask(),
93-
iterfield=["in_file", "operand_file"],
94+
iterfield=["in_file", "operand_value"],
9495
name='bold_mask_roi',
9596
)
9697
mul_roi = pe.MapNode(
9798
fsl.BinaryMaths(operation="mul"),
98-
iterfield=["in_file", "operand_file"],
99+
iterfield=["in_file", "operand_value"],
99100
name='mul_roi',
100101
)
101102
mul_atlas_roi = pe.MapNode(
102103
fsl.BinaryMaths(operation="mul"),
103-
iterfield=["in_file", "operand_file"],
104+
iterfield=["in_file", "operand_value"],
104105
name='mul_atlas_roi',
105106
)
106107
vol_label = pe.MapNode(
@@ -116,7 +117,7 @@ def gen_subcortical_alignment_wf(repetition_time, name='subcortical_alignment_wf
116117
create_dtseries = pe.MapNode(
117118
CiftiCreateDenseTimeseries(),
118119
iterfield=["volume_data", "volume_structure_labels"],
119-
name='create_dtseries'
120+
name='create_dtseries',
120121
)
121122
create_label = pe.MapNode(
122123
CiftiCreateLabel(),
@@ -151,9 +152,9 @@ def gen_subcortical_alignment_wf(repetition_time, name='subcortical_alignment_wf
151152
)
152153

153154
fmt_vols = pe.Node(niu.Function(function=format_volume_rois), name='fmt_vols')
154-
create_dtseries = pe.Node(
155+
create_dtseries_tmpl = pe.Node(
155156
CiftiCreateDenseFromTemplate(series=True, series_step=repetition_time, series_start=0),
156-
name='create_dtseries',
157+
name='create_dtseries_tmpl',
157158
)
158159
fmt_agg_rois = pe.Node(
159160
niu.Function(
@@ -162,7 +163,7 @@ def gen_subcortical_alignment_wf(repetition_time, name='subcortical_alignment_wf
162163
),
163164
name='fmt_agg_rois',
164165
)
165-
agg_rois = pe.MapNode(fsl.MultiImageMaths(), name='agg_rois')
166+
agg_rois = pe.Node(fsl.MultiImageMaths(), name='agg_rois')
166167
final_vol = pe.Node(
167168
CiftiSeparate(direction="COLUMN", volume_all_file='volume_all.nii.gz'),
168169
name="final_vol"
@@ -186,14 +187,16 @@ def gen_subcortical_alignment_wf(repetition_time, name='subcortical_alignment_wf
186187
(atlas_labels, parse_labels, [("out_file", "label_file")]),
187188
# for loop across ROIs
188189
(split_rois, roi2atlas, [("out_files", "in_file")]),
190+
(split_atlas_rois, roi2atlas, [("out_files", "reference")]),
189191
(inputnode, applyxfm_roi, [("bold_file", "in_file")]),
190192
(split_atlas_rois, applyxfm_roi, [("out_files", "reference")]),
193+
(roi2atlas, applyxfm_roi, [("out_matrix_file", "in_matrix_file")]),
191194
(applyxfm_roi, bold_mask_roi, [("out_file", "in_file")]),
192195
(roi2atlas, bold_mask_roi, [("out_file", "mask_file")]),
193196
(roi2atlas, mul_roi, [("out_file", "in_file")]),
194-
(parse_labels, mul_roi, [("label_ids", "operand_file")]),
197+
(parse_labels, mul_roi, [("label_ids", "operand_value")]),
195198
(split_atlas_rois, mul_atlas_roi, [("out_files", "in_file")]),
196-
(parse_labels, mul_atlas_roi, [("label_ids", "operand_file")]),
199+
(parse_labels, mul_atlas_roi, [("label_ids", "operand_value")]),
197200
(mul_roi, vol_label, [("out_file", "in_file")]),
198201
(atlas_labels, vol_label, [("out_file", "label_list_file")]),
199202
(mul_atlas_roi, vol_atlas_label, [("out_file", "in_file")]),
@@ -211,17 +214,18 @@ def gen_subcortical_alignment_wf(repetition_time, name='subcortical_alignment_wf
211214
# end loop
212215
(parse_labels, fmt_vols, [("structures", "structs")]),
213216
(separate, fmt_vols, [("volume_all_file", "rois")]),
214-
(create_dense, create_dtseries, [("out_file", "in_file")]),
215-
(fmt_vols, create_dtseries, [("out", "volume")]),
217+
(create_dense, create_dtseries_tmpl, [("out_file", "in_file")]),
218+
(fmt_vols, create_dtseries_tmpl, [("out", "volume")]),
216219
(mul_roi, fmt_agg_rois, [("out_file", "rois")]),
217220
(fmt_agg_rois, agg_rois, [
218221
("first_image", "in_file"),
219222
("op_files", "operand_files"),
220223
("op_string", "op_string")]),
221-
(create_dtseries, final_vol, [("out_file", "in_file")]),
222-
(final_vol, outputnode, [("out_file", "subcortical_file")]),
224+
(create_dtseries_tmpl, final_vol, [("out_file", "in_file")]),
225+
(final_vol, outputnode, [("volume_all_file", "subcortical_file")]),
223226
])
224227
# fmt: on
228+
return workflow
225229

226230

227231
def parse_roi_labels(label_file):
@@ -236,7 +240,7 @@ def parse_roi_labels(label_file):
236240
>>> structs
237241
['CEREBELLUM_LEFT', 'THALAMUS_LEFT', 'CAUDATE_LEFT']
238242
>>> ids
239-
['8', '10', '11']
243+
[8, 10, 11]
240244
"""
241245

242246
with open(label_file) as fp:
@@ -248,7 +252,7 @@ def parse_roi_labels(label_file):
248252
if idx % 2 == 0:
249253
structs.append(line.strip())
250254
else:
251-
label_ids.append(line.split(' ', 1)[0])
255+
label_ids.append(int(line.split(' ', 1)[0]))
252256
return structs, label_ids
253257

254258

@@ -273,4 +277,4 @@ def format_agg_rois(rois):
273277
op_string
274278
275279
"""
276-
return rois[0], rois[1:], "-add %s " * (len(rois) - 1).strip()
280+
return rois[0], rois[1:], ("-add %s " * (len(rois) - 1)).strip()

0 commit comments

Comments
 (0)