-
Notifications
You must be signed in to change notification settings - Fork 4
Mutate Patch Action #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
allison-li-1016
wants to merge
5
commits into
main
Choose a base branch
from
allison/mutate-action
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mutate Patch Action #214
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
895ba12
initial push of mutate action file
allison-li-1016 7d6ead5
update javadoc descipton
allison-li-1016 fdb895b
adding option in simulation files so action can actually be called
allison-li-1016 b0b281e
editing docstring and intuitive variable names, adding default param …
allison-li-1016 bea52c2
Merge branch 'main' into allison/mutate-action
allison-li-1016 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| package arcade.patch.agent.action; | ||
|
|
||
| import java.util.ArrayList; | ||
| import sim.engine.Schedule; | ||
| import sim.engine.SimState; | ||
| import sim.util.Bag; | ||
| import arcade.core.agent.action.Action; | ||
| import arcade.core.env.location.Location; | ||
| import arcade.core.sim.Series; | ||
| import arcade.core.sim.Simulation; | ||
| import arcade.core.util.MiniBox; | ||
| import arcade.patch.agent.cell.PatchCell; | ||
| import arcade.patch.agent.cell.PatchCellContainer; | ||
| import arcade.patch.env.grid.PatchGrid; | ||
| import arcade.patch.env.location.Coordinate; | ||
| import arcade.patch.sim.PatchSeries; | ||
| import arcade.patch.sim.PatchSimulation; | ||
| import static arcade.patch.util.PatchEnums.Ordering; | ||
|
|
||
| /** | ||
| * Implementation of {@link Action} for converting cells to a different class. | ||
| * | ||
| * <p>The action is stepped once after {@code TIME_DELAY}. The action will convert all the healthy | ||
| * tissue cells within the given radius into cancer cells. | ||
| */ | ||
| public class PatchActionMutate implements Action { | ||
| /** Time delay before calling the action [min]. */ | ||
| private final int timeDelay; | ||
|
|
||
| /** Grid radius where cells are mutated. */ | ||
| private final int mutateRadius; | ||
|
|
||
| /** Population code for cancer. */ | ||
| private int cancerPop; | ||
|
|
||
| /** Population code for healthy cells. */ | ||
| private int healthyPop; | ||
|
|
||
| /** Grid depth that cells are mutated. */ | ||
| private final int mutateDepth; | ||
|
|
||
| /** | ||
| * Creates a {@link Action} for converting healthy cell agents into cancer cell agents. | ||
| * | ||
| * <p>Loaded parameters include: | ||
| * | ||
| * <ul> | ||
| * <li>{@code TIME_DELAY} = time delay before calling the action | ||
| * <li>{@code MUTATE_RADIUS} = grid radius where cells are mutated | ||
| * <li>{@code MUTATE_DEPTH} = grid depth that cells are mutated | ||
| * </ul> | ||
| * | ||
| * @param series the simulation series | ||
| * @param parameters the component parameters dictionary | ||
| */ | ||
| public PatchActionMutate(Series series, MiniBox parameters) { | ||
| // Set loaded parameters. | ||
| timeDelay = parameters.getInt("TIME_DELAY"); | ||
| mutateRadius = parameters.getInt("MUTATE_RADIUS"); | ||
| mutateDepth = ((PatchSeries) series).depth; | ||
| healthyPop = -1; | ||
| cancerPop = -1; | ||
| // Grab popuation codes for healthy and cancer cells. | ||
| for (String popName : series.populations.keySet()) { | ||
| if (series.populations.get(popName).get("CLASS").contains("tissue")) { | ||
| healthyPop = series.populations.get(popName).getInt("CODE"); | ||
| } else if (series.populations.get(popName).get("CLASS").contains("cancer_stem") | ||
| || series.populations.get(popName).get("CLASS").contains("cancer")) { | ||
| cancerPop = series.populations.get(popName).getInt("CODE"); | ||
| } | ||
| } | ||
| if (healthyPop == -1 || cancerPop == -1) { | ||
| throw new IllegalArgumentException( | ||
| "Please initialize both healthy and cancer populations in input file."); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void schedule(Schedule schedule) { | ||
| schedule.scheduleOnce(timeDelay, Ordering.ACTIONS.ordinal(), this); | ||
| } | ||
|
|
||
| @Override | ||
| public void register(Simulation sim, String population) {} | ||
|
|
||
| @Override | ||
| public void step(SimState simstate) { | ||
| PatchSimulation sim = (PatchSimulation) simstate; | ||
| PatchGrid grid = (PatchGrid) sim.getGrid(); | ||
|
|
||
| // Get cells at center of simulation. | ||
| ArrayList<Coordinate> coordinates = | ||
| sim.locationFactory.getCoordinates(mutateRadius, mutateDepth); | ||
| for (Coordinate coordinate : coordinates) { | ||
| Bag bag = (Bag) grid.getObjectAt(coordinate.hashCode()); | ||
|
|
||
| if (bag == null) { | ||
| continue; | ||
| } | ||
|
|
||
| for (int i = 0; i < bag.numObjs; i++) { | ||
| // Select old cell and remove from simulation. | ||
|
allison-li-1016 marked this conversation as resolved.
|
||
| PatchCell oldCell = (PatchCell) bag.get(i); | ||
| // Only remove and mutate if cell is healthy. | ||
| if (oldCell.getPop() == healthyPop) { | ||
| Location location = oldCell.getLocation(); | ||
| grid.removeObject(oldCell, oldCell.getLocation()); | ||
| oldCell.stop(); | ||
|
|
||
| // Create new cancer cell and add to simulation. | ||
| PatchCellContainer cellContainer = | ||
| new PatchCellContainer( | ||
| oldCell.getID(), | ||
| oldCell.getParent(), | ||
| cancerPop, | ||
| oldCell.getAge(), | ||
| oldCell.getDivisions(), | ||
| oldCell.getState(), | ||
| oldCell.getVolume(), | ||
| oldCell.getHeight(), | ||
| oldCell.getCriticalVolume(), | ||
| oldCell.getCriticalHeight()); | ||
| PatchCell newCell = | ||
| (PatchCell) | ||
| cellContainer.convert(sim.cellFactory, location, sim.random); | ||
| grid.addObject(newCell, location); | ||
| newCell.schedule(sim.getSchedule()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.