8
8
import HAL .Util ;
9
9
import java .lang .Math ;
10
10
import java .lang .reflect .Field ;
11
+ import java .util .Arrays ;
11
12
import java .util .List ;
12
13
import java .util .ArrayList ;
13
14
import java .util .Collections ;
@@ -33,9 +34,9 @@ public void StepCell(double dieProb, double divProb, int colorIndex)
33
34
}
34
35
else if (this .color == Util .CategorialColor (TumorCells .colorIndex ))
35
36
{
37
+ this .color = Util .CategorialColor (DoomedCells .colorIndex );
36
38
TumorCells .count --;
37
39
DoomedCells .count ++;
38
- this .color = Util .CategorialColor (DoomedCells .colorIndex );
39
40
}
40
41
else
41
42
{
@@ -44,7 +45,7 @@ else if (this.color == Util.CategorialColor(TumorCells.colorIndex))
44
45
}
45
46
}
46
47
47
- if (G .rng .Double () < divProb )
48
+ else if (this . color == Util . CategorialColor ( TumorCells . colorIndex ) && G .rng .Double () < ( dieProb + divProb ) )
48
49
{
49
50
int options = MapEmptyHood (G .divHood );
50
51
if (options > 0 )
@@ -55,18 +56,22 @@ else if (this.color == Util.CategorialColor(TumorCells.colorIndex))
55
56
}
56
57
}
57
58
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 )
59
66
{
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 ) ;
62
69
Collections .shuffle (availableSpaces );
63
70
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
66
71
67
72
for (int i = 0 ; i < spacesToPick ; i ++)
68
73
{
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 );
70
75
}
71
76
72
77
Lymphocytes .count += spacesToPick ;
@@ -167,6 +172,72 @@ public static double getTumorInfiltrationRate(String className) throws Exception
167
172
throw e ;
168
173
}
169
174
}
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
+ }
170
241
}
171
242
172
243
class Lymphocytes
@@ -200,10 +271,29 @@ class Lymphocytes
200
271
abstract class TumorCells implements Cells
201
272
{
202
273
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 ;
205
276
public static int colorIndex = 1 ;
206
277
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
+ }
207
297
}
208
298
209
299
abstract class DoomedCells implements Cells
@@ -327,10 +417,28 @@ public OnLattice2DGrid(int x, int y)
327
417
public void Init ()
328
418
{
329
419
//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 ;
334
442
}
335
443
336
444
public void StepCells (double dieProb , double divProb , int colorIndex )
@@ -344,22 +452,23 @@ public void StepCells (double dieProb, double divProb, int colorIndex)
344
452
345
453
public void getAvailableSpaces (GridWindow win )
346
454
{
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
348
456
for (int i = 0 ; i < length ; i ++)
349
457
{
350
458
OnLattice2DCells .CellFunctions cell = GetAgent (i );
351
459
if (cell == null )
352
460
{
353
461
cell = NewAgentSQ (i );
354
- cell .Xpt ();
355
- cell .Ypt ();
356
462
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
357
465
cell .Dispose ();
358
466
}
359
467
}
468
+ //availableSpaces.forEach(space -> System.out.println(Arrays.toString(space))); //Not necessary, just a check
360
469
//OnLattice2DCells.CellFunctions cell = new OnLattice2DCells.CellFunctions();
361
470
//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
363
472
}
364
473
365
474
public void DrawModel (GridWindow win )
@@ -467,7 +576,7 @@ else if (colorIndex == 18)
467
576
468
577
public void printPopulation (String name , int colorIndex , int count )
469
578
{
470
- System .out .println ("Total number of " + name + " (" + findColor (colorIndex ) + "): " + count );
579
+ System .out .println ("Population of " + name + " (" + findColor (colorIndex ) + "): " + count );
471
580
}
472
581
473
582
public static void main (String [] args ) throws Exception
@@ -502,6 +611,8 @@ else if (figureCount == 6)
502
611
503
612
for (radiationDose = 10 ; radiationDose <= 20 ; radiationDose += 5 )
504
613
{
614
+ System .out .println (className + ":\n Radiation Dose: " + radiationDose );
615
+
505
616
int x = 100 ;
506
617
int y = 100 ;
507
618
int timesteps = 1000 ;
@@ -529,6 +640,7 @@ else if (figureCount == 6)
529
640
model .printPopulation (Lymphocytes .name , Lymphocytes .colorIndex , Lymphocytes .count );
530
641
model .printPopulation (TumorCells .name , TumorCells .colorIndex , TumorCells .count );
531
642
model .printPopulation (DoomedCells .name , DoomedCells .colorIndex , DoomedCells .count );
643
+ System .out .println ();
532
644
}
533
645
}
534
646
}
0 commit comments