-
Notifications
You must be signed in to change notification settings - Fork 521
/
brainsuite.py
1816 lines (1591 loc) · 73.7 KB
/
brainsuite.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
# -*- coding: utf-8 -*-
"""This script provides interfaces for BrainSuite command line tools.
Please see brainsuite.org for more information.
Author: Jason Wong
"""
import os
import re as regex
from ..base import (
TraitedSpec,
CommandLineInputSpec,
CommandLine,
File,
traits,
isdefined,
)
class BseInputSpec(CommandLineInputSpec):
inputMRIFile = File(mandatory=True, argstr="-i %s", desc="input MRI volume")
outputMRIVolume = File(
desc="output brain-masked MRI volume. If unspecified, output file name will be auto generated.",
argstr="-o %s",
hash_files=False,
genfile=True,
)
outputMaskFile = File(
desc="save smooth brain mask. If unspecified, output file name will be auto generated.",
argstr="--mask %s",
hash_files=False,
genfile=True,
)
diffusionConstant = traits.Float(
25, usedefault=True, desc="diffusion constant", argstr="-d %f"
)
diffusionIterations = traits.Int(
3, usedefault=True, desc="diffusion iterations", argstr="-n %d"
)
edgeDetectionConstant = traits.Float(
0.64, usedefault=True, desc="edge detection constant", argstr="-s %f"
)
radius = traits.Float(
1, usedefault=True, desc="radius of erosion/dilation filter", argstr="-r %f"
)
dilateFinalMask = traits.Bool(
True, usedefault=True, desc="dilate final mask", argstr="-p"
)
trim = traits.Bool(True, usedefault=True, desc="trim brainstem", argstr="--trim")
outputDiffusionFilter = File(
desc="diffusion filter output", argstr="--adf %s", hash_files=False
)
outputEdgeMap = File(desc="edge map output", argstr="--edge %s", hash_files=False)
outputDetailedBrainMask = File(
desc="save detailed brain mask", argstr="--hires %s", hash_files=False
)
outputCortexFile = File(desc="cortex file", argstr="--cortex %s", hash_files=False)
verbosityLevel = traits.Float(
1, usedefault=True, desc=" verbosity level (0=silent)", argstr="-v %f"
)
noRotate = traits.Bool(
desc="retain original orientation(default behavior will auto-rotate input NII files to LPI orientation)",
argstr="--norotate",
)
timer = traits.Bool(desc="show timing", argstr="--timer")
class BseOutputSpec(TraitedSpec):
outputMRIVolume = File(desc="path/name of brain-masked MRI volume")
outputMaskFile = File(desc="path/name of smooth brain mask")
outputDiffusionFilter = File(desc="path/name of diffusion filter output")
outputEdgeMap = File(desc="path/name of edge map output")
outputDetailedBrainMask = File(desc="path/name of detailed brain mask")
outputCortexFile = File(desc="path/name of cortex file")
class Bse(CommandLine):
"""
brain surface extractor (BSE)
This program performs automated skull and scalp removal on T1-weighted MRI volumes.
http://brainsuite.org/processing/surfaceextraction/bse/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> bse = brainsuite.Bse()
>>> bse.inputs.inputMRIFile = example_data('structural.nii')
>>> results = bse.run() #doctest: +SKIP
"""
input_spec = BseInputSpec
output_spec = BseOutputSpec
_cmd = "bse"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
fileToSuffixMap = {
"outputMRIVolume": ".bse.nii.gz",
"outputMaskFile": ".mask.nii.gz",
}
if name in fileToSuffixMap:
return getFileName(self.inputs.inputMRIFile, fileToSuffixMap[name])
return None
def _list_outputs(self):
return l_outputs(self)
class BfcInputSpec(CommandLineInputSpec):
inputMRIFile = File(
mandatory=True, desc="input skull-stripped MRI volume", argstr="-i %s"
)
inputMaskFile = File(desc="mask file", argstr="-m %s", hash_files=False)
outputMRIVolume = File(
desc="output bias-corrected MRI volume. If unspecified, output file name will be auto generated.",
argstr="-o %s",
hash_files=False,
genfile=True,
)
outputBiasField = File(
desc="save bias field estimate", argstr="--bias %s", hash_files=False
)
outputMaskedBiasField = File(
desc="save bias field estimate (masked)",
argstr="--maskedbias %s",
hash_files=False,
)
histogramRadius = traits.Int(desc="histogram radius (voxels)", argstr="-r %d")
biasEstimateSpacing = traits.Int(
desc="bias sample spacing (voxels)", argstr="-s %d"
)
controlPointSpacing = traits.Int(
desc="control point spacing (voxels)", argstr="-c %d"
)
splineLambda = traits.Float(
desc="spline stiffness weighting parameter", argstr="-w %f"
)
histogramType = traits.Enum(
"ellipse",
"block",
desc="""\
Options for type of histogram:
* ``ellipse``: use ellipsoid for ROI histogram
* ``block``:use block for ROI histogram
""",
argstr="%s",
)
iterativeMode = traits.Bool(
desc="iterative mode (overrides -r, -s, -c, -w settings)", argstr="--iterate"
)
correctionScheduleFile = File(desc="list of parameters ", argstr="--schedule %s")
biasFieldEstimatesOutputPrefix = traits.Str(
desc="save iterative bias field estimates as <prefix>.n.field.nii.gz",
argstr="--biasprefix %s",
)
correctedImagesOutputPrefix = traits.Str(
desc="save iterative corrected images as <prefix>.n.bfc.nii.gz",
argstr="--prefix %s",
)
correctWholeVolume = traits.Bool(
desc="apply correction field to entire volume", argstr="--extrapolate"
)
minBias = traits.Float(
0.5, usedefault=True, desc="minimum allowed bias value", argstr="-L %f"
)
maxBias = traits.Float(
1.5, usedefault=True, desc="maximum allowed bias value", argstr="-U %f"
)
biasRange = traits.Enum(
"low",
"medium",
"high",
desc="""\
Preset options for bias_model
* low: small bias model [0.95,1.05]
* medium: medium bias model [0.90,1.10]
* high: high bias model [0.80,1.20]
""",
argstr="%s",
)
intermediate_file_type = traits.Enum(
"analyze",
"nifti",
"gzippedAnalyze",
"gzippedNifti",
desc="Options for the format in which intermediate files are generated",
argstr="%s",
)
convergenceThreshold = traits.Float(desc="convergence threshold", argstr="--eps %f")
biasEstimateConvergenceThreshold = traits.Float(
desc="bias estimate convergence threshold (values > 0.1 disable)",
argstr="--beps %f",
)
verbosityLevel = traits.Int(desc="verbosity level (0=silent)", argstr="-v %d")
timer = traits.Bool(desc="display timing information", argstr="--timer")
class BfcOutputSpec(TraitedSpec):
outputMRIVolume = File(desc="path/name of output file")
outputBiasField = File(desc="path/name of bias field output file")
outputMaskedBiasField = File(desc="path/name of masked bias field output")
correctionScheduleFile = File(desc="path/name of schedule file")
class Bfc(CommandLine):
"""
bias field corrector (BFC)
This program corrects gain variation in T1-weighted MRI.
http://brainsuite.org/processing/surfaceextraction/bfc/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> bfc = brainsuite.Bfc()
>>> bfc.inputs.inputMRIFile = example_data('structural.nii')
>>> bfc.inputs.inputMaskFile = example_data('mask.nii')
>>> results = bfc.run() #doctest: +SKIP
"""
input_spec = BfcInputSpec
output_spec = BfcOutputSpec
_cmd = "bfc"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
fileToSuffixMap = {"outputMRIVolume": ".bfc.nii.gz"}
if name in fileToSuffixMap:
return getFileName(self.inputs.inputMRIFile, fileToSuffixMap[name])
return None
def _format_arg(self, name, spec, value):
if name == "histogramType":
return spec.argstr % {"ellipse": "--ellipse", "block": "--block"}[value]
if name == "biasRange":
return (
spec.argstr
% {"low": "--low", "medium": "--medium", "high": "--high"}[value]
)
if name == "intermediate_file_type":
return (
spec.argstr
% {
"analyze": "--analyze",
"nifti": "--nifti",
"gzippedAnalyze": "--analyzegz",
"gzippedNifti": "--niftigz",
}[value]
)
return super(Bfc, self)._format_arg(name, spec, value)
def _list_outputs(self):
return l_outputs(self)
class PvcInputSpec(CommandLineInputSpec):
inputMRIFile = File(mandatory=True, desc="MRI file", argstr="-i %s")
inputMaskFile = File(desc="brain mask file", argstr="-m %s")
outputLabelFile = File(
desc="output label file. If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
outputTissueFractionFile = File(
desc="output tissue fraction file", argstr="-f %s", genfile=True
)
spatialPrior = traits.Float(desc="spatial prior strength", argstr="-l %f")
verbosity = traits.Int(desc="verbosity level (0 = silent)", argstr="-v %d")
threeClassFlag = traits.Bool(
desc="use a three-class (CSF=0,GM=1,WM=2) labeling", argstr="-3"
)
timer = traits.Bool(desc="time processing", argstr="--timer")
class PvcOutputSpec(TraitedSpec):
outputLabelFile = File(desc="path/name of label file")
outputTissueFractionFile = File(desc="path/name of tissue fraction file")
class Pvc(CommandLine):
"""
partial volume classifier (PVC) tool.
This program performs voxel-wise tissue classification T1-weighted MRI.
Image should be skull-stripped and bias-corrected before tissue classification.
http://brainsuite.org/processing/surfaceextraction/pvc/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> pvc = brainsuite.Pvc()
>>> pvc.inputs.inputMRIFile = example_data('structural.nii')
>>> pvc.inputs.inputMaskFile = example_data('mask.nii')
>>> results = pvc.run() #doctest: +SKIP
"""
input_spec = PvcInputSpec
output_spec = PvcOutputSpec
_cmd = "pvc"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
fileToSuffixMap = {
"outputLabelFile": ".pvc.label.nii.gz",
"outputTissueFractionFile": ".pvc.frac.nii.gz",
}
if name in fileToSuffixMap:
return getFileName(self.inputs.inputMRIFile, fileToSuffixMap[name])
return None
def _list_outputs(self):
return l_outputs(self)
class CerebroInputSpec(CommandLineInputSpec):
inputMRIFile = File(mandatory=True, desc="input 3D MRI volume", argstr="-i %s")
inputAtlasMRIFile = File(
mandatory=True, desc="atlas MRI volume", argstr="--atlas %s"
)
inputAtlasLabelFile = File(
mandatory=True, desc="atlas labeling", argstr="--atlaslabels %s"
)
inputBrainMaskFile = File(desc="brain mask file", argstr="-m %s")
outputCerebrumMaskFile = File(
desc="output cerebrum mask volume. If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
outputLabelVolumeFile = File(
desc="output labeled hemisphere/cerebrum volume. If unspecified, output file name will be auto generated.",
argstr="-l %s",
genfile=True,
)
costFunction = traits.Int(2, usedefault=True, desc="0,1,2", argstr="-c %d")
useCentroids = traits.Bool(
desc="use centroids of data to initialize position", argstr="--centroids"
)
outputAffineTransformFile = File(
desc="save affine transform to file.", argstr="--air %s", genfile=True
)
outputWarpTransformFile = File(
desc="save warp transform to file.", argstr="--warp %s", genfile=True
)
verbosity = traits.Int(desc="verbosity level (0=silent)", argstr="-v %d")
linearConvergence = traits.Float(desc="linear convergence", argstr="--linconv %f")
warpLabel = traits.Int(desc="warp order (2,3,4,5,6,7,8)", argstr="--warplevel %d")
warpConvergence = traits.Float(desc="warp convergence", argstr="--warpconv %f")
keepTempFiles = traits.Bool(desc="don't remove temporary files", argstr="--keep")
tempDirectory = traits.Str(
desc="specify directory to use for temporary files", argstr="--tempdir %s"
)
tempDirectoryBase = traits.Str(
desc="create a temporary directory within this directory",
argstr="--tempdirbase %s",
)
class CerebroOutputSpec(TraitedSpec):
outputCerebrumMaskFile = File(desc="path/name of cerebrum mask file")
outputLabelVolumeFile = File(desc="path/name of label mask file")
outputAffineTransformFile = File(desc="path/name of affine transform file")
outputWarpTransformFile = File(desc="path/name of warp transform file")
class Cerebro(CommandLine):
"""
Cerebrum/cerebellum labeling tool
This program performs automated labeling of cerebellum and cerebrum in T1 MRI.
Input MRI should be skull-stripped or a brain-only mask should be provided.
http://brainsuite.org/processing/surfaceextraction/cerebrum/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> cerebro = brainsuite.Cerebro()
>>> cerebro.inputs.inputMRIFile = example_data('structural.nii')
>>> cerebro.inputs.inputAtlasMRIFile = 'atlasMRIVolume.img'
>>> cerebro.inputs.inputAtlasLabelFile = 'atlasLabels.img'
>>> cerebro.inputs.inputBrainMaskFile = example_data('mask.nii')
>>> results = cerebro.run() #doctest: +SKIP
"""
input_spec = CerebroInputSpec
output_spec = CerebroOutputSpec
_cmd = "cerebro"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
fileToSuffixMap = {
"outputCerebrumMaskFile": ".cerebrum.mask.nii.gz",
"outputLabelVolumeFile": ".hemi.label.nii.gz",
"outputWarpTransformFile": ".warp",
"outputAffineTransformFile": ".air",
}
if name in fileToSuffixMap:
return getFileName(self.inputs.inputMRIFile, fileToSuffixMap[name])
return None
def _list_outputs(self):
return l_outputs(self)
class CortexInputSpec(CommandLineInputSpec):
inputHemisphereLabelFile = File(
mandatory=True, desc="hemisphere / lobe label volume", argstr="-h %s"
)
outputCerebrumMask = File(
desc="output structure mask. If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
inputTissueFractionFile = File(
mandatory=True, desc="tissue fraction file (32-bit float)", argstr="-f %s"
)
tissueFractionThreshold = traits.Float(
50.0,
usedefault=True,
desc="tissue fraction threshold (percentage)",
argstr="-p %f",
)
computeWGBoundary = traits.Bool(
True, usedefault=True, desc="compute WM/GM boundary", argstr="-w"
)
computeGCBoundary = traits.Bool(desc="compute GM/CSF boundary", argstr="-g")
includeAllSubcorticalAreas = traits.Bool(
True,
usedefault=True,
desc="include all subcortical areas in WM mask",
argstr="-a",
)
verbosity = traits.Int(desc="verbosity level", argstr="-v %d")
timer = traits.Bool(desc="timing function", argstr="--timer")
class CortexOutputSpec(TraitedSpec):
outputCerebrumMask = File(desc="path/name of cerebrum mask")
class Cortex(CommandLine):
"""
cortex extractor
This program produces a cortical mask using tissue fraction estimates
and a co-registered cerebellum/hemisphere mask.
http://brainsuite.org/processing/surfaceextraction/cortex/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> cortex = brainsuite.Cortex()
>>> cortex.inputs.inputHemisphereLabelFile = example_data('mask.nii')
>>> cortex.inputs.inputTissueFractionFile = example_data('tissues.nii.gz')
>>> results = cortex.run() #doctest: +SKIP
"""
input_spec = CortexInputSpec
output_spec = CortexOutputSpec
_cmd = "cortex"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
if name == "outputCerebrumMask":
return getFileName(
self.inputs.inputHemisphereLabelFile, ".init.cortex.mask.nii.gz"
)
return None
def _list_outputs(self):
return l_outputs(self)
class ScrubmaskInputSpec(CommandLineInputSpec):
inputMaskFile = File(
mandatory=True, desc="input structure mask file", argstr="-i %s"
)
outputMaskFile = File(
desc="output structure mask file. If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
backgroundFillThreshold = traits.Int(
2, usedefault=True, desc="background fill threshold", argstr="-b %d"
)
foregroundTrimThreshold = traits.Int(
0, usedefault=True, desc="foreground trim threshold", argstr="-f %d"
)
numberIterations = traits.Int(desc="number of iterations", argstr="-n %d")
verbosity = traits.Int(desc="verbosity (0=silent)", argstr="-v %d")
timer = traits.Bool(desc="timing function", argstr="--timer")
class ScrubmaskOutputSpec(TraitedSpec):
outputMaskFile = File(desc="path/name of mask file")
class Scrubmask(CommandLine):
"""
ScrubMask tool
scrubmask filters binary masks to trim loosely connected voxels that may
result from segmentation errors and produce bumps on tessellated surfaces.
http://brainsuite.org/processing/surfaceextraction/scrubmask/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> scrubmask = brainsuite.Scrubmask()
>>> scrubmask.inputs.inputMaskFile = example_data('mask.nii')
>>> results = scrubmask.run() #doctest: +SKIP
"""
input_spec = ScrubmaskInputSpec
output_spec = ScrubmaskOutputSpec
_cmd = "scrubmask"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
if name == "outputMaskFile":
return getFileName(
self.inputs.inputMaskFile, ".cortex.scrubbed.mask.nii.gz"
)
return None
def _list_outputs(self):
return l_outputs(self)
class TcaInputSpec(CommandLineInputSpec):
inputMaskFile = File(mandatory=True, desc="input mask volume", argstr="-i %s")
outputMaskFile = File(
desc="output mask volume. If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
minCorrectionSize = traits.Int(
2500, usedefault=True, desc="maximum correction size", argstr="-m %d"
)
maxCorrectionSize = traits.Int(desc="minimum correction size", argstr="-n %d")
foregroundDelta = traits.Int(
20, usedefault=True, desc="foreground delta", argstr="--delta %d"
)
verbosity = traits.Int(desc="verbosity (0 = quiet)", argstr="-v %d")
timer = traits.Bool(desc="timing function", argstr="--timer")
class TcaOutputSpec(TraitedSpec):
outputMaskFile = File(desc="path/name of mask file")
class Tca(CommandLine):
"""
topological correction algorithm (TCA)
This program removes topological handles from a binary object.
http://brainsuite.org/processing/surfaceextraction/tca/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> tca = brainsuite.Tca()
>>> tca.inputs.inputMaskFile = example_data('mask.nii')
>>> results = tca.run() #doctest: +SKIP
"""
input_spec = TcaInputSpec
output_spec = TcaOutputSpec
_cmd = "tca"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
if name == "outputMaskFile":
return getFileName(self.inputs.inputMaskFile, ".cortex.tca.mask.nii.gz")
return None
def _list_outputs(self):
return l_outputs(self)
class DewispInputSpec(CommandLineInputSpec):
inputMaskFile = File(mandatory=True, desc="input file", argstr="-i %s")
outputMaskFile = File(
desc="output file. If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
verbosity = traits.Int(desc="verbosity", argstr="-v %d")
sizeThreshold = traits.Int(desc="size threshold", argstr="-t %d")
maximumIterations = traits.Int(desc="maximum number of iterations", argstr="-n %d")
timer = traits.Bool(desc="time processing", argstr="--timer")
class DewispOutputSpec(TraitedSpec):
outputMaskFile = File(desc="path/name of mask file")
class Dewisp(CommandLine):
"""
dewisp
removes wispy tendril structures from cortex model binary masks.
It does so based on graph theoretic analysis of connected components,
similar to TCA. Each branch of the structure graph is analyzed to determine
pinch points that indicate a likely error in segmentation that attaches noise
to the image. The pinch threshold determines how many voxels the cross-section
can be before it is considered part of the image.
http://brainsuite.org/processing/surfaceextraction/dewisp/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> dewisp = brainsuite.Dewisp()
>>> dewisp.inputs.inputMaskFile = example_data('mask.nii')
>>> results = dewisp.run() #doctest: +SKIP
"""
input_spec = DewispInputSpec
output_spec = DewispOutputSpec
_cmd = "dewisp"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
if name == "outputMaskFile":
return getFileName(self.inputs.inputMaskFile, ".cortex.dewisp.mask.nii.gz")
return None
def _list_outputs(self):
return l_outputs(self)
class DfsInputSpec(CommandLineInputSpec):
inputVolumeFile = File(mandatory=True, desc="input 3D volume", argstr="-i %s")
outputSurfaceFile = File(
desc="output surface mesh file. If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
inputShadingVolume = File(
desc="shade surface model with data from image volume", argstr="-c %s"
)
smoothingIterations = traits.Int(
10, usedefault=True, desc="number of smoothing iterations", argstr="-n %d"
)
smoothingConstant = traits.Float(
0.5, usedefault=True, desc="smoothing constant", argstr="-a %f"
)
curvatureWeighting = traits.Float(
5.0, usedefault=True, desc="curvature weighting", argstr="-w %f"
)
scalingPercentile = traits.Float(desc="scaling percentile", argstr="-f %f")
nonZeroTessellation = traits.Bool(
desc="tessellate non-zero voxels",
argstr="-nz",
xor=("nonZeroTessellation", "specialTessellation"),
)
tessellationThreshold = traits.Float(
desc="To be used with specialTessellation. Set this value first, then set specialTessellation value.\nUsage: tessellate voxels greater_than, less_than, or equal_to <tessellationThreshold>",
argstr="%f",
)
specialTessellation = traits.Enum(
"greater_than",
"less_than",
"equal_to",
desc="To avoid throwing a UserWarning, set tessellationThreshold first. Then set this attribute.\nUsage: tessellate voxels greater_than, less_than, or equal_to <tessellationThreshold>",
argstr="%s",
xor=("nonZeroTessellation", "specialTessellation"),
requires=["tessellationThreshold"],
position=-1,
)
zeroPadFlag = traits.Bool(
desc="zero-pad volume (avoids clipping at edges)", argstr="-z"
)
noNormalsFlag = traits.Bool(
desc="do not compute vertex normals", argstr="--nonormals"
)
postSmoothFlag = traits.Bool(
desc="smooth vertices after coloring", argstr="--postsmooth"
)
verbosity = traits.Int(desc="verbosity (0 = quiet)", argstr="-v %d")
timer = traits.Bool(desc="timing function", argstr="--timer")
class DfsOutputSpec(TraitedSpec):
outputSurfaceFile = File(desc="path/name of surface file")
class Dfs(CommandLine):
"""
Surface Generator
Generates mesh surfaces using an isosurface algorithm.
http://brainsuite.org/processing/surfaceextraction/inner-cortical-surface/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> dfs = brainsuite.Dfs()
>>> dfs.inputs.inputVolumeFile = example_data('structural.nii')
>>> results = dfs.run() #doctest: +SKIP
"""
input_spec = DfsInputSpec
output_spec = DfsOutputSpec
_cmd = "dfs"
def _format_arg(self, name, spec, value):
if name == "tessellationThreshold":
return "" # blank argstr
if name == "specialTessellation":
threshold = self.inputs.tessellationThreshold
return (
spec.argstr
% {
"greater_than": "".join(("-gt %f" % threshold)),
"less_than": "".join(("-lt %f" % threshold)),
"equal_to": "".join(("-eq %f" % threshold)),
}[value]
)
return super(Dfs, self)._format_arg(name, spec, value)
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
if name == "outputSurfaceFile":
return getFileName(self.inputs.inputVolumeFile, ".inner.cortex.dfs")
return None
def _list_outputs(self):
return l_outputs(self)
class PialmeshInputSpec(CommandLineInputSpec):
inputSurfaceFile = File(mandatory=True, desc="input file", argstr="-i %s")
outputSurfaceFile = File(
desc="output file. If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
verbosity = traits.Int(desc="verbosity", argstr="-v %d")
inputTissueFractionFile = File(
mandatory=True, desc="floating point (32) tissue fraction image", argstr="-f %s"
)
numIterations = traits.Int(
100, usedefault=True, desc="number of iterations", argstr="-n %d"
)
searchRadius = traits.Float(
1, usedefault=True, desc="search radius", argstr="-r %f"
)
stepSize = traits.Float(0.4, usedefault=True, desc="step size", argstr="-s %f")
inputMaskFile = File(
mandatory=True, desc="restrict growth to mask file region", argstr="-m %s"
)
maxThickness = traits.Float(
20, usedefault=True, desc="maximum allowed tissue thickness", argstr="--max %f"
)
tissueThreshold = traits.Float(
1.05, usedefault=True, desc="tissue threshold", argstr="-t %f"
)
# output interval is not an output -- it specifies how frequently the
# output surfaces are generated
outputInterval = traits.Int(
10, usedefault=True, desc="output interval", argstr="--interval %d"
)
exportPrefix = traits.Str(
desc="prefix for exporting surfaces if interval is set", argstr="--prefix %s"
)
laplacianSmoothing = traits.Float(
0.025, usedefault=True, desc="apply Laplacian smoothing", argstr="--smooth %f"
)
timer = traits.Bool(desc="show timing", argstr="--timer")
recomputeNormals = traits.Bool(
desc="recompute normals at each iteration", argstr="--norm"
)
normalSmoother = traits.Float(
0.2, usedefault=True, desc="strength of normal smoother.", argstr="--nc %f"
)
tangentSmoother = traits.Float(
desc="strength of tangential smoother.", argstr="--tc %f"
)
class PialmeshOutputSpec(TraitedSpec):
outputSurfaceFile = File(desc="path/name of surface file")
class Pialmesh(CommandLine):
"""
pialmesh
computes a pial surface model using an inner WM/GM mesh and a tissue fraction map.
http://brainsuite.org/processing/surfaceextraction/pial/
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> pialmesh = brainsuite.Pialmesh()
>>> pialmesh.inputs.inputSurfaceFile = 'input_mesh.dfs'
>>> pialmesh.inputs.inputTissueFractionFile = 'frac_file.nii.gz'
>>> pialmesh.inputs.inputMaskFile = example_data('mask.nii')
>>> results = pialmesh.run() #doctest: +SKIP
"""
input_spec = PialmeshInputSpec
output_spec = PialmeshOutputSpec
_cmd = "pialmesh"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
if name == "outputSurfaceFile":
return getFileName(self.inputs.inputSurfaceFile, ".pial.cortex.dfs")
return None
def _list_outputs(self):
return l_outputs(self)
class HemisplitInputSpec(CommandLineInputSpec):
inputSurfaceFile = File(mandatory=True, desc="input surface", argstr="-i %s")
inputHemisphereLabelFile = File(
mandatory=True, desc="input hemisphere label volume", argstr="-l %s"
)
outputLeftHemisphere = File(
desc="output surface file, left hemisphere. If unspecified, output file name will be auto generated.",
argstr="--left %s",
genfile=True,
)
outputRightHemisphere = File(
desc="output surface file, right hemisphere. If unspecified, output file name will be auto generated.",
argstr="--right %s",
genfile=True,
)
pialSurfaceFile = File(
desc="pial surface file -- must have same geometry as input surface",
argstr="-p %s",
)
outputLeftPialHemisphere = File(
desc="output pial surface file, left hemisphere. If unspecified, output file name will be auto generated.",
argstr="-pl %s",
genfile=True,
)
outputRightPialHemisphere = File(
desc="output pial surface file, right hemisphere. If unspecified, output file name will be auto generated.",
argstr="-pr %s",
genfile=True,
)
verbosity = traits.Int(desc="verbosity (0 = silent)", argstr="-v %d")
timer = traits.Bool(desc="timing function", argstr="--timer")
class HemisplitOutputSpec(TraitedSpec):
outputLeftHemisphere = File(desc="path/name of left hemisphere")
outputRightHemisphere = File(desc="path/name of right hemisphere")
outputLeftPialHemisphere = File(desc="path/name of left pial hemisphere")
outputRightPialHemisphere = File(desc="path/name of right pial hemisphere")
class Hemisplit(CommandLine):
"""
Hemisphere splitter
Splits a surface object into two separate surfaces given an input label volume.
Each vertex is labeled left or right based on the labels being odd (left) or even (right).
The largest contour on the split surface is then found and used as the separation between left and right.
Examples
--------
>>> from nipype.interfaces import brainsuite
>>> from nipype.testing import example_data
>>> hemisplit = brainsuite.Hemisplit()
>>> hemisplit.inputs.inputSurfaceFile = 'input_surf.dfs'
>>> hemisplit.inputs.inputHemisphereLabelFile = 'label.nii'
>>> hemisplit.inputs.pialSurfaceFile = 'pial.dfs'
>>> results = hemisplit.run() #doctest: +SKIP
"""
input_spec = HemisplitInputSpec
output_spec = HemisplitOutputSpec
_cmd = "hemisplit"
def _gen_filename(self, name):
inputs = self.inputs.get()
if isdefined(inputs[name]):
return os.path.abspath(inputs[name])
fileToSuffixMap = {
"outputLeftHemisphere": ".left.inner.cortex.dfs",
"outputLeftPialHemisphere": ".left.pial.cortex.dfs",
"outputRightHemisphere": ".right.inner.cortex.dfs",
"outputRightPialHemisphere": ".right.pial.cortex.dfs",
}
if name in fileToSuffixMap:
return getFileName(self.inputs.inputSurfaceFile, fileToSuffixMap[name])
return None
def _list_outputs(self):
return l_outputs(self)
class SkullfinderInputSpec(CommandLineInputSpec):
inputMRIFile = File(mandatory=True, desc="input file", argstr="-i %s")
inputMaskFile = File(
mandatory=True,
desc="A brain mask file, 8-bit image (0=non-brain, 255=brain)",
argstr="-m %s",
)
outputLabelFile = File(
desc="output multi-colored label volume segmenting brain, scalp, inner skull & outer skull "
"If unspecified, output file name will be auto generated.",
argstr="-o %s",
genfile=True,
)
verbosity = traits.Int(desc="verbosity", argstr="-v %d")
lowerThreshold = traits.Int(desc="Lower threshold for segmentation", argstr="-l %d")
upperThreshold = traits.Int(desc="Upper threshold for segmentation", argstr="-u %d")
surfaceFilePrefix = traits.Str(
desc="if specified, generate surface files for brain, skull, and scalp",
argstr="-s %s",
)
bgLabelValue = traits.Int(
desc="background label value (0-255)", argstr="--bglabel %d"
)