Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/arcade/patch/PatchARCADE.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public OutputSaver getSaver(Series series) {
PatchOutputSaver saver = new PatchOutputSaver(series);
saver.saveGraph = settings.contains("SAVE_GRAPH");
saver.saveLattice = settings.contains("SAVE_LAYERS");
saver.saveEvents = settings.contains("SAVE_EVENTS");
return saver;
}
}
16 changes: 16 additions & 0 deletions src/arcade/patch/agent/module/PatchModuleCytotoxicity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package arcade.patch.agent.module;

import java.util.HashMap;
import java.util.Map;
import ec.util.MersenneTwisterFast;
import arcade.core.sim.Simulation;
import arcade.core.util.Parameters;
import arcade.patch.agent.cell.PatchCell;
import arcade.patch.agent.cell.PatchCellCART;
import arcade.patch.agent.cell.PatchCellTissue;
import arcade.patch.agent.process.PatchProcessInflammation;
import arcade.patch.env.location.PatchLocation;
import arcade.patch.sim.PatchSimulation;
import static arcade.patch.util.PatchEnums.Domain;
import static arcade.patch.util.PatchEnums.State;

Expand Down Expand Up @@ -68,6 +72,18 @@ public void step(MersenneTwisterFast random, Simulation sim) {
tissueCell.setState(State.APOPTOTIC);
granzyme--;
inflammation.setInternal("granzyme", granzyme);

// Log cytotoxicity event
PatchSimulation patchSim = (PatchSimulation) sim;
Map<String, Object> eventData = new HashMap<>();
eventData.put("t-cell-id", cell.getID());
eventData.put("tissue-cell-id", target.getID());
eventData.put("tissue-cell-type", target.getPop());
eventData.put("type", "lysis");
eventData.put("timestamp", (int) ((PatchSimulation) sim).getSchedule().getTime());
eventData.put(
"tissue-location", ((PatchLocation) target.getLocation()).getCoordinate());
patchSim.logEvent(eventData);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/arcade/patch/command.patch.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<commands>
<switch id="SAVE_GRAPH" short="g" long="graph" help="Save the GRAPH output files" />
<switch id="SAVE_LAYERS" short="l" long="layers" help="Save the LAYERS output files" />
<switch id="SAVE_EVENTS" short="e" long="events" help="Save the EVENTS output files" />
</commands>
24 changes: 24 additions & 0 deletions src/arcade/patch/sim/PatchSimulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.gson.reflect.TypeToken;
import sim.engine.Schedule;
Expand Down Expand Up @@ -55,6 +57,9 @@ public abstract class PatchSimulation extends SimState implements Simulation {
/** Cell ID tracker. */
int id;

/** List to store events throughout the simulation. */
private final List<Map<String, Object>> events;

/** Location factory instance for the simulation. */
public final PatchLocationFactory locationFactory;

Expand All @@ -81,6 +86,7 @@ public PatchSimulation(long seed, Series series) {
this.locationFactory = makeLocationFactory();
this.cellFactory = makeCellFactory();
this.latticeFactory = makeLatticeFactory();
this.events = new ArrayList<>();
}

@Override
Expand Down Expand Up @@ -214,6 +220,24 @@ public Set<Location> getAllLocations() {
return locations;
}

/**
* Log an event to the simulation's event list.
*
* @param event logging information corresponding to the event
*/
public void logEvent(Map<String, Object> event) {
events.add(event);
}

/**
* Get the list of events logged during the simulation.
*
* @return the list of events
*/
public List<Map<String, Object>> getEvents() {
return new ArrayList<>(events);
}

/**
* Called at the start of the simulation to set up agents and environment and schedule actions
* and components as needed.
Expand Down
24 changes: 24 additions & 0 deletions src/arcade/patch/sim/output/PatchOutputSaver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package arcade.patch.sim.output;

import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import arcade.core.env.component.Component;
import arcade.core.sim.Series;
Expand All @@ -17,6 +19,9 @@ public final class PatchOutputSaver extends OutputSaver {
/** {@code true} to save lattices, {@code false} otherwise. */
public boolean saveLattice;

/** {@code true} to save events, {@code false} otherwise. */
public boolean saveEvents;

/**
* Creates an {@code PatchOutputSaver} for the series.
*
Expand Down Expand Up @@ -61,6 +66,22 @@ public void saveLayers(int tick) {
write(patch, format(json, FORMAT_ELEMENTS));
}

/**
* Save the collection of events to a JSON.
*
* @param tick the simulation tick
*/
public void saveEventsToFile(int tick) {
if (saveEvents) {
List<Map<String, Object>> events = ((PatchSimulation) sim).getEvents();
if (!events.isEmpty()) {
String json = gson.toJson(events);
String path = prefix + String.format("_%06d.EVENTS.json", tick);
write(path, format(json, FORMAT_ELEMENTS));
}
}
}

@Override
public void save(int tick) {
super.save(tick);
Expand All @@ -70,5 +91,8 @@ public void save(int tick) {
if (saveLattice) {
saveLayers(tick);
}
if (saveEvents) {
saveEventsToFile(tick);
}
}
}
18 changes: 18 additions & 0 deletions test/arcade/patch/agent/module/PatchModuleCytotoxicityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import java.lang.reflect.Field;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import sim.engine.Schedule;
import ec.util.MersenneTwisterFast;
import arcade.core.util.Parameters;
import arcade.patch.agent.cell.PatchCellCART;
import arcade.patch.agent.cell.PatchCellTissue;
import arcade.patch.agent.process.PatchProcessInflammation;
import arcade.patch.env.location.Coordinate;
import arcade.patch.env.location.PatchLocation;
import arcade.patch.sim.PatchSimulation;
import arcade.patch.util.PatchEnums.State;
import static org.mockito.Mockito.*;
Expand All @@ -24,13 +27,20 @@ public class PatchModuleCytotoxicityTest {

private PatchSimulation sim;

private PatchLocation mockLocation;

private Schedule mockSchedule;

private MersenneTwisterFast randomMock;

@BeforeEach
public final void setUp() {
mockCell = mock(PatchCellCART.class);
mockTarget = mock(PatchCellTissue.class);
mockInflammation = mock(PatchProcessInflammation.class);
mockLocation = mock(PatchLocation.class);
mockSchedule = mock(Schedule.class);

sim = mock(PatchSimulation.class);
randomMock = mock(MersenneTwisterFast.class);
Parameters parameters = mock(Parameters.class);
Expand All @@ -41,6 +51,14 @@ public final void setUp() {
when(mockCell.getProcess(any())).thenReturn(mockInflammation);
when(mockInflammation.getInternal("granzyme")).thenReturn(1.0);
when(mockCell.getBoundTarget()).thenReturn(mockTarget);
when(mockCell.getID()).thenReturn(1);
when(mockTarget.getID()).thenReturn(1);
when(mockTarget.getPop()).thenReturn(1);
when(mockTarget.getLocation()).thenReturn(mockLocation);

when(mockLocation.getCoordinate()).thenReturn(mock(Coordinate.class));
when(sim.getSchedule()).thenReturn(mockSchedule);
when(mockSchedule.getTime()).thenReturn(0.0);

action = new PatchModuleCytotoxicity(mockCell);
}
Expand Down
Loading