-
Notifications
You must be signed in to change notification settings - Fork 5
/
e_afni.py
executable file
·1535 lines (1229 loc) · 52.3 KB
/
e_afni.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/frodo/shared/epd/bin/python
#coding: utf-8
import warnings
import os
import nibabel as nb
import numpy as np
import commands
from string import Template
from nipype.utils.filemanip import split_filename
from nipype.interfaces.matlab import MatlabCommand
from nipype.interfaces.base import BaseInterface, BaseInterfaceInputSpec
from nipype.interfaces.fsl.base import FSLCommand, FSLCommandInputSpec
from nipype.interfaces.afni.base import AFNITraitedSpec, AFNICommand, Info
from nipype.interfaces.base import Bunch, TraitedSpec, File, Directory, traits, isdefined
from nipype.interfaces.base import (CommandLineInputSpec, CommandLine, TraitedSpec, traits, isdefined, File)
from nipype.utils.filemanip import load_json, save_json, split_filename, fname_presuffix
warn = warnings.warn
warnings.filterwarnings('always', category=UserWarning)
class AFNICommandGenFile(AFNICommand):
def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True, ext=None):
"""Generate a filename based on the given parameters.
The filename will take the form: cwd/basename<suffix><ext>.
If change_ext is True, it will use the extensions specified in
<instance>inputs.outputtype.
Parameters
----------
basename : str
Filename to base the new filename on.
cwd : str
Path to prefix to the new filename. (default is os.getcwd())
suffix : str
Suffix to add to the `basename`. (default is '')
change_ext : bool
Flag to change the filename extension to the AFNI output type.
(default True)
Returns
-------
fname : str
New filename based on given parameters.
"""
if basename == '':
msg = 'Unable to generate filename for command %s. ' % self.cmd
msg += 'basename is not set!'
raise ValueError(msg)
if cwd is None:
cwd = os.getcwd()
if ext is None:
ext = Info.outputtype_to_ext(self.inputs.outputtype)
if change_ext:
if suffix:
suffix = ''.join((suffix, ext))
else:
suffix = ext
if suffix is None:
suffix = ''
fname = fname_presuffix(basename, suffix = suffix,
use_ext = False, newpath = cwd)
return fname
def _gen_filename(self, name):
if name == 'out_file':
return self._gen_outfilename()
return None
class To3dInputSpec(AFNITraitedSpec):
infolder = Directory(desc = 'folder with DICOM images to convert',
argstr = '%s/*.dcm',
position = -1,
mandatory = True,
exists = True)
outfile = File(desc = 'converted image file',
argstr = '-prefix %s',
position = -2,
mandatory = True)
filetype = traits.Enum('spgr', 'fse', 'epan', 'anat', 'ct', 'spct','pet', 'mra', 'bmap', 'diff',
'omri', 'abuc','fim', 'fith', 'fico', 'fitt', 'fift','fizt', 'fict', 'fibt',
'fibn','figt','fipt','fbuc', argstr = '-%s', desc='type of datafile being converted')
'''use xor'''
skipoutliers = traits.Bool(desc = 'skip the outliers check',
argstr = '-skip_outliers')
assumemosaic = traits.Bool(desc = 'assume that Siemens image is mosaic',
argstr = '-assume_dicom_mosaic')
datatype = traits.Enum('short', 'float', 'byte', 'complex', desc = 'set output file datatype',
argstr = '-datum %s')
funcparams = traits.Str(desc = 'parameters for functional data',
argstr = '-time:zt %s alt+z2')
class To3dOutputSpec(TraitedSpec):
out_file = File(desc = 'converted file',
exists = True)
class To3d(AFNICommand):
"""Create a 3D dataset from 2D image files using AFNI to3d command.
For complete details, see the `to3d Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/to3d.html>`_
To print out the command line help, use:
To3d().inputs_help()
Examples
--------
>>> from nipype.interfaces import afni
>>> to3d = afni.To3d()
AFNI has no environment variable that sets filetype
Nipype uses NIFTI_GZ as default
>>> to3d.inputs.datatype = 'float'
>>> to3d.inputs.infolder='dicomdir'
>>> to3d.inputs.filetype="anat"
>>> res = to3d.run() #doctest: +SKIP
"""
_cmd = 'to3d'
input_spec = To3dInputSpec
output_spec = To3dOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.outfile
return outputs
class ThreedTshiftInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dTShift',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dTshift',
argstr = '-prefix %s',
position = 0,
genfile = True)
tr = traits.Str(desc = 'manually set the TR instead of looking in the header. ' +
'You can attach suffix "s" for seconds or "ms" for milliseconds.',
argstr = '-TR %s')
tzero = traits.Float(desc = 'align each slice to given time offset',
argstr = '-tzero %s',
xor = ['tslice'])
tslice = traits.Int(desc = 'align each slice to time offset of given slice',
argstr = '-slice %s',
xor = ['tzero'])
ignore = traits.Int(desc = 'ignore the first set of points specified',
argstr = '-ignore %s')
interp = traits.Enum(('Fourier', 'linear', 'cubic', 'quintic', 'heptic'),
desc='different interpolation methods (see 3dTShift for details)' +
' default=Fourier', argstr='-%s')
tpattern = traits.Enum(('alt+z', 'alt+z2', 'alt-z', 'alt-z2', 'seq+z', 'seq-z'),
desc='use specified slice time pattern rather than one in header',
argstr='-tpattern %s')
rlt = traits.Bool(desc='Before shifting, remove the mean and linear trend',
argstr="-rlt")
rltplus = traits.Bool(desc='Before shifting, remove the mean and linear trend and ' +
'later put back the mean',
argstr="-rlt+")
suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value
class ThreedTshiftOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'post slice time shifted 4D image')
class ThreedTshift(AFNICommand):
"""Shifts voxel time series from input so that seperate slices are aligned to the same
temporal origin.
For complete details, see the `3dTshift Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTshift.html>`_
"""
_cmd = '3dTshift'
input_spec = ThreedTshiftInputSpec
output_spec = ThreedTshiftOutputSpec
def _gen_filename(self, name):
if name == 'out_file':
return self._list_outputs()[name]
return None
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.out_file
if not isdefined(outputs['out_file']):
if isdefined(self.inputs.suffix):
suffix = self.inputs.suffix
else:
suffix = "_tshift"
outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix)
return outputs
class ThreedrefitInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3drefit',
argstr = '%s',
position = -1,
mandatory = True,
exists = True,
copyfile = True)
deoblique = traits.Bool(desc = 'replace current transformation matrix with cardinal matrix',
argstr = '-deoblique')
xorigin = traits.Str(desc = 'x distance for edge voxel offset',
argstr = '-xorigin %s')
yorigin = traits.Str(desc = 'y distance for edge voxel offset',
argstr = '-yorigin %s')
zorigin = traits.Str(desc = 'z distance for edge voxel offset',
argstr = '-zorigin %s')
class ThreedrefitOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'Same file as original infile with modified matrix',
exists = True)
class Threedrefit(AFNICommand):
""" Use 3drefit for altering header info.
NOTES
-----
The original file is returned but it is CHANGED
"""
_cmd = '3drefit'
input_spec = ThreedrefitInputSpec
output_spec = ThreedrefitOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.in_file
return outputs
class ThreedWarpInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dWarp',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dWarp',
argstr = '-prefix %s',
position = 0,
genfile = True)
tta2mni = traits.Bool(desc = 'transform dataset from Talairach to MNI152',
argstr = '-tta2mni')
mni2tta = traits.Bool(desc = 'transform dataset from MNI152 to Talaraich',
argstr = '-mni2tta')
matparent = File(desc = "apply transformation from 3dWarpDrive",
argstr = "-matparent %s",
exists = True)
deoblique = traits.Bool(desc = 'transform dataset from oblique to cardinal',
argstr = '-deoblique')
interp = traits.Enum(('linear', 'cubic', 'NN', 'quintic'),
desc='spatial interpolation methods [default=linear]',
argstr='-%s')
gridset = File(desc = "copy grid of specified dataset",
argstr = "-gridset %s",
exists = True)
zpad = traits.Int(desc="pad input dataset with N planes of zero on all sides.",
argstr="-zpad %s")
suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value
class ThreedWarpOutputSpec(AFNITraitedSpec):
out_file = File(desc='spatially transformed input image', exists=True)
class ThreedWarp(AFNICommand):
""" Use 3dWarp for spatially transforming a dataset
For complete details, see the `3dTshift Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dWarp.html>`_
"""
_cmd = '3dWarp'
input_spec = ThreedWarpInputSpec
output_spec = ThreedWarpOutputSpec
def _gen_filename(self, name):
if name == 'out_file':
return self._list_outputs()[name]
return None
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.out_file
if not isdefined(outputs['out_file']):
if isdefined(self.inputs.suffix):
suffix = self.inputs.suffix
else:
suffix = "_warp"
outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix)
return outputs
class ThreedresampleInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dresample',
argstr = '-inset %s',
position = -1,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dresample',
argstr = '-prefix %s',
position = -2,
genfile = True)
orientation = traits.Str(desc = 'new orientation code',
argstr = '-orient %s')
suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value
class ThreedresampleOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'reoriented or resampled file',
exists = True)
class Threedresample(AFNICommand):
"""Resample or reorient an image using AFNI 3dresample command.
For complete details, see the `3dresample Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dresample.html>`_
"""
_cmd = '3dresample'
input_spec = ThreedresampleInputSpec
output_spec = ThreedresampleOutputSpec
def _gen_filename(self, name):
if name == 'out_file':
return self._list_outputs()[name]
return None
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.out_file
if not isdefined(outputs['out_file']):
if isdefined(self.inputs.suffix):
suffix = self.inputs.suffix
else:
suffix = [] # allow for resampling command later!
if self.inputs.orientation:
suffix.append("_RPI")
suffix = "".join(suffix)
outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix)
return outputs
class ThreedTstatInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dTstat',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dTstat',
argstr = '-prefix %s',
position = -2,
genfile = True)
options = traits.Str(desc = 'selected statistical output',
argstr = '%s')
class ThreedTstatOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'statistical file',
exists = True)
class ThreedTstat(AFNICommand):
"""Compute voxel-wise statistics using AFNI 3dTstat command.
For complete details, see the `3dTstat Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTstat.html>`_
"""
_cmd = '3dTstat'
input_spec = ThreedTstatInputSpec
output_spec = ThreedTstatOutputSpec
def _gen_filename(self, name):
"""Generate output file name
"""
if name == 'out_file':
_, fname, ext = split_filename(self.inputs.in_file)
return os.path.join(os.getcwd(), ''.join((fname, '_3dT', ext)))
def _list_outputs(self):
outputs = self.output_spec().get()
# outputs['out_file'] = os.path.abspath(self.inputs.out_file)
if not isdefined(self.inputs.out_file):
outputs['out_file'] = self._gen_filename('out_file')
else:
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
return outputs
class ThreedDetrendInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dDetrend',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dTstat',
argstr = '-prefix %s',
position = -2,
genfile = True)
options = traits.Str(desc = 'selected statistical output',
argstr = '%s')
class ThreedDetrendOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'statistical file',
exists = True)
class ThreedDetrend(AFNICommand):
"""Compute voxel-wise statistics using AFNI 3dTstat command.
For complete details, see the `3dTstat Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTstat.html>`_
"""
_cmd = '3dDetrend'
input_spec = ThreedDetrendInputSpec
output_spec = ThreedDetrendOutputSpec
def _gen_filename(self, name):
"""Generate output file name
"""
if name == 'out_file':
_, fname, ext = split_filename(self.inputs.in_file)
return os.path.join(os.getcwd(), ''.join((fname, '_3dD',ext)))
def _list_outputs(self):
outputs = self.output_spec().get()
# outputs['out_file'] = os.path.abspath(self.inputs.out_file)
if not isdefined(self.inputs.out_file):
outputs['out_file'] = self._gen_filename('out_file')
else:
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
return outputs
class ThreedDespikeInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dDespike',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dDespike',
argstr = '-prefix %s',
position = -2,
genfile = True)
options = traits.Str(desc = 'additional args',
argstr = '%s')
class ThreedDespikeOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'despiked img',
exists = True)
class ThreedDespike(AFNICommand):
"""Compute voxel-wise statistics using AFNI 3dTstat command.
For complete details, see the `3dDespike Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dDespike.html>`_
"""
_cmd = '3dDespike'
input_spec = ThreedDespikeInputSpec
output_spec = ThreedDespikeOutputSpec
def _gen_filename(self, name):
"""Generate output file name
"""
if name == 'out_file':
_, fname, ext = split_filename(self.inputs.in_file)
return os.path.join(os.getcwd(), ''.join((fname, '_3dDe', ext)))
def _list_outputs(self):
outputs = self.output_spec().get()
# outputs['out_file'] = os.path.abspath(self.inputs.out_file)
if not isdefined(self.inputs.out_file):
outputs['out_file'] = self._gen_filename('out_file')
else:
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
return outputs
class ThreedAutomaskInputSpec(AFNITraitedSpec):
in_file = File(desc='input file to 3dAutomask',
argstr='%s',
position=-1,
mandatory=True,
exists=True)
out_file = File(desc='output file from 3dAutomask (a brain mask)',
argstr='-prefix %s',
position=-2,
genfile=True)
apply_mask = File(desc="output file from 3dAutomask (masked version of input dataset)",
argstr='-apply_prefix %s')
clfrac = traits.Float(desc='sets the clip level fraction (must be 0.1-0.9). ' +
'A small value will tend to make the mask larger [default=0.5].',
argstr="-dilate %s")
dilate = traits.Int(desc='dilate the mask outwards',
argstr="-dilate %s")
erode = traits.Int(desc='erode the mask inwards',
argstr="-erode %s")
genbrickhead = traits.Bool(desc='gen head brick', argstr="")
options = traits.Str(desc='automask settings',
argstr='%s')
suffix = traits.Str(desc="out_file suffix") # todo: give it a default-value
class ThreedAutomaskOutputSpec(AFNITraitedSpec):
out_file = File(desc='mask file',
exists=True)
brain_file = File(desc='brain file (skull stripped)',
exists=True)
brik_file = File(desc='brick file', exists=True)
head_file = File (desc='head file', exists=True)
class ThreedAutomask(AFNICommand):
"""Create a brain-only mask of the image using AFNI 3dAutomask command.
For complete details, see the `3dAutomask Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dAutomask.html>`_
"""
_cmd = '3dAutomask'
input_spec = ThreedAutomaskInputSpec
output_spec = ThreedAutomaskOutputSpec
def _gen_filename(self, name):
if name == 'out_file':
return self._list_outputs()[name]
if name == 'head_file':
_, fname, ext = split_filename(self.inputs.in_file)
fname = os.path.basename(fname)
return (str(self.inputs.out_file)+ '+orig'+ '.HEAD')
if name == 'brik_file':
_, fname, ext = split_filename(self.inputs.in_file)
fname = os.path.basename(fname)
return (str(self.inputs.out_file)+ '+orig'+ '.BRIK')
return None
def _list_outputs(self):
import sys
outputs = self.output_spec().get()
outputs['brain_file'] = self.inputs.apply_mask
#outputs['out_file'] = self.inputs.out_file
suffix = None
if not isdefined(self.inputs.out_file):
if isdefined(self.inputs.suffix):
suffix = self.inputs.suffix
else:
suffix = "_automask"
outputs['out_file'] = self._gen_fname(self.inputs.in_file, suffix=suffix)
elif isdefined(self.inputs.out_file) and self.inputs.genbrickhead:
outputs['brik_file']= os.path.abspath(self._gen_filename('brik_file'))
outputs['head_file']= os.path.abspath(self._gen_filename('head_file'))
else:
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
return outputs
class ThreedvolregInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dvolreg',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dvolreg',
argstr = '-prefix %s',
position = -2,
genfile = True)
basefile = File(desc = 'base file for registration',
argstr = '-base %s',
position = -6)
zpad = File(desc = 'Zeropad around the edges by \'n\' voxels during rotations',
argstr = '-zpad %s',
position = -5)
md1d_file = File(desc = 'max displacement output file',
argstr = '-maxdisp1D %s',
position = -4,
genfile=True)
oned_file = File(desc = '1D movement parameters output file',
argstr = '-1Dfile %s',
position = -3,
genfile = True)
verbose = traits.Bool(desc = 'more detailed description of the process',
argstr = '-verbose')
timeshift = traits.Bool(desc = 'time shift to mean slice time offset',
argstr = '-tshift 0')
copyorigin = traits.Bool(desc = 'copy base file origin coords to output',
argstr = '-twodup')
other = traits.Str(desc = 'other options',
argstr = '%s')
class ThreedvolregOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'registered file',
exists = True)
md1d_file = File(desc = 'max displacement info file')
oned_file = File(desc = 'movement parameters info file')
class Threedvolreg(AFNICommand):
"""Register input volumes to a base volume using AFNI 3dvolreg command.
For complete details, see the `3dvolreg Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dvolreg.html>`_
"""
_cmd = '3dvolreg'
input_spec = ThreedvolregInputSpec
output_spec = ThreedvolregOutputSpec
def _gen_filename(self, name):
"""Generate output file name
"""
if name == 'out_file':
_, fname, ext = split_filename(self.inputs.in_file)
return ('./' + fname+ '_3dv'+ext)
if name == 'oned_file':
_, fname, ext = split_filename(self.inputs.in_file)
return ('./' + fname+ '_3dv1D'+'.1D')
if name == 'md1d_file':
_, fname, ext = split_filename(self.inputs.in_file)
return ('./' + fname+ '_3dvmd1D'+'.1D')
def _list_outputs(self):
outputs = self.output_spec().get()
if not isdefined(self.inputs.out_file):
outputs['out_file'] = os.path.abspath(self._gen_filename('out_file'))
else:
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
if not isdefined(self.inputs.oned_file):
outputs['oned_file'] = os.path.abspath(self._gen_filename('oned_file'))
else:
outputs['oned_file'] = os.path.abspath(self.inputs.oned_file)
if not isdefined(self.inputs.md1d_file):
outputs['md1d_file'] = os.path.abspath(self._gen_filename('md1d_file'))
else:
outputs['md1d_file'] = os.path.abspath(self.inputs.oned_file)
return outputs
class ThreedmergeInputSpec(AFNITraitedSpec):
infile = File(desc = 'input file to 3dvolreg',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
outfile = File(desc = 'output file from 3dvolreg',
argstr = '-prefix %s',
position = -2,
mandatory = True)
doall = traits.Bool(desc = 'apply options to all sub-bricks in dataset',
argstr = '-doall')
blurfwhm = traits.Int(desc = 'FWHM blur value (mm)',
argstr = '-1blur_fwhm %d',
units = 'mm')
other = traits.Str(desc = 'other options',
argstr = '%s')
class ThreedmergeOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'smoothed file',
exists = True)
class Threedmerge(AFNICommand):
"""Merge or edit volumes using AFNI 3dmerge command.
For complete details, see the `3dmerge Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dmerge.html>`_
"""
_cmd = '3dmerge'
input_spec = ThreedmergeInputSpec
output_spec = ThreedmergeOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.outfile
return outputs
class ThreedcopyInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dcopy',
argstr = '%s',
position = -2,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dcopy',
argstr = '%s',
position = -1,
genfile = True)
class ThreedcopyOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'copied file')
class Threedcopy(AFNICommandGenFile):
"""Copies an image of one type to an image of the same or different type
using 3dcopy command."""
_cmd = '3dcopy'
input_spec = ThreedcopyInputSpec
output_spec = ThreedcopyOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self._gen_outfilename()
return outputs
def _gen_outfilename(self):
out_file = self.inputs.out_file
if not isdefined(out_file) and isdefined(self.inputs.in_file):
out_file = self._gen_fname(self.inputs.in_file, suffix="_copy")
return out_file
class ThreedFourierInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dFourier',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
out_file = File(desc = 'output file from 3dFourier',
argstr = '-prefix %s',
position = -2,
genfile = True)
lowpass = traits.Float(desc = 'lowpass',
argstr = '-lowpass %f',
position = 0,
mandatory = True)
highpass = traits.Float(desc = 'highpass',
argstr = '-highpass %f',
position = 1,
mandatory = True)
other = traits.Str(desc = 'other options',
argstr = '%s')
class ThreedFourierOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'band-pass filtered file',
exists = True)
class ThreedFourier(AFNICommand):
"""Merge or edit volumes using AFNI 3dmerge command.
For complete details, see the `3dmerge Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dmerge.html>`_
"""
_cmd = '3dFourier'
input_spec = ThreedFourierInputSpec
output_spec = ThreedFourierOutputSpec
def _gen_filename(self, name):
"""Generate output file name
"""
if name == 'out_file':
_, fname, ext = split_filename(self.inputs.in_file)
return os.path.join(os.getcwd(), ''.join((fname, '_3dF',ext)))
def _list_outputs(self):
outputs = self.output_spec().get()
#outputs['out_file'] = os.path.abspath(self.inputs.out_file)
if not isdefined(self.inputs.out_file):
outputs['out_file'] = self._gen_filename('out_file')
else:
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
return outputs
class ThreedZcutupInputSpec(AFNITraitedSpec):
infile = File(desc = 'input file to 3dZcutup',
argstr = '%s',
position = -1,
mandatory = True,
exists = True)
outfile = File(desc = 'output file from 3dZcutup',
argstr = '-prefix %s',
position = -2,
mandatory = True)
keep = traits.Str(desc = 'slice range to keep in output',
argstr = '-keep %s')
other = traits.Str(desc = 'other options',
argstr = '%s')
class ThreedZcutupOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'cut file',
exists = True)
class ThreedZcutup(AFNICommand):
"""Cut z-slices from a volume using AFNI 3dZcutup command.
For complete details, see the `3dZcutup Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dZcutup.html>`_
"""
_cmd = '3dZcutup'
input_spec = ThreedZcutupInputSpec
output_spec = ThreedZcutupOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.outfile
return outputs
class ThreedAllineateInputSpec(AFNITraitedSpec):
infile = File(desc = 'input file to 3dAllineate',
argstr = '-source %s',
position = -1,
mandatory = True,
exists = True)
outfile = File(desc = 'output file from 3dAllineate',
argstr = '-prefix %s',
position = -2,
mandatory = True)
matrix = File(desc = 'matrix to align input file',
argstr = '-1dmatrix_apply %s',
position = -3)
class ThreedAllineateOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'cut file',
exists = True)
class ThreedAllineate(AFNICommand):
"""
For complete details, see the `3dAllineate Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dAllineate.html>`_
"""
_cmd = '3dAllineate'
input_spec = ThreedAllineateInputSpec
output_spec = ThreedAllineateOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self.inputs.outfile
return outputs
class ThreedMaskaveInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dmaskave',
argstr = '%s',
position = -2,
mandatory = True,
exists = True)
out_file = File(desc = 'output to the file',
argstr = '> %s',
position = -1,
genfile = True)
mask = File(desc = 'matrix to align input file',
argstr = '-mask %s',
position = 1)
quiet = traits.Bool(desc = 'matrix to align input file',
argstr = '-quiet',
position = 2)
class ThreedMaskaveOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'outfile',
exists = True)
class ThreedMaskave(AFNICommand):
"""
For complete details, see the `3dmaskave Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dmaskave.html>`_
"""
_cmd = '3dmaskave'
input_spec = ThreedMaskaveInputSpec
output_spec = ThreedMaskaveOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
if not isdefined(self.inputs.out_file):
out_file = self._gen_filename('out_file')
else:
out_file = os.path.abspath(self.inputs.out_file)
outputs['out_file'] = out_file
return outputs
def _gen_filename(self, name):
"""Generate output file name
"""
if name == 'out_file':
_, fname, ext = split_filename(self.inputs.in_file)
return os.path.join(os.getcwd(), ''.join((fname, '_3dm','.1D')))
class ThreedSkullStripInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dSkullStrip',
argstr = '-input %s',
position = 1,
mandatory = True,
exists = True)
out_file = File(desc = 'output to the file',
argstr = '%s',
position = -1,
genfile = True)
options = traits.Str(desc = 'options', argstr = '%s', position = 2)
class ThreedSkullStripOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'outfile',
exists = True)
class ThreedSkullStrip(AFNICommandGenFile):
_cmd = '3dSkullStrip'
input_spec = ThreedSkullStripInputSpec
output_spec = ThreedSkullStripOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
outputs['out_file'] = self._gen_outfilename()
return outputs
def _gen_outfilename(self):
out_file = self.inputs.out_file
if not isdefined(out_file) and isdefined(self.inputs.in_file):
out_file = self._gen_fname(self.inputs.in_file, suffix="_surf")
#out_file = self._gen_fname(self.inputs.in_file, suffix="_surf")
return out_file
class ThreedTcatInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dTcat',
argstr = ' %s',
position = -2,
mandatory = True,
exists = True)
out_file = File(desc = 'output to the file',
argstr = '-prefix %s',
position = -2,
genfile = True)
rlt = traits.Str(desc = 'options', argstr = '-rlt%s', position = 1)
class ThreedTcatOutputSpec(AFNITraitedSpec):
out_file = File(desc = 'outfile',
exists = True)
class ThreedTcat(AFNICommand):
"""
For complete details, see the `3dTcat Documentation.
<http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTcat.html>`_
"""
_cmd = '3dTcat'
input_spec = ThreedTcatInputSpec
output_spec = ThreedTcatOutputSpec
def _list_outputs(self):
outputs = self.output_spec().get()
if not isdefined(self.inputs.out_file):
out_file = self._gen_filename('out_file')
else:
out_file = os.path.abspath(self.inputs.out_file)
outputs['out_file'] = out_file
return outputs
def _gen_filename(self, name):
"""Generate output file name
"""
if name == 'out_file':
_, fname, ext = split_filename(self.inputs.in_file)
return os.path.join(os.getcwd(), ''.join((fname, '_3dT',ext)))
class ThreedfimInputSpec(AFNITraitedSpec):
in_file = File(desc = 'input file to 3dfim+',
argstr = ' -input %s',
position = 1,
mandatory = True,
exists = True)
ideal_file = File(desc = 'output to the file',
argstr = '-ideal_file %s',
position = 2,
mandatory = True)
fim_thr = traits.Float(desc = 'fim internal mask threshold value', argstr = '-fim_thr %f', position = 3)
out = traits.Str(desc = 'Flag to output the specified parameter', argstr = '-out %s', position = 4)
out_file = File(desc = 'output file from 3dfim+', argstr = '-bucket %s',
position = -1, genfile=True)