Skip to content

Commit a223a2f

Browse files
committed
ENH: Add interface to aggregate / sort surface files
1 parent 23f9dc4 commit a223a2f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

smriprep/interfaces/surf.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
SimpleInterface,
3434
File,
3535
isdefined,
36+
InputMultiObject,
37+
traits,
3638
)
3739

3840

@@ -114,6 +116,45 @@ def _run_interface(self, runtime):
114116
return runtime
115117

116118

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+
117158
def normalize_surfs(in_file: str, transform_file: str, newpath: Optional[str] = None) -> str:
118159
"""
119160
Update GIFTI metadata and apply rigid coordinate correction.

0 commit comments

Comments
 (0)