def test_apoptosis(): specs = config.geometry.bulk_spec() sheet = Sheet.planar_sheet_3d("flat", 4, 5, 1, 1) sheet.sanitize() datasets = extrude(sheet.datasets, method="translation") mono = Monolayer("mono", datasets, specs) mono.face_df["id"] = mono.face_df.index.values geom.center(mono) geom.update_all(mono) mono.face_df["contractility"] = 1.0 manager = EventManager("face") cell_id = 0 apical_face = mono.face_df[ (mono.face_df.index.isin(mono.get_orbits("cell", "face")[cell_id])) & (mono.face_df.segment == "apical")].index[0] sheet.settings["apoptosis"] = {"cell_id": cell_id} initial_cell_event = [(apoptosis, sheet.settings["apoptosis"])] manager.extend(initial_cell_event) manager.execute(mono) manager.update() assert len(manager.current) == 1 i = 0 while i < 5: manager.execute(mono) manager.update() i = i + 1 assert mono.face_df.loc[apical_face, "contractility"] > 1.0
def test_modify(): datasets, _ = three_faces_sheet() extruded = extrude(datasets, method="translation") mono = Monolayer("test", extruded, config.geometry.bulk_spec()) mono.update_specs(config.dynamics.quasistatic_bulk_spec(), reset=True) modifiers = { "apical": { "edge": { "line_tension": 1.0 }, "face": { "contractility": 0.2 } }, "basal": { "edge": { "line_tension": 3.0 }, "face": { "contractility": 0.1 } }, } utils.modify_segments(mono, modifiers) assert mono.edge_df.loc[mono.apical_edges, "line_tension"].unique()[0] == 1.0 assert mono.edge_df.loc[mono.basal_edges, "line_tension"].unique()[0] == 3.0
def test_find_transitions(): sheet = Sheet.planar_sheet_3d("sheet", 5, 5, 1, 1) sheet.sanitize() datasets = extrude(sheet.datasets, method="translation") eptm = Monolayer("test_IHt", datasets, bulk_spec()) BulkGeometry.update_all(eptm) eptm.settings["threshold_length"] = 1e-3 IH_transition(eptm, 26) BulkGeometry.update_all(eptm) eptm.settings["threshold_length"] = 1e-2 ih, hi = find_rearangements(eptm) assert len(ih) == 0 assert len(hi) == 2 assert len(find_HIs(eptm)) face = eptm.face_df.index[-1] HI_transition(eptm, face) BulkGeometry.update_all(eptm) eptm.settings["threshold_length"] = 2e-1 ih, hi = find_rearangements(eptm) assert len(ih) == 1 assert len(hi) == 0 assert len(find_IHs(eptm))
def test_fix_pinch(): dsets = hdf5.load_datasets(Path(stores_dir) / "with_pinch.hf5") pinched = Monolayer("pinched", dsets) assert not pinched.validate() fix_pinch(pinched) assert pinched.validate() edf = pinched.edge_df[["srce", "trgt", "face", "cell"]].copy() # Nothing happens here fix_pinch(pinched) assert pinched.validate() assert np.all(pinched.edge_df[["srce", "trgt", "face", "cell"]] == edf)
def test_copy(): datasets, specs = three_faces_sheet() extruded = extrude(datasets, method="translation") mono = Monolayer("test", extruded, config.geometry.bulk_spec()) assert mono.Nc == 3 assert mono.Nf == 24 assert mono.Ne == 108 assert mono.Nv == 26 mono2 = mono.copy() assert mono2.Nc == 3 assert isinstance(mono2, Monolayer)
def test_remove_cell(): dsets = hdf5.load_datasets(Path(stores_dir) / "with_4sided_cell.hf5") mono = Monolayer("4", dsets) Nci = mono.Nc cell = mono.cell_df.query("num_faces == 4").index[0] res = remove_cell(mono, cell) MonolayerGeometry.update_all(mono) assert not res assert mono.validate() assert mono.Nc == Nci - 1 with pytest.warns(UserWarning): cell = mono.cell_df.query("num_faces != 4").index[0] res = remove_cell(mono, cell) assert mono.validate()
def test_ab_pull_edge(): specs = config.geometry.bulk_spec() sheet = Sheet.planar_sheet_3d("flat", 4, 5, 1, 1) sheet.sanitize() datasets = extrude(sheet.datasets, method="translation") mono = Monolayer("mono", datasets, specs) geom.center(mono) geom.update_all(mono) mono.edge_df["line_tension"] = 1.0 mono.specs["edge"]["line_tension"] = 1.0 assert len(mono.edge_df.line_tension.unique()) == 1 ab_pull_edge(mono, 1, 2, False) assert len(mono.edge_df.line_tension.unique()) == 2
def test_close_already_closed(caplog): dsets = hdf5.load_datasets(Path(stores_dir) / "with_4sided_cell.hf5") mono = Monolayer("4", dsets) cell = mono.cell_df.query("num_faces != 4").index[0] close_cell(mono, cell) assert caplog.record_tuples[-1][2] == "cell %s is already closed" % cell
def test_verts_in_cell_connectivity(): data, specs = three_faces_sheet() mono = Monolayer("test", extrude(data), bulk_spec()) ccc = connectivity.verts_in_cell_connectivity(mono) assert ccc[0][ccc[0] == 9].shape == (18, ) assert ccc[0][ccc[0] == 18].shape == (6, ) assert ccc[0][ccc[0] == 27].shape == (1, )
def test_shrink(): specs = config.geometry.bulk_spec() sheet = Sheet.planar_sheet_3d("flat", 4, 5, 1, 1) sheet.sanitize() datasets = extrude(sheet.datasets, method="translation") mono = Monolayer("mono", datasets, specs) geom.center(mono) geom.update_all(mono) mono.cell_df["prefered_vol"] = 1.0 mono.cell_df["prefered_area"] = 1.0 shrink(mono, 0, 0.2) assert round(mono.cell_df.loc[0, "prefered_vol"], 4) == 0.8333 assert round(mono.cell_df.loc[0, "prefered_area"], 4) == 0.8855
def test_effector(): sheet_dsets, specs = three_faces_sheet() sheet = Sheet("test", sheet_dsets, specs) mono = Monolayer.from_flat_sheet("test", sheet, config.geometry.bulk_spec()) testing.effector_tester(mono, BorderElasticity)
def test_cell_cell_connectivity(): data, _ = three_faces_sheet() mono = Monolayer("test", extrude(data), bulk_spec()) ccc = connectivity.cell_cell_connectivity(mono) expected = np.array([[0, 36, 36], [36, 0, 36], [36, 36, 0]]) np.testing.assert_array_equal(ccc, expected)
def test_models(): sheet_dsets, specs = three_faces_sheet() sheet = Sheet("test", sheet_dsets, specs) mono = Monolayer.from_flat_sheet("test", sheet, config.geometry.bulk_spec()) testing.model_tester(mono, BulkModel) testing.model_tester(mono, BulkModelwithFreeBorders)
def test_contract(): specs = config.geometry.bulk_spec() sheet = Sheet.planar_sheet_3d("flat", 4, 5, 1, 1) sheet.sanitize() datasets = extrude(sheet.datasets, method="translation") mono = Monolayer("mono", datasets, specs) geom.center(mono) geom.update_all(mono) mono.face_df["contractility"] = 1.0 assert len(mono.face_df.contractility.unique()) == 1 faces = mono.edge_df[mono.edge_df["cell"] == 0]["face"].unique() for f in faces: contract(mono, f, 0.2) assert len(mono.face_df.contractility.unique()) == 2 for f in faces: assert mono.face_df.loc[f, "contractility"] == 1.2
def test_models(): sheet_dsets, specs = three_faces_sheet() sheet = Sheet("test", sheet_dsets, specs) mono = Monolayer.from_flat_sheet("test", sheet, config.geometry.bulk_spec()) testing.model_tester(mono, BulkModel) testing.model_tester(mono, BulkModelwithFreeBorders) datasets = load_datasets( Path(stores_dir) / "small_ellipsoid.hf5", data_names=["vert", "edge", "face", "cell"], ) specs = config.geometry.bulk_spec() monolayer = Monolayer("ell", datasets, specs) testing.model_tester(mono, ClosedMonolayerModel)
def test_cell_centered_patch(): grid = hexa_grid2d(6, 4, 3, 3) datasets = from_2d_voronoi(Voronoi(grid)) _ = Sheet("test", datasets) extruded = extrude(datasets, method="translation") mono = Monolayer("test", extruded, config.geometry.bulk_spec()) submono = utils.cell_centered_patch(mono, 5, 1) assert submono.Nc == 4
def test_effectors(): sheet_dsets, specs = three_faces_sheet() sheet = Sheet("test", sheet_dsets, specs) mono = Monolayer.from_flat_sheet("test", sheet, config.geometry.bulk_spec()) for effector in sheet_effectors: testing.effector_tester(sheet, effector) for effector in bulk_effectors: testing.effector_tester(mono, effector)
def test_face_centered_patch(): grid = hexa_grid2d(6, 4, 3, 3) datasets = from_2d_voronoi(Voronoi(grid)) sheet = Sheet("test", datasets) subsheet = utils.face_centered_patch(sheet, 5, 2) assert subsheet.Nf == 6 extruded = extrude(datasets, method="translation") mono = Monolayer("test", extruded, config.geometry.bulk_spec()) submono = utils.face_centered_patch(mono, 15, 1) assert submono.Nf == 19
def test_HI_transition(): sheet = Sheet.planar_sheet_3d("sheet", 5, 5, 1, 1) sheet.sanitize() datasets = extrude(sheet.datasets, method="translation") eptm = Monolayer("test_HIt", datasets, bulk_spec()) BulkGeometry.update_all(eptm) Nc, Nf, Ne, Nv = eptm.Nc, eptm.Nf, eptm.Ne, eptm.Nv eptm.settings["threshold_length"] = 1e-3 IH_transition(eptm, 26) BulkGeometry.update_all(eptm) face = eptm.face_df.index[-1] HI_transition(eptm, face) assert eptm.Nc == Nc assert eptm.Nf == Nf assert eptm.Ne == Ne assert eptm.Nv == Nv invalid = eptm.get_invalid() assert np.alltrue(1 - invalid) assert np.alltrue(eptm.edge_df["sub_vol"] > 0)
def test_IH_transition(): sheet = Sheet.planar_sheet_3d("sheet", 5, 5, 1, 1) sheet.sanitize() datasets = extrude(sheet.datasets, method="translation") eptm = Monolayer("test_IHt", datasets, bulk_spec()) BulkGeometry.update_all(eptm) Nc, Nf, Ne, Nv = eptm.Nc, eptm.Nf, eptm.Ne, eptm.Nv eptm.settings["threshold_length"] = 1e-3 IH_transition(eptm, 26) BulkGeometry.update_all(eptm) assert eptm.Nc == Nc assert eptm.Nf == Nf + 2 assert eptm.Ne == Ne + 12 assert eptm.Nv == Nv + 1 invalid = eptm.get_invalid() assert np.alltrue(1 - invalid) assert np.alltrue(eptm.edge_df["sub_vol"] > 0) assert ( eptm.face_df[eptm.face_df.segment == "apical"].shape[0] == eptm.cell_df.shape[0] )
def test_monolayer_division(): datasets_2d, _ = three_faces_sheet(zaxis=True) datasets = extrude(datasets_2d, method="translation") eptm = Monolayer("test_volume", datasets, bulk_spec(), coords=["x", "y", "z"]) eptm.vert_df[eptm.coords] += np.random.normal(scale=1e-6, size=(eptm.Nv, 3)) MonolayerGeometry.update_all(eptm) for orientation in ["vertical", "horizontal", "apical"]: monolayer_division(eptm, 0, orientation=orientation) eptm.reset_topo() eptm.reset_index() assert eptm.validate() assert eptm.Nc == 6
def test_monolayer(): sheet = Sheet("test", *three_faces_sheet()) mono = Monolayer.from_flat_sheet("test", sheet, config.geometry.bulk_spec()) assert_array_equal(mono.apical_verts.values, np.arange(13)) assert_array_equal(mono.basal_verts.values, np.arange(13) + 13) assert_array_equal(mono.apical_edges.values, np.arange(18)) assert_array_equal(mono.basal_edges.values, np.arange(18) + 18) assert_array_equal(mono.lateral_edges.values, np.arange(72) + 36) assert_array_equal(mono.apical_faces.values, np.arange(3)) assert_array_equal(mono.basal_faces.values, np.arange(3) + 3) assert_array_equal(mono.lateral_faces.values, np.arange(18) + 6)
def test_monolayer_division(): datasets_2d, specs = three_faces_sheet(zaxis=True) datasets = extrude(datasets_2d, method="translation") eptm = Monolayer("test_volume", datasets, bulk_spec(), coords=["x", "y", "z"]) MonoLayerGeometry.update_all(eptm) for orientation in ["vertical", "horizontal"]: daughter = cell_division(eptm, 0, orientation=orientation) eptm.reset_topo() eptm.reset_index() assert eptm.validate() assert eptm.Nc == 5
def test_close_two_holes(): dsets = hdf5.load_datasets(Path(stores_dir) / "small_ellipsoid.hf5") mono = Monolayer("4", dsets) cell = mono.cell_df.query("num_faces != 4").index[0] edges = mono.edge_df.query(f"cell == {cell}") faces = edges["face"].iloc[[0, 8]] face_edges = edges[edges["face"].isin(faces)].index mono.face_df.drop(faces, axis=0, inplace=True) mono.edge_df.drop(face_edges, axis=0, inplace=True) mono.reset_index() mono.reset_topo() with pytest.raises(ValueError): close_cell(mono, cell)
def test_face_face_connectivity(): data, specs = three_faces_sheet() sheet = Sheet("test", data, specs) ffc = connectivity.face_face_connectivity(sheet, exclude_opposites=False) expected = np.array([[0, 2, 2], [2, 0, 2], [2, 2, 0]]) np.testing.assert_array_equal(ffc, expected) ffc = connectivity.face_face_connectivity(sheet, exclude_opposites=True) expected = np.array([[0, 2, 2], [2, 0, 2], [2, 2, 0]]) np.testing.assert_array_equal(ffc, expected) mono = Monolayer("test", extrude(data), bulk_spec()) ffc = connectivity.face_face_connectivity(mono, exclude_opposites=False) assert ffc[0][ffc[0] == 2].shape == (10, ) assert ffc[0][ffc[0] == 1].shape == (4, ) assert ffc.max() == 4 ffc = connectivity.face_face_connectivity(mono, exclude_opposites=True) assert ffc[0][ffc[0] == 2].shape == (10, ) assert ffc[0][ffc[0] == 1].shape == (4, ) assert ffc.max() == 2
def test_bulk_division(): cells = hexa_grid3d(4, 4, 6) datasets = from_3d_voronoi(Voronoi(cells)) specs = bulk_spec() bulk = Epithelium("bulk", datasets, specs) bulk.reset_topo() bulk.reset_index() bulk.sanitize() bulk.reset_topo() bulk.reset_index() cell_division(bulk, 4, BulkGeometry) dsets = hdf5.load_datasets(Path(stores_dir) / "with_4sided_cell.hf5") bulk = Monolayer("4", dsets) BulkGeometry.update_all(bulk) # daughter = cell_division(bulk, 12, BulkGeometry) with pytest.warns(UserWarning): cell_division(bulk, 4, BulkGeometry) assert bulk.validate()
def get_initial_follicle(specs, recreate=False, Nc=200): """Retrieves or recreates a spherical epithelium""" if recreate: ## Lloy_relax=True takes time but should give more spherical epithelium follicle = spherical_monolayer(9.0, 12.0, Nc, apical="in", Lloyd_relax=True) geom.update_all(follicle) geom.scale(follicle, follicle.cell_df.vol.mean() ** (-1 / 3), list("xyz")) geom.update_all(follicle) else: follicle = Monolayer("follicle", hdf5.load_datasets("initial_follicle.hf5")) follicle.settings["lumen_side"] = "apical" geom.update_all(follicle) follicle.update_specs(specs, reset=True) follicle.cell_df["id"] = follicle.cell_df.index wgeom = WAMonolayerGeometry model = model_factory( [ effectors.LumenVolumeElasticity, WeightedCellAreaElasticity, effectors.CellVolumeElasticity, ] ) print("Finding static equilibrium") follicle.face_df.loc[follicle.apical_faces, "weight"] = specs["settings"][ "apical_weight" ] wgeom.update_all(follicle) solver = QSSolver() res = solver.find_energy_min(follicle, wgeom, model) return follicle, model
def test_close_cell(): dsets = hdf5.load_datasets(Path(stores_dir) / "with_4sided_cell.hf5") mono = Monolayer("4", dsets) cell = mono.cell_df.query("num_faces != 4").index[0] Nfi = mono.cell_df.loc[cell, "num_faces"] Nei = mono.Ne edges = mono.edge_df.query(f"cell == {cell}") face = edges["face"].iloc[0] face_edges = edges.query(f"face == {face}").index Nsi = len(face_edges) mono.face_df.drop(face, axis=0, inplace=True) mono.edge_df.drop(face_edges, axis=0, inplace=True) mono.reset_index() mono.reset_topo() assert mono.cell_df.loc[cell, "num_faces"] == Nfi - 1 assert mono.Ne == Nei - Nsi res = close_cell(mono, cell) MonolayerGeometry.update_all(mono) mono.reset_index() mono.reset_topo() assert not res assert mono.validate() assert mono.cell_df.loc[cell, "num_faces"] == Nfi assert mono.Ne == Nei
def test_constriction(): specs = config.geometry.bulk_spec() sheet = Sheet.planar_sheet_3d("flat", 6, 8, 1, 1) sheet.sanitize() datasets = extrude(sheet.datasets, method="translation") mono = Monolayer("mono", datasets, specs) geom.center(mono) geom.update_all(mono) dyn_specs = config.dynamics.quasistatic_bulk_spec() dyn_specs["cell"]["area_elasticity"] = 0.05 dyn_specs["cell"]["prefered_area"] = 6.0 dyn_specs["cell"]["vol_elasticity"] = 1.0 dyn_specs["cell"]["prefered_vol"] = 1.2 dyn_specs["face"]["contractility"] = 0.0 dyn_specs["edge"]["line_tension"] = 0.0 mono.update_specs(dyn_specs, reset=True) mono.face_df.loc[mono.apical_faces, "contractility"] = 1.12 mono.face_df.loc[mono.basal_faces, "contractility"] = 1.12 manager = EventManager("face") sheet.face_df["enter_in_process"] = 0 mono.settings["constriction"] = {} mono.cell_df["is_mesoderm"] = False mono.face_df["is_mesoderm"] = False cell_to_constrict = [12] apical_face = mono.face_df[(mono.face_df.index.isin( mono.get_orbits("cell", "face")[cell_to_constrict[0]])) & (mono.face_df.segment == "apical")].index[0] mono.cell_df.loc[cell_to_constrict, "is_mesoderm"] = True mono.cell_df["id"] = mono.cell_df.index.values mono.face_df["id"] = mono.face_df.index.values list_face_in_cell = mono.get_orbits("cell", "face") cell_in_mesoderm = mono.cell_df[mono.cell_df.is_mesoderm].index.values for i in cell_in_mesoderm: faces_in_cell = mono.face_df.loc[list_face_in_cell[i].unique()] for f in faces_in_cell.index.values: mono.face_df.loc[f, "is_mesoderm"] = True for i in cell_to_constrict: delam_kwargs = mono.settings["constriction"].copy() delam_kwargs.update({ "cell_id": i, "contract_rate": 2, "critical_area": 0.02, "shrink_rate": 0.4, "critical_volume": 0.1, "radial_tension": 3, "max_traction": 35, "contract_neighbors": True, "contract_span": 1, "with_rearrangement": True, "critical_area_reduction": 5, }) initial_cell_event = [(constriction, delam_kwargs)] manager.extend(initial_cell_event) manager.execute(mono) manager.update() assert len(manager.current) == 1 i = 0 while i < 10: manager.execute(mono) manager.update() i = i + 1 assert mono.face_df.loc[apical_face, "contractility"] > 1.0 for c in cell_to_constrict: assert mono.cell_df.loc[c, "num_faces"] <= 4