implement sample plates with random well populations

This commit is contained in:
2022-02-23 08:14:17 -06:00
parent 7323093bdc
commit dd2164c250

View File

@@ -2,6 +2,8 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import java.util.InputMismatchException; import java.util.InputMismatchException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// //
public class InteractiveInterface { public class InteractiveInterface {
@@ -84,7 +86,7 @@ public class InteractiveInterface {
Double stdDev = 0.0; Double stdDev = 0.0;
Integer numWells = 0; Integer numWells = 0;
Integer numSections; Integer numSections;
Integer[] concentrations = {1}; Integer[] populations = {1};
Double dropOutRate = 0.0; Double dropOutRate = 0.0;
boolean poisson = false; boolean poisson = false;
boolean exponential = false; boolean exponential = false;
@@ -139,23 +141,55 @@ public class InteractiveInterface {
if(numWells < 1){ if(numWells < 1){
throw new InputMismatchException("No wells on plate"); throw new InputMismatchException("No wells on plate");
} }
System.out.println("\nThe plate can be evenly sectioned to allow multiple concentrations of T-cells/well"); //choose whether to make T cell population/well random
boolean randomWellPopulations;
System.out.println("Randomize number of T cells in each well? (y/n)");
String ans = sc.next();
Pattern pattern = Pattern.compile("(?:yes|y)", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(ans);
if(matcher.matches()){
randomWellPopulations = true;
}
else{
randomWellPopulations = false;
}
if(randomWellPopulations) { //if T cell population/well is random
numSections = numWells;
Integer minPop;
Integer maxPop;
System.out.print("Please enter minimum number of T cells in a well: ");
minPop = sc.nextInt();
if(minPop < 1) {
throw new InputMismatchException("Minimum well population must be positive");
}
System.out.println("Please enter maximum number of T cells in a well: ");
maxPop = sc.nextInt();
if(maxPop < minPop) {
throw new InputMismatchException("Max well population must be greater than min well population");
}
populations = new Integer[numSections];
for(int i = 0; i < numSections; i++) {
populations[i] = Equations.getRandomInt(minPop, maxPop);
}
}
else{ //if T cell population/well is not random
System.out.println("\nThe plate can be evenly sectioned to allow different numbers of T cells per well.");
System.out.println("How many sections would you like to make (minimum 1)?"); System.out.println("How many sections would you like to make (minimum 1)?");
numSections = sc.nextInt(); numSections = sc.nextInt();
if (numSections < 1) { if (numSections < 1) {
throw new InputMismatchException("Too few sections."); throw new InputMismatchException("Too few sections.");
} } else if (numSections > numWells) {
else if (numSections > numWells) {
throw new InputMismatchException("Cannot have more sections than wells."); throw new InputMismatchException("Cannot have more sections than wells.");
} }
int i = 1; int i = 1;
concentrations = new Integer[numSections]; populations = new Integer[numSections];
while (numSections > 0) { while (numSections > 0) {
System.out.print("Enter number of T-cells per well in section " + i +": "); System.out.print("Enter number of T cells per well in section " + i + ": ");
concentrations[i - 1] = sc.nextInt(); populations[i - 1] = sc.nextInt();
i++; i++;
numSections--; numSections--;
} }
}
System.out.println("\nErrors in amplification can induce a well dropout rate for sequences"); System.out.println("\nErrors in amplification can induce a well dropout rate for sequences");
System.out.print("Enter well dropout rate (0.0 to 1.0): "); System.out.print("Enter well dropout rate (0.0 to 1.0): ");
dropOutRate = sc.nextDouble(); dropOutRate = sc.nextDouble();
@@ -170,7 +204,7 @@ public class InteractiveInterface {
assert cellFile != null; assert cellFile != null;
CellFileReader cellReader = new CellFileReader(cellFile); CellFileReader cellReader = new CellFileReader(cellFile);
if(exponential){ if(exponential){
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations); Plate samplePlate = new Plate(numWells, dropOutRate, populations);
samplePlate.fillWellsExponential(cellReader.getFilename(), cellReader.getCells(), lambda); samplePlate.fillWellsExponential(cellReader.getFilename(), cellReader.getCells(), lambda);
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate); PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
writer.writePlateFile(); writer.writePlateFile();
@@ -179,7 +213,7 @@ public class InteractiveInterface {
if (poisson) { if (poisson) {
stdDev = Math.sqrt(cellReader.getCellCount()); //gaussian with square root of elements approximates poisson stdDev = Math.sqrt(cellReader.getCellCount()); //gaussian with square root of elements approximates poisson
} }
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations); Plate samplePlate = new Plate(numWells, dropOutRate, populations);
samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev); samplePlate.fillWells(cellReader.getFilename(), cellReader.getCells(), stdDev);
assert filename != null; assert filename != null;
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate); PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
@@ -232,7 +266,7 @@ 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.setGraph(data); BiGpairSEQ.setGraphInMemory(data);
BiGpairSEQ.setGraphFilename(filename); BiGpairSEQ.setGraphFilename(filename);
System.out.println("Graph and Data file " + filename + " cached."); System.out.println("Graph and Data file " + filename + " cached.");
} }
@@ -275,17 +309,17 @@ 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.getGraph() == null) { if(!(graphFilename.equals(BiGpairSEQ.getGraphFilename())) || BiGpairSEQ.getGraphInMemory() == null) {
BiGpairSEQ.clearGraph(); BiGpairSEQ.clearGraphInMemory();
//read object data from file //read object data from file
GraphDataObjectReader dataReader = new GraphDataObjectReader(graphFilename); GraphDataObjectReader dataReader = new GraphDataObjectReader(graphFilename);
data = dataReader.getData(); data = dataReader.getData();
//set new graph in memory and new filename //set new graph in memory and new filename
BiGpairSEQ.setGraph(data); BiGpairSEQ.setGraphInMemory(data);
BiGpairSEQ.setGraphFilename(graphFilename); BiGpairSEQ.setGraphFilename(graphFilename);
} }
else { else {
data = BiGpairSEQ.getGraph(); data = BiGpairSEQ.getGraphInMemory();
} }
//simulate matching //simulate matching
MatchingResult results = Simulator.matchCDR3s(data, graphFilename, lowThreshold, highThreshold, maxOccupancyDiff, MatchingResult results = Simulator.matchCDR3s(data, graphFilename, lowThreshold, highThreshold, maxOccupancyDiff,