Skip to content

Commit 91a885e

Browse files
committed
finished code so that all cell counts save to csv file
1 parent 93bd52e commit 91a885e

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "HAL"]
2+
path = HAL
3+
url = https://github.com/HTigee/HAL.git

HAL

Submodule HAL added at 4033751

OnLattice2DCells/OnLattice2DGrid.java

+57-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
import java.util.List;
1313
import java.util.ArrayList;
1414
import java.util.Collections;
15+
import java.io.BufferedWriter;
16+
import java.io.FileWriter;
17+
import java.io.IOException;
1518

16-
//Author: Hannah Simon, HTiigee on Git
19+
//Author: Hannah Simon, HTigee on Git
1720

1821
class CellFunctions extends AgentSQ2Dunstackable<OnLattice2DCells.OnLattice2DGrid>
1922
{
@@ -409,6 +412,10 @@ public class OnLattice2DGrid extends AgentGrid2D<OnLattice2DCells.CellFunctions>
409412
public static String className = "Figure2";
410413
public static int radiationDose;
411414

415+
public static final String directory = "C:\\Users\\Hannah\\Documents\\HALModeling2024Outs\\";
416+
public static final String fileName = "TrialRun.csv";
417+
public static final String fullPath = directory + fileName;
418+
412419
public OnLattice2DGrid(int x, int y)
413420
{
414421
super(x, y, OnLattice2DCells.CellFunctions.class);
@@ -574,6 +581,38 @@ else if (colorIndex == 18)
574581
}
575582
}
576583

584+
public void saveToCSV(String fullPath, boolean append, int timestep)
585+
{
586+
//System.out.println("Attempting to write to: " + fullPath);
587+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(fullPath, append)))
588+
{
589+
if (timestep == 0)
590+
{
591+
writer.write("Timestep," + Lymphocytes.name + "," + TumorCells.name + "," + DoomedCells.name);
592+
writer.newLine();
593+
}
594+
writer.write(timestep + "," + Lymphocytes.count + "," + TumorCells.count + "," + DoomedCells.count);
595+
writer.newLine();
596+
597+
/*writer.write("Cell Type, Count");
598+
writer.newLine();
599+
writer.write(Lymphocytes.name + "," + Lymphocytes.count);
600+
writer.newLine();
601+
writer.write( TumorCells.name + "," + TumorCells.count);
602+
writer.newLine();
603+
writer.write(DoomedCells.name + "," + DoomedCells.count);
604+
writer.newLine();
605+
writer.write("Total Cells," + Pop());*/
606+
//System.out.println("CSV file written successfully");
607+
}
608+
catch (IOException e)
609+
{
610+
System.err.println("Failed to write CSV file: " + e.getMessage());
611+
e.printStackTrace();
612+
System.exit(0);
613+
}
614+
}
615+
577616
public void printPopulation(String name, int colorIndex, int count)
578617
{
579618
System.out.println("Population of " + name + " (" + findColor(colorIndex) + "): " + count);
@@ -620,27 +659,43 @@ else if (figureCount == 6)
620659
OnLattice2DCells.OnLattice2DGrid model = new OnLattice2DCells.OnLattice2DGrid(x, y);
621660

622661
model.Init();
662+
663+
int timestep = 0;
664+
model.saveToCSV(fullPath, false, timestep);
665+
timestep++;
623666
//Lymphocytes.dieProb = CellFunctions.survivingFraction("radiationSensitivityOfLymphocytesAlpha", "radiationSensitivityOfLymphocytesBeta");
624667
//TumorCells.dieProb = CellFunctions.survivingFraction("radiationSensitivityOfTumorCellsAlpha", "radiationSensitivityOfTumorCellsBeta");
625668

626669
for (int i = 0; i < timesteps; i++) //this for loop loops over all the time steps. The model stops running after we finish all timesteps.
627670
{
628-
win.TickPause(20);
671+
win.TickPause(1);
629672
if (model.Pop() == 0)
630673
{
674+
timesteps += timestep - 1;
675+
631676
model.Init();
677+
timestep = 0;
678+
model.saveToCSV(fullPath, true, timestep);
679+
timestep++;
632680
}
681+
//I considered adding checks for if either lymphocytes or tumor cells only reaches zero, but not necessary
682+
633683
model.StepCells(Lymphocytes.dieProb, Lymphocytes.divProb, Lymphocytes.colorIndex);
634684
model.StepCells(TumorCells.dieProb, TumorCells.divProb, TumorCells.colorIndex);
635685
model.StepCells(DoomedCells.dieProb, DoomedCells.divProb, DoomedCells.colorIndex);
636686
model.getAvailableSpaces(win);
637687
model.DrawModel(win);
688+
689+
model.saveToCSV(fullPath, true, timestep);
690+
timestep++;
638691
}
639692

640693
model.printPopulation(Lymphocytes.name, Lymphocytes.colorIndex, Lymphocytes.count);
641694
model.printPopulation(TumorCells.name, TumorCells.colorIndex, TumorCells.count);
642695
model.printPopulation(DoomedCells.name, DoomedCells.colorIndex, DoomedCells.count);
696+
System.out.println("Population Total: " + model.Pop());
643697
System.out.println();
698+
System.exit(0);
644699
}
645700
}
646701
}

0 commit comments

Comments
 (0)