Cache everything

This commit is contained in:
2022-02-23 10:30:42 -06:00
parent 74ffbfd8ac
commit decdb147a9
5 changed files with 96 additions and 29 deletions

View File

@@ -34,6 +34,11 @@ public class BiGpairSEQ {
BiGpairSEQ.cellSampleInMemory = cellSampleInMemory;
}
public static void clearCellSampleInMemory() {
cellSampleInMemory = null;
System.gc();
}
public static String getCellFilename() {
return cellFilename;
}
@@ -50,7 +55,7 @@ public class BiGpairSEQ {
BiGpairSEQ.plateInMemory = plateInMemory;
}
public static void clearPlate() {
public static void clearPlateInMemory() {
plateInMemory = null;
System.gc();
}

View File

@@ -13,6 +13,7 @@ public class CellFileReader {
private String filename;
private List<Integer[]> distinctCells = new ArrayList<>();
private Integer cdr1Freq;
public CellFileReader(String filename) {
if(!filename.matches(".*\\.csv")){
@@ -38,19 +39,37 @@ public class CellFileReader {
cell[3] = Integer.valueOf(record.get("Beta CDR1"));
distinctCells.add(cell);
}
} catch(IOException ex){
System.out.println("cell file " + filename + " not found.");
System.err.println(ex);
}
//get CDR1 frequency
ArrayList<Integer> cdr1Alphas = new ArrayList<>();
for (Integer[] cell : distinctCells) {
cdr1Alphas.add(cell[3]);
}
double count = cdr1Alphas.stream().distinct().count();
count = Math.ceil(distinctCells.size() / count);
cdr1Freq = (int) count;
}
public CellSample getCellSample() {
return new CellSample(distinctCells, cdr1Freq);
}
public String getFilename() { return filename;}
public List<Integer[]> getCells(){
//Refactor everything that uses this to have access to a Cell Sample and get the cells there instead.
public List<Integer[]> getListOfDistinctCellsDEPRECATED(){
return distinctCells;
}
public Integer getCellCount() {
public Integer getCellCountDEPRECATED() {
//Refactor everything that uses this to have access to a Cell Sample and get the count there instead.
return distinctCells.size();
}
}

View File

@@ -18,7 +18,7 @@ public class CellSample {
return cdr1Freq;
}
public Integer population(){
public Integer getCellCount(){
return cells.size();
}

View File

@@ -297,7 +297,7 @@ public class CommandLineInterface {
Integer numWells, Integer[] concentrations, Double dropOutRate){
CellFileReader cellReader = new CellFileReader(cellFile);
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
samplePlate.fillWellsExponential(cellReader.getFilename(), cellReader.getCells(), lambda);
samplePlate.fillWellsExponential(cellReader.getFilename(), cellReader.getListOfDistinctCellsDEPRECATED(), lambda);
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
writer.writePlateFile();
}
@@ -305,9 +305,9 @@ public class CommandLineInterface {
private static void makePlatePoisson(String cellFile, String filename, Integer numWells,
Integer[] concentrations, Double dropOutRate){
CellFileReader cellReader = new CellFileReader(cellFile);
Double stdDev = Math.sqrt(cellReader.getCellCount());
Double stdDev = Math.sqrt(cellReader.getCellCountDEPRECATED());
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev);
samplePlate.fillWells(cellReader.getFilename(), cellReader.getListOfDistinctCellsDEPRECATED(), stdDev);
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
writer.writePlateFile();
}
@@ -316,7 +316,7 @@ public class CommandLineInterface {
Integer numWells, Integer[] concentrations, Double dropOutRate){
CellFileReader cellReader = new CellFileReader(cellFile);
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev);
samplePlate.fillWells(cellReader.getFilename(), cellReader.getListOfDistinctCellsDEPRECATED(), stdDev);
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
writer.writePlateFile();
}

View File

@@ -74,8 +74,15 @@ public class InteractiveInterface {
}
CellSample sample = Simulator.generateCellSample(numCells, cdr1Freq);
assert filename != null;
System.out.println("Writing cells to file");
CellFileWriter writer = new CellFileWriter(filename, sample);
writer.writeCellsToFile();
System.out.println("Cell sample written to: " + filename);
if(BiGpairSEQ.getCellSampleInMemory() != null) {
BiGpairSEQ.clearCellSampleInMemory();
}
BiGpairSEQ.setCellSampleInMemory(sample);
BiGpairSEQ.setCellFilename(filename);
}
//Output a CSV of sample plate
@@ -203,27 +210,40 @@ public class InteractiveInterface {
System.out.println(ex);
sc.next();
}
System.out.println("Reading Cell Sample file: " + cellFile);
assert cellFile != null;
CellFileReader cellReader = new CellFileReader(cellFile);
CellSample cells;
if (cellFile.equals(BiGpairSEQ.getCellFilename())){
cells = BiGpairSEQ.getCellSampleInMemory();
}
else {
System.out.println("Reading Cell Sample file: " + cellFile);
CellFileReader cellReader = new CellFileReader(cellFile);
cells = cellReader.getCellSample();
BiGpairSEQ.clearCellSampleInMemory();
BiGpairSEQ.setCellSampleInMemory(cells);
BiGpairSEQ.setCellFilename(cellFile);
}
assert filename != null;
Plate samplePlate;
PlateFileWriter writer;
if(exponential){
Plate samplePlate = new Plate(numWells, dropOutRate, populations);
samplePlate.fillWellsExponential(cellReader.getFilename(), cellReader.getCells(), lambda);
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
writer.writePlateFile();
samplePlate = new Plate(numWells, dropOutRate, populations);
samplePlate.fillWellsExponential(cellFile, cells.getCells(), lambda);
writer = new PlateFileWriter(filename, samplePlate);
}
else {
if (poisson) {
stdDev = Math.sqrt(cellReader.getCellCount()); //gaussian with square root of elements approximates poisson
stdDev = Math.sqrt(cells.getCellCount()); //gaussian with square root of elements approximates poisson
}
Plate samplePlate = new Plate(numWells, dropOutRate, populations);
samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev);
assert filename != null;
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
System.out.println("Writing Sample Plate to file");
writer.writePlateFile();
System.out.println("Sample Plate written to file: " + filename);
samplePlate = new Plate(numWells, dropOutRate, populations);
samplePlate.fillWells(cellFile, cells.getCells(), stdDev);
writer = new PlateFileWriter(filename, samplePlate);
}
System.out.println("Writing Sample Plate to file");
writer.writePlateFile();
System.out.println("Sample Plate written to file: " + filename);
BiGpairSEQ.setPlateInMemory(samplePlate);
BiGpairSEQ.setPlateFilename(filename);
}
//Output serialized binary of GraphAndMapData object
@@ -247,14 +267,37 @@ public class InteractiveInterface {
System.out.println(ex);
sc.next();
}
System.out.println("Reading Cell Sample file: " + cellFile);
assert cellFile != null;
CellFileReader cellReader = new CellFileReader(cellFile);
System.out.println("Reading Sample Plate file: " + plateFile);
CellSample cellSample;
//check if cells are already in memory
if(cellFile.equals(BiGpairSEQ.getCellFilename())) {
cellSample = BiGpairSEQ.getCellSampleInMemory();
}
else {
BiGpairSEQ.clearCellSampleInMemory();
System.out.println("Reading Cell Sample file: " + cellFile);
CellFileReader cellReader = new CellFileReader(cellFile);
cellSample = cellReader.getCellSample();
BiGpairSEQ.setCellSampleInMemory(cellSample);
BiGpairSEQ.setCellFilename(cellFile);
}
assert plateFile != null;
PlateFileReader plateReader = new PlateFileReader(plateFile);
Plate plate = new Plate(plateReader.getFilename(), plateReader.getWells());
if (cellReader.getCells().size() == 0){
Plate plate;
//check if plate is already in memory
if(plateFile.equals(BiGpairSEQ.getPlateFilename())){
plate = BiGpairSEQ.getPlateInMemory();
}
else {
BiGpairSEQ.clearPlateInMemory();
System.out.println("Reading Sample Plate file: " + plateFile);
PlateFileReader plateReader = new PlateFileReader(plateFile);
plate = new Plate(plateReader.getFilename(), plateReader.getWells());
BiGpairSEQ.setPlateInMemory(plate);
BiGpairSEQ.setPlateFilename(plateFile);
}
if (cellSample.getCells().size() == 0){
System.out.println("No cell sample found.");
System.out.println("Returning to main menu.");
}
@@ -263,7 +306,7 @@ public class InteractiveInterface {
System.out.println("Returning to main menu.");
}
else{
List<Integer[]> cells = cellReader.getCells();
List<Integer[]> cells = cellSample.getCells();
GraphWithMapData data = Simulator.makeGraph(cells, plate, true);
assert filename != null;
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);