Added read_annotations_file()

This commit is contained in:
2007-02-15 22:49:40 +00:00
parent b17f04466b
commit e6cf8f765a
2 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
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')
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,56 @@
import unittest
import sys
sys.path.append('../..')
from system.dataset import *
from scipy import rand,shape, array
class DatasetTest(unittest.TestCase):
def setUp(self):
dim_0_ids = ('sample_a','sample_b')
dim_1_ids = ('gene_a','gene_b','gene_c')
dim_labels = ('samples','genes')
identifiers= [(dim_labels[0],dim_0_ids),(dim_labels[1],dim_1_ids)]
self.array = rand(2,3)
self.testdata = Dataset(self.array,identifiers)
def testCreation(self):
data = self.testdata
assert data._array == self.array
assert 'sample_a' in data['samples'].keys()
assert data['samples']['sample_b']==1
assert 'gene_c' in data['genes'].keys()
assert data['genes']['gene_c']==2
def testLookupIndicesOfIdentifiers(self):
data = self.testdata
# base case
self.assertEquals([0, 1, 2], data.get_indices('genes', ['gene_a', 'gene_b', 'gene_c']))
# "advanced" lookup
self.assertEquals([2, 0], data.get_indices('genes', ['gene_c', 'gene_a']))
# other dimension
self.assertEquals([0, 1], data.get_indices('samples', ['sample_a', 'sample_b']))
def testLookupIdentifiersOfIndices(self):
data = self.testdata
# base case
self.assertEquals(['gene_a', 'gene_b', 'gene_c'], data.get_identifiers('genes', [0, 1, 2]))
# "advanced" lookup
self.assertEquals(['gene_c', 'gene_a'], data.get_identifiers('genes', [2, 0]))
# handle empty matrix of indices
self.assertEquals([], data.get_identifiers('samples', array([])))
# other dimension
self.assertEquals(['sample_a', 'sample_b'], data.get_identifiers('samples', [0, 1]))
#def testExtraction(self):
# ids = ['gene_a','gene_b']
# dim_name = 'genes'
# subset = self.testdata.extract_data(ids,dim_name)
# assert shape(subset._data) == (2,2)
# assert subset.ids[dim_name].keys() == ids
# assert subset.ids[dim_name].values() == [0,1]
if __name__ == '__main__':
unittest.main()