Skip to content

Commit c7ccec9

Browse files
committed
🐛 Fix dvars_after connection
1 parent 4c6accf commit c7ccec9

File tree

1 file changed

+51
-42
lines changed

1 file changed

+51
-42
lines changed

CPAC/qc/xcp.py

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _connect_motion(wf, nodes, strat_pool, qc_file, pipe_num):
146146
cal_DVARS_strip = pe.Node(
147147
Function(
148148
input_names=["file_1D"],
149-
output_names=["out_file"],
149+
output_names=["out_file", "out_matrix"],
150150
function=DVARS_strip_t0,
151151
as_module=True,
152152
),
@@ -168,7 +168,11 @@ def _connect_motion(wf, nodes, strat_pool, qc_file, pipe_num):
168168
[(nodes["space-bold_desc-brain_mask"].out, "mask")],
169169
),
170170
(cal_DVARS, cal_DVARS_strip, [("out_file", "file_1D")]),
171-
(cal_DVARS_strip, qc_file, [("out_file", "dvars_after")]),
171+
(
172+
cal_DVARS_strip,
173+
qc_file,
174+
[("out_file", "dvars_after_path"), ("out_matrix", "dvars_after")],
175+
),
172176
(
173177
nodes[motion_name].node,
174178
qc_file,
@@ -200,83 +204,87 @@ def dvcorr(dvars, fdj):
200204
# This function is for a function node for which
201205
# Nipype will connect many other nodes as inputs
202206
def generate_xcp_qc( # noqa: PLR0913
203-
sub,
204-
ses,
205-
task,
206-
run,
207-
desc,
208-
regressors,
209-
bold2t1w_mask,
210-
t1w_mask,
211-
bold2template_mask,
212-
template_mask,
213-
original_func,
214-
final_func,
215-
movement_parameters,
216-
dvars,
217-
censor_indices,
218-
framewise_displacement_jenkinson,
219-
dvars_after,
220-
template,
221-
):
207+
sub: str,
208+
ses: str,
209+
task: str,
210+
run: str | int,
211+
desc: str,
212+
regressors: str,
213+
bold2t1w_mask: str,
214+
t1w_mask: str,
215+
bold2template_mask: str,
216+
template_mask: str,
217+
original_func: str,
218+
final_func: str,
219+
movement_parameters: str,
220+
dvars: str,
221+
censor_indices: list[int],
222+
framewise_displacement_jenkinson: str,
223+
dvars_after: np.ndarray,
224+
dvars_after_path: str,
225+
template: str,
226+
) -> str:
222227
"""
223228
Generate an RBC-style QC CSV.
224229
225230
Parameters
226231
----------
227-
sub : str
232+
sub
228233
subject ID
229234
230-
ses : str
235+
ses
231236
session ID
232237
233-
task : str
238+
task
234239
task ID
235240
236-
run : str or int
241+
run
237242
run ID
238243
239-
desc : str
244+
desc
240245
description string
241246
242-
regressors : str
247+
regressors
243248
'Name' of regressors in fork
244249
245-
original_func : str
250+
original_func
246251
path to original 'bold' image
247252
248-
final_bold : str
253+
final_bold
249254
path to 'space-template_desc-preproc_bold' image
250255
251-
bold2t1w_mask : str
256+
bold2t1w_mask
252257
path to bold-to-T1w transform applied to space-bold_desc-brain_mask
253258
with space-T1w_desc-brain_mask reference
254259
255-
t1w_mask : str
260+
t1w_mask
256261
path to space-T1w_desc-brain_mask
257262
258-
bold2template_mask : str
263+
bold2template_mask
259264
path to space-template_desc-bold_mask
260265
261-
template_mask : str
266+
template_mask
262267
path to T1w-brain-template-mask or EPI-template-mask
263268
264-
movement_parameters: str
269+
movement_parameters
265270
path to movement parameters
266271
267-
dvars : str
272+
dvars
268273
path to DVARS before motion correction
269274
270-
censor_indices : list
275+
censor_indices
271276
list of indices of censored volumes
272277
273-
framewise_displacement_jenkinson : str
278+
framewise_displacement_jenkinson
274279
path to framewise displacement (Jenkinson) before motion correction
275280
276-
dvars_after : str
277-
path to DVARS on final 'bold' image
281+
dvars_after
282+
DVARS matrix for final 'bold' image
283+
284+
dvars_after_path
285+
path to DVARS matrix for final 'bold' image
278286
279-
template : str
287+
template
280288
path to registration template
281289
282290
Returns
@@ -343,10 +351,10 @@ def generate_xcp_qc( # noqa: PLR0913
343351
meanDV["motionDVCorrInit"] = dvcorr(dvars, framewise_displacement_jenkinson)
344352
except ValueError as value_error:
345353
meanDV["motionDVCorrInit"] = f"ValueError({value_error!s})"
346-
meanDV["meanDVFinal"] = np.mean(np.loadtxt(dvars_after))
354+
meanDV["meanDVFinal"] = np.mean(dvars_after)
347355
try:
348356
meanDV["motionDVCorrFinal"] = dvcorr(
349-
dvars_after, framewise_displacement_jenkinson
357+
dvars_after_path, framewise_displacement_jenkinson
350358
)
351359
except ValueError as value_error:
352360
meanDV["motionDVCorrFinal"] = f"ValueError({value_error!s})"
@@ -515,6 +523,7 @@ def qc_xcp(wf, cfg, strat_pool, pipe_num, opt=None):
515523
"censor_indices",
516524
"regressors",
517525
"framewise_displacement_jenkinson",
526+
"dvars_after_path",
518527
"dvars_after",
519528
],
520529
output_names=["qc_file"],

0 commit comments

Comments
 (0)