|
16 | 16 |
|
17 | 17 | from .base import (AFNICommandBase, AFNICommand, AFNICommandInputSpec, AFNICommandOutputSpec,
|
18 | 18 | Info, no_afni)
|
19 |
| -from ..base import CommandLineInputSpec |
20 |
| -from ..base import (Directory, TraitedSpec, |
| 19 | +from ..base import (CommandLineInputSpec, CommandLine, Directory, TraitedSpec, |
21 | 20 | traits, isdefined, File, InputMultiPath, Undefined)
|
22 | 21 | from ...external.six import string_types
|
23 | 22 | from ...utils.filemanip import (load_json, save_json, split_filename)
|
@@ -2372,3 +2371,133 @@ def _list_outputs(self):
|
2372 | 2371 |
|
2373 | 2372 | outputs['fwhm'] = tuple(sout)
|
2374 | 2373 | return outputs
|
| 2374 | + |
| 2375 | + |
| 2376 | +class OutlierCountInputSpec(CommandLineInputSpec): |
| 2377 | + in_file = File(argstr='%s', mandatory=True, exists=True, position=-2, desc='input dataset') |
| 2378 | + mask = File(exists=True, argstr='-mask %s', xor=['autoclip', 'automask'], |
| 2379 | + desc='only count voxels within the given mask') |
| 2380 | + qthr = traits.Range(value=1e-3, low=0.0, high=1.0, argstr='-qthr %.5f', |
| 2381 | + desc='indicate a value for q to compute alpha') |
| 2382 | + |
| 2383 | + autoclip = traits.Bool(False, usedefault=True, argstr='-autoclip', xor=['in_file'], |
| 2384 | + desc='clip off small voxels') |
| 2385 | + automask = traits.Bool(False, usedefault=True, argstr='-automask', xor=['in_file'], |
| 2386 | + desc='clip off small voxels') |
| 2387 | + |
| 2388 | + fraction = traits.Bool(False, usedefault=True, argstr='-fraction', |
| 2389 | + desc='write out the fraction of masked voxels' |
| 2390 | + ' which are outliers at each timepoint') |
| 2391 | + interval = traits.Bool(False, usedefault=True, argstr='-range', |
| 2392 | + desc='write out the median + 3.5 MAD of outlier' |
| 2393 | + ' count with each timepoint') |
| 2394 | + save_outliers = traits.Bool(False, usedefault=True, desc='enables out_file option') |
| 2395 | + outliers_file = File( |
| 2396 | + name_template="%s_outliers", argstr='-save %s', name_source=["in_file"], |
| 2397 | + output_name='out_outliers', keep_extension=True, desc='output image file name') |
| 2398 | + |
| 2399 | + polort = traits.Int(argstr='-polort %d', |
| 2400 | + desc='detrend each voxel timeseries with polynomials') |
| 2401 | + legendre = traits.Bool(False, usedefault=True, argstr='-legendre', |
| 2402 | + desc='use Legendre polynomials') |
| 2403 | + out_file = File( |
| 2404 | + name_template='%s_outliers', name_source=['in_file'], argstr='> %s', |
| 2405 | + keep_extension=False, position=-1, desc='capture standard output') |
| 2406 | + |
| 2407 | + |
| 2408 | +class OutlierCountOutputSpec(TraitedSpec): |
| 2409 | + out_outliers = File(exists=True, desc='output image file name') |
| 2410 | + out_file = File( |
| 2411 | + name_template='%s_tqual', name_source=['in_file'], argstr='> %s', |
| 2412 | + keep_extension=False, position=-1, desc='capture standard output') |
| 2413 | + |
| 2414 | + |
| 2415 | +class OutlierCount(CommandLine): |
| 2416 | + """Create a 3D dataset from 2D image files using AFNI to3d command |
| 2417 | +
|
| 2418 | + For complete details, see the `to3d Documentation |
| 2419 | + <http://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html>`_ |
| 2420 | +
|
| 2421 | + Examples |
| 2422 | + ======== |
| 2423 | +
|
| 2424 | + >>> from nipype.interfaces import afni |
| 2425 | + >>> toutcount = afni.OutlierCount() |
| 2426 | + >>> toutcount.inputs.in_file = 'functional.nii' |
| 2427 | + >>> toutcount.cmdline #doctest: +ELLIPSIS |
| 2428 | + '3dToutcount functional.nii > functional_outliers' |
| 2429 | + >>> res = toutcount.run() #doctest: +SKIP |
| 2430 | +
|
| 2431 | + """ |
| 2432 | + |
| 2433 | + _cmd = '3dToutcount' |
| 2434 | + input_spec = OutlierCountInputSpec |
| 2435 | + output_spec = OutlierCountOutputSpec |
| 2436 | + |
| 2437 | + def _parse_inputs(self, skip=None): |
| 2438 | + if skip is None: |
| 2439 | + skip = [] |
| 2440 | + |
| 2441 | + if not self.inputs.save_outliers: |
| 2442 | + skip += ['outliers_file'] |
| 2443 | + return super(OutlierCount, self)._parse_inputs(skip) |
| 2444 | + |
| 2445 | + def _list_outputs(self): |
| 2446 | + outputs = self.output_spec().get() |
| 2447 | + if self.inputs.save_outliers: |
| 2448 | + outputs['out_outliers'] = op.abspath(self.inputs.outliers_file) |
| 2449 | + outputs['out_file'] = op.abspath(self.inputs.out_file) |
| 2450 | + return outputs |
| 2451 | + |
| 2452 | + |
| 2453 | +class QualityIndexInputSpec(CommandLineInputSpec): |
| 2454 | + in_file = File(argstr='%s', mandatory=True, exists=True, position=-2, desc='input dataset') |
| 2455 | + mask = File(exists=True, argstr='-mask %s', xor=['autoclip', 'automask'], |
| 2456 | + desc='compute correlation only across masked voxels') |
| 2457 | + spearman = traits.Bool(False, usedefault=True, argstr='-spearman', |
| 2458 | + desc='Quality index is 1 minus the Spearman (rank) ' |
| 2459 | + 'correlation coefficient of each sub-brick ' |
| 2460 | + 'with the median sub-brick. (default)') |
| 2461 | + quadrant = traits.Bool(False, usedefault=True, argstr='-quadrant', |
| 2462 | + desc='Similar to -spearman, but using 1 minus the ' |
| 2463 | + 'quadrant correlation coefficient as the ' |
| 2464 | + 'quality index.') |
| 2465 | + autoclip = traits.Bool(False, usedefault=True, argstr='-autoclip', xor=['mask'], |
| 2466 | + desc='clip off small voxels') |
| 2467 | + automask = traits.Bool(False, usedefault=True, argstr='-automask', xor=['mask'], |
| 2468 | + desc='clip off small voxels') |
| 2469 | + clip = traits.Float(argstr='-clip %f', desc='clip off values below') |
| 2470 | + |
| 2471 | + interval = traits.Bool(False, usedefault=True, argstr='-range', |
| 2472 | + desc='write out the median + 3.5 MAD of outlier' |
| 2473 | + ' count with each timepoint') |
| 2474 | + out_file = File( |
| 2475 | + name_template='%s_tqual', name_source=['in_file'], argstr='> %s', |
| 2476 | + keep_extension=False, position=-1, desc='capture standard output') |
| 2477 | + |
| 2478 | + |
| 2479 | +class QualityIndexOutputSpec(TraitedSpec): |
| 2480 | + out_file = File(desc='file containing the caputured standard output') |
| 2481 | + |
| 2482 | + |
| 2483 | +class QualityIndex(CommandLine): |
| 2484 | + """Create a 3D dataset from 2D image files using AFNI to3d command |
| 2485 | +
|
| 2486 | + For complete details, see the `to3d Documentation |
| 2487 | + <http://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html>`_ |
| 2488 | +
|
| 2489 | + Examples |
| 2490 | + ======== |
| 2491 | +
|
| 2492 | + >>> from nipype.interfaces import afni |
| 2493 | + >>> tqual = afni.QualityIndex() |
| 2494 | + >>> tqual.inputs.in_file = 'functional.nii' |
| 2495 | + >>> tqual.cmdline #doctest: +ELLIPSIS |
| 2496 | + '3dTqual functional.nii > functional_tqual' |
| 2497 | + >>> res = tqual.run() #doctest: +SKIP |
| 2498 | +
|
| 2499 | + """ |
| 2500 | + |
| 2501 | + _cmd = '3dTqual' |
| 2502 | + input_spec = QualityIndexInputSpec |
| 2503 | + output_spec = QualityIndexOutputSpec |
0 commit comments