1
+ from nipype .interfaces .matlab import MatlabCommand
2
+ from nipype .interfaces .base import TraitedSpec , \
3
+ BaseInterface , BaseInterfaceInputSpec , File
4
+ import os
5
+ from string import Template
6
+
7
+
8
+ class ConmapTxt2MatInputSpec (BaseInterfaceInputSpec ):
9
+ in_file = File (exists = True , mandatory = True )
10
+ out_file = File ('cmatrix.mat' , usedefault = True )
11
+
12
+
13
+ class ConmapTxt2MatOutputSpec (TraitedSpec ):
14
+ out_file = File (exists = True )
15
+
16
+
17
+ class ConmapTxt2Mat (BaseInterface ):
18
+ input_spec = ConmapTxt2MatInputSpec
19
+ output_spec = ConmapTxt2MatOutputSpec
20
+
21
+ def _run_interface (self , runtime ):
22
+ d = dict (in_file = self .inputs .in_file ,
23
+ out_file = self .inputs .out_file )
24
+ # This is your MATLAB code template
25
+ script = Template ("""in_file = '$in_file';
26
+ out_file = '$out_file';
27
+ ConmapTxt2Mat(in_file, out_file);
28
+ exit;
29
+ """ ).substitute (d )
30
+
31
+ # mfile = True will create an .m file with your script and executed.
32
+ # Alternatively
33
+ # mfile can be set to False which will cause the matlab code to be
34
+ # passed
35
+ # as a commandline argument to the matlab executable
36
+ # (without creating any files).
37
+ # This, however, is less reliable and harder to debug
38
+ # (code will be reduced to
39
+ # a single line and stripped of any comments).
40
+ mlab = MatlabCommand (script = script , mfile = True )
41
+ result = mlab .run ()
42
+ return result .runtime
43
+
44
+ def _list_outputs (self ):
45
+ outputs = self ._outputs ().get ()
46
+ outputs ['out_file' ] = os .path .abspath (self .inputs .out_file )
47
+ return outputs
0 commit comments