diff --git a/system/annotations.py b/system/annotations.py new file mode 100644 index 0000000..eaf5139 --- /dev/null +++ b/system/annotations.py @@ -0,0 +1,33 @@ +import logger + +class Annotations: + def __init__(self, *dimensions): + """ Initializes a new Annotation with the given dimension labels. + dimensions is a list of dimension labels. + """ + if len(dimensions) == 2: + logger.log('error', 'Annotations only supports two dimensions.') + + self.dimensions = {} + for d in dimensions: + self.dimensions[d] = {} + + def add_annotations(self, dim, id, ann_dim, annotations): + if not self.dimensions[dim]: + logger.log('warning', 'Annotations object does not contain dimension %s' % dim) + return None + for a in annotations: + self.annotations[ann_dim][a].add(id) + self.annotations[dim][id] = annotations + + def get_annotations(self, dim, id): + if not self.dimensions[dim]: + logger.log('warning', 'Annotations object does not contain dimension %s' % dim) + return None + + if self.dimensions[dim].has_key(id): + return self.dimensions[dim][id].values() + return None + + def has_dimension(self, dim): + return self.dimensions.has_key(dim) diff --git a/system/workflow.py b/system/workflow.py index 4c2ed67..bcba4a2 100644 --- a/system/workflow.py +++ b/system/workflow.py @@ -87,7 +87,7 @@ class EinarsWorkflow (Workflow): regression.add_function(Function('pls', 'PLS')) self.add_stage(regression) - logger.log('debug', 'Einar\'s workflow is now active') + logger.log('debug', '\tEinar\'s workflow is now active') class WorkflowView (gtk.VBox): diff --git a/test/system/annotationtest.py b/test/system/annotationtest.py new file mode 100644 index 0000000..9b85575 --- /dev/null +++ b/test/system/annotationtest.py @@ -0,0 +1,19 @@ + +import unittest +import sys +sys.path.append('../../system') +from annotations import * + +class AnnotationTest(unittest.TestCase): + + def setUp(self): + pass + + def testCreation(self): + a = Annotations('x', 'y') + assert a.has_dimension('x') + assert a.has_dimension('y') + assert not a.has_dimension('z') + +if __name__ == '__main__': + unittest.main()