Skip to content

Commit 4a41f5e

Browse files
author
Adam Richie-Halford
committed
Add glob stuff back in
1 parent 5675276 commit 4a41f5e

File tree

2 files changed

+37
-46
lines changed

2 files changed

+37
-46
lines changed

.zenodo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@
594594
"affiliation": "University of Washington",
595595
"name": "Richie-Halford, Adam",
596596
"orcid": "0000-0001-9276-9084"
597-
},
597+
}
598598
],
599599
"keywords": [
600600
"neuroimaging",

nipype/interfaces/fsl/epi.py

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,64 +1298,50 @@ class EddyQuadInputSpec(FSLCommandInputSpec):
12981298
class EddyQuadOutputSpec(TraitedSpec):
12991299
out_qc_json = File(
13001300
exists=True,
1301-
mandatory=True,
13021301
desc=("Single subject database containing quality metrics and data "
13031302
"info.")
13041303
)
13051304

13061305
out_qc_pdf = File(
13071306
exists=True,
1308-
mandatory=True,
13091307
desc="Single subject QC report."
13101308
)
13111309

13121310
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.")
13191314
)
13201315

13211316
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.")
13291321
)
13301322

13311323
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.")
13391328
)
13401329

13411330
out_vdm_png = File(
13421331
exists=True,
1343-
mandatory=False,
13441332
desc=("Image showing mid-sagittal, -coronal and -axial slices of "
13451333
"the voxel displacement map. Generated when using the -f "
13461334
"option.")
13471335
)
13481336

13491337
out_residuals = File(
13501338
exists=True,
1351-
mandatory=False,
13521339
desc=("Text file containing the volume-wise mask-averaged squared "
13531340
"residuals. Generated when residual maps are available.")
13541341
)
13551342

13561343
out_clean_volumes = File(
13571344
exists=True,
1358-
mandatory=False,
13591345
desc=("Text file containing a list of clean volumes, based on "
13601346
"the eddy squared residuals. To generate a version of the "
13611347
"pre-processed dataset without outlier volumes, use: "
@@ -1397,41 +1383,46 @@ class EddyQuad(FSLCommand):
13971383
output_spec = EddyQuadOutputSpec
13981384

13991385
def _list_outputs(self):
1400-
import json
1386+
from glob import glob
14011387
outputs = self.output_spec().get()
14021388
out_dir = os.path.abspath(self.inputs.output_dir)
14031389
outputs['out_qc_json'] = os.path.join(out_dir, 'qc.json')
14041390
outputs['out_qc_pdf'] = os.path.join(out_dir, 'qc.pdf')
14051391

1406-
with open(outputs['out_qc_json']) as fp:
1407-
qc = json.load(fp)
1408-
14091392
outputs['out_avg_b_png'] = [
14101393
os.path.join(out_dir, 'avg_b{bval:d}.png'.format(bval=bval))
14111394
for bval in list(set([0] + qc.get('data_unique_bvals')))
14121395
]
14131396

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)
14191414

14201415
outputs['out_vdm_png'] = os.path.join(out_dir, 'vdm.png')
14211416

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')))
14271418

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
14301422

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
14341426

14351427
return outputs
14361428

1437-

0 commit comments

Comments
 (0)