Refactor sequences to be strings instead of integers, to make simulating read errors easier

This commit is contained in:
eugenefischer
2022-09-26 13:37:48 -05:00
parent f84dfb2b4b
commit 02c8e6aacb
10 changed files with 101 additions and 115 deletions

View File

@@ -12,7 +12,7 @@ import java.util.List;
public class CellFileReader { public class CellFileReader {
private String filename; private String filename;
private List<Integer[]> distinctCells = new ArrayList<>(); private List<String[]> distinctCells = new ArrayList<>();
private Integer cdr1Freq; private Integer cdr1Freq;
public CellFileReader(String filename) { public CellFileReader(String filename) {
@@ -32,11 +32,11 @@ public class CellFileReader {
CSVParser parser = new CSVParser(reader, cellFileFormat); CSVParser parser = new CSVParser(reader, cellFileFormat);
){ ){
for(CSVRecord record: parser.getRecords()) { for(CSVRecord record: parser.getRecords()) {
Integer[] cell = new Integer[4]; String[] cell = new String[4];
cell[0] = Integer.valueOf(record.get("Alpha CDR3")); cell[0] = record.get("Alpha CDR3");
cell[1] = Integer.valueOf(record.get("Beta CDR3")); cell[1] = record.get("Beta CDR3");
cell[2] = Integer.valueOf(record.get("Alpha CDR1")); cell[2] = record.get("Alpha CDR1");
cell[3] = Integer.valueOf(record.get("Beta CDR1")); cell[3] = record.get("Beta CDR1");
distinctCells.add(cell); distinctCells.add(cell);
} }
@@ -47,8 +47,8 @@ public class CellFileReader {
} }
//get CDR1 frequency //get CDR1 frequency
ArrayList<Integer> cdr1Alphas = new ArrayList<>(); ArrayList<String> cdr1Alphas = new ArrayList<>();
for (Integer[] cell : distinctCells) { for (String[] cell : distinctCells) {
cdr1Alphas.add(cell[3]); cdr1Alphas.add(cell[3]);
} }
double count = cdr1Alphas.stream().distinct().count(); double count = cdr1Alphas.stream().distinct().count();
@@ -62,14 +62,4 @@ public class CellFileReader {
} }
public String getFilename() { return filename;} public String getFilename() { return filename;}
//Refactor everything that uses this to have access to a Cell Sample and get the cells there instead.
public List<Integer[]> getListOfDistinctCellsDEPRECATED(){
return distinctCells;
}
public Integer getCellCountDEPRECATED() {
//Refactor everything that uses this to have access to a Cell Sample and get the count there instead.
return distinctCells.size();
}
} }

View File

@@ -11,7 +11,7 @@ import java.util.List;
public class CellFileWriter { public class CellFileWriter {
private String[] headers = {"Alpha CDR3", "Beta CDR3", "Alpha CDR1", "Beta CDR1"}; private String[] headers = {"Alpha CDR3", "Beta CDR3", "Alpha CDR1", "Beta CDR1"};
List<Integer[]> cells; List<String[]> cells;
String filename; String filename;
Integer cdr1Freq; Integer cdr1Freq;
@@ -35,7 +35,7 @@ public class CellFileWriter {
printer.printComment("Sample contains 1 unique CDR1 for every " + cdr1Freq + "unique CDR3s."); printer.printComment("Sample contains 1 unique CDR1 for every " + cdr1Freq + "unique CDR3s.");
printer.printRecords(cells); printer.printRecords(cells);
} catch(IOException ex){ } catch(IOException ex){
System.out.println("Could not make new file named "+filename); System.out.println("Could not make new file named " + filename);
System.err.println(ex); System.err.println(ex);
} }
} }

View File

@@ -5,7 +5,7 @@ import java.util.stream.IntStream;
public class CellSample { public class CellSample {
private List<Integer[]> cells; private List<String[]> cells;
private Integer cdr1Freq; private Integer cdr1Freq;
public CellSample(Integer numDistinctCells, Integer cdr1Freq){ public CellSample(Integer numDistinctCells, Integer cdr1Freq){
@@ -24,28 +24,28 @@ public class CellSample {
//Each cell represented by 4 values //Each cell represented by 4 values
//two CDR3s, and two CDR1s. First two values are CDR3s (alpha, beta), second two are CDR1s (alpha, beta) //two CDR3s, and two CDR1s. First two values are CDR3s (alpha, beta), second two are CDR1s (alpha, beta)
List<Integer[]> distinctCells = new ArrayList<>(); List<String[]> distinctCells = new ArrayList<>();
for(int i = 0; i < numbersCDR3.size() - 1; i = i + 2){ for(int i = 0; i < numbersCDR3.size() - 1; i = i + 2){
//Go through entire CDR3 list once, make pairs of alphas and betas //Go through entire CDR3 list once, make pairs of alphas and betas
Integer tmpCDR3a = numbersCDR3.get(i); String tmpCDR3a = numbersCDR3.get(i).toString();
Integer tmpCDR3b = numbersCDR3.get(i+1); String tmpCDR3b = numbersCDR3.get(i+1).toString();
//Go through (likely shorter) CDR1 list as many times as necessary, make pairs of alphas and betas //Go through the (likely shorter) CDR1 list as many times as necessary, make pairs of alphas and betas
Integer tmpCDR1a = numbersCDR1.get(i % numbersCDR1.size()); String tmpCDR1a = numbersCDR1.get(i % numbersCDR1.size()).toString();
Integer tmpCDR1b = numbersCDR1.get((i+1) % numbersCDR1.size()); String tmpCDR1b = numbersCDR1.get((i+1) % numbersCDR1.size()).toString();
//Make the array representing the cell //Make the array representing the cell
Integer[] tmp = {tmpCDR3a, tmpCDR3b, tmpCDR1a, tmpCDR1b}; String[] tmp = {tmpCDR3a, tmpCDR3b, tmpCDR1a, tmpCDR1b};
//Add the cell to the list of distinct cells //Add the cell to the list of distinct cells
distinctCells.add(tmp); distinctCells.add(tmp);
} }
this.cells = distinctCells; this.cells = distinctCells;
} }
public CellSample(List<Integer[]> cells, Integer cdr1Freq){ public CellSample(List<String[]> cells, Integer cdr1Freq){
this.cells = cells; this.cells = cells;
this.cdr1Freq = cdr1Freq; this.cdr1Freq = cdr1Freq;
} }
public List<Integer[]> getCells(){ public List<String[]> getCells(){
return cells; return cells;
} }

View File

@@ -15,7 +15,7 @@ public class GraphWithMapData implements java.io.Serializable {
private Integer[] wellPopulations; private Integer[] wellPopulations;
private Integer alphaCount; private Integer alphaCount;
private Integer betaCount; private Integer betaCount;
private final Map<Integer, Integer> distCellsMapAlphaKey; private final Map<String, String> 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;
// private final Map<Integer, Integer> plateAtoVMap; // private final Map<Integer, Integer> plateAtoVMap;
@@ -25,7 +25,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,
Map<Integer, Integer> distCellsMapAlphaKey, Integer alphaCount, Integer betaCount, Duration time){ Map<String, String> distCellsMapAlphaKey, Integer alphaCount, Integer betaCount, Duration time){
// Map<Integer, Integer> plateVtoAMap, // Map<Integer, Integer> plateVtoAMap,
// Map<Integer,Integer> plateVtoBMap, Map<Integer, Integer> plateAtoVMap, // Map<Integer,Integer> plateVtoBMap, Map<Integer, Integer> plateAtoVMap,
@@ -66,7 +66,7 @@ public class GraphWithMapData implements java.io.Serializable {
return betaCount; return betaCount;
} }
public Map<Integer, Integer> getDistCellsMapAlphaKey() { public Map<String, String> getDistCellsMapAlphaKey() {
return distCellsMapAlphaKey; return distCellsMapAlphaKey;
} }

View File

@@ -9,11 +9,11 @@ public class MatchingResult {
private final List<String> comments; private final List<String> comments;
private final List<String> headers; private final List<String> headers;
private final List<List<String>> allResults; private final List<List<String>> allResults;
private final Map<Integer, Integer> matchMap; private final Map<String, String> matchMap;
private final Duration time; private final Duration time;
public MatchingResult(Map<String, String> metadata, List<String> headers, public MatchingResult(Map<String, String> metadata, List<String> headers,
List<List<String>> allResults, Map<Integer, Integer>matchMap, Duration time){ List<List<String>> allResults, Map<String, String>matchMap, Duration time){
/* /*
* POSSIBLE KEYS FOR METADATA MAP ARE: * POSSIBLE KEYS FOR METADATA MAP ARE:
* sample plate filename * * sample plate filename *
@@ -57,7 +57,7 @@ public class MatchingResult {
return headers; return headers;
} }
public Map<Integer, Integer> getMatchMap() { public Map<String, String> getMatchMap() {
return matchMap; return matchMap;
} }

View File

@@ -11,7 +11,7 @@ public class Plate {
private CellSample cells; private CellSample cells;
private String sourceFile; private String sourceFile;
private String filename; private String filename;
private List<List<Integer[]>> wells; private List<List<String[]>> wells;
private final Random rand = BiGpairSEQ.getRand(); private final Random rand = BiGpairSEQ.getRand();
private int size; private int size;
private double error; private double error;
@@ -48,13 +48,13 @@ public class Plate {
} }
//constructor for returning a Plate from a PlateFileReader //constructor for returning a Plate from a PlateFileReader
public Plate(String filename, List<List<Integer[]>> wells) { public Plate(String filename, List<List<String[]>> wells) {
this.filename = filename; this.filename = filename;
this.wells = wells; this.wells = wells;
this.size = wells.size(); this.size = wells.size();
List<Integer> concentrations = new ArrayList<>(); List<Integer> concentrations = new ArrayList<>();
for (List<Integer[]> w: wells) { for (List<String[]> w: wells) {
if(!concentrations.contains(w.size())){ if(!concentrations.contains(w.size())){
concentrations.add(w.size()); concentrations.add(w.size());
} }
@@ -65,7 +65,7 @@ public class Plate {
} }
} }
private void fillWellsExponential(List<Integer[]> cells, double lambda){ private void fillWellsExponential(List<String[]> cells, double lambda){
this.lambda = lambda; this.lambda = lambda;
exponential = true; exponential = true;
int numSections = populations.length; int numSections = populations.length;
@@ -74,17 +74,17 @@ public class Plate {
int n; int n;
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<String[]> well = new ArrayList<>();
for (int j = 0; j < populations[section]; j++) { for (int j = 0; j < populations[section]; j++) {
do { do {
//inverse transform sampling: for random number u in [0,1), x = log(1-u) / (-lambda) //inverse transform sampling: for random number u in [0,1), x = log(1-u) / (-lambda)
m = (Math.log10((1 - rand.nextDouble()))/(-lambda)) * Math.sqrt(cells.size()); m = (Math.log10((1 - rand.nextDouble()))/(-lambda)) * Math.sqrt(cells.size());
} while (m >= cells.size() || m < 0); } while (m >= cells.size() || m < 0);
n = (int) Math.floor(m); n = (int) Math.floor(m);
Integer[] cellToAdd = cells.get(n).clone(); String[] cellToAdd = cells.get(n).clone();
for(int k = 0; k < cellToAdd.length; k++){ for(int k = 0; k < cellToAdd.length; k++){
if(Math.abs(rand.nextDouble()) < error){//error applied to each seqeunce if(Math.abs(rand.nextDouble()) < error){//error applied to each seqeunce
cellToAdd[k] = -1; cellToAdd[k] = "-1";
} }
} }
well.add(cellToAdd); well.add(cellToAdd);
@@ -95,7 +95,7 @@ public class Plate {
} }
} }
private void fillWells( List<Integer[]> cells, double stdDev) { private void fillWells( List<String[]> cells, double stdDev) {
this.stdDev = stdDev; this.stdDev = stdDev;
int numSections = populations.length; int numSections = populations.length;
int section = 0; int section = 0;
@@ -103,16 +103,16 @@ public class Plate {
int n; int n;
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<String[]> well = new ArrayList<>();
for (int j = 0; j < populations[section]; j++) { for (int j = 0; j < populations[section]; j++) {
do { do {
m = (rand.nextGaussian() * stdDev) + (cells.size() / 2); m = (rand.nextGaussian() * stdDev) + (cells.size() / 2);
} while (m >= cells.size() || m < 0); } while (m >= cells.size() || m < 0);
n = (int) Math.floor(m); n = (int) Math.floor(m);
Integer[] cellToAdd = cells.get(n).clone(); String[] cellToAdd = cells.get(n).clone();
for(int k = 0; k < cellToAdd.length; k++){ for(int k = 0; k < cellToAdd.length; k++){
if(Math.abs(rand.nextDouble()) < error){//error applied to each sequence if(Math.abs(rand.nextDouble()) < error){//error applied to each sequence
cellToAdd[k] = -1; cellToAdd[k] = "-1";
} }
} }
well.add(cellToAdd); well.add(cellToAdd);
@@ -143,23 +143,23 @@ public class Plate {
return error; return error;
} }
public List<List<Integer[]>> getWells() { public List<List<String[]>> getWells() {
return wells; return wells;
} }
//returns a map of the counts of the sequence at cell index sIndex, in all wells //returns a map of the counts of the sequence at cell index sIndex, in all wells
public Map<Integer, Integer> assayWellsSequenceS(int... sIndices){ public Map<String, Integer> assayWellsSequenceS(int... sIndices){
return this.assayWellsSequenceS(0, size, sIndices); return this.assayWellsSequenceS(0, size, sIndices);
} }
//returns a map of the counts of the sequence at cell index sIndex, in a specific well //returns a map of the counts of the sequence at cell index sIndex, in a specific well
public Map<Integer, Integer> assayWellsSequenceS(int n, int... sIndices) { public Map<String, Integer> assayWellsSequenceS(int n, int... sIndices) {
return this.assayWellsSequenceS(n, n+1, sIndices); return this.assayWellsSequenceS(n, n+1, sIndices);
} }
//returns a map of the counts of the sequence at cell index sIndex, in a range of wells //returns a map of the counts of the sequence at cell index sIndex, in a range of wells
public Map<Integer, Integer> assayWellsSequenceS(int start, int end, int... sIndices) { public Map<String, Integer> assayWellsSequenceS(int start, int end, int... sIndices) {
Map<Integer,Integer> assay = new HashMap<>(); Map<String, Integer> assay = new HashMap<>();
for(int sIndex: sIndices){ for(int sIndex: sIndices){
for(int i = start; i < end; i++){ for(int i = start; i < end; i++){
countSequences(assay, wells.get(i), sIndex); countSequences(assay, wells.get(i), sIndex);
@@ -168,11 +168,11 @@ public class Plate {
return assay; return assay;
} }
//For the sequences at cell indices sIndices, counts number of unique sequences in the given well into the given map //For the sequences at cell indices sIndices, counts number of unique sequences in the given well into the given map
private void countSequences(Map<Integer, Integer> wellMap, List<Integer[]> well, int... sIndices) { private void countSequences(Map<String, Integer> wellMap, List<String[]> well, int... sIndices) {
for(Integer[] cell : well) { for(String[] cell : well) {
for(int sIndex: sIndices){ for(int sIndex: sIndices){
//skip dropout sequences, which have value -1 //skip dropout sequences, which have value -1
if(cell[sIndex] != -1){ if(!"-1".equals(cell[sIndex])){
wellMap.merge(cell[sIndex], 1, (oldValue, newValue) -> oldValue + newValue); wellMap.merge(cell[sIndex], 1, (oldValue, newValue) -> oldValue + newValue);
} }
} }

View File

@@ -13,7 +13,7 @@ import java.util.regex.Pattern;
public class PlateFileReader { public class PlateFileReader {
private List<List<Integer[]>> wells = new ArrayList<>(); private List<List<String[]>> wells = new ArrayList<>();
private String filename; private String filename;
public PlateFileReader(String filename){ public PlateFileReader(String filename){
@@ -32,17 +32,17 @@ public class PlateFileReader {
CSVParser parser = new CSVParser(reader, plateFileFormat); CSVParser parser = new CSVParser(reader, plateFileFormat);
){ ){
for(CSVRecord record: parser.getRecords()) { for(CSVRecord record: parser.getRecords()) {
List<Integer[]> well = new ArrayList<>(); List<String[]> well = new ArrayList<>();
for(String s: record) { for(String s: record) {
if(!"".equals(s)) { if(!"".equals(s)) {
String[] intString = s.replaceAll("\\[", "") String[] sequences = s.replaceAll("\\[", "")
.replaceAll("]", "") .replaceAll("]", "")
.replaceAll(" ", "") .replaceAll(" ", "")
.split(","); .split(",");
//System.out.println(intString); //System.out.println(sequences);
Integer[] arr = new Integer[intString.length]; String[] arr = new String[sequences.length];
for (int i = 0; i < intString.length; i++) { for (int i = 0; i < sequences.length; i++) {
arr[i] = Integer.valueOf(intString[i]); arr[i] = sequences[i];
} }
well.add(arr); well.add(arr);
} }

View File

@@ -10,7 +10,7 @@ import java.util.*;
public class PlateFileWriter { public class PlateFileWriter {
private int size; private int size;
private List<List<Integer[]>> wells; private List<List<String[]>> wells;
private double stdDev; private double stdDev;
private double lambda; private double lambda;
private Double error; private Double error;
@@ -40,13 +40,13 @@ public class PlateFileWriter {
} }
public void writePlateFile(){ public void writePlateFile(){
Comparator<List<Integer[]>> listLengthDescending = Comparator.comparingInt(List::size); Comparator<List<String[]>> listLengthDescending = Comparator.comparingInt(List::size);
wells.sort(listLengthDescending.reversed()); wells.sort(listLengthDescending.reversed());
int maxLength = wells.get(0).size(); int maxLength = wells.get(0).size();
List<List<String>> wellsAsStrings = new ArrayList<>(); List<List<String>> wellsAsStrings = new ArrayList<>();
for (List<Integer[]> w: wells){ for (List<String[]> w: wells){
List<String> tmp = new ArrayList<>(); List<String> tmp = new ArrayList<>();
for(Integer[] c: w) { for(String[] c: w) {
tmp.add(Arrays.toString(c)); tmp.add(Arrays.toString(c));
} }
wellsAsStrings.add(tmp); wellsAsStrings.add(tmp);

View File

@@ -12,9 +12,6 @@ import java.text.NumberFormat;
import java.time.Instant; import java.time.Instant;
import java.time.Duration; import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.stream.IntStream;
import static java.lang.Float.*;
//NOTE: "sequence" in method and variable names refers to a peptide sequence from a simulated T cell //NOTE: "sequence" in method and variable names refers to a peptide sequence from a simulated T cell
public class Simulator implements GraphModificationFunctions { public class Simulator implements GraphModificationFunctions {
@@ -26,7 +23,7 @@ public class Simulator implements GraphModificationFunctions {
//even if not directed. //even if not directed.
public static GraphWithMapData makeGraph(CellSample cellSample, Plate samplePlate, boolean verbose) { public static GraphWithMapData makeGraph(CellSample cellSample, Plate samplePlate, boolean verbose) {
Instant start = Instant.now(); Instant start = Instant.now();
List<Integer[]> distinctCells = cellSample.getCells(); List<String[]> distinctCells = cellSample.getCells();
int[] alphaIndices = {SequenceType.CDR3_ALPHA.ordinal()}; int[] alphaIndices = {SequenceType.CDR3_ALPHA.ordinal()};
int[] betaIndices = {SequenceType.CDR3_BETA.ordinal()}; int[] betaIndices = {SequenceType.CDR3_BETA.ordinal()};
@@ -34,13 +31,13 @@ public class Simulator implements GraphModificationFunctions {
if(verbose){System.out.println("Making cell maps");} if(verbose){System.out.println("Making cell maps");}
//HashMap keyed to Alphas, values Betas //HashMap keyed to Alphas, values Betas
Map<Integer, Integer> distCellsMapAlphaKey = makeSequenceToSequenceMap(distinctCells, 0, 1); Map<String, String> distCellsMapAlphaKey = makeSequenceToSequenceMap(distinctCells, 0, 1);
if(verbose){System.out.println("Cell maps made");} if(verbose){System.out.println("Cell maps made");}
if(verbose){System.out.println("Making well maps");} if(verbose){System.out.println("Making well maps");}
Map<Integer, Integer> allAlphas = samplePlate.assayWellsSequenceS(alphaIndices); Map<String, Integer> allAlphas = samplePlate.assayWellsSequenceS(alphaIndices);
Map<Integer, Integer> allBetas = samplePlate.assayWellsSequenceS(betaIndices); Map<String, Integer> allBetas = samplePlate.assayWellsSequenceS(betaIndices);
int alphaCount = allAlphas.size(); int alphaCount = allAlphas.size();
if(verbose){System.out.println("All alphas count: " + alphaCount);} if(verbose){System.out.println("All alphas count: " + alphaCount);}
int betaCount = allBetas.size(); int betaCount = allBetas.size();
@@ -63,17 +60,17 @@ public class Simulator implements GraphModificationFunctions {
//distinct indices between the rows and columns. vertexStartValue lets me track where I switch //distinct indices between the rows and columns. vertexStartValue lets me track where I switch
//from numbering rows to columns, so I can assign unique numbers to every vertex, and then //from numbering rows to columns, so I can assign unique numbers to every vertex, and then
//subtract the vertexStartValue from betas to use their vertex labels as array indices //subtract the vertexStartValue from betas to use their vertex labels as array indices
Integer vertexStartValue = 0; int vertexStartValue = 0;
//keys are sequential integer vertices, values are alphas //keys are sequential integer vertices, values are alphas
Map<Integer, Integer> plateVtoAMap = makeVertexToSequenceMap(allAlphas, vertexStartValue); Map<Integer, String> plateVtoAMap = makeVertexToSequenceMap(allAlphas, vertexStartValue);
//new start value for vertex to beta map should be one more than final vertex value in alpha map //new start value for vertex to beta map should be one more than final vertex value in alpha map
vertexStartValue += plateVtoAMap.size(); vertexStartValue += plateVtoAMap.size();
//keys are sequential integers vertices, values are betas //keys are sequential integers vertices, values are betas
Map<Integer, Integer> plateVtoBMap = makeVertexToSequenceMap(allBetas, vertexStartValue); Map<Integer, String> plateVtoBMap = makeVertexToSequenceMap(allBetas, vertexStartValue);
//keys are alphas, values are sequential integer vertices from previous map //keys are alphas, values are sequential integer vertices from previous map
Map<Integer, Integer> plateAtoVMap = invertVertexMap(plateVtoAMap); Map<String, Integer> plateAtoVMap = invertVertexMap(plateVtoAMap);
//keys are betas, values are sequential integer vertices from previous map //keys are betas, values are sequential integer vertices from previous map
Map<Integer, Integer> plateBtoVMap = invertVertexMap(plateVtoBMap); Map<String, Integer> plateBtoVMap = invertVertexMap(plateVtoBMap);
if(verbose){System.out.println("Vertex maps made");} if(verbose){System.out.println("Vertex maps made");}
//make adjacency matrix for bipartite graph generator //make adjacency matrix for bipartite graph generator
@@ -81,9 +78,9 @@ public class Simulator implements GraphModificationFunctions {
//for a bipartite graph, and all the SimpleWeightedBipartiteGraphMatrixGenerator class expects.) //for a bipartite graph, and all the SimpleWeightedBipartiteGraphMatrixGenerator class expects.)
if(verbose){System.out.println("Creating adjacency matrix");} if(verbose){System.out.println("Creating adjacency matrix");}
//Count how many wells each alpha sequence appears in //Count how many wells each alpha sequence appears in
Map<Integer, Integer> alphaWellCounts = new HashMap<>(); Map<String, Integer> alphaWellCounts = new HashMap<>();
//count how many wells each beta sequence appears in //count how many wells each beta sequence appears in
Map<Integer, Integer> betaWellCounts = new HashMap<>(); Map<String, Integer> betaWellCounts = new HashMap<>();
//the adjacency matrix to be used by the graph generator //the adjacency matrix to be used by the graph generator
double[][] weights = new double[plateVtoAMap.size()][plateVtoBMap.size()]; double[][] weights = new double[plateVtoAMap.size()][plateVtoBMap.size()];
countSequencesAndFillMatrix(samplePlate, allAlphas, allBetas, plateAtoVMap, countSequencesAndFillMatrix(samplePlate, allAlphas, allBetas, plateAtoVMap,
@@ -101,7 +98,7 @@ public class Simulator implements GraphModificationFunctions {
//List<Integer> alphaVertices = new ArrayList<>(plateVtoAMap.keySet()); //This will work because LinkedHashMap preserves order of entry //List<Integer> alphaVertices = new ArrayList<>(plateVtoAMap.keySet()); //This will work because LinkedHashMap preserves order of entry
List<Vertex> alphaVertices = new ArrayList<>(); List<Vertex> alphaVertices = new ArrayList<>();
//start with map of all alphas mapped to vertex values, get occupancy from the alphaWellCounts map //start with map of all alphas mapped to vertex values, get occupancy from the alphaWellCounts map
for (Integer seq : plateAtoVMap.keySet()) { for (String seq : plateAtoVMap.keySet()) {
Vertex alphaVertex = new Vertex(SequenceType.CDR3_ALPHA, seq, alphaWellCounts.get(seq), plateAtoVMap.get(seq)); Vertex alphaVertex = new Vertex(SequenceType.CDR3_ALPHA, seq, alphaWellCounts.get(seq), plateAtoVMap.get(seq));
alphaVertices.add(alphaVertex); alphaVertices.add(alphaVertex);
} }
@@ -112,7 +109,7 @@ public class Simulator implements GraphModificationFunctions {
//the list of beta vertices //the list of beta vertices
//List<Integer> betaVertices = new ArrayList<>(plateVtoBMap.keySet());//This will work because LinkedHashMap preserves order of entry //List<Integer> betaVertices = new ArrayList<>(plateVtoBMap.keySet());//This will work because LinkedHashMap preserves order of entry
List<Vertex> betaVertices = new ArrayList<>(); List<Vertex> betaVertices = new ArrayList<>();
for (Integer seq : plateBtoVMap.keySet()) { for (String seq : plateBtoVMap.keySet()) {
Vertex betaVertex = new Vertex(SequenceType.CDR3_BETA, seq, betaWellCounts.get(seq), plateBtoVMap.get(seq)); Vertex betaVertex = new Vertex(SequenceType.CDR3_BETA, seq, betaWellCounts.get(seq), plateBtoVMap.get(seq));
betaVertices.add(betaVertex); betaVertices.add(betaVertex);
} }
@@ -147,7 +144,7 @@ public class Simulator implements GraphModificationFunctions {
int numWells = data.getNumWells(); int numWells = data.getNumWells();
//Integer alphaCount = data.getAlphaCount(); //Integer alphaCount = data.getAlphaCount();
//Integer betaCount = data.getBetaCount(); //Integer betaCount = data.getBetaCount();
Map<Integer, Integer> distCellsMapAlphaKey = data.getDistCellsMapAlphaKey(); Map<String, String> distCellsMapAlphaKey = data.getDistCellsMapAlphaKey();
Set<Vertex> alphas = new HashSet<>(); Set<Vertex> alphas = new HashSet<>();
Set<Vertex> betas = new HashSet<>(); Set<Vertex> betas = new HashSet<>();
for(Vertex v: graph.vertexSet()) { for(Vertex v: graph.vertexSet()) {
@@ -228,7 +225,7 @@ public class Simulator implements GraphModificationFunctions {
int trueCount = 0; int trueCount = 0;
int falseCount = 0; int falseCount = 0;
boolean check; boolean check;
Map<Integer, Integer> matchMap = new HashMap<>(); Map<String, String> matchMap = new HashMap<>();
while(weightIter.hasNext()) { while(weightIter.hasNext()) {
e = weightIter.next(); e = weightIter.next();
Vertex source = graph.getEdgeSource(e); Vertex source = graph.getEdgeSource(e);
@@ -637,14 +634,14 @@ public class Simulator implements GraphModificationFunctions {
// } // }
//Remove sequences based on occupancy //Remove sequences based on occupancy
public static void filterByOccupancyThresholds(Map<Integer, Integer> wellMap, int low, int high){ public static void filterByOccupancyThresholds(Map<String, Integer> wellMap, int low, int high){
List<Integer> noise = new ArrayList<>(); List<String> noise = new ArrayList<>();
for(Integer k: wellMap.keySet()){ for(String k: wellMap.keySet()){
if((wellMap.get(k) > high) || (wellMap.get(k) < low)){ if((wellMap.get(k) > high) || (wellMap.get(k) < low)){
noise.add(k); noise.add(k);
} }
} }
for(Integer k: noise) { for(String k: noise) {
wellMap.remove(k); wellMap.remove(k);
} }
} }
@@ -652,35 +649,35 @@ public class Simulator implements GraphModificationFunctions {
//Counts the well occupancy of the row peptides and column peptides into given maps, and //Counts the well occupancy of the row peptides and column peptides into given maps, and
//fills weights in the given 2D array //fills weights in the given 2D array
private static void countSequencesAndFillMatrix(Plate samplePlate, private static void countSequencesAndFillMatrix(Plate samplePlate,
Map<Integer,Integer> allRowSequences, Map<String, Integer> allRowSequences,
Map<Integer,Integer> allColumnSequences, Map<String, Integer> allColumnSequences,
Map<Integer,Integer> rowSequenceToVertexMap, Map<String, Integer> rowSequenceToVertexMap,
Map<Integer,Integer> columnSequenceToVertexMap, Map<String, Integer> columnSequenceToVertexMap,
int[] rowSequenceIndices, int[] rowSequenceIndices,
int[] colSequenceIndices, int[] colSequenceIndices,
Map<Integer, Integer> rowSequenceCounts, Map<String, Integer> rowSequenceCounts,
Map<Integer,Integer> columnSequenceCounts, Map<String, Integer> columnSequenceCounts,
double[][] weights){ double[][] weights){
Map<Integer, Integer> wellNRowSequences = null; Map<String, Integer> wellNRowSequences = null;
Map<Integer, Integer> wellNColumnSequences = null; Map<String, Integer> wellNColumnSequences = null;
int vertexStartValue = rowSequenceToVertexMap.size(); int vertexStartValue = rowSequenceToVertexMap.size();
int numWells = samplePlate.getSize(); int numWells = samplePlate.getSize();
for (int n = 0; n < numWells; n++) { for (int n = 0; n < numWells; n++) {
wellNRowSequences = samplePlate.assayWellsSequenceS(n, rowSequenceIndices); wellNRowSequences = samplePlate.assayWellsSequenceS(n, rowSequenceIndices);
for (Integer a : wellNRowSequences.keySet()) { for (String a : wellNRowSequences.keySet()) {
if(allRowSequences.containsKey(a)){ if(allRowSequences.containsKey(a)){
rowSequenceCounts.merge(a, 1, (oldValue, newValue) -> oldValue + newValue); rowSequenceCounts.merge(a, 1, (oldValue, newValue) -> oldValue + newValue);
} }
} }
wellNColumnSequences = samplePlate.assayWellsSequenceS(n, colSequenceIndices); wellNColumnSequences = samplePlate.assayWellsSequenceS(n, colSequenceIndices);
for (Integer b : wellNColumnSequences.keySet()) { for (String b : wellNColumnSequences.keySet()) {
if(allColumnSequences.containsKey(b)){ if(allColumnSequences.containsKey(b)){
columnSequenceCounts.merge(b, 1, (oldValue, newValue) -> oldValue + newValue); columnSequenceCounts.merge(b, 1, (oldValue, newValue) -> oldValue + newValue);
} }
} }
for (Integer i : wellNRowSequences.keySet()) { for (String i : wellNRowSequences.keySet()) {
if(allRowSequences.containsKey(i)){ if(allRowSequences.containsKey(i)){
for (Integer j : wellNColumnSequences.keySet()) { for (String j : wellNColumnSequences.keySet()) {
if(allColumnSequences.containsKey(j)){ if(allColumnSequences.containsKey(j)){
weights[rowSequenceToVertexMap.get(i)][columnSequenceToVertexMap.get(j) - vertexStartValue] += 1.0; weights[rowSequenceToVertexMap.get(i)][columnSequenceToVertexMap.get(j) - vertexStartValue] += 1.0;
} }
@@ -691,27 +688,27 @@ public class Simulator implements GraphModificationFunctions {
} }
} }
private static Map<Integer, Integer> makeSequenceToSequenceMap(List<Integer[]> cells, int keySequenceIndex, private static Map<String, String> makeSequenceToSequenceMap(List<String[]> cells, int keySequenceIndex,
int valueSequenceIndex){ int valueSequenceIndex){
Map<Integer, Integer> keySequenceToValueSequenceMap = new HashMap<>(); Map<String, String> keySequenceToValueSequenceMap = new HashMap<>();
for (Integer[] cell : cells) { for (String[] cell : cells) {
keySequenceToValueSequenceMap.put(cell[keySequenceIndex], cell[valueSequenceIndex]); keySequenceToValueSequenceMap.put(cell[keySequenceIndex], cell[valueSequenceIndex]);
} }
return keySequenceToValueSequenceMap; return keySequenceToValueSequenceMap;
} }
private static Map<Integer, Integer> makeVertexToSequenceMap(Map<Integer, Integer> sequences, Integer startValue) { private static Map<Integer, String> makeVertexToSequenceMap(Map<String, Integer> sequences, Integer startValue) {
Map<Integer, Integer> map = new LinkedHashMap<>(); //LinkedHashMap to preserve order of entry Map<Integer, String> map = new LinkedHashMap<>(); //LinkedHashMap to preserve order of entry
Integer index = startValue; //is this necessary? I don't think I use this. Integer index = startValue; //is this necessary? I don't think I use this.
for (Integer k: sequences.keySet()) { for (String k: sequences.keySet()) {
map.put(index, k); map.put(index, k);
index++; index++;
} }
return map; return map;
} }
private static Map<Integer, Integer> invertVertexMap(Map<Integer, Integer> map) { private static Map<String, Integer> invertVertexMap(Map<Integer, String> map) {
Map<Integer, Integer> inverse = new HashMap<>(); Map<String, Integer> inverse = new HashMap<>();
for (Integer k : map.keySet()) { for (Integer k : map.keySet()) {
inverse.put(map.get(k), k); inverse.put(map.get(k), k);
} }

View File

@@ -5,7 +5,7 @@ import java.io.Serializable;
public class Vertex implements Serializable, Comparable<Vertex> { public class Vertex implements Serializable, Comparable<Vertex> {
private SequenceType type; private SequenceType type;
private Integer vertexLabel; private Integer vertexLabel;
private Integer sequence; private String sequence;
private Integer occupancy; private Integer occupancy;
private Integer readCount; private Integer readCount;
private Double potential; private Double potential;
@@ -18,14 +18,14 @@ public class Vertex implements Serializable, Comparable<Vertex> {
this.vertexLabel = Integer.parseInt((vertexLabel)); this.vertexLabel = Integer.parseInt((vertexLabel));
} }
public Vertex(SequenceType type, Integer sequence, Integer occupancy, Integer vertexLabel) { public Vertex(SequenceType type, String sequence, Integer occupancy, Integer vertexLabel) {
this.type = type; this.type = type;
this.vertexLabel = vertexLabel; this.vertexLabel = vertexLabel;
this.sequence = sequence; this.sequence = sequence;
this.occupancy = occupancy; this.occupancy = occupancy;
} }
public Vertex(SequenceType type, Integer sequence, Integer occupancy, Integer vertexLabel, Integer readCount) { public Vertex(SequenceType type, String sequence, Integer occupancy, Integer vertexLabel, Integer readCount) {
this.type = type; this.type = type;
this.vertexLabel = vertexLabel; this.vertexLabel = vertexLabel;
this.sequence = sequence; this.sequence = sequence;
@@ -50,13 +50,12 @@ public class Vertex implements Serializable, Comparable<Vertex> {
this.vertexLabel = Integer.parseInt(label); this.vertexLabel = Integer.parseInt(label);
} }
public Integer getSequence() { public String getSequence() {
return sequence; return sequence;
} }
public void setSequence(String sequence) { public void setSequence(String sequence) {
this.sequence = Integer.parseInt(sequence); this.sequence = sequence;
} }
public Integer getOccupancy() { public Integer getOccupancy() {