Skip to content

Commit 7708b9c

Browse files
surchschrisgorgo
authored andcommitted
added FSLGLM
Conflicts: nipype/interfaces/fsl/__init__.py nipype/interfaces/fsl/model.py
1 parent 04b1529 commit 7708b9c

File tree

2 files changed

+185
-10
lines changed

2 files changed

+185
-10
lines changed

nipype/interfaces/fsl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
SliceTimer, SUSAN, PRELUDE, FUGUE, FIRST)
1212
from .model import (Level1Design, FEAT, FEATModel, FILMGLS, FEATRegister,
1313
FLAMEO, ContrastMgr, MultipleRegressDesign, L2Model, SMM,
14-
MELODIC, SmoothEstimate, Cluster, Randomise, GLM)
14+
MELODIC, SmoothEstimate, Cluster, Randomise, GLM, FSLGLM)
1515
from .utils import (Smooth, Merge, ExtractROI, Split, ImageMaths, ImageMeants,
1616
ImageStats, FilterRegressor, Overlay, Slicer,
1717
PlotTimeSeries, PlotMotionParams, ConvertXFM,

nipype/interfaces/fsl/model.py

Lines changed: 184 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def _get_design_root(self, infile):
404404
return fname.split('.')[0]
405405

406406
def _list_outputs(self):
407-
#TODO: figure out file names and get rid off the globs
407+
# TODO: figure out file names and get rid off the globs
408408
outputs = self._outputs().get()
409409
root = self._get_design_root(list_to_filename(self.inputs.fsf_file))
410410
design_file = glob(os.path.join(os.getcwd(), '%s*.mat' % root))
@@ -430,14 +430,14 @@ def _list_outputs(self):
430430
# ohinds: 2009-12-28
431431

432432
class FILMGLSInputSpec(FSLCommandInputSpec):
433-
in_file = File(exists=True, mandatory=True, position=-3,
433+
in_file = File(exists=True, mandatory=True, position= -3,
434434
argstr='%s',
435435
desc='input data file')
436-
design_file = File(exists=True, position=-2,
436+
design_file = File(exists=True, position= -2,
437437
argstr='%s',
438438
desc='design matrix file')
439439
threshold = traits.Float(1000, min=0, argstr='%f',
440-
position=-1,
440+
position= -1,
441441
desc='threshold')
442442
smooth_autocorr = traits.Bool(argstr='-sa',
443443
desc='Smooth auto corr estimates')
@@ -549,6 +549,181 @@ def _list_outputs(self):
549549
cwd=results_dir)
550550
return outputs
551551

552+
class FSLGLMInputSpec(FSLCommandInputSpec):
553+
"""
554+
Use FSL GLM
555+
@author: sebastian urchs
556+
557+
558+
"""
559+
560+
in_file = File(exists=True, argstr='-i %s', mandatory=True, position=1,
561+
desc='input file name (text matrix or 3D/4D image file)')
562+
563+
output_file = File(argstr='-o %s', mandatory=True, position=3,
564+
desc=('filename for GLM parameter estimates'
565+
+ ' (GLM betas)'))
566+
567+
design_file = File(exists=True, argstr='-d %s', mandatory=True, position=2,
568+
desc=('file name of the GLM design matrix (text time'
569+
+ ' courses for temporal regression or an image'
570+
+ ' file for spatial regression)'))
571+
572+
contrasts = File(exists=True, argstr='-c %s', desc=('matrix of t-statics'
573+
+ ' contrasts'))
574+
575+
mask = File(exists=True, argstr='-m %s', desc=('mask image file name if'
576+
+ ' input is image'))
577+
578+
dof = traits.Int(argstr='--dof %d', desc=('set degrees of freedom'
579+
+ ' explicitly'))
580+
581+
des_norm = traits.Bool(argstr='--des_norm', desc=('switch on normalization'
582+
+ ' of the design matrix'
583+
+ ' columns to unit std'
584+
+ ' deviation'))
585+
586+
dat_norm = traits.Bool(argstr='--dat_norm', desc=('switch on normalization'
587+
+ ' of the data time'
588+
+ ' series to unit std'
589+
+ ' deviation'))
590+
591+
var_norm = traits.Bool(argstr='--vn', desc=('perform MELODIC variance-'
592+
+ 'normalisation on data'))
593+
594+
demean = traits.Bool(argstr='--demean', desc=('switch on demeaining of '
595+
+ ' design and data'))
596+
597+
out_cope = File(argstr='--out_cope=%s',
598+
desc='output file name for COPE (either as txt or image')
599+
600+
out_z_name = File(argstr='--out_z=%s',
601+
desc='output file name for Z-stats (either as txt or image')
602+
603+
out_t_name = File(argstr='--out_t=%s',
604+
desc='output file name for t-stats (either as txt or image')
605+
606+
out_p_name = File(argstr='--out_p=%s',
607+
desc=('output file name for p-values of Z-stats (either as'
608+
+ ' text file or image)'))
609+
610+
out_f_name = File(argstr='--out_f=%s',
611+
desc='output file name for F-value of full model fit')
612+
613+
out_pf_name = File(argstr='--out_pf=%s',
614+
desc='output file name for p-value for full model fit')
615+
616+
out_res_name = File(argstr='--out_res=%s',
617+
desc='output file name for residuals')
618+
619+
out_varcb_name = File(argstr='--out_varcb=%s',
620+
desc='output file name for variance of COPEs')
621+
622+
out_sigsq_name = File(argstr='--out_sigsq=%s',
623+
desc=('output file name for residual noise variance'
624+
+ ' sigma-square'))
625+
626+
out_data_name = File(argstr='--out_data=%s',
627+
desc='output file name for pre-processed data')
628+
629+
out_vnscales_name = File(argstr='--out_vnscales=%s',
630+
desc=('output file name for scaling factors for variance'
631+
+ ' normalisation'))
632+
633+
634+
class FSLGLMOutputSpec(TraitedSpec):
635+
out_file = File(exists=True, desc=('file name of GLM parameters'
636+
+ ' (if generated)'))
637+
638+
out_cope = OutputMultiPath(exists=True, desc='output file name for COPEs' +
639+
' (either as text file or image)')
640+
641+
out_z = OutputMultiPath(exists=True, desc='output file name for COPEs' +
642+
' (either as text file or image)')
643+
644+
out_t = OutputMultiPath(exists=True, desc='output file name for t-stats' +
645+
' (either as text file or image)')
646+
647+
out_p = OutputMultiPath(exists=True, desc='output file name for p-values' +
648+
' of Z-stats (either as text file or image)')
649+
650+
out_f = OutputMultiPath(exists=True, desc='output file name for F-value' +
651+
' of full model fit')
652+
653+
out_pf = OutputMultiPath(exists=True, desc='output file name for p-value' +
654+
' for full model fit')
655+
656+
out_res = OutputMultiPath(exists=True, desc='output file name for' +
657+
' residuals')
658+
659+
out_varcb = OutputMultiPath(exists=True, desc='output file name for' +
660+
' variance of COPEs')
661+
662+
out_sigsq = OutputMultiPath(exists=True, desc='output file name for' +
663+
' residual noise variance sigma-square')
664+
665+
out_data = OutputMultiPath(exists=True, desc='output file name for' +
666+
' residual noise variance sigma-square')
667+
668+
out_vnscales = OutputMultiPath(exists=True, desc='output file name' +
669+
' for scaling factors for variance' +
670+
' normalisation')
671+
672+
673+
class FSLGLM(FSLCommand):
674+
"""
675+
Use FSL GLM.
676+
@author: sebastian urchs
677+
678+
@status: testing
679+
680+
"""
681+
_cmd = 'fsl_glm'
682+
input_spec = FSLGLMInputSpec
683+
output_spec = FSLGLMOutputSpec
684+
685+
def _list_outputs(self):
686+
import os
687+
outputs = self.output_spec().get()
688+
689+
outputs['out_file'] = os.path.join(os.getcwd(), self.inputs.output_file)
690+
691+
if isdefined(self.inputs.out_cope):
692+
outputs['out_cope'] = os.path.join(os.getcwd(), self.inputs.out_cope)
693+
694+
if isdefined(self.inputs.out_z_name):
695+
outputs['out_z'] = os.path.join(os.getcwd(), self.inputs.out_z_name)
696+
697+
if isdefined(self.inputs.out_t_name):
698+
outputs['out_t'] = os.path.join(os.getcwd(), self.inputs.out_t_name)
699+
700+
if isdefined(self.inputs.out_p_name):
701+
outputs['out_p'] = os.path.join(os.getcwd(), self.inputs.out_p_name)
702+
703+
if isdefined(self.inputs.out_f_name):
704+
outputs['out_f'] = os.path.join(os.getcwd(), self.inputs.out_f_name)
705+
706+
if isdefined(self.inputs.out_pf_name):
707+
outputs['out_pf'] = os.path.join(os.getcwd(), self.inputs.out_pf_name)
708+
709+
if isdefined(self.inputs.out_res_name):
710+
outputs['out_res'] = os.path.join(os.getcwd(), self.inputs.out_res_name)
711+
712+
if isdefined(self.inputs.out_varcb_name):
713+
outputs['out_varcb'] = os.path.join(os.getcwd(), self.inputs.out_varcb_name)
714+
715+
if isdefined(self.inputs.out_sigsq_name):
716+
outputs['out_sigsq'] = os.path.join(os.getcwd(), self.inputs.out_sigsq_name)
717+
718+
if isdefined(self.inputs.out_data_name):
719+
outputs['out_data'] = os.path.join(os.getcwd(), self.inputs.out_data_name)
720+
721+
if isdefined(self.inputs.out_vnscales_name):
722+
outputs['out_vnscales'] = os.path.join(os.getcwd(), self.inputs.out_vnscales_name)
723+
724+
return outputs
725+
726+
552727

553728
class FEATRegisterInputSpec(BaseInterfaceInputSpec):
554729
feat_dirs = InputMultiPath(Directory(), exist=True, desc="Lower level feat dirs",
@@ -732,7 +907,7 @@ def _list_outputs(self):
732907

733908
class ContrastMgrInputSpec(FSLCommandInputSpec):
734909
tcon_file = File(exists=True, mandatory=True,
735-
argstr='%s', position=-1,
910+
argstr='%s', position= -1,
736911
desc='contrast file containing T-contrasts')
737912
fcon_file = File(exists=True, argstr='-f %s',
738913
desc='contrast file containing F-contrasts')
@@ -744,7 +919,7 @@ class ContrastMgrInputSpec(FSLCommandInputSpec):
744919
desc='statistical corrections used within FILM modelling')
745920
dof_file = File(exists=True, argstr='', copyfile=False, mandatory=True,
746921
desc='degrees of freedom')
747-
sigmasquareds = File(exists=True, argstr='', position=-2,
922+
sigmasquareds = File(exists=True, argstr='', position= -2,
748923
copyfile=False, mandatory=True,
749924
desc='summary of residuals, See Woolrich, et. al., 2001')
750925
contrast_num = traits.Int(min=1, argstr='-cope',
@@ -905,7 +1080,7 @@ def _run_interface(self, runtime):
9051080
'/NumContrasts 1',
9061081
'/PPheights %e' % 1,
9071082
'/RequiredEffect 100.0', # XX where does this
908-
#number come from
1083+
# number come from
9091084
'',
9101085
'/Matrix',
9111086
'%e' % 1]
@@ -1121,7 +1296,7 @@ class SMM(FSLCommand):
11211296

11221297
def _list_outputs(self):
11231298
outputs = self._outputs().get()
1124-
#TODO get the true logdir from the stdout
1299+
# TODO get the true logdir from the stdout
11251300
outputs['null_p_map'] = self._gen_fname(basename="w1_mean", cwd="logdir")
11261301
outputs['activation_p_map'] = self._gen_fname(basename="w2_mean", cwd="logdir")
11271302
if not isdefined(self.inputs.no_deactivation_class) or not self.inputs.no_deactivation_class:
@@ -1382,7 +1557,7 @@ def _list_outputs(self):
13821557
if inval:
13831558
change_ext = True
13841559
if suffix.endswith('.txt'):
1385-
change_ext=False
1560+
change_ext = False
13861561
outputs[outkey] = self._gen_fname(self.inputs.in_file,
13871562
suffix='_' + suffix,
13881563
change_ext=change_ext)

0 commit comments

Comments
 (0)