bugfix
This commit is contained in:
@@ -28,6 +28,8 @@ public class Plate {
|
|||||||
int section = 0;
|
int section = 0;
|
||||||
double m;
|
double m;
|
||||||
int n;
|
int n;
|
||||||
|
//testing
|
||||||
|
//System.out.println("Cell size: " + cells.get(0).length);
|
||||||
while (section < numSections){
|
while (section < numSections){
|
||||||
for (int i = 0; i < (size / numSections); i++) {
|
for (int i = 0; i < (size / numSections); i++) {
|
||||||
List<Integer[]> well = new ArrayList<>();
|
List<Integer[]> well = new ArrayList<>();
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ public class Simulator {
|
|||||||
return new MatchingResult(comments, header, allResults, matchMap);
|
return new MatchingResult(comments, header, allResults, matchMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MatchingResult matchCDR1s(List<Integer[]> distinctCells,
|
public static MatchingResult[] matchCDR1s(List<Integer[]> distinctCells,
|
||||||
Plate samplePlate, Integer lowThreshold,
|
Plate samplePlate, Integer lowThreshold,
|
||||||
Integer highThreshold, Map<Integer, Integer> previousMatches){
|
Integer highThreshold, Map<Integer, Integer> previousMatches){
|
||||||
int numWells = samplePlate.getSize();
|
int numWells = samplePlate.getSize();
|
||||||
@@ -256,9 +256,9 @@ public class Simulator {
|
|||||||
Map<Integer, Integer> allCDR3s = samplePlate.assayWellsCDR3();
|
Map<Integer, Integer> allCDR3s = samplePlate.assayWellsCDR3();
|
||||||
Map<Integer, Integer> allCDR1s = samplePlate.assayWellsCDR1();
|
Map<Integer, Integer> allCDR1s = samplePlate.assayWellsCDR1();
|
||||||
int CDR3Count = allCDR3s.size();
|
int CDR3Count = allCDR3s.size();
|
||||||
System.out.println("all alphas count: " + CDR3Count);
|
System.out.println("all CDR3s count: " + CDR3Count);
|
||||||
int CDR1Count = allCDR1s.size();
|
int CDR1Count = allCDR1s.size();
|
||||||
System.out.println("all betas count: " + CDR1Count);
|
System.out.println("all CDR1s count: " + CDR1Count);
|
||||||
System.out.println("Well maps made");
|
System.out.println("Well maps made");
|
||||||
|
|
||||||
System.out.println("Making vertex maps");
|
System.out.println("Making vertex maps");
|
||||||
@@ -279,9 +279,9 @@ public class Simulator {
|
|||||||
System.out.println("Vertex maps made");
|
System.out.println("Vertex maps made");
|
||||||
|
|
||||||
System.out.println("Creating Graph");
|
System.out.println("Creating Graph");
|
||||||
//Count how many wells each alpha appears in
|
//Count how many wells each CDR3 appears in
|
||||||
Map<Integer, Integer> CDR3WellCounts = new HashMap<>();
|
Map<Integer, Integer> CDR3WellCounts = new HashMap<>();
|
||||||
//count how many wells each beta appears in
|
//count how many wells each CDR1 appears in
|
||||||
Map<Integer, Integer> CDR1WellCounts = new HashMap<>();
|
Map<Integer, Integer> CDR1WellCounts = new HashMap<>();
|
||||||
//add edges, where weights are number of wells the peptides share in common.
|
//add edges, where weights are number of wells the peptides share in common.
|
||||||
//If this is too slow, can make a 2d array and use the SimpleWeightedGraphMatrixGenerator class
|
//If this is too slow, can make a 2d array and use the SimpleWeightedGraphMatrixGenerator class
|
||||||
@@ -300,8 +300,10 @@ public class Simulator {
|
|||||||
CDR1WellCounts.merge(b, 1, (oldValue, newValue) -> oldValue + newValue);
|
CDR1WellCounts.merge(b, 1, (oldValue, newValue) -> oldValue + newValue);
|
||||||
}
|
}
|
||||||
for (Integer i : wellNCDR3s.keySet()) {
|
for (Integer i : wellNCDR3s.keySet()) {
|
||||||
for (Integer j : wellNCDR1s.keySet()) {
|
if(CDR3AtoBMap.containsKey(i)||CDR3BtoAMap.containsKey(i)){//only consider ones we have matches for
|
||||||
weights[plateCDR3toVMap.get(i)][plateCDR1toVMap.get(j) - vertexStartValue] += 1.0;
|
for (Integer j : wellNCDR1s.keySet()) {
|
||||||
|
weights[plateCDR3toVMap.get(i)][plateCDR1toVMap.get(j) - vertexStartValue] += 1.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,6 +317,7 @@ public class Simulator {
|
|||||||
graphGenerator.weights(weights);
|
graphGenerator.weights(weights);
|
||||||
graphGenerator.generateGraph(graph);
|
graphGenerator.generateGraph(graph);
|
||||||
System.out.println("Graph created");
|
System.out.println("Graph created");
|
||||||
|
System.out.println("Number of edges: " + graph.edgeSet().size());
|
||||||
|
|
||||||
System.out.println("Finding first maximum weighted matching");
|
System.out.println("Finding first maximum weighted matching");
|
||||||
MaximumWeightBipartiteMatching firstMaxWeightMatching =
|
MaximumWeightBipartiteMatching firstMaxWeightMatching =
|
||||||
@@ -333,13 +336,15 @@ public class Simulator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Integer source = graph.getEdgeSource(e);
|
Integer source = graph.getEdgeSource(e);
|
||||||
if(!(CDR3AtoBMap.containsKey(source) || CDR3BtoAMap.containsKey(source))){
|
// if(!(CDR3AtoBMap.containsKey(source) || CDR3BtoAMap.containsKey(source))){
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
Integer target = graph.getEdgeTarget(e);
|
Integer target = graph.getEdgeTarget(e);
|
||||||
firstMatchCDR3toCDR1Map.put(plateVtoCDR3Map.get(source), plateVtoCDR1Map.get(target));
|
firstMatchCDR3toCDR1Map.put(plateVtoCDR3Map.get(source), plateVtoCDR1Map.get(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("First pass matches: " + firstMatchCDR3toCDR1Map.size());
|
||||||
|
|
||||||
//zero out the edge weights in the matching
|
//zero out the edge weights in the matching
|
||||||
weightIter = graphMatching.iterator();
|
weightIter = graphMatching.iterator();
|
||||||
while(weightIter.hasNext()){
|
while(weightIter.hasNext()){
|
||||||
@@ -353,6 +358,7 @@ public class Simulator {
|
|||||||
graphMatching = secondMaxWeightMatching.getMatching();
|
graphMatching = secondMaxWeightMatching.getMatching();
|
||||||
System.out.println("Second maximum weighted matching found");
|
System.out.println("Second maximum weighted matching found");
|
||||||
|
|
||||||
|
|
||||||
//second processing run
|
//second processing run
|
||||||
Map<Integer, Integer> secondMatchCDR3toCDR1Map = new HashMap<>();
|
Map<Integer, Integer> secondMatchCDR3toCDR1Map = new HashMap<>();
|
||||||
weightIter = graphMatching.iterator();
|
weightIter = graphMatching.iterator();
|
||||||
@@ -362,13 +368,31 @@ public class Simulator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Integer source = graph.getEdgeSource(e);
|
Integer source = graph.getEdgeSource(e);
|
||||||
if(!(CDR3AtoBMap.containsKey(source) || CDR3BtoAMap.containsKey(source))){
|
// if(!(CDR3AtoBMap.containsKey(source) || CDR3BtoAMap.containsKey(source))){
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
Integer target = graph.getEdgeTarget(e);
|
Integer target = graph.getEdgeTarget(e);
|
||||||
secondMatchCDR3toCDR1Map.put(plateVtoCDR3Map.get(source), plateVtoCDR1Map.get(target));
|
secondMatchCDR3toCDR1Map.put(plateVtoCDR3Map.get(source), plateVtoCDR1Map.get(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Second pass matches: " + secondMatchCDR3toCDR1Map.size());
|
||||||
|
|
||||||
|
|
||||||
|
//get linked map for first matching attempt
|
||||||
|
Map<Integer, Integer> firstMatchesMap = new LinkedHashMap<>();
|
||||||
|
for(Integer alphaCDR3: CDR3AtoBMap.keySet()) {
|
||||||
|
if (!(firstMatchCDR3toCDR1Map.containsKey(alphaCDR3))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Integer betaCDR3 = CDR3AtoBMap.get(alphaCDR3);
|
||||||
|
if (!(firstMatchCDR3toCDR1Map.containsKey(betaCDR3))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
firstMatchesMap.put(alphaCDR3, firstMatchCDR3toCDR1Map.get(alphaCDR3));
|
||||||
|
firstMatchesMap.put(betaCDR3, firstMatchCDR3toCDR1Map.get(betaCDR3));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Look for matches that simply swapped already-matched alpha and beta CDR3s
|
//Look for matches that simply swapped already-matched alpha and beta CDR3s
|
||||||
Map<Integer, Integer> dualMatchesMap = new LinkedHashMap<>();
|
Map<Integer, Integer> dualMatchesMap = new LinkedHashMap<>();
|
||||||
for(Integer alphaCDR3: CDR3AtoBMap.keySet()) {
|
for(Integer alphaCDR3: CDR3AtoBMap.keySet()) {
|
||||||
@@ -387,6 +411,7 @@ public class Simulator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//results for dual map
|
||||||
List<List<String>> allResults = new ArrayList<>();
|
List<List<String>> allResults = new ArrayList<>();
|
||||||
Integer trueCount = 0;
|
Integer trueCount = 0;
|
||||||
Iterator iter = dualMatchesMap.keySet().iterator();
|
Iterator iter = dualMatchesMap.keySet().iterator();
|
||||||
@@ -415,6 +440,7 @@ public class Simulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> comments = new ArrayList<>();
|
List<String> comments = new ArrayList<>();
|
||||||
|
comments.add("Plate size: " + samplePlate.getSize() + " wells");
|
||||||
comments.add("Previous pairs found: " + previousMatches.size());
|
comments.add("Previous pairs found: " + previousMatches.size());
|
||||||
comments.add("CDR1 matches attempted: " + allResults.size());
|
comments.add("CDR1 matches attempted: " + allResults.size());
|
||||||
double attemptRate = (double) allResults.size() / previousMatches.size();
|
double attemptRate = (double) allResults.size() / previousMatches.size();
|
||||||
@@ -430,7 +456,57 @@ public class Simulator {
|
|||||||
headers.add("second matched CDR1");
|
headers.add("second matched CDR1");
|
||||||
headers.add("Correct match?");
|
headers.add("Correct match?");
|
||||||
|
|
||||||
return new MatchingResult(comments, headers, allResults, dualMatchesMap);
|
for(String s: comments){
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
MatchingResult dualTest = new MatchingResult(comments, headers, allResults, dualMatchesMap);
|
||||||
|
|
||||||
|
|
||||||
|
//results for first map
|
||||||
|
allResults = new ArrayList<>();
|
||||||
|
trueCount = 0;
|
||||||
|
iter = firstMatchesMap.keySet().iterator();
|
||||||
|
while(iter.hasNext()){
|
||||||
|
Boolean proven = false;
|
||||||
|
List<String> tmp = new ArrayList<>();
|
||||||
|
tmp.add(iter.next().toString());
|
||||||
|
tmp.add(iter.next().toString());
|
||||||
|
tmp.add(firstMatchesMap.get(Integer.valueOf(tmp.get(0))).toString());
|
||||||
|
tmp.add(firstMatchesMap.get(Integer.valueOf(tmp.get(1))).toString());
|
||||||
|
if(alphaCDR3toCDR1Map.get(Integer.valueOf(tmp.get(0))).equals(Integer.valueOf(tmp.get(2)))){
|
||||||
|
if(betaCDR3toCDR1Map.get(Integer.valueOf(tmp.get(1))).equals(Integer.valueOf(tmp.get(3)))){
|
||||||
|
proven = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(alphaCDR3toCDR1Map.get(Integer.valueOf(tmp.get(0))).equals(Integer.valueOf(tmp.get(3)))){
|
||||||
|
if(betaCDR3toCDR1Map.get(Integer.valueOf(tmp.get(1))).equals(Integer.valueOf(tmp.get(2)))){
|
||||||
|
proven = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmp.add(proven.toString());
|
||||||
|
allResults.add(tmp);
|
||||||
|
if(proven){
|
||||||
|
trueCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
comments = new ArrayList<>();
|
||||||
|
comments.add("Plate size: " + samplePlate.getSize() + " wells");
|
||||||
|
comments.add("Previous pairs found: " + previousMatches.size());
|
||||||
|
comments.add("CDR1 matches attempted: " + allResults.size());
|
||||||
|
attemptRate = (double) allResults.size() / previousMatches.size();
|
||||||
|
comments.add("Matching attempt rate: " + attemptRate);
|
||||||
|
comments.add("Number of correct matches: " + trueCount);
|
||||||
|
correctRate = (double) trueCount / allResults.size();
|
||||||
|
comments.add("Correct matching rate: " + correctRate);
|
||||||
|
|
||||||
|
for(String s: comments){
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
MatchingResult firstTest = new MatchingResult(comments, headers, allResults, dualMatchesMap);
|
||||||
|
MatchingResult[] output = {firstTest, dualTest};
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -255,12 +255,15 @@ public class UserInterface {
|
|||||||
}
|
}
|
||||||
List<Integer[]> cells = cellReader.getCells();
|
List<Integer[]> cells = cellReader.getCells();
|
||||||
MatchingResult preliminaryResults = Simulator.matchCDR3s(cells, plate, lowThresholdCDR3, highThresholdCDR3);
|
MatchingResult preliminaryResults = Simulator.matchCDR3s(cells, plate, lowThresholdCDR3, highThresholdCDR3);
|
||||||
MatchingResult results = Simulator.matchCDR1s(cells, plate, lowThresholdCDR1,
|
MatchingResult[] results = Simulator.matchCDR1s(cells, plate, lowThresholdCDR1,
|
||||||
highThresholdCDR1, preliminaryResults.getMatchMap());
|
highThresholdCDR1, preliminaryResults.getMatchMap());
|
||||||
|
|
||||||
//result writer
|
//result writer
|
||||||
MatchingFileWriter writer = new MatchingFileWriter(filename, results.getComments(),
|
MatchingFileWriter writer = new MatchingFileWriter(filename + "First", results[0].getComments(),
|
||||||
results.getHeaders(), results.getAllResults());
|
results[0].getHeaders(), results[0].getAllResults());
|
||||||
|
writer.writeResultsToFile();
|
||||||
|
writer = new MatchingFileWriter(filename + "Dual", results[1].getComments(),
|
||||||
|
results[1].getHeaders(), results[1].getAllResults());
|
||||||
writer.writeResultsToFile();
|
writer.writeResultsToFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user