Refactor plate assay methods to use maps passed as parameters rather than returning maps

This commit is contained in:
eugenefischer
2022-09-26 17:00:25 -05:00
parent 36c628cde5
commit 19a2a35f07
2 changed files with 16 additions and 14 deletions

View File

@@ -149,24 +149,22 @@ public class Plate {
}
//returns a map of the counts of the sequence at cell index sIndex, in all wells
public Map<String, Integer> assayWellsSequenceS(int... sIndices){
return this.assayWellsSequenceS(0, size, sIndices);
public void assayWellsSequenceS(Map<String, Integer> sequences, int... sIndices){
this.assayWellsSequenceS(sequences, 0, size, sIndices);
}
//returns a map of the counts of the sequence at cell index sIndex, in a specific well
public Map<String, Integer> assayWellsSequenceS(int n, int... sIndices) {
return this.assayWellsSequenceS(n, n+1, sIndices);
public void assayWellsSequenceS(Map<String, Integer> sequences, int n, int... sIndices) {
this.assayWellsSequenceS(sequences, n, n+1, sIndices);
}
//returns a map of the counts of the sequence at cell index sIndex, in a range of wells
public Map<String, Integer> assayWellsSequenceS(int start, int end, int... sIndices) {
Map<String, Integer> assay = new HashMap<>();
public void assayWellsSequenceS(Map<String, Integer> sequences, int start, int end, int... sIndices) {
for(int sIndex: sIndices){
for(int i = start; i < end; i++){
countSequences(assay, wells.get(i), sIndex);
countSequences(sequences, wells.get(i), sIndex);
}
}
return assay;
}
//For the sequences at cell indices sIndices, counts number of unique sequences in the given well into the given map
private void countSequences(Map<String, Integer> wellMap, List<String[]> well, int... sIndices) {

View File

@@ -36,8 +36,10 @@ public class Simulator implements GraphModificationFunctions {
if(verbose){System.out.println("Making well maps");}
Map<String, Integer> allAlphas = samplePlate.assayWellsSequenceS(alphaIndices);
Map<String, Integer> allBetas = samplePlate.assayWellsSequenceS(betaIndices);
Map<String, Integer> allAlphas = new HashMap<>();
samplePlate.assayWellsSequenceS(allAlphas, alphaIndices);
Map<String, Integer> allBetas = new HashMap<>();
samplePlate.assayWellsSequenceS(allBetas, betaIndices);
int alphaCount = allAlphas.size();
if(verbose){System.out.println("All alphas count: " + alphaCount);}
int betaCount = allBetas.size();
@@ -658,18 +660,20 @@ public class Simulator implements GraphModificationFunctions {
Map<String, Integer> rowSequenceCounts,
Map<String, Integer> columnSequenceCounts,
double[][] weights){
Map<String, Integer> wellNRowSequences = null;
Map<String, Integer> wellNColumnSequences = null;
Map<String, Integer> wellNRowSequences;
Map<String, Integer> wellNColumnSequences;
int vertexStartValue = rowSequenceToVertexMap.size();
int numWells = samplePlate.getSize();
for (int n = 0; n < numWells; n++) {
wellNRowSequences = samplePlate.assayWellsSequenceS(n, rowSequenceIndices);
wellNRowSequences = new HashMap<>();
samplePlate.assayWellsSequenceS(wellNRowSequences, n, rowSequenceIndices);
for (String a : wellNRowSequences.keySet()) {
if(allRowSequences.containsKey(a)){
rowSequenceCounts.merge(a, 1, (oldValue, newValue) -> oldValue + newValue);
}
}
wellNColumnSequences = samplePlate.assayWellsSequenceS(n, colSequenceIndices);
wellNColumnSequences = new HashMap<>();
samplePlate.assayWellsSequenceS(wellNColumnSequences, n, colSequenceIndices);
for (String b : wellNColumnSequences.keySet()) {
if(allColumnSequences.containsKey(b)){
columnSequenceCounts.merge(b, 1, (oldValue, newValue) -> oldValue + newValue);