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

View File

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