|
33 | 33 | SimpleInterface,
|
34 | 34 | File,
|
35 | 35 | isdefined,
|
| 36 | + InputMultiObject, |
| 37 | + traits, |
36 | 38 | )
|
37 | 39 |
|
38 | 40 |
|
@@ -114,6 +116,45 @@ def _run_interface(self, runtime):
|
114 | 116 | return runtime
|
115 | 117 |
|
116 | 118 |
|
| 119 | +class AggregateSurfacesInputSpec(TraitedSpec): |
| 120 | + surfaces = InputMultiObject(File(exists=True), desc="Input surfaces") |
| 121 | + morphometrics = InputMultiObject(File(exists=True), desc="Input morphometrics") |
| 122 | + |
| 123 | + |
| 124 | +class AggregateSurfacesOutputSpec(TraitedSpec): |
| 125 | + pial = traits.List(File(), maxlen=2, desc="Pial surfaces") |
| 126 | + white = traits.List(File(), maxlen=2, desc="White surfaces") |
| 127 | + inflated = traits.List(File(), maxlen=2, desc="Inflated surfaces") |
| 128 | + midthickness = traits.List(File(), maxlen=2, desc="Midthickness (or graymid) surfaces") |
| 129 | + thickness = traits.List(File(), maxlen=2, desc="Cortical thickness maps") |
| 130 | + sulc = traits.List(File(), maxlen=2, desc="Sulcal depth maps") |
| 131 | + curv = traits.List(File(), maxlen=2, desc="Curvature maps") |
| 132 | + |
| 133 | + |
| 134 | +class AggregateSurfaces(SimpleInterface): |
| 135 | + """Aggregate and group surfaces & morphometrics into left/right pairs.""" |
| 136 | + input_spec = AggregateSurfacesInputSpec |
| 137 | + output_spec = AggregateSurfacesOutputSpec |
| 138 | + |
| 139 | + def _run_interface(self, runtime): |
| 140 | + from collections import defaultdict |
| 141 | + import os |
| 142 | + import re |
| 143 | + |
| 144 | + container = defaultdict(list) |
| 145 | + inputs = (self.inputs.surfaces or []) + (self.inputs.morphometrics or []) |
| 146 | + findre = re.compile( |
| 147 | + r'(?:^|[^d])(?P<name>white|pial|inflated|midthickness|thickness|sulc|curv)' |
| 148 | + ) |
| 149 | + for surface in sorted(inputs, key=os.path.basename): |
| 150 | + match = findre.search(os.path.basename(surface)) |
| 151 | + if match: |
| 152 | + container[match.group('name')].append(surface) |
| 153 | + for name, files in container.items(): |
| 154 | + self._results[name] = files |
| 155 | + return runtime |
| 156 | + |
| 157 | + |
117 | 158 | def normalize_surfs(in_file: str, transform_file: str, newpath: Optional[str] = None) -> str:
|
118 | 159 | """
|
119 | 160 | Update GIFTI metadata and apply rigid coordinate correction.
|
|
0 commit comments