Skip to content
Snippets Groups Projects
Commit 66eb47f4 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Freesurfer checks label and stats directories for vertex data

files. Adjustment to gifti.relatedFiles.
parent f8a52e27
No related branches found
No related tags found
No related merge requests found
...@@ -93,7 +93,6 @@ VERTEX_DATA_FILES = ['?h.thickness', ...@@ -93,7 +93,6 @@ VERTEX_DATA_FILES = ['?h.thickness',
'?h.curv', '?h.curv',
'?h.area', '?h.area',
'?h.sulc', '?h.sulc',
'?h.*.stats',
'.mgh', '.mgh',
'.mgz'] '.mgz']
"""File patterns which are interpreted as Freesurfer vertex data files, """File patterns which are interpreted as Freesurfer vertex data files,
...@@ -225,7 +224,7 @@ class FreesurferMesh(fslmesh.Mesh): ...@@ -225,7 +224,7 @@ class FreesurferMesh(fslmesh.Mesh):
self.addVertexData(key, vdata) self.addVertexData(key, vdata)
if isvlabel: if isvannot:
self.__luts[key] = lut, names, lut self.__luts[key] = lut, names, lut
return vdata return vdata
...@@ -368,9 +367,20 @@ def relatedVertexDataFiles(fname): ...@@ -368,9 +367,20 @@ def relatedVertexDataFiles(fname):
fpats = VERTEX_DATA_FILES + VERTEX_LABEL_FILES + VERTEX_ANNOT_FILES fpats = VERTEX_DATA_FILES + VERTEX_LABEL_FILES + VERTEX_ANNOT_FILES
fpats = [hemi + p[1:] if p.startswith('?h') else p for p in fpats] fpats = [hemi + p[1:] if p.startswith('?h') else p for p in fpats]
related = [glob.glob(op.join(dirname, p)) for p in fpats] basedir = op.dirname(dirname)
searchDirs = set([dirname,
op.join(basedir, 'surf'),
op.join(basedir, 'stats'),
op.join(basedir, 'label')])
searchPats = it.product(searchDirs, fpats)
related = []
for sdir, spat in searchPats:
related.extend(glob.glob(op.join(sdir, spat)))
return list(it.chain(*related)) return related
def findReferenceImage(fname): def findReferenceImage(fname):
......
...@@ -77,6 +77,7 @@ class GiftiMesh(fslmesh.Mesh): ...@@ -77,6 +77,7 @@ class GiftiMesh(fslmesh.Mesh):
surfimg, vertices, indices = loadGiftiMesh(infile) surfimg, vertices, indices = loadGiftiMesh(infile)
fslmesh.Mesh.__init__(self, fslmesh.Mesh.__init__(self,
indices, indices,
name=name, name=name,
...@@ -278,35 +279,35 @@ def relatedFiles(fname, ftypes=None): ...@@ -278,35 +279,35 @@ def relatedFiles(fname, ftypes=None):
# directory which have the following name: # directory which have the following name:
# #
# [prefix].*[ftype] # [subj].[hemi].[type].*.[ftype]
# #
# where # where
# - prefix is the file prefix, and which # - [subj] is the subject ID, and matches fname
# may include periods.
# #
# - we don't care about the middle # - [hemi] is the hemisphere, and matches fname
# #
# - suffix is func, shape, label, time, or `ftype` # - [type] defines the file contents
# #
# - suffix is func, shape, label, time, or `ftype`
# We determine the unique prefix of the path = op.abspath(fname)
# given file, and back-up to the most dirname, fname = op.split(path)
# recent period. Then search for other
# files which have that same (non-unique)
# prefix.
prefix = fslpath.uniquePrefix(fname)
lastdot = prefix.rfind('.')
prefix = prefix[:lastdot]
if lastdot == -1: # get the [subj].[hemi] prefix
try:
subj, hemi, _ = fname.split('.', 2)
prefix = '.'.join((subj, hemi))
except Exception:
return [] return []
related = [] related = []
for ftype in ftypes: for ftype in ftypes:
related += list(glob.glob('{}*{}'.format(prefix, ftype))) related.extend(
glob.glob(op.join(dirname, '{}*{}'.format(prefix, ftype))))
return [r for r in related if r != fname] return [r for r in related if r != path]
class GiftiSurface(fslmesh.TriangleMesh): class GiftiSurface(fslmesh.TriangleMesh):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment