Skip to content

Commit

Permalink
Make PottsCell Abstract Class (#13)
Browse files Browse the repository at this point in the history
* Broke setState into two functions so in future setStateModule can be implemented differently by different cell types

* added divisions setter for use in future subclass make functions

* added getCriticalRegionVolumes and Heights for use in future subclass cell constructors

* changed parameter name to overcome HiddenFieldCheck error

* added Javadoc comments on new getters and setters

* changed parameter name in setStateModule to overcome hidden field error. Formatting fix.

* added getter and setter tests. formatting fix

* formatting fix

* deleted getters/setters. Made necessary fields not public. Deleted associated tests

* deleted unnecessary imports and formatting fix

* made fields that alread had getters public so no elements of PottsCell constructor need to be accessed via getters

* typo fix

* deleted unnecessary import and formatting fix

* made PottsCell abstract class. Made default cell type PottsCellStem. Changed PottsCell tests to be PottsCellStem tests. Changed PottsCellContainer to default to making PottsCellStem cells

* fixed merge issues

* Moved assignment of potts cell class when none specified to PottsSeries. Deleted abstract make in PottsCell. Casted to PottsCell in PottsModule

* updated parameters mock to return stem when parameters.get(CLASS) is called

* Moved PottsCell make, state, and module tests into PottsCellStemTest. Made mock implementation of PottsCell for PottsCellTest

* added content to PottsSeriesTest to make sure class is set to stem as default and to a given string if a given string is provided

* Finished adjusting PottsSeriesTest to test for default cell class being set

* formatting fixes

* Addressing Jessica's comments

* formattig fixes

* removing code comments

* added ability to assign one real state to PottsCellMock for testing purposes

* formatting fix

* added mocks for PottsModule getPhase return in PottsCellTest tests

* formatting

* Fix minor formatting and move remaining make test to PottsCellStem

---------

Co-authored-by: jessicasyu <[email protected]>
  • Loading branch information
Jannetty and jessicasyu committed Jul 30, 2024
1 parent f15f446 commit 1c6b1bb
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 187 deletions.
42 changes: 2 additions & 40 deletions src/arcade/potts/agent/cell/PottsCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sim.engine.Schedule;
import sim.engine.SimState;
import sim.engine.Stoppable;
import ec.util.MersenneTwisterFast;
import arcade.core.agent.cell.Cell;
import arcade.core.agent.cell.CellContainer;
import arcade.core.agent.cell.CellState;
Expand All @@ -15,15 +14,9 @@
import arcade.core.sim.Simulation;
import arcade.core.util.MiniBox;
import arcade.potts.agent.module.PottsModule;
import arcade.potts.agent.module.PottsModuleApoptosisSimple;
import arcade.potts.agent.module.PottsModuleAutosis;
import arcade.potts.agent.module.PottsModuleNecrosis;
import arcade.potts.agent.module.PottsModuleProliferationSimple;
import arcade.potts.agent.module.PottsModuleQuiescence;
import arcade.potts.env.location.PottsLocation;
import static arcade.potts.util.PottsEnums.Ordering;
import static arcade.potts.util.PottsEnums.Region;
import static arcade.potts.util.PottsEnums.State;

/**
* Implementation of {@link Cell} for potts models.
Expand All @@ -46,7 +39,7 @@
* by the specific Hamiltonian class instance.
*/

public final class PottsCell implements Cell {
public abstract class PottsCell implements Cell {
/** Stopper used to stop this agent from being stepped in the schedule. */
Stoppable stopper;

Expand Down Expand Up @@ -303,15 +296,6 @@ public double getCriticalHeight(Region region) {
@Override
public void stop() { stopper.stop(); }

@Override
public PottsCell make(int newID, CellState newState, Location newLocation,
MersenneTwisterFast random) {
divisions++;
return new PottsCell(newID, id, pop, newState, age, divisions, newLocation,
hasRegions, parameters, criticalVolume, criticalHeight,
criticalRegionVolumes, criticalRegionHeights);
}

@Override
public void setState(CellState newState) {
this.state = newState;
Expand All @@ -323,29 +307,7 @@ public void setState(CellState newState) {
*
* @param newState the cell state
*/
public void setStateModule(CellState newState) {
switch ((State) newState) {
case QUIESCENT:
module = new PottsModuleQuiescence(this);
break;
case PROLIFERATIVE:
module = new PottsModuleProliferationSimple(this);
break;
case APOPTOTIC:
module = new PottsModuleApoptosisSimple(this);
break;
case NECROTIC:
module = new PottsModuleNecrosis(this);
break;
case AUTOTIC:
module = new PottsModuleAutosis(this);
break;
default:
// State must be one of the above cases.
module = null;
break;
}
}
abstract void setStateModule(CellState newState);

@Override
public void schedule(Schedule schedule) {
Expand Down
21 changes: 12 additions & 9 deletions src/arcade/potts/agent/cell/PottsCellContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,18 @@ private Cell convert(PottsCellFactory factory, Location location) {

// Make cell.
PottsCell cell;

if (factory.popToRegions.get(pop)) {
cell = new PottsCell(id, parent, pop, state, age, divisions,
location, true, parameters, criticalVolume, criticalHeight,
criticalRegionVolumes, criticalRegionHeights);
} else {
cell = new PottsCell(id, parent, pop, state, age, divisions,
location, false, parameters, criticalVolume, criticalHeight,
null, null);
switch (parameters.get("CLASS")) {
default:
case "stem":
if (factory.popToRegions.get(pop)) {
cell = new PottsCellStem(id, parent, pop, state, age, divisions,
location, true, parameters, criticalVolume, criticalHeight,
criticalRegionVolumes, criticalRegionHeights);
} else {
cell = new PottsCellStem(id, parent, pop, state, age, divisions,
location, false, parameters, criticalVolume, criticalHeight,
null, null);
}
}

// Update cell module.
Expand Down
82 changes: 82 additions & 0 deletions src/arcade/potts/agent/cell/PottsCellStem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package arcade.potts.agent.cell;

import java.util.EnumMap;
import ec.util.MersenneTwisterFast;
import arcade.core.agent.cell.CellState;
import arcade.core.env.location.Location;
import arcade.core.util.MiniBox;
import arcade.potts.agent.module.PottsModuleApoptosisSimple;
import arcade.potts.agent.module.PottsModuleAutosis;
import arcade.potts.agent.module.PottsModuleNecrosis;
import arcade.potts.agent.module.PottsModuleProliferationSimple;
import arcade.potts.agent.module.PottsModuleQuiescence;
import static arcade.potts.util.PottsEnums.Region;
import static arcade.potts.util.PottsEnums.State;

/**
* Extension of {@link PottsCell} for stem cells.
* <p>
* This is the default cell type for Potts models.
*/
public final class PottsCellStem extends PottsCell {

/**
* Creates a {@code PottsCellStem} agent.
*
* @param id the cell ID
* @param parent the parent ID
* @param pop the cell population index
* @param state the cell state
* @param age the cell age
* @param divisions the number of cell divisions
* @param location the {@link Location} of the cell
* @param hasRegions {@code true} if cell has regions, {@code false} otherwise
* @param parameters the dictionary of parameters
* @param criticalVolume the critical cell volume
* @param criticalHeight the critical cell height
* @param criticalRegionVolumes the map of critical volumes for regions
* @param criticalRegionHeights the map of critical heights for regions
*/
public PottsCellStem(int id, int parent, int pop, CellState state, int age, int divisions,
Location location, boolean hasRegions, MiniBox parameters,
double criticalVolume, double criticalHeight,
EnumMap<Region, Double> criticalRegionVolumes,
EnumMap<Region, Double> criticalRegionHeights) {
super(id, parent, pop, state, age, divisions, location, hasRegions, parameters,
criticalVolume, criticalHeight, criticalRegionVolumes, criticalRegionHeights);
}

@Override
public PottsCell make(int newID, CellState newState, Location newLocation,
MersenneTwisterFast random) {
divisions++;
return new PottsCellStem(newID, id, pop, newState, age, divisions, newLocation,
hasRegions, parameters, criticalVolume, criticalHeight,
criticalRegionVolumes, criticalRegionHeights);
}

@Override
void setStateModule(CellState newState) {
switch ((State) newState) {
case QUIESCENT:
module = new PottsModuleQuiescence(this);
break;
case PROLIFERATIVE:
module = new PottsModuleProliferationSimple(this);
break;
case APOPTOTIC:
module = new PottsModuleApoptosisSimple(this);
break;
case NECROTIC:
module = new PottsModuleNecrosis(this);
break;
case AUTOTIC:
module = new PottsModuleAutosis(this);
break;
default:
// State must be one of the above cases.
module = null;
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void addCell(MersenneTwisterFast random, Simulation sim) {

// Create and schedule new cell.
int newID = sim.getID();
PottsCell newCell = cell.make(newID, State.PROLIFERATIVE, newLocation, random);
PottsCell newCell = (PottsCell) cell.make(newID, State.PROLIFERATIVE, newLocation, random);
sim.getGrid().addObject(newCell, null);
potts.register(newCell);
newCell.reset(potts.ids, potts.regions);
Expand Down
9 changes: 9 additions & 0 deletions src/arcade/potts/sim/PottsSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public final class PottsSeries extends Series {
/** Separator character for targets. */
public static final String TARGET_SEPARATOR = ":";

/** Default cell class. */
public static final String DEFAULT_CELL_CLASS = "stem";

/** Map of potts settings. */
public MiniBox potts;

Expand Down Expand Up @@ -184,6 +187,12 @@ protected void updatePopulations(ArrayList<Box> populationsBox, MiniBox populati
String id = box.getValue("id");
String populationClass = box.getValue("class");

if (populationClass == null) {
populationClass = DEFAULT_CELL_CLASS;
}

// TODO: Use logger to print message when default class is used.

Check failure on line 194 in src/arcade/potts/sim/PottsSeries.java

View workflow job for this annotation

GitHub Actions / checkstyle

[checkstyle] src/arcade/potts/sim/PottsSeries.java#L194 <com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck>

Comment matches to-do format 'TODO:'.
Raw output
/github/workspace/./src/arcade/potts/sim/PottsSeries.java:194:15: error: Comment matches to-do format 'TODO:'. (com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck)

// Create new population and update code.
MiniBox population = new MiniBox();
population.put("CODE", code++);
Expand Down
2 changes: 2 additions & 0 deletions test/arcade/potts/agent/cell/PottsCellContainerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void convert_noRegions_createsObject() {
double criticalVolume = randomDoubleBetween(10, 100);
double criticalHeight = randomDoubleBetween(10, 100);
MiniBox parameters = mock(MiniBox.class);
when(parameters.get("CLASS")).thenReturn("");

factory.popToParameters.put(cellPop, parameters);
factory.popToRegions.put(cellPop, false);
Expand Down Expand Up @@ -147,6 +148,7 @@ public void convert_withRegions_createsObject() {
double criticalVolume = randomDoubleBetween(10, 100);
double criticalHeight = randomDoubleBetween(10, 100);
MiniBox parameters = mock(MiniBox.class);
when(parameters.get("CLASS")).thenReturn("");

EnumSet<Region> regionList = EnumSet.of(Region.NUCLEUS, Region.UNDEFINED);
doReturn(regionList).when(location).getRegions();
Expand Down
Loading

0 comments on commit 1c6b1bb

Please sign in to comment.