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.Scanner;
import java.util.InputMismatchException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//
public class InteractiveInterface {
@@ -84,7 +86,7 @@ public class InteractiveInterface {
Double stdDev = 0.0;
Integer numWells = 0;
Integer numSections;
Integer[] concentrations = {1};
Integer[] populations = {1};
Double dropOutRate = 0.0;
boolean poisson = false;
boolean exponential = false;
@@ -139,22 +141,54 @@ public class InteractiveInterface {
if(numWells < 1){
throw new InputMismatchException("No wells on plate");
}
System.out.println("\nThe plate can be evenly sectioned to allow multiple concentrations of T-cells/well");
System.out.println("How many sections would you like to make (minimum 1)?");
numSections = sc.nextInt();
if(numSections < 1) {
throw new InputMismatchException("Too few sections.");
//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 if (numSections > numWells) {
throw new InputMismatchException("Cannot have more sections than wells.");
else{
randomWellPopulations = false;
}
int i = 1;
concentrations = new Integer[numSections];
while(numSections > 0) {
System.out.print("Enter number of T-cells per well in section " + i +": ");
concentrations[i - 1] = sc.nextInt();
i++;
numSections--;
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)?");
numSections = sc.nextInt();
if (numSections < 1) {
throw new InputMismatchException("Too few sections.");
} else if (numSections > numWells) {
throw new InputMismatchException("Cannot have more sections than wells.");
}
int i = 1;
populations = new Integer[numSections];
while (numSections > 0) {
System.out.print("Enter number of T cells per well in section " + i + ": ");
populations[i - 1] = sc.nextInt();
i++;
numSections--;
}
}
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): ");
@@ -170,7 +204,7 @@ public class InteractiveInterface {
assert cellFile != null;
CellFileReader cellReader = new CellFileReader(cellFile);
if(exponential){
Plate samplePlate = new Plate(numWells, dropOutRate, concentrations);
Plate samplePlate = new Plate(numWells, dropOutRate, populations);
samplePlate.fillWellsExponential(cellReader.getFilename(), cellReader.getCells(), lambda);
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
writer.writePlateFile();
@@ -179,7 +213,7 @@ public class InteractiveInterface {
if (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);
assert filename != null;
PlateFileWriter writer = new PlateFileWriter(filename, samplePlate);
@@ -232,7 +266,7 @@ public class InteractiveInterface {
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);
dataWriter.writeDataToFile();
System.out.println("Graph and Data file written to: " + filename);
BiGpairSEQ.setGraph(data);
BiGpairSEQ.setGraphInMemory(data);
BiGpairSEQ.setGraphFilename(filename);
System.out.println("Graph and Data file " + filename + " cached.");
}
@@ -275,17 +309,17 @@ 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.getGraph() == null) {
BiGpairSEQ.clearGraph();
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.setGraph(data);
BiGpairSEQ.setGraphInMemory(data);
BiGpairSEQ.setGraphFilename(graphFilename);
}
else {
data = BiGpairSEQ.getGraph();
data = BiGpairSEQ.getGraphInMemory();
}
//simulate matching
MatchingResult results = Simulator.matchCDR3s(data, graphFilename, lowThreshold, highThreshold, maxOccupancyDiff,