Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/test/fluents/annotationtest.py

67 lines
2.2 KiB
Python

import unittest
import sys
sys.path.append('../../')
from fluents import annotations
class AnnotationsTest(unittest.TestCase):
def setUp(self):
pass
def testAddAnnotations(self):
h = annotations.DictAnnotationHandler()
annotations.set_dim_handler('go-terms', h)
assert annotations.get_dim_handler('go-terms') == h
assert annotations.get_dim_handler('foobar') == None
def testGetDimAnnotations(self):
h = annotations.DictAnnotationHandler()
annotations.set_dim_handler('go-terms', h)
d = {'GO:0': 'biological_process',
'GO:1': 'foo',
'GO:2': 'bar'}
h.add_annotations('name', d)
ann0 = annotations.get_dim_annotations('go-terms', 'name', [])
assert ann0 == []
ann1 = annotations.get_dim_annotations('go-terms', 'name', ['GO:0'])
assert len(ann1) == 1
assert ann1[0] == 'biological_process'
ann2 = annotations.get_dim_annotations('go-terms', 'name', ['GO:1', 'baz'])
assert len(ann2) == 2
assert ann2 == ['foo', None]
def testDictAnnotationHandler(self):
h = annotations.DictAnnotationHandler()
annotations.set_dim_handler('go-terms', h)
d = {'GO:0': 'biological_process',
'GO:1': 'foo',
'GO:2': 'bar'}
h.add_annotations('name', d)
ann0 = h.get_annotations('name', [])
assert ann0 == []
ann1 = h.get_annotations('name', ['unexisting'])
assert ann1 == [None]
ann2 = h.get_annotations('name', ['unexisting'], 42)
assert ann2 == [42]
assert h.get_annotation_names() == ['name']
def testReadAnnotationsFile(self):
ann = annotations.read_annotations_file('../data/annotations.fann')
assert ann != None
assert ann == annotations.get_dim_handler('dim1')
assert 'Ann1' in ann.get_annotation_names()
assert 'Ann2' in ann.get_annotation_names()
assert not ('Ann3' in ann.get_annotation_names())
assert annotations.get_dim_annotations('dim1', 'Ann1', ['id1']) == ['11']
if __name__ == '__main__':
unittest.main()