Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.37 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #ICA_AROMA pulled from: https://github.com/rhr-pruim/ICA-AROMA
  3.  
  4. from nipype.interfaces.base import (
  5.     TraitedSpec,
  6.     CommandLineInputSpec,
  7.     CommandLine,
  8.     File,
  9.     Directory,
  10.     traits
  11. )
  12. import os
  13.  
  14. class ICA_AROMAInputSpec(CommandLineInputSpec):
  15.     #How do I format different processing streams (featdir versus manual inputs)?
  16.     #e.g. I want featDir to be mutually exclusive with infile,mask,affmat,warp, and mc.
  17.     #....xor can make all the options mutually exclusive with eachother, but I want
  18.     #to group the options (infile,mask,affmat,warp,mc)
  19.     #idk how xor works, my attempt    
  20.     _xor_inputs = ('featDir','infile')
  21.     featDir = Directory(exists=True,
  22.                         desc='If a feat directory exists and temporal filtering '
  23.                         'has not been run yet, ICA_AROMA can use the files in '
  24.                         'this directory.',mandatory=False,xor=_xor_inputs)
  25.     infile = File(exists=True,
  26.                   desc='volume to be denoised',
  27.                   argstr='-i %s',xor=_xor_inputs)
  28.     outdir = Directory(desc='path to output directory',
  29.                   argstr='-o %s',mandatory=True)
  30.     mask = File(exists=True,
  31.                 desc='path/name volume mask',
  32.                 argstr='-m %s')
  33.     dim = traits.Int(desc='Dimensionality reduction when running '
  34.                      'MELODIC (defualt is automatic estimation)',
  35.                      argstr='-dim %d')
  36.     TR = traits.Float(desc='TR in seconds. If this is not specified '
  37.                       'the TR will be extracted from the header of the fMRI nifti file.',
  38.                       argstr='%.2f')
  39.     melodic_dir = Directory(exists=True,
  40.                             desc='path to MELODIC directory if MELODIC has already been ran',
  41.                             argstr='-meldir %s')
  42.     affmat = File(exists=True,
  43.                   desc='path/name of the mat-file describing the '
  44.                   'affine registration (e.g. FSL FLIRT) of the '
  45.                   'functional data to structural space (.mat file)',
  46.                   argstr='-affmat %s')
  47.     warp = File(exists=True,
  48.                 desc='File name of the warp-file describing '
  49.                 'the non-linear registration (e.g. FSL FNIRT) '
  50.                 'of the structural data to MNI152 space (.nii.gz)',
  51.                 argstr='-warp %s')
  52.     mc = File(exists=True,
  53.               desc='motion parameters file',
  54.               argstr='-mc %s')
  55.     denoise_type = traits.Str(argstr='-den %s',
  56.                               desc='Type of denoising strategy: '
  57.                               '-none: only classification, no denoising '
  58.                               '-nonaggr (default): non-aggresssive denoising, i.e. partial component regression '
  59.                               '-aggr: aggressive denoising, i.e. full component regression '
  60.                               '-both: both aggressive and non-aggressive denoising (two outputs)',
  61.                               mandatory=True)
  62.  
  63. class ICA_AROMAOutputSpec(TraitedSpec):
  64.     denoised_func_data_nonaggr = File(desc='if generated: denoised volume (non aggressive)')
  65.     denoised_func_data_aggr = File(desc='if generated: denoised volume (aggressive)')
  66.  
  67. class ICA_AROMA(CommandLine):
  68.     _cmd = 'ICA_AROMA.py'
  69.     input_spec = ICA_AROMAInputSpec
  70.     output_spec = ICA_AROMAOutputSpec
  71.  
  72.     def _list_outputs(self):
  73.         #How do the outputs output_spec actually relate to the output filenames?
  74.         outputs = self.output_spec.get()
  75.         outdir = self.input_spec.outdir
  76.         denoising_strategy = input_spec.denoise_type
  77.  
  78.         if denoising_strategy is "noaggr":
  79.           out_file = os.path.join(outdir,'denoised_func_data_nonaggr.nii.gz')
  80.         elif denoising_strategy is "aggr":
  81.           out_file = os.path.join(outdir,'denoised_func_data_aggr.nii.gz')
  82.         elif denoising_strategy is "both":
  83.           #this is a tuple, versus the single outputs, how do I return a variable number of outputs?
  84.           out_file = (os.path.join(outdir,'denoised_func_data_nonaggr.nii.gz'), os.path.join(outdir,'denoised_func_data_aggr.nii.gz'))
  85.         elif denoising_strategy is "none":
  86.           print "No denoising selected"
  87.         else:
  88.           raise RuntimeError('denoise_type must be specified as one of'
  89.                              ' noaggr,aggr,both, or none')
  90.  
  91.         return out_file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement