Commit 66eb47f4 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Freesurfer checks label and stats directories for vertex data

files. Adjustment to gifti.relatedFiles.
parent f8a52e27
......@@ -93,7 +93,6 @@ VERTEX_DATA_FILES = ['?h.thickness',
'?h.curv',
'?h.area',
'?h.sulc',
'?h.*.stats',
'.mgh',
'.mgz']
"""File patterns which are interpreted as Freesurfer vertex data files,
......@@ -225,7 +224,7 @@ class FreesurferMesh(fslmesh.Mesh):
self.addVertexData(key, vdata)
if isvlabel:
if isvannot:
self.__luts[key] = lut, names, lut
return vdata
......@@ -368,9 +367,20 @@ def relatedVertexDataFiles(fname):
fpats = VERTEX_DATA_FILES + VERTEX_LABEL_FILES + VERTEX_ANNOT_FILES
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):
......
......@@ -77,6 +77,7 @@ class GiftiMesh(fslmesh.Mesh):
surfimg, vertices, indices = loadGiftiMesh(infile)
fslmesh.Mesh.__init__(self,
indices,
name=name,
......@@ -278,35 +279,35 @@ def relatedFiles(fname, ftypes=None):
# directory which have the following name:
#
# [prefix].*[ftype]
# [subj].[hemi].[type].*.[ftype]
#
# where
# - prefix is the file prefix, and which
# may include periods.
# - [subj] is the subject ID, and matches fname
#
# - 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
# given file, and back-up to the most
# recent period. Then search for other
# files which have that same (non-unique)
# prefix.
prefix = fslpath.uniquePrefix(fname)
lastdot = prefix.rfind('.')
prefix = prefix[:lastdot]
path = op.abspath(fname)
dirname, fname = op.split(path)
if lastdot == -1:
# get the [subj].[hemi] prefix
try:
subj, hemi, _ = fname.split('.', 2)
prefix = '.'.join((subj, hemi))
except Exception:
return []
related = []
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):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment