Skip to content

Commit 93bd52e

Browse files
committed
finished implementing all math equations. Next steps: get an initial population of tumor cells & lymphocites before running the algorithm that includes doomed cells, get GIFs and CSV files working, fix the counts
1 parent 5d02058 commit 93bd52e

File tree

1 file changed

+131
-19
lines changed

1 file changed

+131
-19
lines changed

OnLattice2DCells/OnLattice2DGrid.java

+131-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import HAL.Util;
99
import java.lang.Math;
1010
import java.lang.reflect.Field;
11+
import java.util.Arrays;
1112
import java.util.List;
1213
import java.util.ArrayList;
1314
import java.util.Collections;
@@ -33,9 +34,9 @@ public void StepCell(double dieProb, double divProb, int colorIndex)
3334
}
3435
else if (this.color == Util.CategorialColor(TumorCells.colorIndex))
3536
{
37+
this.color = Util.CategorialColor(DoomedCells.colorIndex);
3638
TumorCells.count--;
3739
DoomedCells.count++;
38-
this.color = Util.CategorialColor(DoomedCells.colorIndex);
3940
}
4041
else
4142
{
@@ -44,7 +45,7 @@ else if (this.color == Util.CategorialColor(TumorCells.colorIndex))
4445
}
4546
}
4647

47-
if (G.rng.Double() < divProb)
48+
else if (this.color == Util.CategorialColor(TumorCells.colorIndex) && G.rng.Double() < (dieProb + divProb))
4849
{
4950
int options = MapEmptyHood(G.divHood);
5051
if (options > 0)
@@ -55,18 +56,22 @@ else if (this.color == Util.CategorialColor(TumorCells.colorIndex))
5556
}
5657
}
5758

58-
public void lymphociteMigration(List<int[]> availableSpaces)
59+
public int mapEmptyHood(OnLattice2DGrid G)
60+
{
61+
int options = MapEmptyHood(G.divHood);
62+
return options;
63+
}
64+
65+
public void lymphociteMigration(List<int[]> availableSpaces, OnLattice2DGrid G)
5966
{
60-
System.out.println(availableSpaces); //Not necessary, just a check
61-
int newLymphocytes = (int) Lymphocytes.tumorInfiltrationRate * TumorCells.count;
67+
//System.out.println(availableSpaces); //Not necessary, just a check
68+
int newLymphocytes = (int) (Lymphocytes.tumorInfiltrationRate * TumorCells.count);
6269
Collections.shuffle(availableSpaces);
6370
int spacesToPick = Math.min(newLymphocytes, availableSpaces.size()); // Ensure we don’t pick more spaces than available
64-
List<int[]> randomSpaces = availableSpaces.subList(0, spacesToPick); // Get the first "spacesToPick" number of spaces from the shuffled list
65-
System.out.println(randomSpaces); //Not necessary, just a check
6671

6772
for (int i = 0; i < spacesToPick; i++)
6873
{
69-
G.NewAgentSQ(randomSpaces.get(i)[0], randomSpaces.get(i)[1]).Init(Lymphocytes.colorIndex);
74+
G.NewAgentSQ(availableSpaces.get(i)[0], availableSpaces.get(i)[1]).Init(Lymphocytes.colorIndex);
7075
}
7176

7277
Lymphocytes.count += spacesToPick;
@@ -167,6 +172,72 @@ public static double getTumorInfiltrationRate(String className) throws Exception
167172
throw e;
168173
}
169174
}
175+
176+
public static double getPrimaryImmuneResponse(String className, String rateOfCellKilling, String immuneSuppressionEffect) throws Exception
177+
{
178+
try
179+
{
180+
double primaryImmuneResponse;
181+
double concentrationAntiPD1_PDL1 = 0;
182+
183+
Class<?> clazz = Class.forName(className);
184+
185+
Field field1 = clazz.getDeclaredField(rateOfCellKilling);
186+
Object value1 = field1.get(null);
187+
188+
Field field2 = clazz.getDeclaredField(immuneSuppressionEffect);
189+
Object value2 = field2.get(null);
190+
191+
return ((Double) value1 * Lymphocytes.count) / (1 + ((Double) value2 * Math.pow(TumorCells.count, 2/3) * Lymphocytes.count) / (1 + concentrationAntiPD1_PDL1));
192+
}
193+
catch (ClassNotFoundException e)
194+
{
195+
System.err.println("Class not found: " + e.getMessage());
196+
e.printStackTrace();
197+
throw e;
198+
}
199+
catch (NoSuchFieldException e)
200+
{
201+
System.err.println("Field not found: " + e.getMessage());
202+
e.printStackTrace();
203+
throw e;
204+
}
205+
catch (Exception e)
206+
{
207+
System.err.println("Error during reflection: " + e.getMessage());
208+
e.printStackTrace();
209+
throw e;
210+
}
211+
}
212+
213+
public static double getTumorGrowthRate(String className) throws Exception
214+
{
215+
try
216+
{
217+
Class<?> clazz = Class.forName(className);
218+
Field field = clazz.getDeclaredField("tumorGrowthRate");
219+
Object value = field.get(null);
220+
return (Double) value;
221+
}
222+
catch (ClassNotFoundException e)
223+
{
224+
System.err.println("Class not found: " + e.getMessage());
225+
e.printStackTrace();
226+
throw e;
227+
}
228+
catch (NoSuchFieldException e)
229+
{
230+
System.err.println("Field not found: " + e.getMessage());
231+
e.printStackTrace();
232+
throw e;
233+
}
234+
catch (Exception e)
235+
{
236+
System.err.println("Error during reflection: " + e.getMessage());
237+
e.printStackTrace();
238+
throw e;
239+
}
240+
}
170241
}
171242

172243
class Lymphocytes
@@ -200,10 +271,29 @@ class Lymphocytes
200271
abstract class TumorCells implements Cells
201272
{
202273
public static String name = "Tumor Cells";
203-
public static double dieProb = 0.1;
204-
public static double divProb = 0.2;
274+
public static double dieProb;
275+
public static double divProb;
205276
public static int colorIndex = 1;
206277
public static int count = 0;
278+
public static double survivingFractionT;
279+
public static double primaryImmuneResponse;
280+
281+
static
282+
{
283+
try
284+
{
285+
String fullName = "OnLattice2DCells." + OnLattice2DGrid.className;
286+
survivingFractionT = CellFunctions.getSurvivingFraction(OnLattice2DGrid.radiationDose, fullName, "radiationSensitivityOfTumorCellsAlpha", "radiationSensitivityOfTumorCellsBeta");
287+
primaryImmuneResponse = CellFunctions.getPrimaryImmuneResponse(fullName, "rateOfCellKilling", "immuneSuppressionEffect");
288+
dieProb = 1 - survivingFractionT + survivingFractionT * primaryImmuneResponse;
289+
290+
divProb = survivingFractionT * (1 - primaryImmuneResponse) + CellFunctions.getTumorGrowthRate(fullName);
291+
}
292+
catch (Exception e)
293+
{
294+
throw new RuntimeException(e);
295+
}
296+
}
207297
}
208298

209299
abstract class DoomedCells implements Cells
@@ -327,10 +417,28 @@ public OnLattice2DGrid(int x, int y)
327417
public void Init()
328418
{
329419
//model.NewAgentSQ(model.xDim/2, model.yDim/2).Init(TumorCells.colorIndex);
330-
NewAgentSQ(xDim/2, yDim/2).Init(TumorCells.colorIndex);
331-
NewAgentSQ(20, 20).Init(Lymphocytes.colorIndex);
332-
Lymphocytes.count++;
333-
TumorCells.count++;
420+
int tumorSize = 1; //number of cells in initial tumor before beginning treatment
421+
int lymphocitePopulation = 1; //number of initial lymphocite cells before beginning treatment
422+
423+
for (int i = 0; i < tumorSize; i++)
424+
{
425+
NewAgentSQ(xDim/2, yDim/2).Init(TumorCells.colorIndex);
426+
// int options = new OnLattice2DCells.CellFunctions().mapEmptyHood(this);
427+
// if (options > 0)
428+
// {
429+
// this.NewAgentSQ(this.divHood[this.rng.Int(options)]).Init(TumorCells.colorIndex); //creates a new agent in a random location in the neighborhood around the cell
430+
// TumorCells.count++;
431+
// }
432+
433+
}
434+
435+
for (int i = 0; i < lymphocitePopulation; i++)
436+
{
437+
NewAgentSQ(2, 20).Init(Lymphocytes.colorIndex);
438+
}
439+
440+
Lymphocytes.count += lymphocitePopulation;
441+
TumorCells.count += tumorSize;
334442
}
335443

336444
public void StepCells (double dieProb, double divProb, int colorIndex)
@@ -344,22 +452,23 @@ public void StepCells (double dieProb, double divProb, int colorIndex)
344452

345453
public void getAvailableSpaces(GridWindow win)
346454
{
347-
List<int[]> availableSpaces = new ArrayList<>(); //This is a list of arrays
455+
List<int[]> availableSpaces = new ArrayList<>(); //This is a list of arrays, each array will store x- and y-coodinate
348456
for (int i = 0; i < length; i++)
349457
{
350458
OnLattice2DCells.CellFunctions cell = GetAgent(i);
351459
if (cell == null)
352460
{
353461
cell = NewAgentSQ(i);
354-
cell.Xpt();
355-
cell.Ypt();
356462
availableSpaces.add(new int[]{(int) cell.Xpt(),(int) cell.Ypt()});
463+
//System.out.print((int) cell.Xpt() + " "); //Not necessary, just a check
464+
//System.out.println((int) cell.Ypt()); //Not necessary, just a check
357465
cell.Dispose();
358466
}
359467
}
468+
//availableSpaces.forEach(space -> System.out.println(Arrays.toString(space))); //Not necessary, just a check
360469
//OnLattice2DCells.CellFunctions cell = new OnLattice2DCells.CellFunctions();
361470
//cell.lymphociteMigration(availableSpaces);
362-
new OnLattice2DCells.CellFunctions().lymphociteMigration(availableSpaces); //Doing the above in 1 line
471+
new OnLattice2DCells.CellFunctions().lymphociteMigration(availableSpaces, this); //Doing the above 2 lines in 1 line
363472
}
364473

365474
public void DrawModel(GridWindow win)
@@ -467,7 +576,7 @@ else if (colorIndex == 18)
467576

468577
public void printPopulation(String name, int colorIndex, int count)
469578
{
470-
System.out.println("Total number of " + name + " (" + findColor(colorIndex) + "): " + count);
579+
System.out.println("Population of " + name + " (" + findColor(colorIndex) + "): " + count);
471580
}
472581

473582
public static void main (String[] args) throws Exception
@@ -502,6 +611,8 @@ else if (figureCount == 6)
502611

503612
for (radiationDose = 10; radiationDose <= 20; radiationDose += 5)
504613
{
614+
System.out.println(className + ":\nRadiation Dose: " + radiationDose);
615+
505616
int x = 100;
506617
int y = 100;
507618
int timesteps = 1000;
@@ -529,6 +640,7 @@ else if (figureCount == 6)
529640
model.printPopulation(Lymphocytes.name, Lymphocytes.colorIndex, Lymphocytes.count);
530641
model.printPopulation(TumorCells.name, TumorCells.colorIndex, TumorCells.count);
531642
model.printPopulation(DoomedCells.name, DoomedCells.colorIndex, DoomedCells.count);
643+
System.out.println();
532644
}
533645
}
534646
}

0 commit comments

Comments
 (0)