From 559e5188f34d148f48e45bbf389349211259dafe Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Tue, 18 Apr 2017 16:03:50 +0100
Subject: [PATCH] Fixes and tweaks to volumelabels and fixlabels modules

---
 fsl/data/fixlabels.py    |  2 +-
 fsl/data/volumelabels.py | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fsl/data/fixlabels.py b/fsl/data/fixlabels.py
index 8cc0a99c9..86eaadb67 100644
--- a/fsl/data/fixlabels.py
+++ b/fsl/data/fixlabels.py
@@ -252,7 +252,7 @@ def saveLabelFile(allLabels,
 
     # The first line - the melodic directory name
     if dirname is not None:
-        lines.append(op.abspath(dirname))
+        lines.append(dirname)
 
     # A line for each component
     for i, labels in enumerate(allLabels):
diff --git a/fsl/data/volumelabels.py b/fsl/data/volumelabels.py
index cf95150c4..b31af600b 100644
--- a/fsl/data/volumelabels.py
+++ b/fsl/data/volumelabels.py
@@ -8,6 +8,8 @@
 manage labels associated with the volumes of an :class:`.Image`.  This class
 is primarily used for managing component classifications of a
 :class:`.MelodicImage`.
+
+See also the :func:`.fixlabels` module for loading/saving melodic label files.
 """
 
 
@@ -22,7 +24,8 @@ log = logging.getLogger(__name__)
 
 class VolumeLabels(notifier.Notifier):
     """The ``VolumeLabels`` class is a convenience class for managing a
-    collection of classification labels fgor the volumes of an :class:`.Image`.
+    collection of classification labels for the volumes of an :class:`.Image`.
+
     The ``VolumeLabels`` class refers to *volumes* as *components*, because
     it was originally written to manage classification labels associated wirh
     the components of a Melodic analysis.
@@ -230,8 +233,12 @@ class VolumeLabels(notifier.Notifier):
         labels.remove(label)
         comps .remove(component)
 
-        self.__components[label]     = comps        
-        self.__labels[    component] = labels
+        if len(comps) == 0:
+            self.__components.pop(label, None)
+        else:
+            self.__components[label] = comps
+
+        self.__labels[component] = labels
 
         log.debug('Label removed from component: {} <-> {}'.format(component,
                                                                    label))
@@ -273,12 +280,12 @@ class VolumeLabels(notifier.Notifier):
     
     def addComponent(self, label, component):
         """Adds the given label to the given component. """
-        self.addLabel(component, label)
+        return self.addLabel(component, label)
 
 
     def removeComponent(self, label, component, notify=True):
         """Removes the given label from the given component. """
-        self.removeLabel(component, label, notify)
+        return self.removeLabel(component, label, notify)
 
     
     def clearComponents(self, label):
-- 
GitLab