def test_single_location_two_segments_uneven(self): mother = MagicMock() mother.starts = np.array([0, 5], dtype = np.uint32) mother.end = 20 mother.founder = np.array([1, 2], dtype = np.uint32) father = MagicMock() father.starts = np.array([0, 10], dtype = np.uint32) father.end = 20 father.founder = np.array([3, 4], dtype = np.uint32) locations = [(2, 11)] new_mother, new_father = recomb_genome._swap_at_locations(mother, father, locations) np.testing.assert_array_equal(new_mother.starts, np.array([0, 2, 10, 11], dtype = np.uint32)) np.testing.assert_array_equal(new_mother.founder, np.array([1, 3, 4, 2], dtype = np.uint32)) np.testing.assert_array_equal(new_father.starts, np.array([0, 2, 5, 11], dtype = np.uint32)) np.testing.assert_array_equal(new_father.founder, np.array([3, 1, 2, 4], dtype = np.uint32))
def test_two_locations_at_boundary_two_segments (self): mother = MagicMock() mother.starts = np.array([0, 10], dtype = np.uint32) mother.end = 20 mother.founder = np.array([1, 2], dtype = np.uint32) father = MagicMock() father.starts = np.array([0, 10], dtype = np.uint32) father.end = 20 father.founder = np.array([3, 4], dtype = np.uint32) locations = [(0, 5), (15, 20)] new_mother, new_father = recomb_genome._swap_at_locations(mother, father, locations) np.testing.assert_array_equal(new_mother.starts, np.array([0, 5, 10, 15], dtype = np.uint32)) np.testing.assert_array_equal(new_mother.founder, np.array([3, 1, 2, 4], dtype = np.uint32)) np.testing.assert_array_equal(new_father.starts, np.array([0, 5, 10, 15], dtype = np.uint32)) np.testing.assert_array_equal(new_father.founder, np.array([1, 3, 4, 2], dtype = np.uint32))
def test_multiple_locations_single_segment(self): mother = MagicMock() mother.starts = np.array([0], dtype = np.uint32) mother.end = 10 mother.founder = np.array([1], dtype = np.uint32) father = MagicMock() father.starts = np.array([0], dtype = np.uint32) father.end = 10 father.founder = np.array([2], dtype = np.uint32) locations = [(0, 4), (6, 10)] new_mother, new_father = recomb_genome._swap_at_locations(mother, father, locations) np.testing.assert_array_equal(new_mother.starts, np.array([0, 4, 6], dtype = np.uint32)) np.testing.assert_array_equal(new_mother.founder, np.array([2, 1, 2], dtype = np.uint32)) np.testing.assert_array_equal(new_father.starts, np.array([0, 4, 6], dtype = np.uint32)) np.testing.assert_array_equal(new_father.founder, np.array([1, 2, 1], dtype = np.uint32))
def test_single_location_middle_boundary(self): mother = MagicMock() mother.starts = np.array([0], dtype = np.uint32) mother.end = 10 mother.founder = np.array([1], dtype = np.uint32) father = MagicMock() father.starts = np.array([0], dtype = np.uint32) father.end = 10 father.founder = np.array([2], dtype = np.uint32) locations = [(2, 8)] new_mother, new_father = recomb_genome._swap_at_locations(mother, father, locations) np.testing.assert_array_equal(new_mother.starts, np.array([0, 2, 8], dtype = np.uint32)) np.testing.assert_array_equal(new_mother.founder, np.array([1, 2, 1], dtype = np.uint32)) np.testing.assert_array_equal(new_father.starts, np.array([0, 2, 8], dtype = np.uint32)) np.testing.assert_array_equal(new_father.founder, np.array([2, 1, 2], dtype = np.uint32))
def test_single_location_left_boundary(self): mother = MagicMock() mother.starts = np.array([0], dtype = np.uint32) mother.end = 10 mother.founder = np.array([1], dtype = np.uint32) father = MagicMock() father.starts = np.array([0], dtype = np.uint32) father.end = 10 father.founder = np.array([2], dtype = np.uint32) locations = [(0, 5)] new_mother, new_father = recomb_genome._swap_at_locations(mother, father, locations) np.testing.assert_array_equal(new_mother.starts, np.array([0, 5], dtype = np.uint32)) np.testing.assert_array_equal(new_mother.founder, np.array([2, 1], dtype = np.uint32)) np.testing.assert_array_equal(new_father.starts, np.array([0, 5], dtype = np.uint32)) np.testing.assert_array_equal(new_father.founder, np.array([1, 2], dtype = np.uint32))