Skip to content

Commit c024235

Browse files
committed
added this now to new fork of repo
1 parent f3e7d50 commit c024235

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

nipype/interfaces/fsl/fix.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2+
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
"""The fix module provides classes for interfacing with the `FSL FIX
4+
<http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FIX/index.html>`_ command line tools.
5+
This was written to work with FSL version v5.0
6+
Change directory to provide relative paths for doctests
7+
>>> import os
8+
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
9+
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
10+
>>> os.chdir(datadir)
11+
"""
12+
13+
from nipype.interfaces.base import (
14+
TraitedSpec,
15+
CommandLineInputSpec,
16+
CommandLine,
17+
Directory,
18+
InputMultiPath,
19+
traits,
20+
File
21+
)
22+
import os
23+
24+
class FIXInputSpec(CommandLineInputSpec):
25+
mel_ica = InputMultiPath(Directory(exists=True), copyfile=False,
26+
desc='Melodic output directory or directories',
27+
argstr='%s', position=-1)
28+
29+
30+
# Different modes of operation, which are pretty much mutually exclusive
31+
_xor_inputs = ('extract_features', 'classify', 'apply_cleanup', 'train', 'test_accuracy')
32+
33+
# /usr/local/fix/fix -f <mel.ica>
34+
extract_features = traits.Bool(desc='Extract features (for later training and/or classifying)',
35+
argstr='-f', xor=_xor_inputs, requires='mel_ica')
36+
37+
# /usr/local/fix/fix -c <mel.ica> <training.RData> <thresh>
38+
classify = traits.Bool(desc='Classify ICA components using a specific training dataset (<thresh> is in the range 0-100, typically 5-20)',
39+
argstr='-c', xor=_xor_inputs, requires='mel_ica')
40+
41+
# /usr/local/fix/fix -a <mel.ica/fix4melview_TRAIN_thr.txt> [-m [-h <highpass>]] [-A] [-x <confound>] [-x <confound2>] etc.
42+
apply_cleanup = traits.Bool(desc='Apply cleanup, using artefacts listed in the .txt file',
43+
argstr='-a', xor=_xor_inputs, requires='artifacts_list_file') # todo, optional args, required inputs
44+
45+
train = traits.Bool(desc='Train the classifier based on your own FEAT/MELODIC output directory',
46+
argstr='-t %s', value="training", xor=_xor_inputs) # todo, optional args
47+
48+
test_accuracy = traits.Bool(desc='Test the accuracy of an existing training dataset on a set of hand-labelled subjects',
49+
argstr='-C', xor=_xor_inputs)
50+
51+
52+
# shared args for different modes
53+
artifacts_list_file = File(desc='Text file listing which ICs are artifacts; can be the output from classification or can be created manually', argstr='%s')
54+
55+
trained_wts_file = File(desc='trained-weights file', argstr='%s')
56+
57+
58+
59+
60+
# leave-one-out cross validation
61+
loo = traits.Bool(argstr='-l', requires=['train'],
62+
desc='full leave-one-out test with classifier training')
63+
64+
# args for classify
65+
66+
highpass = traits.Float(argstr='-m -h %f', requires=['apply_cleanup'],
67+
desc='cleanup motion confounds', value=100, xor=_xor_cleanup)
68+
69+
70+
# for apply_cleanup
71+
72+
_xor_cleanup = ('cleanup_motion', 'highpass_filter')
73+
74+
cleanup_motion = traits.Bool(argstr='-m', requires=['apply_cleanup'],
75+
desc='cleanup motion confounds, looks for design.fsf for highpass filter cut-off', xor=_xor_cleanup)
76+
77+
highpass = traits.Float(argstr='-m -h %f', requires=['apply_cleanup'],
78+
desc='cleanup motion confounds', value=100, xor=_xor_cleanup)
79+
80+
aggressive = traits.Bool(argstr='-A', requires=['apply_cleanup'],
81+
desc='Apply aggressive (full variance) cleanup, instead of the default less-aggressive (unique variance) cleanup.')
82+
83+
confound_file = traits.File(argstr='-x %s', requires=['apply_cleanup'],
84+
desc='Include additional confound file.')
85+
86+
confound_file_1 = traits.File(argstr='-x %s', requires=['apply_cleanup'],
87+
desc='Include additional confound file.')
88+
89+
confound_file_2 = traits.File(argstr='-x %s', requires=['apply_cleanup'],
90+
desc='Include additional confound file.')
91+
92+
93+
94+
class FIXOutputSpec(TraitedSpec):
95+
output_file = File(desc = "Zip file", exists = True)
96+
97+
class FIX(CommandLine):
98+
input_spec = FIXInputSpec
99+
output_spec = FIXOutputSpec
100+
cmd = 'fix'
101+
102+
def _list_outputs(self):
103+
outputs = self.output_spec().get()
104+
return outputs
105+
106+
if __name__ == '__main__':
107+
108+
fix = FIX()
109+
print fix.cmdline
110+
fix.run()

0 commit comments

Comments
 (0)