def test_init(self): """JointEnumeration init should work as expected""" # should work for alphabet object a = JointEnumeration([DnaBases, RnaBases]) self.assertEqual(len(a), 16) self.assertEqual(a.shape, (4, 4)) self.assertEqual(a[0], ("T", "U")) self.assertEqual(a[-1], ("G", "G")) assert_equal(a._sub_enum_factors, array([[4], [1]])) # should work for arbitrary sequences a = JointEnumeration(["TCAG", "UCAG"]) self.assertEqual(len(a), 16) self.assertEqual(a[0], ("T", "U")) self.assertEqual(a[-1], ("G", "G")) assert_equal(a._sub_enum_factors, array([[4], [1]])) # should work for different length sequences a = JointEnumeration(["TCA", "UCAG"]) self.assertEqual(a.shape, (3, 4)) self.assertEqual(len(a), 12) self.assertEqual(a[0], ("T", "U")) self.assertEqual(a[-1], ("A", "G")) assert_equal(a._sub_enum_factors, array([[4], [1]])) # note: _not_ [3,1]
def test_unpack_arrays(self): """JointEnumeration unpack_arrays should return correct arrays.""" a = JointEnumeration(["xyz", "abcd", "ef"]) v = [7, 15, 18, 0] result = a.unpack_arrays(v) self.assertEqual(result, array([[0, 1, 2, 0], [3, 3, 1, 0], [1, 1, 0, 0]]))
def test_pack_arrays(self): """JointEnumeration pack_arrays should return correct array.""" a = JointEnumeration(["xyz", "abcd", "ef"]) v = [[0, 1, 2, 0], [3, 3, 1, 0], [1, 1, 0, 0]] result = a.pack_arrays(v) assert_equal(result, array([7, 15, 18, 0]))
def test_from_indices(self): """JointEnumeration from_indices should return correct tuples""" a = JointEnumeration(["TCAG", "UCAG"]) i = a.from_indices([0, 15, 15]) self.assertEqual(i, [("T", "U"), ("G", "G"), ("G", "G")])
def test_to_indices(self): """JointEnumeration to_indices should convert tuples correctly""" a = JointEnumeration(["TCAG", "UCAG"]) i = a.to_indices([("T", "U"), ("G", "G"), ("G", "G")]) self.assertEqual(i, [0, 15, 15])