From 8e7afb004d807699cb766c058d8867c9dfd6edf2 Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Fri, 23 Oct 2015 17:51:18 +0100
Subject: [PATCH] Started working on adding support for Melodic analyses. Just
 skeletons and stubs so far.

---
 fsl/data/featresults.py    | 16 ++++++++++++++++
 fsl/data/melodicimage.py   | 23 +++++++++++++++++++++++
 fsl/data/melodicresults.py | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 fsl/data/melodicimage.py
 create mode 100644 fsl/data/melodicresults.py

diff --git a/fsl/data/featresults.py b/fsl/data/featresults.py
index 218626e3a..719092a03 100644
--- a/fsl/data/featresults.py
+++ b/fsl/data/featresults.py
@@ -15,6 +15,7 @@ following functions are provided:
 
    isFEATDir
    getFEATDir
+   hasMelodicDir
    loadDesign
    loadContrasts
    loadSettings
@@ -30,6 +31,7 @@ The following functions return the names of various files of interest:
 
    getDataFile
    getResidualFile
+   getMelodicFile
    getPEFile
    getCOPEFile
    getZStatFile
@@ -104,6 +106,13 @@ def getFEATDir(path):
     return None
 
 
+def hasMelodicDir(featdir):
+    """Returns ``True`` if the data for the given FEAT directory has had
+    MELODIC run on it, ``False`` otherwise.
+    """
+    return op.exists(getMelodicFile(featdir))
+
+
 def loadDesign(featdir):
     """Loads the design matrix from a FEAT directory.
 
@@ -441,6 +450,13 @@ def getDataFile(featdir):
     return glob.glob((op.join(featdir, 'filtered_func_data.*')))[0]
 
 
+def getMelodicFile(featdir):
+    """Returns the name of the file in the FEAT results which contains the
+    melodic components. This file can be loaded as a :class:`.MelodicImage`.
+    """
+    return op.join(featdir, 'filtered_func_data.ica', 'melodic_IC.nii.gz')
+
+
 def getResidualFile(featdir):
     """Returns the name of the file in the FEAT results which contains
     the model fit residuals (typically called ``res4d.nii.gz``).
diff --git a/fsl/data/melodicimage.py b/fsl/data/melodicimage.py
new file mode 100644
index 000000000..d0c4b5f8a
--- /dev/null
+++ b/fsl/data/melodicimage.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+#
+# melodicimage.py - An Image subclass which has some MELODIC-specific
+# functionality.
+#
+# Author: Paul McCarthy <pauldmccarthy@gmail.com>
+#
+"""This module provides the :class:`MelodicImage` class, an :class:`.Image`
+sub-class which encapsulates data from a MELODIC analysis.
+"""
+
+import image          as fslimage
+import melodicresults as melresults
+
+
+class MelodicImage(fslimage.Image):
+    """
+    """
+
+    def __init__(self, path):
+        """
+        """
+        pass
diff --git a/fsl/data/melodicresults.py b/fsl/data/melodicresults.py
new file mode 100644
index 000000000..492a76e62
--- /dev/null
+++ b/fsl/data/melodicresults.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+#
+# melodicresults.py - Utility functions for loading/querying the contents of a
+# MELODIC analysis directory.
+# 
+# Author: Paul McCarthy <pauldmccarthy@gmail.com>
+#
+"""This module provides a set of functions for accessing the contents of a
+MELODIC analysis directory. These functions are primarily intended to be used
+by the :class:`.MELODICImage` class, but are available for other uses. The
+following functions are provided:
+
+.. autosummary::
+   nosignatures:
+
+   isMELODICDir
+   getMELODICDir
+
+   getICFile
+
+   getNumComponents
+   getComponentTimeSeries
+"""
+
+
+def isMELODICDir(path):
+    """
+    """
+
+    # A MELODIC directory:
+    #   - Must be called *.ica
+    #   - Must contain melodic_IC.nii.gz
+    #   - Must contain melodic_mix
-- 
GitLab