@@ -266,7 +266,7 @@ def run_dmriprep_pe(dwi_file, dwi_file_AP, dwi_file_PA, bvec_file, bval_file,
266
266
eddy .inputs .repol = True
267
267
eddy .inputs .niter = 1 # TODO: make this a parameter to the function with default 5
268
268
269
- def drop_outliers_fn (outlier_report , threshold ):
269
+ def drop_outliers_fn (outlier_report , threshold , dwi_file ):
270
270
"""Get list of scans that exceed threshold for number of outliers
271
271
272
272
Parameters
@@ -280,14 +280,19 @@ def drop_outliers_fn(outlier_report, threshold):
280
280
treated the fraction of allowed outlier slices before we drop the
281
281
whole volume. Float param in not yet implemented
282
282
283
+ dwi_file: string
284
+ Path to nii dwi file to determine total number of slices
285
+
283
286
Returns
284
287
-------
285
288
drop_scans: numpy.ndarray
286
289
List of scan indices to drop
287
290
"""
291
+ import nibabel as nib
288
292
import numpy as np
289
293
import os .path as op
290
294
import parse
295
+
291
296
with open (op .abspath (outlier_report ), 'r' ) as fp :
292
297
lines = fp .readlines ()
293
298
@@ -303,6 +308,9 @@ def drop_outliers_fn(outlier_report, threshold):
303
308
def num_outliers (scan , outliers ):
304
309
return len ([d for d in outliers if d ['scan' ] == scan ])
305
310
311
+ if 0 < threshold < 1 :
312
+ threshold *= threshold * nib .load (dwi_file ).shape [2 ]
313
+
306
314
drop_scans = np .array ([
307
315
s for s in scans
308
316
if num_outliers (s , outliers ) > threshold
@@ -311,13 +319,14 @@ def num_outliers(scan, outliers):
311
319
return drop_scans
312
320
313
321
drop_outliers_node = pe .Node (niu .Function (
314
- input_names = ["outlier_report" , "threshold" ],
322
+ input_names = ["outlier_report" , "threshold" , "dwi_file" ],
315
323
output_names = ["drop_scans" ],
316
324
function = drop_outliers_fn ),
317
325
name = "drop_outliers_node"
318
326
)
319
327
320
- drop_outliers_node .inputs .threshold = 1
328
+ drop_outliers_node .inputs .threshold = 0.02
329
+ drop_outliers_node .inputs .dwi_file = dwi_file
321
330
wf .connect (prep , "fsl_eddy.out_outlier_report" ,
322
331
drop_outliers_node , "outlier_report" )
323
332
0 commit comments