Relocate overlap threshold filters

This commit is contained in:
2022-02-20 03:05:56 -06:00
parent cb2c5a6024
commit d1c37b5ccd
4 changed files with 42 additions and 57 deletions

View File

@@ -14,8 +14,6 @@ public class GraphWithMapData implements java.io.Serializable {
private Integer[] wellConcentrations; private Integer[] wellConcentrations;
private Integer alphaCount; private Integer alphaCount;
private Integer betaCount; private Integer betaCount;
private Integer lowThreshold;
private Integer highThreshold;
private final Map<Integer, Integer> distCellsMapAlphaKey; private final Map<Integer, Integer> distCellsMapAlphaKey;
private final Map<Integer, Integer> plateVtoAMap; private final Map<Integer, Integer> plateVtoAMap;
private final Map<Integer, Integer> plateVtoBMap; private final Map<Integer, Integer> plateVtoBMap;
@@ -26,7 +24,7 @@ public class GraphWithMapData implements java.io.Serializable {
private final Duration time; private final Duration time;
public GraphWithMapData(SimpleWeightedGraph graph, Integer numWells, Integer[] wellConcentrations, public GraphWithMapData(SimpleWeightedGraph graph, Integer numWells, Integer[] wellConcentrations,
Integer alphaCount, Integer betaCount, Integer lowThreshold, Integer highThreshold, Integer alphaCount, Integer betaCount,
Map<Integer, Integer> distCellsMapAlphaKey, Map<Integer, Integer> plateVtoAMap, Map<Integer, Integer> distCellsMapAlphaKey, Map<Integer, Integer> plateVtoAMap,
Map<Integer,Integer> plateVtoBMap, Map<Integer, Integer> plateAtoVMap, Map<Integer,Integer> plateVtoBMap, Map<Integer, Integer> plateAtoVMap,
Map<Integer, Integer> plateBtoVMap, Map<Integer, Integer> alphaWellCounts, Map<Integer, Integer> plateBtoVMap, Map<Integer, Integer> alphaWellCounts,
@@ -36,8 +34,6 @@ public class GraphWithMapData implements java.io.Serializable {
this.wellConcentrations = wellConcentrations; this.wellConcentrations = wellConcentrations;
this.alphaCount = alphaCount; this.alphaCount = alphaCount;
this.betaCount = betaCount; this.betaCount = betaCount;
this.lowThreshold = lowThreshold;
this.highThreshold = highThreshold;
this.distCellsMapAlphaKey = distCellsMapAlphaKey; this.distCellsMapAlphaKey = distCellsMapAlphaKey;
this.plateVtoAMap = plateVtoAMap; this.plateVtoAMap = plateVtoAMap;
this.plateVtoBMap = plateVtoBMap; this.plateVtoBMap = plateVtoBMap;
@@ -68,14 +64,6 @@ public class GraphWithMapData implements java.io.Serializable {
return betaCount; return betaCount;
} }
public Integer getLowThreshold() {
return lowThreshold;
}
public Integer getHighThreshold() {
return highThreshold;
}
public Map<Integer, Integer> getDistCellsMapAlphaKey() { public Map<Integer, Integer> getDistCellsMapAlphaKey() {
return distCellsMapAlphaKey; return distCellsMapAlphaKey;
} }

View File

@@ -45,8 +45,7 @@ public class Simulator {
} }
//Make the graph needed for matching CDR3s //Make the graph needed for matching CDR3s
public static GraphWithMapData makeGraph(List<Integer[]> distinctCells, Plate samplePlate, Integer lowThreshold, public static GraphWithMapData makeGraph(List<Integer[]> distinctCells, Plate samplePlate, boolean verbose) {
Integer highThreshold, boolean verbose) {
Instant start = Instant.now(); Instant start = Instant.now();
int[] alphaIndex = {cdr3AlphaIndex}; int[] alphaIndex = {cdr3AlphaIndex};
int[] betaIndex = {cdr3BetaIndex}; int[] betaIndex = {cdr3BetaIndex};
@@ -70,9 +69,9 @@ public class Simulator {
//Remove saturating-occupancy sequences because they have no signal value. //Remove saturating-occupancy sequences because they have no signal value.
//Remove sequences with total occupancy below minimum pair overlap threshold //Remove sequences with total occupancy below minimum pair overlap threshold
if(verbose){System.out.println("Removing sequences present in all wells.");} if(verbose){System.out.println("Removing sequences present in all wells.");}
if(verbose){System.out.println("Removing sequences with occupancy below the minimum overlap threshold");} //if(verbose){System.out.println("Removing sequences with occupancy below the minimum overlap threshold");}
filterByOccupancyThreshold(allAlphas, lowThreshold, numWells - 1); filterByOccupancyThreshold(allAlphas, 1, numWells - 1);
filterByOccupancyThreshold(allBetas, lowThreshold, numWells - 1); filterByOccupancyThreshold(allBetas, 1, numWells - 1);
if(verbose){System.out.println("Sequences removed");} if(verbose){System.out.println("Sequences removed");}
int pairableAlphaCount = allAlphas.size(); int pairableAlphaCount = allAlphas.size();
if(verbose){System.out.println("Remaining alphas count: " + pairableAlphaCount);} if(verbose){System.out.println("Remaining alphas count: " + pairableAlphaCount);}
@@ -130,25 +129,20 @@ public class Simulator {
graphGenerator.generateGraph(graph); graphGenerator.generateGraph(graph);
if(verbose){System.out.println("Graph created");} if(verbose){System.out.println("Graph created");}
//remove weights outside given overlap thresholds
if(verbose){System.out.println("Eliminating edges with weights outside overlap threshold values");}
filterByOccupancyThreshold(graph, lowThreshold, highThreshold);
if(verbose){System.out.println("Over- and under-weight edges set to 0.0");}
Instant stop = Instant.now(); Instant stop = Instant.now();
Duration time = Duration.between(start, stop); Duration time = Duration.between(start, stop);
//return GraphWithMapData object //return GraphWithMapData object
return new GraphWithMapData(graph, numWells, samplePlate.getConcentrations(), alphaCount, betaCount, lowThreshold, highThreshold, return new GraphWithMapData(graph, numWells, samplePlate.getConcentrations(), alphaCount, betaCount,
distCellsMapAlphaKey, plateVtoAMap, plateVtoBMap, plateAtoVMap, distCellsMapAlphaKey, plateVtoAMap, plateVtoBMap, plateAtoVMap,
plateBtoVMap, alphaWellCounts, betaWellCounts, time); plateBtoVMap, alphaWellCounts, betaWellCounts, time);
} }
//match CDR3s. //match CDR3s.
public static MatchingResult matchCDR3s(GraphWithMapData data, Integer maxOccupancyDifference, public static MatchingResult matchCDR3s(GraphWithMapData data, Integer lowThreshold, Integer highThreshold,
Integer minOverlapPercent, boolean verbose) { Integer maxOccupancyDifference, Integer minOverlapPercent,
boolean verbose) {
Instant start = Instant.now(); Instant start = Instant.now();
int numWells = data.getNumWells(); int numWells = data.getNumWells();
Integer highThreshold = data.getHighThreshold();
Integer lowThreshold = data.getLowThreshold();
Integer alphaCount = data.getAlphaCount(); Integer alphaCount = data.getAlphaCount();
Integer betaCount = data.getBetaCount(); Integer betaCount = data.getBetaCount();
Map<Integer, Integer> distCellsMapAlphaKey = data.getDistCellsMapAlphaKey(); Map<Integer, Integer> distCellsMapAlphaKey = data.getDistCellsMapAlphaKey();
@@ -158,6 +152,11 @@ public class Simulator {
Map<Integer, Integer> betaWellCounts = data.getBetaWellCounts(); Map<Integer, Integer> betaWellCounts = data.getBetaWellCounts();
SimpleWeightedGraph<Integer, DefaultWeightedEdge> graph = data.getGraph(); SimpleWeightedGraph<Integer, DefaultWeightedEdge> graph = data.getGraph();
//remove weights outside given overlap thresholds
if(verbose){System.out.println("Eliminating edges with weights outside overlap threshold values");}
filterByOccupancyThreshold(graph, lowThreshold, highThreshold);
if(verbose){System.out.println("Over- and under-weight edges set to 0.0");}
//Filter by overlap size //Filter by overlap size
if(verbose){System.out.println("Eliminating edges with weights less than " + minOverlapPercent.toString() + if(verbose){System.out.println("Eliminating edges with weights less than " + minOverlapPercent.toString() +
" percent of vertex occupancy value.");} " percent of vertex occupancy value.");}

View File

@@ -303,10 +303,10 @@ public class UserInterface {
System.out.println("\nThe cells will be written to a CSV file."); System.out.println("\nThe cells will be written to a CSV file.");
System.out.print("Please enter a file name: "); System.out.print("Please enter a file name: ");
filename = sc.next(); filename = sc.next();
System.out.println("CDR3 sequences are more diverse than CDR1 sequences."); System.out.println("\nCDR3 sequences are more diverse than CDR1 sequences.");
System.out.println("Please enter the factor by which distinct CDR3s outnumber CDR1s: "); System.out.println("Please enter the factor by which distinct CDR3s outnumber CDR1s: ");
cdr1Freq = sc.nextInt(); cdr1Freq = sc.nextInt();
System.out.print("Please enter the number of T-cells to generate: "); System.out.print("\nPlease enter the number of T-cells to generate: ");
numCells = sc.nextInt(); numCells = sc.nextInt();
if(numCells <= 0){ if(numCells <= 0){
throw new InputMismatchException("Number of cells must be a positive integer."); throw new InputMismatchException("Number of cells must be a positive integer.");
@@ -380,7 +380,7 @@ public class UserInterface {
System.out.println("\nThe sample plate will be written to a CSV 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: "); System.out.print("Please enter a name for the output file: ");
filename = sc.next(); filename = sc.next();
System.out.println("Select T-cell frequency distribution function"); System.out.println("\nSelect T-cell frequency distribution function");
System.out.println("1) Poisson"); System.out.println("1) Poisson");
System.out.println("2) Gaussian"); System.out.println("2) Gaussian");
System.out.println("3) Exponential"); System.out.println("3) Exponential");
@@ -413,12 +413,12 @@ public class UserInterface {
System.out.println("Invalid input. Defaulting to exponential."); System.out.println("Invalid input. Defaulting to exponential.");
exponential = true; exponential = true;
} }
System.out.print("Number of wells on plate: "); System.out.print("\nNumber of wells on plate: ");
numWells = sc.nextInt(); numWells = sc.nextInt();
if(numWells < 1){ if(numWells < 1){
throw new InputMismatchException("No wells on plate"); throw new InputMismatchException("No wells on plate");
} }
System.out.println("The plate can be evenly sectioned to allow multiple concentrations of T-cells/well"); 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)?"); 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) {
@@ -435,7 +435,7 @@ public class UserInterface {
i++; i++;
numSections--; numSections--;
} }
System.out.println("Errors 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();
if(dropOutRate < 0.0 || dropOutRate > 1.0) { if(dropOutRate < 0.0 || dropOutRate > 1.0) {
@@ -468,26 +468,18 @@ public class UserInterface {
String filename = null; String filename = null;
String cellFile = null; String cellFile = null;
String plateFile = null; String plateFile = null;
Integer lowThreshold = 0;
Integer highThreshold = Integer.MAX_VALUE;
try { try {
String str = "\nGenerating bipartite weighted graph encoding occupancy overlap data "; String str = "\nGenerating bipartite weighted graph encoding occupancy overlap data ";
str = str.concat("\nrequires a cell sample file and a sample plate file."); str = str.concat("\nrequires a cell sample file and a sample plate file.");
System.out.println(str); System.out.println(str);
System.out.print("Please enter name of an existing cell sample file: "); System.out.print("\nPlease enter name of an existing cell sample file: ");
cellFile = sc.next(); cellFile = sc.next();
System.out.print("Please enter name of an existing sample plate file: "); System.out.print("\nPlease enter name of an existing sample plate file: ");
plateFile = sc.next(); plateFile = sc.next();
System.out.println("The graph and occupancy data will be written to a serialized binary file."); System.out.println("\nThe graph and occupancy data will be written to a serialized binary file.");
System.out.print("Please enter a name for the output 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?");
lowThreshold = sc.nextInt();
if(lowThreshold < 1){
throw new InputMismatchException("Minimum value for low threshold set to 1");
}
System.out.println("What is the maximum number of CDR3 alpha/beta overlap wells to include in graph?");
highThreshold = sc.nextInt();
} catch (InputMismatchException ex) { } catch (InputMismatchException ex) {
System.out.println(ex); System.out.println(ex);
sc.next(); sc.next();
@@ -504,11 +496,9 @@ public class UserInterface {
System.out.println("Returning to main menu."); System.out.println("Returning to main menu.");
} }
else{ else{
if(highThreshold >= plate.getSize()){
highThreshold = plate.getSize() - 1;
}
List<Integer[]> cells = cellReader.getCells(); List<Integer[]> cells = cellReader.getCells();
GraphWithMapData data = Simulator.makeGraph(cells, plate, lowThreshold, highThreshold, true); GraphWithMapData data = Simulator.makeGraph(cells, plate, true);
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data); GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);
System.out.println("Writing graph and occupancy data to file. This may take some time."); System.out.println("Writing graph and occupancy data to file. This may take some time.");
System.out.println("File I/O time is not included in results."); System.out.println("File I/O time is not included in results.");
@@ -520,6 +510,8 @@ public class UserInterface {
private static void matchCDR3s() throws IOException { private static void matchCDR3s() throws IOException {
String filename = null; String filename = null;
String dataFile = null; String dataFile = null;
Integer lowThreshold = 0;
Integer highThreshold = Integer.MAX_VALUE;
Integer maxOccupancyDiff = Integer.MAX_VALUE; Integer maxOccupancyDiff = Integer.MAX_VALUE;
Integer minOverlapPercent = 0; Integer minOverlapPercent = 0;
try { try {
@@ -529,13 +521,18 @@ public class UserInterface {
System.out.println("The matching results will be written to a file."); System.out.println("The matching results will be written to a file.");
System.out.print("Please enter a name for the output file: "); System.out.print("Please enter a name for the output file: ");
filename = sc.next(); filename = sc.next();
System.out.println("Bipartite graph can be pre-filtered for relative alpha/beta occupancy."); filename = sc.next();
System.out.println("(To skip pre-filtering: enter number of wells on the plate used to make graph)"); System.out.println("\nWhat is the minimum number of CDR3 alpha/beta overlap wells to attempt matching?");
System.out.println("What is the maximum difference in alpha/beta occupancy to attempt matching?"); lowThreshold = sc.nextInt();
if(lowThreshold < 1){
throw new InputMismatchException("Minimum value for low threshold set to 1");
}
System.out.println("\nWhat is the maximum number of CDR3 alpha/beta overlap wells to attempt matching?");
highThreshold = sc.nextInt();
System.out.println("\nWhat is the maximum difference in alpha/beta occupancy to attempt matching?");
maxOccupancyDiff = sc.nextInt(); maxOccupancyDiff = sc.nextInt();
System.out.println("Bipartite graph can be pre-filtered for pair well overlap percentage"); System.out.println("\nWell overlap percentage = pair overlap / sequence occupancy");
System.out.println("(To skip pre-filtering: enter 0)"); System.out.println("What is the minimum well overlap percentage to attempt matching? (0 to 100)");
System.out.println("What is the minimum overlap percentage to attempt matching? (0 - 100)");
minOverlapPercent = sc.nextInt(); minOverlapPercent = sc.nextInt();
if (minOverlapPercent < 0 || minOverlapPercent > 100) { if (minOverlapPercent < 0 || minOverlapPercent > 100) {
throw new InputMismatchException("Value outside range. Minimum percent set to 0"); throw new InputMismatchException("Value outside range. Minimum percent set to 0");
@@ -552,7 +549,8 @@ public class UserInterface {
//set source file name //set source file name
data.setSourceFilename(dataFile); data.setSourceFilename(dataFile);
//simulate matching //simulate matching
MatchingResult results = Simulator.matchCDR3s(data, maxOccupancyDiff, minOverlapPercent, true); MatchingResult results = Simulator.matchCDR3s(data, lowThreshold, highThreshold, maxOccupancyDiff,
minOverlapPercent, true);
//write results to file //write results to file
MatchingFileWriter writer = new MatchingFileWriter(filename, results); MatchingFileWriter writer = new MatchingFileWriter(filename, results);
System.out.println("Writing results to file"); System.out.println("Writing results to file");