~nipy-developers/nipy/trunk-interfaces

« back to all changes in this revision

Viewing changes to nipy/pypemodules/MITio.py

  • Committer: Satrajit Ghosh
  • Date: 2009-07-22 01:37:55 UTC
  • Revision ID: satra@ba5-20090722013755-x99u9jay3aauowg3
updated data sink options

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        # check to see that the output file exists.
42
42
        self.outputs['subj_id'] = self.inputs['subj_id']
43
43
 
 
44
class MITsink(nif.InterfaceBase):
 
45
    def __init__(self):
 
46
        super(MITsink,self).__init__()
 
47
        self.diskbased = False
 
48
        self.name = 'MITsink'
 
49
        self.parameterization = ''
 
50
        self.log = {}
 
51
        self.inputs['use_parameterization'] = False
 
52
        self.inputs['base_dir'] = None
 
53
        self.inputs['subj_id'] = None
 
54
        self.inputs['subj_template'] = None
 
55
 
 
56
    def pre_execute(self):
 
57
        pass
 
58
    
 
59
    def execute(self):
 
60
        # check to see that the output file exists.
 
61
        if not os.path.exists(self.inputs['base_dir']):
 
62
            os.mkdir(self.inputs['base_dir'])
 
63
        outdir = self.inputs['base_dir']
 
64
        if self.inputs['subj_id'] is not None:
 
65
            outdir = os.path.join(outdir,self.inputs['subj_template'] % self.inputs['subj_id'])
 
66
            if not os.path.exists(outdir):
 
67
                os.mkdir(outdir)
 
68
        if self.inputs['use_parameterization'] and self.parameterization is not '':
 
69
            outdir = os.path.join(outdir,self.parameterization)
 
70
            if not os.path.exists(outdir):
 
71
                os.mkdir(outdir)
 
72
        fieldstocopy = []
 
73
        for k,v in self.inputs.items():
 
74
            if type(v) is type([]):
 
75
                if len(v) > 0:
 
76
                    dirnames = k.split('.')
 
77
                    tempoutdir = outdir
 
78
                    for d in k.split('.'):
 
79
                        tempoutdir = os.path.join(tempoutdir,d)
 
80
                        if not os.path.exists(tempoutdir):
 
81
                            os.mkdir(tempoutdir)
 
82
                    nif.copyfiles_to_cwd(self.inputs,[k],tempoutdir,hashnames=False,symlink=False)
 
83
 
 
84
    def post_execute(self):
 
85
        pass
 
86
 
 
87
class MITL2source(nif.InterfaceBase):
 
88
    def __init__(self):
 
89
        super(MITL2source,self).__init__()
 
90
        self.diskbased = False
 
91
        self.name = 'FBIRNsource'
 
92
        self.log = {}
 
93
        self.inputs['base_dir'] = None
 
94
        self.inputs['subject_id'] = None
 
95
        self.inputs['contrast_id'] = None
 
96
        self.outputs['conimages'] = None
 
97
 
 
98
    def pre_execute(self):
 
99
        pass
 
100
 
 
101
    def execute(self):
 
102
        """Execute the cmd
 
103
        """
 
104
        self.log['returncode'] = 0
 
105
        self.outputs['conimages'] = []
 
106
        for subj in self.inputs['subject_id']:
 
107
            subjdir = '_subject_id_%s' % subj
 
108
            conimg = 'con_%04d.img' % self.inputs['contrast_id']
 
109
            con_path = os.path.join(self.inputs['base_dir'],subjdir,conimg)
 
110
            self.outputs['conimages'].extend(glob.glob(con_path))
 
111
    
 
112
    def post_execute(self):
 
113
        # check to see that the output file exists.
 
114
        pass