@@ -2372,3 +2372,145 @@ def _list_outputs(self):
23722372
23732373 outputs ['fwhm' ] = tuple (sout )
23742374 return outputs
2375+
2376+
2377+ class OutlierCountInputSpec (AFNICommandInputSpec ):
2378+ in_file = File (argstr = '%s' , mandatory = True , exists = True , position = - 2 , desc = 'input dataset' )
2379+ mask = File (exists = True , argstr = '-mask %s' , xor = ['autoclip' , 'automask' ],
2380+ desc = 'only count voxels within the given mask' )
2381+ qthr = traits .Range (value = 1e-3 , low = 0.0 , high = 1.0 , argstr = '-qthr %.5f' ,
2382+ desc = 'indicate a value for q to compute alpha' )
2383+
2384+ autoclip = traits .Bool (False , usedefault = True , argstr = '-autoclip' , xor = ['in_file' ],
2385+ desc = 'clip off small voxels' )
2386+ automask = traits .Bool (False , usedefault = True , argstr = '-automask' , xor = ['in_file' ],
2387+ desc = 'clip off small voxels' )
2388+
2389+ fraction = traits .Bool (False , usedefault = True , argstr = '-fraction' ,
2390+ desc = 'write out the fraction of masked voxels'
2391+ ' which are outliers at each timepoint' )
2392+ interval = traits .Bool (False , usedefault = True , argstr = '-range' ,
2393+ desc = 'write out the median + 3.5 MAD of outlier'
2394+ ' count with each timepoint' )
2395+ save_outliers = traits .Bool (False , usedefault = True , desc = 'enables out_file option' )
2396+ outliers_file = File (name_template = "%s_outliers" , argstr = '-save %s' , name_source = ["in_file" ],
2397+ 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 (name_template = '%s_outliers' , name_source = ['in_file' ], argstr = '> %s' ,
2404+ keep_extension = False , position = - 1 , desc = 'capture standard output' )
2405+
2406+
2407+ class OutlierCountOutputSpec (AFNICommandOutputSpec ):
2408+ outliers_file = File (exists = True , desc = 'output image file name' )
2409+ outliers = traits .List (traits .Float ,
2410+ desc = 'parse standard output to get the count of outliers' )
2411+
2412+
2413+ class OutlierCount (AFNICommand ):
2414+ """Create a 3D dataset from 2D image files using AFNI to3d command
2415+
2416+ For complete details, see the `to3d Documentation
2417+ <http://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html>`_
2418+
2419+ Examples
2420+ ========
2421+
2422+ >>> from nipype.interfaces import afni
2423+ >>> toutcount = afni.OutlierCount()
2424+ >>> toutcount.inputs.in_file = 'functional.nii'
2425+ >>> toutcount.cmdline #doctest: +ELLIPSIS
2426+ '3dToutcount functional.nii > functional_outliers'
2427+ >>> res = toutcount.run() #doctest: +SKIP
2428+
2429+ """
2430+
2431+ _cmd = '3dToutcount'
2432+ input_spec = OutlierCountInputSpec
2433+ output_spec = OutlierCountOutputSpec
2434+
2435+ def _parse_inputs (self , skip = None ):
2436+ if skip is None :
2437+ skip = []
2438+
2439+ if not self .inputs .save_outliers :
2440+ skip += ['outliers_file' ]
2441+ return super (OutlierCount , self )._parse_inputs (skip )
2442+
2443+ def _list_outputs (self ):
2444+ outputs = self .output_spec ().get ()
2445+ outputs ['outliers_file' ] = (Undefined if not self .inputs .save_outliers
2446+ else self .inputs .outliers_file )
2447+
2448+
2449+ with open (self .inputs .out_file , 'r' ) as fout :
2450+ lines = fout .readlines ()
2451+ # remove general information and warnings
2452+ outputs ['outliers' ] = [float (l )
2453+ for l in lines if re .match ("[0-9]+$" , l .strip ())]
2454+ return outputs
2455+
2456+
2457+ class QualityIndexInputSpec (AFNICommandInputSpec ):
2458+ in_file = File (argstr = '%s' , mandatory = True , exists = True , position = - 2 , desc = 'input dataset' )
2459+ mask = File (exists = True , argstr = '-mask %s' ,
2460+ desc = 'compute correlation only across masked voxels' )
2461+ spearman = traits .Bool (False , usedefault = True , argstr = '-spearman' ,
2462+ desc = 'Quality index is 1 minus the Spearman (rank) '
2463+ 'correlation coefficient of each sub-brick '
2464+ 'with the median sub-brick. (default)' )
2465+ quadrant = traits .Bool (False , usedefault = True , argstr = '-quadrant' ,
2466+ desc = 'Similar to -spearman, but using 1 minus the '
2467+ 'quadrant correlation coefficient as the '
2468+ 'quality index.' )
2469+ autoclip = traits .Bool (False , usedefault = True , argstr = '-autoclip' ,
2470+ desc = 'clip off small voxels' )
2471+ automask = traits .Bool (False , usedefault = True , argstr = '-automask' ,
2472+ desc = 'clip off small voxels' )
2473+ clip = traits .Float (argstr = '-clip %f' , desc = 'clip off values below' )
2474+
2475+ interval = traits .Bool (False , usedefault = True , argstr = '-range' ,
2476+ desc = 'write out the median + 3.5 MAD of outlier'
2477+ ' count with each timepoint' )
2478+ out_file = File (name_template = '%s_tqual' , name_source = ['in_file' ], argstr = '> %s' ,
2479+ keep_extension = False , position = - 1 , desc = 'capture standard output' )
2480+
2481+
2482+ class QualityIndexOutputSpec (AFNICommandOutputSpec ):
2483+ qi_value = traits .List (traits .Float , desc = 'output quality index' )
2484+
2485+
2486+ class QualityIndex (AFNICommand ):
2487+ """Create a 3D dataset from 2D image files using AFNI to3d command
2488+
2489+ For complete details, see the `to3d Documentation
2490+ <http://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html>`_
2491+
2492+ Examples
2493+ ========
2494+
2495+ >>> from nipype.interfaces import afni
2496+ >>> tqual = afni.QualityIndex()
2497+ >>> tqual.inputs.in_file = 'functional.nii'
2498+ >>> tqual.cmdline #doctest: +ELLIPSIS
2499+ '3dTqual functional.nii > functional_tqual'
2500+ >>> res = tqual.run() #doctest: +SKIP
2501+
2502+ """
2503+
2504+ _cmd = '3dTqual'
2505+ input_spec = QualityIndexInputSpec
2506+ output_spec = QualityIndexOutputSpec
2507+
2508+ def _list_outputs (self ):
2509+ outputs = self .output_spec ().get ()
2510+ with open (self .inputs .out_file , 'r' ) as fout :
2511+ lines = fout .readlines ()
2512+ # remove general information
2513+ lines = [l for l in lines if l [:2 ] != "++" ]
2514+ # remove general information and warnings
2515+ outputs ['qi_value' ] = [float (l .strip ()) for l in lines ]
2516+ return outputs
0 commit comments