Compare commits
5 Commits
v1.2
...
2829b88689
| Author | SHA1 | Date | |
|---|---|---|---|
| 2829b88689 | |||
| 108b0ec13f | |||
| a8b58d3f79 | |||
| bf64d57731 | |||
| c068c3db3c |
23
readme.md
23
readme.md
@@ -58,13 +58,14 @@ main menu looks like this:
|
|||||||
```
|
```
|
||||||
--------BiGPairSEQ SIMULATOR--------
|
--------BiGPairSEQ SIMULATOR--------
|
||||||
ALPHA/BETA T CELL RECEPTOR MATCHING
|
ALPHA/BETA T CELL RECEPTOR MATCHING
|
||||||
USING WEIGHTED BIPARTITE GRAPHS
|
USING WEIGHTED BIPARTITE GRAPHS
|
||||||
------------------------------------
|
------------------------------------
|
||||||
Please select an option:
|
Please select an option:
|
||||||
1) Generate a population of distinct cells
|
1) Generate a population of distinct cells
|
||||||
2) Generate a sample plate of T cells
|
2) Generate a sample plate of T cells
|
||||||
3) Generate CDR3 alpha/beta occupancy data and overlap graph
|
3) Generate CDR3 alpha/beta occupancy data and overlap graph
|
||||||
4) Simulate bipartite graph CDR3 alpha/beta matching (BiGpairSEQ)
|
4) Simulate bipartite graph CDR3 alpha/beta matching (BiGpairSEQ)
|
||||||
|
8) Options
|
||||||
9) About/Acknowledgments
|
9) About/Acknowledgments
|
||||||
0) Exit
|
0) Exit
|
||||||
```
|
```
|
||||||
@@ -77,18 +78,20 @@ To run the simulation, the program reads and writes 4 kinds of files:
|
|||||||
* Graph/Data files in binary object serialization format
|
* Graph/Data files in binary object serialization format
|
||||||
* Matching Results files in CSV format
|
* Matching Results files in CSV format
|
||||||
|
|
||||||
These files are often generated in sequence. To save file I/O time, the most recent instance of each of these four
|
These files are often generated in sequence. When entering filenames, it is not necessary to include the file extension
|
||||||
files either generated or read from disk is cached in program memory. This is especially important for Graph/Data files,
|
(.csv or .ser). When reading or writing files, the program will automatically add the correct extension to any filename without one.
|
||||||
|
|
||||||
|
To save file I/O time, the most recent instance of each of these four
|
||||||
|
files either generated or read from disk can be cached in program memory. This is especially important for Graph/Data files,
|
||||||
which can be several gigabytes in size. Since some simulations may require running multiple,
|
which can be several gigabytes in size. Since some simulations may require running multiple,
|
||||||
differntly-configured BiGpairSEQ matchings on the same graph, keeping the most recent graph cached drastically reduces
|
differently-configured BiGpairSEQ matchings on the same graph, keeping the most recent graph cached can reduce execution time
|
||||||
execution time.
|
|
||||||
|
|
||||||
Subsequent uses of the same data file won't need to be read in again until another file of that type is used or generated.
|
Subsequent uses of the same data file won't need to be read in again until another file of that type is used or generated,
|
||||||
The program checks whether it needs to update its cached data by comparing filenames as entered by the user. On
|
or caching is turned off for that file type. The program checks whether it needs to update its cached data by comparing
|
||||||
encountering a new filename, the program flushes its cache and reads in the new file.
|
filenames as entered by the user. On encountering a new filename, the program flushes its cache and reads in the new file.
|
||||||
|
|
||||||
When entering filenames, it is not necessary to include the file extension (.csv or .ser). When reading or
|
The program's caching behavior can be controlled in the Options menu. By default, caching for cell sample and
|
||||||
writing files, the program will automatically add the correct extension to any filename without one.
|
sample plate files is OFF, and caching for graph/data files is ON.
|
||||||
|
|
||||||
#### Cell Sample Files
|
#### Cell Sample Files
|
||||||
Cell Sample files consist of any number of distinct "T cells." Every cell contains
|
Cell Sample files consist of any number of distinct "T cells." Every cell contains
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ public class BiGpairSEQ {
|
|||||||
private static String plateFilename = null;
|
private static String plateFilename = null;
|
||||||
private static GraphWithMapData graphInMemory = null;
|
private static GraphWithMapData graphInMemory = null;
|
||||||
private static String graphFilename = null;
|
private static String graphFilename = null;
|
||||||
|
private static boolean cacheCells = false;
|
||||||
|
private static boolean cachePlate = false;
|
||||||
|
private static boolean cacheGraph = true;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
@@ -30,66 +33,122 @@ 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();
|
||||||
|
System.out.println("Cell sample file cache cleared.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCellFilename() {
|
public static String getCellFilename() {
|
||||||
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();
|
||||||
|
System.out.println("Sample plate file cache cleared.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPlateFilename() {
|
public static String getPlateFilename() {
|
||||||
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();
|
||||||
|
System.out.println("Graph and data file cache cleared.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getGraphFilename() {
|
public static String getGraphFilename() {
|
||||||
return graphFilename;
|
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();
|
||||||
|
System.out.println("Cell sample file caching: OFF.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Cell sample file caching: ON.");
|
||||||
|
}
|
||||||
|
BiGpairSEQ.cacheCells = cacheCells;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean cachePlate() {
|
||||||
|
return cachePlate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCachePlate(boolean cachePlate) {
|
||||||
|
//if not caching, clear the memory
|
||||||
|
if(!cachePlate) {
|
||||||
|
BiGpairSEQ.clearPlateInMemory();
|
||||||
|
System.out.println("Sample plate file caching: OFF.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Sample plate file caching: ON.");
|
||||||
|
}
|
||||||
|
BiGpairSEQ.cachePlate = cachePlate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean cacheGraph() {
|
||||||
|
return cacheGraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCacheGraph(boolean cacheGraph) {
|
||||||
|
//if not caching, clear the memory
|
||||||
|
if(!cacheGraph) {
|
||||||
|
BiGpairSEQ.clearGraphInMemory();
|
||||||
|
System.out.println("Graph/data file caching: OFF.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Graph/data file caching: ON.");
|
||||||
|
}
|
||||||
|
BiGpairSEQ.cacheGraph = cacheGraph;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class InteractiveInterface {
|
|||||||
//Need to re-do the CDR3/CDR1 matching to correspond to new pattern
|
//Need to re-do the CDR3/CDR1 matching to correspond to new pattern
|
||||||
//System.out.println("5) Generate CDR3/CDR1 occupancy graph");
|
//System.out.println("5) Generate CDR3/CDR1 occupancy graph");
|
||||||
//System.out.println("6) Simulate CDR3/CDR1 T cell matching");
|
//System.out.println("6) Simulate CDR3/CDR1 T cell matching");
|
||||||
|
System.out.println("8) Options");
|
||||||
System.out.println("9) About/Acknowledgments");
|
System.out.println("9) About/Acknowledgments");
|
||||||
System.out.println("0) Exit");
|
System.out.println("0) Exit");
|
||||||
try {
|
try {
|
||||||
@@ -37,6 +38,7 @@ public class InteractiveInterface {
|
|||||||
case 3 -> makeCDR3Graph();
|
case 3 -> makeCDR3Graph();
|
||||||
case 4 -> matchCDR3s();
|
case 4 -> matchCDR3s();
|
||||||
//case 6 -> matchCellsCDR1();
|
//case 6 -> matchCellsCDR1();
|
||||||
|
case 8 -> options();
|
||||||
case 9 -> acknowledge();
|
case 9 -> acknowledge();
|
||||||
case 0 -> quit = true;
|
case 0 -> quit = true;
|
||||||
default -> throw new InputMismatchException("Invalid input.");
|
default -> throw new InputMismatchException("Invalid input.");
|
||||||
@@ -78,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
|
||||||
@@ -219,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;
|
||||||
@@ -242,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
|
||||||
@@ -271,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;
|
||||||
@@ -290,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.");
|
||||||
@@ -312,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.");
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,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,
|
||||||
@@ -493,6 +493,35 @@ public class InteractiveInterface {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
private static void options(){
|
||||||
|
boolean backToMain = false;
|
||||||
|
while(!backToMain) {
|
||||||
|
System.out.println("\n--------------OPTIONS---------------");
|
||||||
|
System.out.println("1) Turn " + getOnOff(!BiGpairSEQ.cacheCells()) + " cell sample file caching");
|
||||||
|
System.out.println("2) Turn " + getOnOff(!BiGpairSEQ.cachePlate()) + " plate file caching");
|
||||||
|
System.out.println("3) Turn " + getOnOff(!BiGpairSEQ.cacheGraph()) + " graph/data file caching");
|
||||||
|
System.out.println("0) Return to main menu");
|
||||||
|
try {
|
||||||
|
input = sc.nextInt();
|
||||||
|
switch (input) {
|
||||||
|
case 1 -> BiGpairSEQ.setCacheCells(!BiGpairSEQ.cacheCells());
|
||||||
|
case 2 -> BiGpairSEQ.setCachePlate(!BiGpairSEQ.cachePlate());
|
||||||
|
case 3 -> BiGpairSEQ.setCacheGraph(!BiGpairSEQ.cacheGraph());
|
||||||
|
case 0 -> backToMain = true;
|
||||||
|
default -> throw new InputMismatchException("Invalid input.");
|
||||||
|
}
|
||||||
|
} catch (InputMismatchException ex) {
|
||||||
|
System.out.println(ex);
|
||||||
|
sc.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getOnOff(boolean b) {
|
||||||
|
if (b) { return "on";}
|
||||||
|
else { return "off"; }
|
||||||
|
}
|
||||||
|
|
||||||
private static void acknowledge(){
|
private static void acknowledge(){
|
||||||
System.out.println("This program simulates BiGpairSEQ, a graph theory based adaptation");
|
System.out.println("This program simulates BiGpairSEQ, a graph theory based adaptation");
|
||||||
System.out.println("of the pairSEQ algorithm for pairing T cell receptor sequences.");
|
System.out.println("of the pairSEQ algorithm for pairing T cell receptor sequences.");
|
||||||
|
|||||||
Reference in New Issue
Block a user