* annotations.py: Annotation class for two-way annotations. Does only support
exactly two dimensions.
This commit is contained in:
parent
5853216df4
commit
eb45c125aa
|
@ -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)
|
|
@ -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):
|
||||
|
||||
|
|
|
@ -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()
|
Reference in New Issue