From 7ddfb2cf2af105d825913574b653ff3bc2f07e19 Mon Sep 17 00:00:00 2001 From: Allison Li Date: Mon, 23 Oct 2023 15:18:08 -0700 Subject: [PATCH] move step() down to TissueCell --- src/arcade/patch/agent/cell/PatchCell.java | 61 ++----------------- .../patch/agent/cell/PatchCellTissue.java | 58 ++++++++++++++++++ test/arcade/patch/util/PatchEnumsTest.java | 23 +++++++ 3 files changed, 86 insertions(+), 56 deletions(-) diff --git a/src/arcade/patch/agent/cell/PatchCell.java b/src/arcade/patch/agent/cell/PatchCell.java index 9cf3da4d..213655c3 100644 --- a/src/arcade/patch/agent/cell/PatchCell.java +++ b/src/arcade/patch/agent/cell/PatchCell.java @@ -3,7 +3,6 @@ import java.util.HashMap; import java.util.Map; import sim.engine.Schedule; -import sim.engine.SimState; import sim.engine.Stoppable; import sim.util.Bag; import ec.util.MersenneTwisterFast; @@ -85,7 +84,7 @@ public abstract class PatchCell implements Cell { int age; /** Cell energy [fmol ATP]. */ - private double energy; + double energy; /** Number of divisions. */ int divisions; @@ -103,19 +102,19 @@ public abstract class PatchCell implements Cell { final double criticalHeight; /** Cell state change flag. */ - private Flag flag; + Flag flag; /** Variation in cell agent parameters. */ private final double heterogeneity; /** Fraction of necrotic cells that become apoptotic. */ - private final double necroticFraction; + final double necroticFraction; /** Fraction of senescent cells that become apoptotic. */ - private final double senescentFraction; + final double senescentFraction; /** Maximum energy deficit before necrosis. */ - private final double energyThreshold; + final double energyThreshold; /** Cell state module. */ protected Module module; @@ -309,56 +308,6 @@ public void schedule(Schedule schedule) { stopper = schedule.scheduleRepeating(this, Ordering.CELLS.ordinal(), 1); } - @Override - public void step(SimState simstate) { - Simulation sim = (Simulation) simstate; - - // Increase age of cell. - age++; - - // TODO: check for death due to age - - // Step metabolism process. - processes.get(Domain.METABOLISM).step(simstate.random, sim); - - // Check energy status. If cell has less energy than threshold, it will - // necrose. If overall energy is negative, then cell enters quiescence. - if (state != State.APOPTOTIC && energy < 0) { - if (energy < energyThreshold) { - if (simstate.random.nextDouble() > necroticFraction) { - setState(State.APOPTOTIC); - } else { - setState(State.NECROTIC); - } - } else if (state != State.QUIESCENT && state != State.SENESCENT) { - setState(State.QUIESCENT); - } - } - - // Step signaling network process. - processes.get(Domain.SIGNALING).step(simstate.random, sim); - - // Change state from undefined. - if (state == State.UNDEFINED) { - if (flag == Flag.MIGRATORY) { - setState(State.MIGRATORY); - } else if (divisions == 0) { - if (simstate.random.nextDouble() > senescentFraction) { - setState(State.APOPTOTIC); - } else { - setState(State.SENESCENT); - } - } else { - setState(State.PROLIFERATIVE); - } - } - - // Step the module for the cell state. - if (module != null) { - module.step(simstate.random, sim); - } - } - @Override public CellContainer convert() { return new PatchCellContainer(id, parent, pop, age, divisions, state, diff --git a/src/arcade/patch/agent/cell/PatchCellTissue.java b/src/arcade/patch/agent/cell/PatchCellTissue.java index 5caaae3e..1b349c53 100644 --- a/src/arcade/patch/agent/cell/PatchCellTissue.java +++ b/src/arcade/patch/agent/cell/PatchCellTissue.java @@ -5,6 +5,11 @@ import arcade.core.env.location.Location; import arcade.core.util.MiniBox; +import sim.engine.SimState; +import arcade.core.sim.Simulation; +import static arcade.patch.util.PatchEnums.Domain; +import static arcade.patch.util.PatchEnums.Flag; +import static arcade.patch.util.PatchEnums.State; /** * Extension of {@link PatchCell} for healthy tissue cells. */ @@ -40,4 +45,57 @@ public PatchCell make(int newID, CellState newState, Location newLocation, return new PatchCellTissue(newID, id, pop, newState, age, divisions, newLocation, parameters, volume, height, criticalVolume, criticalHeight); } + + /* consider making PatchCell parameters protected instead of private */ + /* make step() method that overrides main that is moved over from PatchCell */ + + @Override + public void step(SimState simstate) { + Simulation sim = (Simulation) simstate; + + // Increase age of cell. + super.age++; + + // TODO: check for death due to age + + // Step metabolism process. + super.processes.get(Domain.METABOLISM).step(simstate.random, sim); + + // Check energy status. If cell has less energy than threshold, it will + // necrose. If overall energy is negative, then cell enters quiescence. + if (state != State.APOPTOTIC && energy < 0) { + if (super.energy < super.energyThreshold) { + if (simstate.random.nextDouble() > super.necroticFraction) { + super.setState(State.APOPTOTIC); + } else { + super.setState(State.NECROTIC); + } + } else if (state != State.QUIESCENT && state != State.SENESCENT) { + super.setState(State.QUIESCENT); + } + } + + // Step signaling network process. + super.processes.get(Domain.SIGNALING).step(simstate.random, sim); + + // Change state from undefined. + if (super.state == State.UNDEFINED) { + if (super.flag == Flag.MIGRATORY) { + super.setState(State.MIGRATORY); + } else if (super.divisions == 0) { + if (simstate.random.nextDouble() > super.senescentFraction) { + super.setState(State.APOPTOTIC); + } else { + super.setState(State.SENESCENT); + } + } else { + super.setState(State.PROLIFERATIVE); + } + } + + // Step the module for the cell state. + if (super.module != null) { + super.module.step(simstate.random, sim); + } + } } diff --git a/test/arcade/patch/util/PatchEnumsTest.java b/test/arcade/patch/util/PatchEnumsTest.java index 067bc883..22286eaf 100644 --- a/test/arcade/patch/util/PatchEnumsTest.java +++ b/test/arcade/patch/util/PatchEnumsTest.java @@ -1,8 +1,15 @@ package arcade.patch.util; import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumSet; import org.junit.Test; + +import arcade.patch.util.PatchEnums.Category; +import arcade.patch.util.PatchEnums.Domain; +import arcade.patch.util.PatchEnums.Flag; +import arcade.patch.util.PatchEnums.Ordering; +import arcade.patch.util.PatchEnums.State; import ec.util.MersenneTwisterFast; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -101,4 +108,20 @@ public void Category_random_returnsCategory() { EnumSet enumSetRandom = EnumSet.copyOf(enumRandom); assertEquals(enumSet, enumSetRandom); } + + @Test + public void Ordering_in_expected_order() { + // Create list of all values. + ArrayList enumList = new ArrayList(Arrays.asList(Ordering.values())); + + int n = -1; + int verify = -2; + // Grabbing order of items in enum + for (Ordering x: enumList){ + verify = x.ordinal(); + n++; + // Verify order of enum + assertEquals(n, verify); + } + } }