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

RF: isMelodicDir no longer requires dir to end in .ica, and no longer accepts

a file or sub-dir
parent 34084a75
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,6 @@ import logging ...@@ -33,7 +33,6 @@ import logging
import os.path as op import os.path as op
import numpy as np import numpy as np
import fsl.utils.path as fslpath
import fsl.data.image as fslimage import fsl.data.image as fslimage
import fsl.data.featanalysis as featanalysis import fsl.data.featanalysis as featanalysis
...@@ -63,10 +62,9 @@ def isMelodicImage(path): ...@@ -63,10 +62,9 @@ def isMelodicImage(path):
def isMelodicDir(path): def isMelodicDir(path):
"""Returns ``True`` if the given path looks like it is contained within """Returns ``True`` if the given path looks like it is a MELODIC directory,
a MELODIC directory, ``False`` otherwise. A melodic directory: ``False`` otherwise. A MELODIC directory:
- Must be named ``*.ica``.
- Must contain a file called ``melodic_IC.nii.gz`` or - Must contain a file called ``melodic_IC.nii.gz`` or
``melodic_oIC.nii.gz``. ``melodic_oIC.nii.gz``.
- Must contain a file called ``melodic_mix``. - Must contain a file called ``melodic_mix``.
...@@ -75,12 +73,7 @@ def isMelodicDir(path): ...@@ -75,12 +73,7 @@ def isMelodicDir(path):
path = op.abspath(path) path = op.abspath(path)
if op.isdir(path): dirname = path if not op.isdir(path):
else: dirname = op.dirname(path)
sufs = ['.ica']
if not any([dirname.endswith(suf) for suf in sufs]):
return False return False
# Must contain an image file called # Must contain an image file called
...@@ -88,7 +81,7 @@ def isMelodicDir(path): ...@@ -88,7 +81,7 @@ def isMelodicDir(path):
prefixes = ['melodic_IC', 'melodic_oIC'] prefixes = ['melodic_IC', 'melodic_oIC']
for p in prefixes: for p in prefixes:
try: try:
fslimage.addExt(op.join(dirname, p)) fslimage.addExt(op.join(path, p))
break break
except fslimage.PathError: except fslimage.PathError:
pass pass
...@@ -97,8 +90,8 @@ def isMelodicDir(path): ...@@ -97,8 +90,8 @@ def isMelodicDir(path):
# Must contain files called # Must contain files called
# melodic_mix and melodic_FTmix # melodic_mix and melodic_FTmix
if not op.exists(op.join(dirname, 'melodic_mix')): return False if not op.exists(op.join(path, 'melodic_mix')): return False
if not op.exists(op.join(dirname, 'melodic_FTmix')): return False if not op.exists(op.join(path, 'melodic_FTmix')): return False
return True return True
...@@ -108,10 +101,13 @@ def getAnalysisDir(path): ...@@ -108,10 +101,13 @@ def getAnalysisDir(path):
to that MELODIC directory is returned. Otherwise, ``None`` is returned. to that MELODIC directory is returned. Otherwise, ``None`` is returned.
""" """
meldir = fslpath.deepest(path, ['.ica']) if not op.isdir(path):
path = op.dirname(path)
if meldir is not None and isMelodicDir(meldir): while path not in (op.sep, ''):
return meldir if isMelodicDir(path):
return path
path = op.dirname(path)
return None return None
......
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