@@ -1298,64 +1298,50 @@ class EddyQuadInputSpec(FSLCommandInputSpec):
1298
1298
class EddyQuadOutputSpec (TraitedSpec ):
1299
1299
out_qc_json = File (
1300
1300
exists = True ,
1301
- mandatory = True ,
1302
1301
desc = ("Single subject database containing quality metrics and data "
1303
1302
"info." )
1304
1303
)
1305
1304
1306
1305
out_qc_pdf = File (
1307
1306
exists = True ,
1308
- mandatory = True ,
1309
1307
desc = "Single subject QC report."
1310
1308
)
1311
1309
1312
1310
out_avg_b_png = traits .List (
1313
- File (
1314
- exists = True ,
1315
- mandatory = True ,
1316
- desc = ("Image showing mid-sagittal, -coronal and -axial slices of "
1317
- "each averaged b-shell volume." )
1318
- )
1311
+ File (exists = True ),
1312
+ desc = ("Image showing mid-sagittal, -coronal and -axial slices of "
1313
+ "each averaged b-shell volume." )
1319
1314
)
1320
1315
1321
1316
out_avg_b0_pe_png = traits .List (
1322
- File (
1323
- exists = True ,
1324
- mandatory = False ,
1325
- desc = ("Image showing mid-sagittal, -coronal and -axial slices of "
1326
- "each averaged pe-direction b0 volume. Generated when using "
1327
- "the -f option." )
1328
- )
1317
+ File (exists = True ),
1318
+ desc = ("Image showing mid-sagittal, -coronal and -axial slices of "
1319
+ "each averaged pe-direction b0 volume. Generated when using "
1320
+ "the -f option." )
1329
1321
)
1330
1322
1331
1323
out_cnr_png = traits .List (
1332
- File (
1333
- exists = True ,
1334
- mandatory = False ,
1335
- desc = ("Image showing mid-sagittal, -coronal and -axial slices of "
1336
- "each b-shell CNR volume. Generated when CNR maps are "
1337
- "available." )
1338
- )
1324
+ File (exists = True ),
1325
+ desc = ("Image showing mid-sagittal, -coronal and -axial slices of "
1326
+ "each b-shell CNR volume. Generated when CNR maps are "
1327
+ "available." )
1339
1328
)
1340
1329
1341
1330
out_vdm_png = File (
1342
1331
exists = True ,
1343
- mandatory = False ,
1344
1332
desc = ("Image showing mid-sagittal, -coronal and -axial slices of "
1345
1333
"the voxel displacement map. Generated when using the -f "
1346
1334
"option." )
1347
1335
)
1348
1336
1349
1337
out_residuals = File (
1350
1338
exists = True ,
1351
- mandatory = False ,
1352
1339
desc = ("Text file containing the volume-wise mask-averaged squared "
1353
1340
"residuals. Generated when residual maps are available." )
1354
1341
)
1355
1342
1356
1343
out_clean_volumes = File (
1357
1344
exists = True ,
1358
- mandatory = False ,
1359
1345
desc = ("Text file containing a list of clean volumes, based on "
1360
1346
"the eddy squared residuals. To generate a version of the "
1361
1347
"pre-processed dataset without outlier volumes, use: "
@@ -1397,41 +1383,46 @@ class EddyQuad(FSLCommand):
1397
1383
output_spec = EddyQuadOutputSpec
1398
1384
1399
1385
def _list_outputs (self ):
1400
- import json
1386
+ from glob import glob
1401
1387
outputs = self .output_spec ().get ()
1402
1388
out_dir = os .path .abspath (self .inputs .output_dir )
1403
1389
outputs ['out_qc_json' ] = os .path .join (out_dir , 'qc.json' )
1404
1390
outputs ['out_qc_pdf' ] = os .path .join (out_dir , 'qc.pdf' )
1405
1391
1406
- with open (outputs ['out_qc_json' ]) as fp :
1407
- qc = json .load (fp )
1408
-
1409
1392
outputs ['out_avg_b_png' ] = [
1410
1393
os .path .join (out_dir , 'avg_b{bval:d}.png' .format (bval = bval ))
1411
1394
for bval in list (set ([0 ] + qc .get ('data_unique_bvals' )))
1412
1395
]
1413
1396
1414
- if qc .get ('qc_field_flag' ):
1415
- outputs ['out_avg_b0_pe_png' ] = [
1416
- os .path .join (out_dir , 'avg_b0_pe{i:d}' .format (i = i ))
1417
- for i in range (qc .get ('data_no_PE_dirs' ))
1418
- ]
1397
+ # Grab all b* files here. This will also grab the b0_pe* files
1398
+ # as well, but only if the field input was provided. So we'll remove
1399
+ # them later in the next conditional.
1400
+ outputs ['out_avg_b_png' ] = sorted (glob (
1401
+ os .path .join (out_dir , 'avg_b*.png' )
1402
+ ))
1403
+
1404
+ if isdefined (self .inputs .field ):
1405
+ outputs ['out_avg_b0_pe_png' ] = sorted (glob (
1406
+ os .path .join (out_dir , 'avg_b0_pe*.png' )
1407
+ ))
1408
+
1409
+ # The previous glob for `out_avg_b_png` also grabbed the
1410
+ # `out_avg_b0_pe_png` files so we have to remove them
1411
+ # from `out_avg_b_png`.
1412
+ for fname in outputs ['out_avg_b0_pe_png' ]:
1413
+ outputs ['out_avg_b_png' ].remove (fname )
1419
1414
1420
1415
outputs ['out_vdm_png' ] = os .path .join (out_dir , 'vdm.png' )
1421
1416
1422
- if qc .get ('qc_cnr_flag' ):
1423
- outputs ['out_cnr_png' ] = [
1424
- os .path .join (out_dir , 'cnr{i:04d}.nii.gz.png' )
1425
- for i , _ in enumerate (qc .get ('qc_cnr_avg' ))
1426
- ]
1417
+ outputs ['out_cnr_png' ] = sorted (glob (os .path .join (out_dir , 'cnr*.png' )))
1427
1418
1428
- if qc .get ('qc_rss_flag' ):
1429
- outputs ['out_residuals' ] = os .path .join (out_dir , 'eddy_msr.txt' )
1419
+ residuals = os .path .join (out_dir , 'eddy_msr.txt' )
1420
+ if os .path .isfile (residuals ):
1421
+ outputs ['out_residuals' ] = residuals
1430
1422
1431
- if qc . get ( 'qc_ol_flag' ):
1432
- outputs [ 'out_clean_volumes' ] = os .path .join ( out_dir ,
1433
- 'vols_no_outliers.txt' )
1423
+ clean_volumes = os . path . join ( out_dir , 'vols_no_outliers.txt' )
1424
+ if os .path .isfile ( clean_volumes ):
1425
+ outputs [ 'out_clean_volumes' ] = clean_volumes
1434
1426
1435
1427
return outputs
1436
1428
1437
-
0 commit comments