Skip to content
Snippets Groups Projects
Commit c124b6c1 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Functions in both featresults and melodicresults to get current analysis

directory given a path, and to get top level analysis directory.
parent cbd87869
No related branches found
No related tags found
No related merge requests found
......@@ -105,6 +105,14 @@ class FEATImage(fslimage.Image):
name, minus the ``.feat`` / ``.gfeat`` suffix.
"""
return self.__analysisName
def getTopLevelAnalysisDir(self):
"""Returns the path to the higher level analysis directory of
which this FEAT analysis is a part, or ``None`` if this analysis
is not part of another analysis.
"""
return featresults.getTopLevelAnalysisDir(self.__featDir)
def getDesign(self):
......
......@@ -16,6 +16,8 @@ following functions are provided:
isFEATImage
isFEATDir
hasMelodicDir
getAnalysisDir
getTopLevelAnalysisDir
loadDesign
loadContrasts
loadSettings
......@@ -102,6 +104,55 @@ def hasMelodicDir(featdir):
return op.exists(getMelodicFile(featdir))
def getAnalysisDir(path):
"""If the given path is contained within a FEAT directory, the path
to that FEAT directory is returned. Otherwise, ``None`` is returned.
"""
# This is basically the opposite to
# the getTopLevelAnalysisDir function
path = path.strip()
if path == op.sep or path == '':
return None
path = path.rstrip(op.sep)
sufs = ['.feat', '.gfeat']
if any([path.endswith(suf) for suf in sufs]):
return path
return getAnalysisDir(op.dirname(path))
def getTopLevelAnalysisDir(path):
"""If the given path is contained within a FEAT directory, or a
MELODIC directory, the path to the latter directory is returned.
Otherwise, ``None`` is returned.
"""
path = path.strip()
# We've reached the root of the file system
if path == op.sep or path == '':
return None
path = path.rstrip(op.sep)
parent = getTopLevelAnalysisDir(op.dirname(path))
if parent is not None:
return parent
sufs = ['.ica', '.gica', '.feat', '.gfeat']
if any([path.endswith(suf) for suf in sufs]):
return path
return None
def loadDesign(featdir):
"""Loads the design matrix from a FEAT directory.
......
......@@ -38,7 +38,8 @@ import numpy as np
import props
import fsl.data.image as fslimage
import fsl.data.image as fslimage
import fsl.data.featresults as featresults
log = logging.getLogger(__name__)
......@@ -90,30 +91,7 @@ def isMelodicDir(path):
return True
def getTopLevelAnalysisDir(path):
"""If the given path is a MELODIC directory, and it is contained within
a FEAT directory, or another MELODIC directory, the path to the latter
directory is returned. Otherwise, ``None`` is returned.
"""
path = path.strip()
# We've reached the root of the file system
if path == op.sep or path == '':
return None
path = path.rstrip(op.sep)
parent = getTopLevelAnalysisDir(op.dirname(path))
if parent is not None:
return parent
sufs = ['.ica', '.gica', '.feat', '.gfeat']
if any([path.endswith(suf) for suf in sufs]):
return path
return None
getTopLevelAnalysisDir = featresults.getTopLevelAnalysisDir
def getDataFile(meldir):
......
......@@ -787,17 +787,20 @@ nifti = TypeDict({
feat = TypeDict({
'analysisName' : 'Analysis name',
'numPoints' : 'Number of volumes',
'numEVs' : 'Number of EVs',
'numContrasts' : 'Number of contrasts',
'report' : 'Link to report',
'analysisName' : 'Analysis name',
'analysisDir' : 'Analysis directory',
'partOfAnalysis' : 'Part of higher level analysis',
'numPoints' : 'Number of volumes',
'numEVs' : 'Number of EVs',
'numContrasts' : 'Number of contrasts',
'report' : 'Link to report',
})
melodic = TypeDict({
'dataFile' : 'Data file',
'partOfAnalysis' : 'Part of analysis',
'analysisDir' : 'Analysis directory',
'partOfAnalysis' : 'Part of higher level analysis',
'numComponents' : 'Number of ICs',
'tr' : 'TR time',
'report' : 'Link to report',
......
......@@ -276,17 +276,22 @@ class OverlayInfoPanel(fslpanel.FSLEyesPanel):
"""
info = self.__getImageInfo(overlay, display)
featInfo = collections.OrderedDict([
featInfo = [
('analysisName', overlay.getAnalysisName()),
('analysisDir', overlay.getFEATDir()),
('numPoints', overlay.numPoints()),
('numEVs', overlay.numEVs()),
('numContrasts', overlay.numContrasts()),
])
('numContrasts', overlay.numContrasts())]
topLevel = overlay.getTopLevelAnalysisDir()
if topLevel is not None:
featInfo.insert(2, ('partOfAnalysis', topLevel))
secName = strings.labels[self, overlay, 'featInfo']
info.addSection(secName)
for k, v in featInfo.items():
for k, v in featInfo:
info.addInfo(strings.feat[k], v, section=secName)
return info
......@@ -303,17 +308,21 @@ class OverlayInfoPanel(fslpanel.FSLEyesPanel):
info = self.__getImageInfo(overlay, display)
melInfo = collections.OrderedDict([
('tr', overlay.tr),
melInfo = [
('dataFile', overlay.getDataFile()),
('partOfAnalysis', overlay.getTopLevelAnalysisDir()),
('numComponents', overlay.numComponents()),
])
('analysisDir', overlay.getMelodicDir()),
('tr', overlay.tr),
('numComponents', overlay.numComponents())]
topLevel = overlay.getTopLevelAnalysisDir()
if topLevel is not None:
melInfo.insert(2, ('partOfAnalysis', topLevel))
secName = strings.labels[self, overlay, 'melodicInfo']
info.addSection(secName)
for k, v in melInfo.items():
for k, v in melInfo:
info.addInfo(strings.melodic[k], v, section=secName)
return info
......
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