implement option menu for file caching

This commit is contained in:
2022-02-24 12:30:47 -06:00
parent c068c3db3c
commit bf64d57731
2 changed files with 63 additions and 53 deletions

View File

@@ -33,12 +33,18 @@ public class BiGpairSEQ {
return cellSampleInMemory; return cellSampleInMemory;
} }
public static void setCellSampleInMemory(CellSample cellSampleInMemory) { public static void setCellSampleInMemory(CellSample cellSample, String filename) {
BiGpairSEQ.cellSampleInMemory = cellSampleInMemory; if(cellSampleInMemory != null) {
clearCellSampleInMemory();
}
cellSampleInMemory = cellSample;
cellFilename = filename;
System.out.println("Cell sample file " + filename + " cached.");
} }
public static void clearCellSampleInMemory() { public static void clearCellSampleInMemory() {
cellSampleInMemory = null; cellSampleInMemory = null;
cellFilename = null;
System.gc(); System.gc();
} }
@@ -46,20 +52,22 @@ public class BiGpairSEQ {
return cellFilename; return cellFilename;
} }
public static void setCellFilename(String cellFilename) {
BiGpairSEQ.cellFilename = cellFilename;
}
public static Plate getPlateInMemory() { public static Plate getPlateInMemory() {
return plateInMemory; return plateInMemory;
} }
public static void setPlateInMemory(Plate plateInMemory) { public static void setPlateInMemory(Plate plate, String filename) {
BiGpairSEQ.plateInMemory = plateInMemory; if(plateInMemory != null) {
clearPlateInMemory();
}
plateInMemory = plate;
plateFilename = filename;
System.out.println("Sample plate file " + filename + " cached.");
} }
public static void clearPlateInMemory() { public static void clearPlateInMemory() {
plateInMemory = null; plateInMemory = null;
plateFilename = null;
System.gc(); System.gc();
} }
@@ -67,23 +75,22 @@ public class BiGpairSEQ {
return plateFilename; return plateFilename;
} }
public static void setPlateFilename(String plateFilename) {
BiGpairSEQ.plateFilename = plateFilename; public static GraphWithMapData getGraphInMemory() {return graphInMemory;
} }
public static GraphWithMapData getGraphInMemory() { public static void setGraphInMemory(GraphWithMapData g, String filename) {
return graphInMemory;
}
public static void setGraphInMemory(GraphWithMapData g) {
if (graphInMemory != null) { if (graphInMemory != null) {
clearGraphInMemory(); clearGraphInMemory();
} }
graphInMemory = g; graphInMemory = g;
graphFilename = filename;
System.out.println("Graph and data file " + filename + " cached.");
} }
public static void clearGraphInMemory() { public static void clearGraphInMemory() {
graphInMemory = null; graphInMemory = null;
graphFilename = null;
System.gc(); System.gc();
} }
@@ -91,15 +98,16 @@ public class BiGpairSEQ {
return graphFilename; return graphFilename;
} }
public static void setGraphFilename(String filename) {
graphFilename = filename;
}
public static boolean cacheCells() { public static boolean cacheCells() {
return cacheCells; return cacheCells;
} }
public static void setCacheCells(boolean cacheCells) { public static void setCacheCells(boolean cacheCells) {
//if not caching, clear the memory
if(!cacheCells){
BiGpairSEQ.clearCellSampleInMemory();
}
BiGpairSEQ.cacheCells = cacheCells; BiGpairSEQ.cacheCells = cacheCells;
} }
@@ -108,6 +116,10 @@ public class BiGpairSEQ {
} }
public static void setCachePlate(boolean cachePlate) { public static void setCachePlate(boolean cachePlate) {
//if not caching, clear the memory
if(!cachePlate) {
BiGpairSEQ.clearPlateInMemory();
}
BiGpairSEQ.cachePlate = cachePlate; BiGpairSEQ.cachePlate = cachePlate;
} }
@@ -116,6 +128,10 @@ public class BiGpairSEQ {
} }
public static void setCacheGraph(boolean cacheGraph) { public static void setCacheGraph(boolean cacheGraph) {
//if not caching, clear the memory
if(!cacheGraph) {
BiGpairSEQ.clearGraphInMemory();
}
BiGpairSEQ.cacheGraph = cacheGraph; BiGpairSEQ.cacheGraph = cacheGraph;
} }
} }

View File

@@ -80,11 +80,9 @@ public class InteractiveInterface {
CellFileWriter writer = new CellFileWriter(filename, sample); CellFileWriter writer = new CellFileWriter(filename, sample);
writer.writeCellsToFile(); writer.writeCellsToFile();
System.out.println("Cell sample written to: " + filename); System.out.println("Cell sample written to: " + filename);
if(BiGpairSEQ.getCellSampleInMemory() != null) { if(BiGpairSEQ.cacheCells()) {
BiGpairSEQ.clearCellSampleInMemory(); BiGpairSEQ.setCellSampleInMemory(sample, filename);
} }
BiGpairSEQ.setCellSampleInMemory(sample);
BiGpairSEQ.setCellFilename(filename);
} }
//Output a CSV of sample plate //Output a CSV of sample plate
@@ -221,9 +219,9 @@ public class InteractiveInterface {
System.out.println("Reading Cell Sample file: " + cellFile); System.out.println("Reading Cell Sample file: " + cellFile);
CellFileReader cellReader = new CellFileReader(cellFile); CellFileReader cellReader = new CellFileReader(cellFile);
cells = cellReader.getCellSample(); cells = cellReader.getCellSample();
BiGpairSEQ.clearCellSampleInMemory(); if(BiGpairSEQ.cacheCells()) {
BiGpairSEQ.setCellSampleInMemory(cells); BiGpairSEQ.setCellSampleInMemory(cells, cellFile);
BiGpairSEQ.setCellFilename(cellFile); }
} }
assert filename != null; assert filename != null;
Plate samplePlate; Plate samplePlate;
@@ -244,8 +242,9 @@ public class InteractiveInterface {
System.out.println("Writing Sample Plate to file"); System.out.println("Writing Sample Plate to file");
writer.writePlateFile(); writer.writePlateFile();
System.out.println("Sample Plate written to file: " + filename); System.out.println("Sample Plate written to file: " + filename);
BiGpairSEQ.setPlateInMemory(samplePlate); if(BiGpairSEQ.cachePlate()) {
BiGpairSEQ.setPlateFilename(filename); BiGpairSEQ.setPlateInMemory(samplePlate, filename);
}
} }
//Output serialized binary of GraphAndMapData object //Output serialized binary of GraphAndMapData object
@@ -273,16 +272,16 @@ public class InteractiveInterface {
assert cellFile != null; assert cellFile != null;
CellSample cellSample; CellSample cellSample;
//check if cells are already in memory //check if cells are already in memory
if(cellFile.equals(BiGpairSEQ.getCellFilename())) { if(cellFile.equals(BiGpairSEQ.getCellFilename()) && BiGpairSEQ.getCellSampleInMemory() != null) {
cellSample = BiGpairSEQ.getCellSampleInMemory(); cellSample = BiGpairSEQ.getCellSampleInMemory();
} }
else { else {
BiGpairSEQ.clearCellSampleInMemory();
System.out.println("Reading Cell Sample file: " + cellFile); System.out.println("Reading Cell Sample file: " + cellFile);
CellFileReader cellReader = new CellFileReader(cellFile); CellFileReader cellReader = new CellFileReader(cellFile);
cellSample = cellReader.getCellSample(); cellSample = cellReader.getCellSample();
BiGpairSEQ.setCellSampleInMemory(cellSample); if(BiGpairSEQ.cacheCells()) {
BiGpairSEQ.setCellFilename(cellFile); BiGpairSEQ.setCellSampleInMemory(cellSample, cellFile);
}
} }
assert plateFile != null; assert plateFile != null;
@@ -292,12 +291,12 @@ public class InteractiveInterface {
plate = BiGpairSEQ.getPlateInMemory(); plate = BiGpairSEQ.getPlateInMemory();
} }
else { else {
BiGpairSEQ.clearPlateInMemory();
System.out.println("Reading Sample Plate file: " + plateFile); System.out.println("Reading Sample Plate file: " + plateFile);
PlateFileReader plateReader = new PlateFileReader(plateFile); PlateFileReader plateReader = new PlateFileReader(plateFile);
plate = new Plate(plateReader.getFilename(), plateReader.getWells()); plate = new Plate(plateReader.getFilename(), plateReader.getWells());
BiGpairSEQ.setPlateInMemory(plate); if(BiGpairSEQ.cachePlate()) {
BiGpairSEQ.setPlateFilename(plateFile); BiGpairSEQ.setPlateInMemory(plate, plateFile);
}
} }
if (cellSample.getCells().size() == 0){ if (cellSample.getCells().size() == 0){
System.out.println("No cell sample found."); System.out.println("No cell sample found.");
@@ -314,9 +313,10 @@ public class InteractiveInterface {
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data); GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);
dataWriter.writeDataToFile(); dataWriter.writeDataToFile();
System.out.println("Graph and Data file written to: " + filename); System.out.println("Graph and Data file written to: " + filename);
BiGpairSEQ.setGraphInMemory(data); if(BiGpairSEQ.cacheGraph()) {
BiGpairSEQ.setGraphFilename(filename); BiGpairSEQ.setGraphInMemory(data, filename);
System.out.println("Graph and Data file " + filename + " cached.");
}
} }
} }
@@ -368,17 +368,15 @@ public class InteractiveInterface {
assert graphFilename != null; assert graphFilename != null;
//check if this is the same graph we already have in memory. //check if this is the same graph we already have in memory.
GraphWithMapData data; GraphWithMapData data;
if(!(graphFilename.equals(BiGpairSEQ.getGraphFilename())) || BiGpairSEQ.getGraphInMemory() == null) { if(graphFilename.equals(BiGpairSEQ.getGraphFilename())) {
BiGpairSEQ.clearGraphInMemory(); data = BiGpairSEQ.getGraphInMemory();
//read object data from file
GraphDataObjectReader dataReader = new GraphDataObjectReader(graphFilename);
data = dataReader.getData();
//set new graph in memory and new filename
BiGpairSEQ.setGraphInMemory(data);
BiGpairSEQ.setGraphFilename(graphFilename);
} }
else { else {
data = BiGpairSEQ.getGraphInMemory(); GraphDataObjectReader dataReader = new GraphDataObjectReader(graphFilename);
data = dataReader.getData();
if(BiGpairSEQ.cacheGraph()) {
BiGpairSEQ.setGraphInMemory(data, graphFilename);
}
} }
//simulate matching //simulate matching
MatchingResult results = Simulator.matchCDR3s(data, graphFilename, lowThreshold, highThreshold, maxOccupancyDiff, MatchingResult results = Simulator.matchCDR3s(data, graphFilename, lowThreshold, highThreshold, maxOccupancyDiff,
@@ -498,7 +496,7 @@ public class InteractiveInterface {
private static void options(){ private static void options(){
boolean backToMain = false; boolean backToMain = false;
while(!backToMain) { while(!backToMain) {
System.out.println("-------------OPTIONS----------------"); System.out.println("--------------OPTIONS---------------");
System.out.println("1) Turn cell sample file caching " + getOnOff(!BiGpairSEQ.cacheCells())); System.out.println("1) Turn cell sample file caching " + getOnOff(!BiGpairSEQ.cacheCells()));
System.out.println("2) Turn sample plate file caching " + getOnOff(!BiGpairSEQ.cachePlate())); System.out.println("2) Turn sample plate file caching " + getOnOff(!BiGpairSEQ.cachePlate()));
System.out.println("3) Turn graph/data file caching " + getOnOff(!BiGpairSEQ.cacheGraph())); System.out.println("3) Turn graph/data file caching " + getOnOff(!BiGpairSEQ.cacheGraph()));
@@ -520,12 +518,8 @@ public class InteractiveInterface {
} }
private static String getOnOff(boolean b) { private static String getOnOff(boolean b) {
if (b) { if (b) { return "on";}
return "on"; else { return "off"; }
}
else {
return "off";
}
} }
private static void acknowledge(){ private static void acknowledge(){