UI cleanup, some code cleanup
This commit is contained in:
@@ -256,15 +256,20 @@ public class UserInterface {
|
||||
// }
|
||||
// else {
|
||||
while (!quit) {
|
||||
System.out.println("\nALPHA/BETA T-CELL RECEPTOR MATCHING SIMULATOR");
|
||||
System.out.println("");
|
||||
System.out.println("--------BiGPairSEQ SIMULATOR--------");
|
||||
System.out.println("ALPHA/BETA T-CELL RECEPTOR MATCHING");
|
||||
System.out.println(" USING WEIGHTED BIPARTITE GRAPHS ");
|
||||
System.out.println("------------------------------------");
|
||||
System.out.println("Please select an option:");
|
||||
System.out.println("1) Generate a population of distinct cells");
|
||||
System.out.println("2) Generate a sample plate of T cells");
|
||||
System.out.println("3) Generate CDR3 alpha/beta occupancy graph and data");
|
||||
System.out.println("4) Simulate CDR3 alpha/beta T cell matching");
|
||||
System.out.println("3) Generate CDR3 alpha/beta occupancy data and overlap graph");
|
||||
System.out.println("4) Simulate bipartite graph CDR3 alpha/beta matching (BiGpairSEQ)");
|
||||
//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("6) Simulate CDR3/CDR1 T cell matching");
|
||||
System.out.println("7) Acknowledgements");
|
||||
//System.out.println("6) Simulate CDR3/CDR1 T cell matching");
|
||||
System.out.println("9) Acknowledgements");
|
||||
System.out.println("0) Exit");
|
||||
try {
|
||||
input = sc.nextInt();
|
||||
@@ -273,8 +278,8 @@ public class UserInterface {
|
||||
case 2 -> makePlate();
|
||||
case 3 -> makeCDR3Graph();
|
||||
case 4 -> matchCDR3s();
|
||||
case 6 -> matchCellsCDR1();
|
||||
case 7 -> acknowledge();
|
||||
//case 6 -> matchCellsCDR1();
|
||||
case 9 -> acknowledge();
|
||||
case 0 -> quit = true;
|
||||
default -> throw new InputMismatchException("Invalid input.");
|
||||
}
|
||||
@@ -295,7 +300,7 @@ public class UserInterface {
|
||||
System.out.println("\nSimulated T-Cells consist of integer values representing:\n" +
|
||||
"* a pair of alpha and beta CDR3 peptides (unique within simulated population)\n" +
|
||||
"* a pair of alpha and beta CDR1 peptides (not necessarily unique).");
|
||||
System.out.println("\nThe cells will be written to a file.");
|
||||
System.out.println("\nThe cells will be written to a CSV file.");
|
||||
System.out.print("Please enter a file name: ");
|
||||
filename = sc.next();
|
||||
System.out.println("CDR3 sequences are more diverse than CDR1 sequences.");
|
||||
@@ -311,7 +316,6 @@ public class UserInterface {
|
||||
sc.next();
|
||||
}
|
||||
CellSample sample = Simulator.generateCellSample(numCells, cdr1Freq);
|
||||
//CellSample sample = Simulator.generateCellSampleExp(numCells, cdr1Freq);
|
||||
CellFileWriter writer = new CellFileWriter(filename, sample);
|
||||
writer.writeCellsToFile();
|
||||
}
|
||||
@@ -364,10 +368,16 @@ public class UserInterface {
|
||||
boolean exponential = false;
|
||||
double lambda = 1.5;
|
||||
try {
|
||||
System.out.println("\nSimulated sample plates consist of:");
|
||||
System.out.println("* a number of wells");
|
||||
System.out.println(" * separated into one or more sections");
|
||||
System.out.println(" * each of which has a set quantity of cells per well");
|
||||
System.out.println(" * selected from a statistical distribution of distinct cells");
|
||||
System.out.println(" * with a set dropout rate for individual sequences within a cell");
|
||||
System.out.println("\nMaking a sample plate requires a population of distinct cells");
|
||||
System.out.println("Please enter name of an existing cell sample file: ");
|
||||
cellFile = sc.next();
|
||||
System.out.println("\nThe sample plate will be written to file");
|
||||
System.out.println("\nThe sample plate will be written to a CSV file");
|
||||
System.out.print("Please enter a name for the output file: ");
|
||||
filename = sc.next();
|
||||
System.out.println("Select T-cell frequency distribution function");
|
||||
@@ -401,7 +411,6 @@ public class UserInterface {
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid input. Defaulting to exponential.");
|
||||
//poisson = true;
|
||||
exponential = true;
|
||||
}
|
||||
System.out.print("Number of wells on plate: ");
|
||||
@@ -426,7 +435,7 @@ public class UserInterface {
|
||||
i++;
|
||||
numSections--;
|
||||
}
|
||||
System.out.println("Errors in amplification can induce a well dropout rate for peptides");
|
||||
System.out.println("Errors in amplification can induce a well dropout rate for sequences");
|
||||
System.out.print("Enter well dropout rate (0.0 to 1.0): ");
|
||||
dropOutRate = sc.nextDouble();
|
||||
if(dropOutRate < 0.0 || dropOutRate > 1.0) {
|
||||
@@ -462,14 +471,14 @@ public class UserInterface {
|
||||
Integer lowThreshold = 0;
|
||||
Integer highThreshold = Integer.MAX_VALUE;
|
||||
try {
|
||||
String str = "\nGenerating bipartite weighted graph encoding occupancy data requires ";
|
||||
str = str.concat("a cell sample file and a sample plate file.");
|
||||
String str = "\nGenerating bipartite weighted graph encoding occupancy overlap data ";
|
||||
str = str.concat("\nrequires a cell sample file and a sample plate file.");
|
||||
System.out.println(str);
|
||||
System.out.print("Please enter name of an existing cell sample file: ");
|
||||
cellFile = sc.next();
|
||||
System.out.print("Please enter name of an existing sample plate file: ");
|
||||
plateFile = sc.next();
|
||||
System.out.println("The graph and occupancy data will be written to a file.");
|
||||
System.out.println("The graph and occupancy data will be written to a serialized binary file.");
|
||||
System.out.print("Please enter a name for the output file: ");
|
||||
filename = sc.next();
|
||||
System.out.println("What is the minimum number of CDR3 alpha/beta overlap wells to include in graph?");
|
||||
@@ -502,7 +511,7 @@ public class UserInterface {
|
||||
GraphWithMapData data = Simulator.makeGraph(cells, plate, lowThreshold, highThreshold, true);
|
||||
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);
|
||||
System.out.println("Writing graph and occupancy data to file. This may take some time.");
|
||||
System.out.println("Time to write file is not included in simulation time data.");
|
||||
System.out.println("File I/O time is not included in results.");
|
||||
dataWriter.writeDataToFile();
|
||||
}
|
||||
}
|
||||
@@ -514,14 +523,18 @@ public class UserInterface {
|
||||
Integer maxOccupancyDiff = Integer.MAX_VALUE;
|
||||
Integer minOverlapPercent = 0;
|
||||
try {
|
||||
System.out.println("\nSimulated matching experiment requires graph and occupancy data file");
|
||||
System.out.println("\nBiGpairSEQ simulation requires an occupancy data and overlap graph file");
|
||||
System.out.println("Please enter name of an existing graph and occupancy data file: ");
|
||||
dataFile = sc.next();
|
||||
System.out.println("The matching results will be written to a file.");
|
||||
System.out.print("Please enter a name for the output file: ");
|
||||
filename = sc.next();
|
||||
System.out.println("Bipartite graph can be pre-filtered for relative alpha/beta occupancy.");
|
||||
System.out.println("(To skip pre-filtering: enter number of wells on the sample plate used to make graph)");
|
||||
System.out.println("What is the maximum difference in alpha/beta occupancy to attempt matching?");
|
||||
maxOccupancyDiff = sc.nextInt();
|
||||
System.out.println("Bipartite graph can be pre-filtered for pair well overlap percentage");
|
||||
System.out.println("(To skip pre-filtering: enter 0");
|
||||
System.out.println("What is the minimum overlap percentage to attempt matching? (0 - 100)");
|
||||
minOverlapPercent = sc.nextInt();
|
||||
if (minOverlapPercent < 0 || minOverlapPercent > 100) {
|
||||
@@ -532,8 +545,8 @@ public class UserInterface {
|
||||
sc.next();
|
||||
}
|
||||
//read object data from file
|
||||
System.out.println("Reading data from file. This may take some time");
|
||||
System.out.println("Time to read file is not included in simulation time data");
|
||||
System.out.println("Reading graph data from file. This may take some time");
|
||||
System.out.println("File I/O time is not included in results");
|
||||
GraphDataObjectReader dataReader = new GraphDataObjectReader(dataFile);
|
||||
GraphWithMapData data = dataReader.getData();
|
||||
//set source file name
|
||||
@@ -546,15 +559,26 @@ public class UserInterface {
|
||||
writer.writeResultsToFile();
|
||||
}
|
||||
|
||||
//old version before I wrote graph data to a file
|
||||
// private static void matchCells() {
|
||||
///////
|
||||
//Rewrite this to fit new matchCDR3 method with file I/O
|
||||
///////
|
||||
// public static void matchCellsCDR1(){
|
||||
// /*
|
||||
// The idea here is that we'll get the CDR3 alpha/beta matches first. Then we'll try to match CDR3s to CDR1s by
|
||||
// looking at the top two matches for each CDR3. If CDR3s in the same cell simply swap CDR1s, we assume a correct
|
||||
// match
|
||||
// */
|
||||
// String filename = null;
|
||||
// String preliminaryResultsFilename = null;
|
||||
// String cellFile = null;
|
||||
// String plateFile = null;
|
||||
// Integer lowThreshold = 0;
|
||||
// Integer highThreshold = Integer.MAX_VALUE;
|
||||
// Integer maxOccupancyDiff = 96; //no filtering if max difference is all wells by default
|
||||
// Integer minOverlapPercent = 0; //no filtering if min percentage is zero by default
|
||||
// Integer lowThresholdCDR3 = 0;
|
||||
// Integer highThresholdCDR3 = Integer.MAX_VALUE;
|
||||
// Integer maxOccupancyDiffCDR3 = 96; //no filtering if max difference is all wells by default
|
||||
// Integer minOverlapPercentCDR3 = 0; //no filtering if min percentage is zero by default
|
||||
// Integer lowThresholdCDR1 = 0;
|
||||
// Integer highThresholdCDR1 = Integer.MAX_VALUE;
|
||||
// boolean outputCDR3Matches = false;
|
||||
// try {
|
||||
// System.out.println("\nSimulated experiment requires a cell sample file and a sample plate file.");
|
||||
// System.out.print("Please enter name of an existing cell sample file: ");
|
||||
@@ -564,20 +588,42 @@ public class UserInterface {
|
||||
// System.out.println("The matching results will be written to a file.");
|
||||
// System.out.print("Please enter a name for the output file: ");
|
||||
// filename = sc.next();
|
||||
// System.out.println("What is the minimum number of alpha/beta overlap wells to attempt matching?");
|
||||
// lowThreshold = sc.nextInt();
|
||||
// if(lowThreshold < 1){
|
||||
// System.out.println("What is the minimum number of CDR3 alpha/beta overlap wells to attempt matching?");
|
||||
// lowThresholdCDR3 = sc.nextInt();
|
||||
// if(lowThresholdCDR3 < 1){
|
||||
// throw new InputMismatchException("Minimum value for low threshold is 1");
|
||||
// }
|
||||
// System.out.println("What is the maximum number of alpha/beta overlap wells to attempt matching?");
|
||||
// highThreshold = sc.nextInt();
|
||||
// System.out.println("What is the maximum difference in alpha/beta occupancy to attempt matching?");
|
||||
// maxOccupancyDiff = sc.nextInt();
|
||||
// System.out.println("What is the minimum overlap percentage to attempt matching? (0 - 100)");
|
||||
// minOverlapPercent = sc.nextInt();
|
||||
// if (minOverlapPercent < 0 || minOverlapPercent > 100) {
|
||||
// System.out.println("What is the maximum number of CDR3 alpha/beta overlap wells to attempt matching?");
|
||||
// highThresholdCDR3 = sc.nextInt();
|
||||
// System.out.println("What is the maximum difference in CDR3 alpha/beta occupancy to attempt matching?");
|
||||
// maxOccupancyDiffCDR3 = sc.nextInt();
|
||||
// System.out.println("What is the minimum CDR3 overlap percentage to attempt matching? (0 - 100)");
|
||||
// minOverlapPercentCDR3 = sc.nextInt();
|
||||
// if (minOverlapPercentCDR3 < 0 || minOverlapPercentCDR3 > 100) {
|
||||
// throw new InputMismatchException("Value outside range. Minimum percent set to 0");
|
||||
// }
|
||||
// System.out.println("What is the minimum number of CDR3/CDR1 overlap wells to attempt matching?");
|
||||
// lowThresholdCDR1 = sc.nextInt();
|
||||
// if(lowThresholdCDR1 < 1){
|
||||
// throw new InputMismatchException("Minimum value for low threshold is 1");
|
||||
// }
|
||||
// System.out.println("What is the maximum number of CDR3/CDR1 overlap wells to attempt matching?");
|
||||
// highThresholdCDR1 = sc.nextInt();
|
||||
// System.out.println("Matching CDR3s to CDR1s requires first matching CDR3 alpha/betas.");
|
||||
// System.out.println("Output a file for CDR3 alpha/beta match results as well?");
|
||||
// System.out.print("Please enter y/n: ");
|
||||
// String ans = sc.next();
|
||||
// Pattern pattern = Pattern.compile("(?:yes|y)", Pattern.CASE_INSENSITIVE);
|
||||
// Matcher matcher = pattern.matcher(ans);
|
||||
// if(matcher.matches()){
|
||||
// outputCDR3Matches = true;
|
||||
// System.out.println("Please enter filename for CDR3 alpha/beta match results");
|
||||
// preliminaryResultsFilename = sc.next();
|
||||
// System.out.println("CDR3 alpha/beta matches will be output to file");
|
||||
// }
|
||||
// else{
|
||||
// System.out.println("CDR3 alpha/beta matches will not be output to file");
|
||||
// }
|
||||
// } catch (InputMismatchException ex) {
|
||||
// System.out.println(ex);
|
||||
// sc.next();
|
||||
@@ -592,129 +638,40 @@ public class UserInterface {
|
||||
// else if(plate.getWells().size() == 0){
|
||||
// System.out.println("No sample plate found.");
|
||||
// System.out.println("Returning to main menu.");
|
||||
//
|
||||
// }
|
||||
// else{
|
||||
// if(highThreshold >= plate.getSize()){
|
||||
// highThreshold = plate.getSize() - 1;
|
||||
// if(highThresholdCDR3 >= plate.getSize()){
|
||||
// highThresholdCDR3 = plate.getSize() - 1;
|
||||
// }
|
||||
// if(highThresholdCDR1 >= plate.getSize()){
|
||||
// highThresholdCDR1 = plate.getSize() - 1;
|
||||
// }
|
||||
// List<Integer[]> cells = cellReader.getCells();
|
||||
// GraphWithMapData data = Simulator.makeGraph(cells, plate, lowThreshold, highThreshold, true);
|
||||
// //write data to a file
|
||||
//
|
||||
// MatchingResult results = Simulator.matchCDR3s(data, maxOccupancyDiff,minOverlapPercent, true);
|
||||
// //result writer
|
||||
// MatchingFileWriter writer = new MatchingFileWriter(filename, results);
|
||||
// MatchingResult preliminaryResults = Simulator.matchCDR3s(cells, plate, lowThresholdCDR3, highThresholdCDR3,
|
||||
// maxOccupancyDiffCDR3, minOverlapPercentCDR3, true);
|
||||
// MatchingResult[] results = Simulator.matchCDR1s(cells, plate, lowThresholdCDR1,
|
||||
// highThresholdCDR1, preliminaryResults);
|
||||
// MatchingFileWriter writer = new MatchingFileWriter(filename + "_FirstPass", results[0]);
|
||||
// writer.writeResultsToFile();
|
||||
// writer = new MatchingFileWriter(filename + "_SecondPass", results[1]);
|
||||
// writer.writeResultsToFile();
|
||||
// if(outputCDR3Matches){
|
||||
// writer = new MatchingFileWriter(preliminaryResultsFilename, preliminaryResults);
|
||||
// writer.writeResultsToFile();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void matchCellsCDR1(){
|
||||
/*
|
||||
The idea here is that we'll get the CDR3 alpha/beta matches first. Then we'll try to match CDR3s to CDR1s by
|
||||
looking at the top two matches for each CDR3. If CDR3s in the same cell simply swap CDR1s, we assume a correct
|
||||
match
|
||||
*/
|
||||
String filename = null;
|
||||
String preliminaryResultsFilename = null;
|
||||
String cellFile = null;
|
||||
String plateFile = null;
|
||||
Integer lowThresholdCDR3 = 0;
|
||||
Integer highThresholdCDR3 = Integer.MAX_VALUE;
|
||||
Integer maxOccupancyDiffCDR3 = 96; //no filtering if max difference is all wells by default
|
||||
Integer minOverlapPercentCDR3 = 0; //no filtering if min percentage is zero by default
|
||||
Integer lowThresholdCDR1 = 0;
|
||||
Integer highThresholdCDR1 = Integer.MAX_VALUE;
|
||||
boolean outputCDR3Matches = false;
|
||||
try {
|
||||
System.out.println("\nSimulated experiment requires a cell sample file and a sample plate file.");
|
||||
System.out.print("Please enter name of an existing cell sample file: ");
|
||||
cellFile = sc.next();
|
||||
System.out.print("Please enter name of an existing sample plate file: ");
|
||||
plateFile = sc.next();
|
||||
System.out.println("The matching results will be written to a file.");
|
||||
System.out.print("Please enter a name for the output file: ");
|
||||
filename = sc.next();
|
||||
System.out.println("What is the minimum number of CDR3 alpha/beta overlap wells to attempt matching?");
|
||||
lowThresholdCDR3 = sc.nextInt();
|
||||
if(lowThresholdCDR3 < 1){
|
||||
throw new InputMismatchException("Minimum value for low threshold is 1");
|
||||
}
|
||||
System.out.println("What is the maximum number of CDR3 alpha/beta overlap wells to attempt matching?");
|
||||
highThresholdCDR3 = sc.nextInt();
|
||||
System.out.println("What is the maximum difference in CDR3 alpha/beta occupancy to attempt matching?");
|
||||
maxOccupancyDiffCDR3 = sc.nextInt();
|
||||
System.out.println("What is the minimum CDR3 overlap percentage to attempt matching? (0 - 100)");
|
||||
minOverlapPercentCDR3 = sc.nextInt();
|
||||
if (minOverlapPercentCDR3 < 0 || minOverlapPercentCDR3 > 100) {
|
||||
throw new InputMismatchException("Value outside range. Minimum percent set to 0");
|
||||
}
|
||||
System.out.println("What is the minimum number of CDR3/CDR1 overlap wells to attempt matching?");
|
||||
lowThresholdCDR1 = sc.nextInt();
|
||||
if(lowThresholdCDR1 < 1){
|
||||
throw new InputMismatchException("Minimum value for low threshold is 1");
|
||||
}
|
||||
System.out.println("What is the maximum number of CDR3/CDR1 overlap wells to attempt matching?");
|
||||
highThresholdCDR1 = sc.nextInt();
|
||||
System.out.println("Matching CDR3s to CDR1s requires first matching CDR3 alpha/betas.");
|
||||
System.out.println("Output a file for CDR3 alpha/beta match results as well?");
|
||||
System.out.print("Please enter y/n: ");
|
||||
String ans = sc.next();
|
||||
Pattern pattern = Pattern.compile("(?:yes|y)", Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(ans);
|
||||
if(matcher.matches()){
|
||||
outputCDR3Matches = true;
|
||||
System.out.println("Please enter filename for CDR3 alpha/beta match results");
|
||||
preliminaryResultsFilename = sc.next();
|
||||
System.out.println("CDR3 alpha/beta matches will be output to file");
|
||||
}
|
||||
else{
|
||||
System.out.println("CDR3 alpha/beta matches will not be output to file");
|
||||
}
|
||||
} catch (InputMismatchException ex) {
|
||||
System.out.println(ex);
|
||||
sc.next();
|
||||
}
|
||||
CellFileReader cellReader = new CellFileReader(cellFile);
|
||||
PlateFileReader plateReader = new PlateFileReader(plateFile);
|
||||
Plate plate = new Plate(plateReader.getFilename(), plateReader.getWells());
|
||||
if (cellReader.getCells().size() == 0){
|
||||
System.out.println("No cell sample found.");
|
||||
System.out.println("Returning to main menu.");
|
||||
}
|
||||
else if(plate.getWells().size() == 0){
|
||||
System.out.println("No sample plate found.");
|
||||
System.out.println("Returning to main menu.");
|
||||
|
||||
}
|
||||
else{
|
||||
if(highThresholdCDR3 >= plate.getSize()){
|
||||
highThresholdCDR3 = plate.getSize() - 1;
|
||||
}
|
||||
if(highThresholdCDR1 >= plate.getSize()){
|
||||
highThresholdCDR1 = plate.getSize() - 1;
|
||||
}
|
||||
List<Integer[]> cells = cellReader.getCells();
|
||||
MatchingResult preliminaryResults = Simulator.matchCDR3s(cells, plate, lowThresholdCDR3, highThresholdCDR3,
|
||||
maxOccupancyDiffCDR3, minOverlapPercentCDR3, true);
|
||||
MatchingResult[] results = Simulator.matchCDR1s(cells, plate, lowThresholdCDR1,
|
||||
highThresholdCDR1, preliminaryResults);
|
||||
MatchingFileWriter writer = new MatchingFileWriter(filename + "_FirstPass", results[0]);
|
||||
writer.writeResultsToFile();
|
||||
writer = new MatchingFileWriter(filename + "_SecondPass", results[1]);
|
||||
writer.writeResultsToFile();
|
||||
if(outputCDR3Matches){
|
||||
writer = new MatchingFileWriter(preliminaryResultsFilename, preliminaryResults);
|
||||
writer.writeResultsToFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void acknowledge(){
|
||||
System.out.println("Simulation based on:");
|
||||
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("");
|
||||
System.out.println("pairSEQ citation:");
|
||||
System.out.println("Howie, B., Sherwood, A. M., et. al.");
|
||||
System.out.println("High-throughput pairing of T cell receptor alpha and beta sequences.");
|
||||
System.out.println("Sci. Transl. Med. 7, 301ra131 (2015)");
|
||||
System.out.println("");
|
||||
System.out.println("Simulation by Eugene Fischer, 2021");
|
||||
System.out.println("Simulation by Eugene Fischer, 2021-2022");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user