|
18 | 18 |
|
19 | 19 | import numpy as np
|
20 | 20 |
|
21 |
| -from nipype.interfaces.fsl.base import (FSLCommand, FSLCommandInputSpec) |
| 21 | +from nipype.interfaces.fsl.base import (FSLCommand, FSLCommandInputSpec, Info) |
22 | 22 | from nipype.interfaces.base import (load_template, File, traits, isdefined,
|
23 | 23 | TraitedSpec, BaseInterface, Directory,
|
24 | 24 | InputMultiPath, OutputMultiPath,
|
25 | 25 | BaseInterfaceInputSpec)
|
26 |
| -from nipype.utils.filemanip import (list_to_filename, filename_to_list) |
| 26 | +from nipype.utils.filemanip import (list_to_filename, filename_to_list, split_filename) |
27 | 27 | from nibabel import load
|
28 | 28 |
|
29 | 29 | warn = warnings.warn
|
@@ -1511,3 +1511,66 @@ def _list_outputs(self):
|
1511 | 1511 | outputs['f_corrected_p_files'] = glob(self._gen_fname(\
|
1512 | 1512 | '%s_%s_corrp_fstat*.nii' % (self.inputs.base_name, prefix)))
|
1513 | 1513 | return outputs
|
| 1514 | + |
| 1515 | + |
| 1516 | +class GLMInputSpec(FSLCommandInputSpec): |
| 1517 | + in_file = File( |
| 1518 | + exists=True,mandatory=True, |
| 1519 | + argstr='-i %s', |
| 1520 | + desc='input 3d+t file',) |
| 1521 | + design = File( |
| 1522 | + exists=True, mandatory=True, |
| 1523 | + argstr='-d %s', |
| 1524 | + desc='design file or image file') |
| 1525 | + out_file = File( |
| 1526 | + genfile=True, argstr="-o %s", |
| 1527 | + desc="file or image output") |
| 1528 | + mask = File( |
| 1529 | + exists=True, |
| 1530 | + argstr='-m %s', |
| 1531 | + desc='mask file') |
| 1532 | + contrasts = File( |
| 1533 | + exists=True, |
| 1534 | + argstr='-c %s', |
| 1535 | + desc='t-contrasts file') |
| 1536 | + options = traits.String( |
| 1537 | + argstr='%s', |
| 1538 | + desc = 'fsl_glm options') |
| 1539 | +class GLMOutputSpec(TraitedSpec): |
| 1540 | + out_file = File( |
| 1541 | + exists=True, |
| 1542 | + desc = 'file or image output') |
| 1543 | + |
| 1544 | +class GLM(FSLCommand): |
| 1545 | + """ |
| 1546 | + FSL GLM: |
| 1547 | +
|
| 1548 | + Example |
| 1549 | + ------- |
| 1550 | + >>> import nipype.interfaces.fsl as fsl |
| 1551 | + >>> glm = fsl.GLM(in_file='functional.nii', design = 'maps.nii') |
| 1552 | + >>> glm.cmdline |
| 1553 | + """ |
| 1554 | + _cmd = 'fsl_glm' |
| 1555 | + input_spec = GLMInputSpec |
| 1556 | + output_spec = GLMOutputSpec |
| 1557 | + |
| 1558 | + def _list_outputs(self): |
| 1559 | + outputs = self.output_spec().get() |
| 1560 | + outputs['out_file'] = self.inputs.out_file |
| 1561 | + # Generate an out_file if one is not provided |
| 1562 | + if not isdefined(outputs['out_file']) and isdefined(self.inputs.in_file): |
| 1563 | + ext = Info.output_type_to_ext(self.inputs.output_type) |
| 1564 | + if split_filename(self.inputs.in_file)[-1] in Info.ftypes.values(): |
| 1565 | + ext = '.txt' |
| 1566 | + outputs['out_file'] = self._gen_fname(self.inputs.in_file, |
| 1567 | + suffix='_glm', |
| 1568 | + ext=ext) |
| 1569 | + |
| 1570 | + return outputs |
| 1571 | + |
| 1572 | + def _gen_filename(self, name): |
| 1573 | + if name in ('out_file'): |
| 1574 | + return self._list_outputs()[name] |
| 1575 | + else: |
| 1576 | + return None |
0 commit comments