2006-04-17 00:57:50 +02:00
|
|
|
import unittest
|
|
|
|
import sys
|
2006-05-02 15:21:24 +02:00
|
|
|
sys.path.append('../..')
|
|
|
|
from system.dataset import *
|
2006-05-02 17:40:54 +02:00
|
|
|
from scipy import rand,shape, array
|
2006-04-17 00:57:50 +02:00
|
|
|
|
|
|
|
class DatasetTest(unittest.TestCase):
|
2006-04-24 11:53:07 +02:00
|
|
|
|
2006-04-17 00:57:50 +02:00
|
|
|
def setUp(self):
|
2006-04-24 11:53:07 +02:00
|
|
|
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)]
|
2006-04-17 00:57:50 +02:00
|
|
|
self.array = rand(2,3)
|
2006-04-24 11:53:07 +02:00
|
|
|
self.testdata = Dataset(self.array,identifiers)
|
2006-04-17 00:57:50 +02:00
|
|
|
|
|
|
|
def testCreation(self):
|
2006-04-24 11:53:07 +02:00
|
|
|
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
|
2006-05-02 16:06:48 +02:00
|
|
|
|
|
|
|
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]))
|
2006-05-02 17:40:54 +02:00
|
|
|
# handle empty matrix of indices
|
|
|
|
self.assertEquals([], data.get_identifiers('samples', array([])))
|
2006-05-02 16:06:48 +02:00
|
|
|
# other dimension
|
|
|
|
self.assertEquals(['sample_a', 'sample_b'], data.get_identifiers('samples', [0, 1]))
|
2006-04-17 00:57:50 +02:00
|
|
|
|
2006-05-02 17:40:54 +02:00
|
|
|
|
2006-04-24 11:53:07 +02:00
|
|
|
#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]
|
2006-04-17 00:57:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|