Implement read count for vertices
This commit is contained in:
@@ -12,7 +12,6 @@ public interface GraphModificationFunctions {
|
|||||||
static Map<Vertex[], Integer> filterByOverlapThresholds(SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph,
|
static Map<Vertex[], Integer> filterByOverlapThresholds(SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph,
|
||||||
int low, int high, boolean saveEdges) {
|
int low, int high, boolean saveEdges) {
|
||||||
Map<Vertex[], Integer> removedEdges = new HashMap<>();
|
Map<Vertex[], Integer> removedEdges = new HashMap<>();
|
||||||
//List<Integer[]> removedEdges = new ArrayList<>();
|
|
||||||
for (DefaultWeightedEdge e : graph.edgeSet()) {
|
for (DefaultWeightedEdge e : graph.edgeSet()) {
|
||||||
if ((graph.getEdgeWeight(e) > high) || (graph.getEdgeWeight(e) < low)) {
|
if ((graph.getEdgeWeight(e) > high) || (graph.getEdgeWeight(e) < low)) {
|
||||||
if(saveEdges) {
|
if(saveEdges) {
|
||||||
@@ -94,6 +93,37 @@ public interface GraphModificationFunctions {
|
|||||||
return removedEdges;
|
return removedEdges;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Map<Vertex[], Integer> filterByRelativeReadCount (SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph, Integer threshold, boolean saveEdges) {
|
||||||
|
Map<Vertex[], Integer> removedEdges = new HashMap<>();
|
||||||
|
Boolean passes;
|
||||||
|
for (DefaultWeightedEdge e : graph.edgeSet()) {
|
||||||
|
Integer alphaReadCount = graph.getEdgeSource(e).getReadCount();
|
||||||
|
Integer betaReadCount = graph.getEdgeTarget(e).getReadCount();
|
||||||
|
passes = RelativeReadCountFilterFunction(threshold, alphaReadCount, betaReadCount);
|
||||||
|
if (!passes) {
|
||||||
|
if (saveEdges) {
|
||||||
|
Vertex source = graph.getEdgeSource(e);
|
||||||
|
Vertex target = graph.getEdgeTarget(e);
|
||||||
|
Integer intWeight = (int) graph.getEdgeWeight(e);
|
||||||
|
Vertex[] edge = {source, target};
|
||||||
|
removedEdges.put(edge, intWeight);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
graph.setEdgeWeight(e, 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(saveEdges) {
|
||||||
|
for (Vertex[] edge : removedEdges.keySet()) {
|
||||||
|
graph.removeEdge(edge[0], edge[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return removedEdges;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Boolean RelativeReadCountFilterFunction(Integer threshold, Integer alphaReadCount, Integer betaReadCount) {
|
||||||
|
return Math.abs(alphaReadCount - betaReadCount) < threshold;
|
||||||
|
}
|
||||||
static void addRemovedEdges(SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph,
|
static void addRemovedEdges(SimpleWeightedGraph<Vertex, DefaultWeightedEdge> graph,
|
||||||
Map<Vertex[], Integer> removedEdges) {
|
Map<Vertex[], Integer> removedEdges) {
|
||||||
for (Vertex[] edge : removedEdges.keySet()) {
|
for (Vertex[] edge : removedEdges.keySet()) {
|
||||||
@@ -102,4 +132,6 @@ public interface GraphModificationFunctions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +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 int readDepth;
|
||||||
private final Map<String, String> 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;
|
||||||
@@ -25,7 +26,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<String, String> distCellsMapAlphaKey, Integer alphaCount, Integer betaCount, Duration time){
|
Map<String, String> distCellsMapAlphaKey, Integer alphaCount, Integer betaCount, int readDepth, 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,
|
||||||
@@ -94,6 +95,8 @@ public class GraphWithMapData implements java.io.Serializable {
|
|||||||
// return betaWellCounts;
|
// return betaWellCounts;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public int getReadDepth() { return readDepth; }
|
||||||
|
|
||||||
public Duration getTime() {
|
public Duration getTime() {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,6 +273,9 @@ public class InteractiveInterface {
|
|||||||
if (simulateReadDepth) {
|
if (simulateReadDepth) {
|
||||||
System.out.print("\nPlease enter read depth (the integer number of reads per sequence): ");
|
System.out.print("\nPlease enter read depth (the integer number of reads per sequence): ");
|
||||||
readDepth = sc.nextInt();
|
readDepth = sc.nextInt();
|
||||||
|
if(readDepth < 1) {
|
||||||
|
throw new InputMismatchException("The read depth must be an integer >= 1");
|
||||||
|
}
|
||||||
System.out.print("\nPlease enter probability of a sequence read error (0.0 to 1.0): ");
|
System.out.print("\nPlease enter probability of a sequence read error (0.0 to 1.0): ");
|
||||||
readErrorRate = sc.nextDouble();
|
readErrorRate = sc.nextDouble();
|
||||||
if(readErrorRate < 0.0 || readErrorRate > 1.0) {
|
if(readErrorRate < 0.0 || readErrorRate > 1.0) {
|
||||||
@@ -332,7 +335,7 @@ public class InteractiveInterface {
|
|||||||
System.out.println("Returning to main menu.");
|
System.out.println("Returning to main menu.");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
GraphWithMapData data = Simulator.makeGraph(cellSample, plate, true);
|
GraphWithMapData data = Simulator.makeGraph(cellSample, plate, readDepth, readErrorRate, errorCollisionRate, true);
|
||||||
assert filename != null;
|
assert filename != null;
|
||||||
if(BiGpairSEQ.outputBinary()) {
|
if(BiGpairSEQ.outputBinary()) {
|
||||||
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);
|
GraphDataObjectWriter dataWriter = new GraphDataObjectWriter(filename, data);
|
||||||
|
|||||||
@@ -178,17 +178,30 @@ public class Plate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//returns a map of the counts of the sequence at cell index sIndex, in a specific of wells
|
||||||
|
//Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
|
||||||
|
public void assayWellsSequenceSWithReadDepth(Map<String, Integer> occupancyMap, Map<String, Integer> readCountMap,
|
||||||
|
int readDepth, double readErrorProb, double errorCollisionProb, int... sIndices) {
|
||||||
|
this.assayWellsSequenceSWithReadDepth(occupancyMap, readCountMap, readDepth, readErrorProb, errorCollisionProb, 0, size, sIndices);
|
||||||
|
}
|
||||||
|
//returns a map of the counts of the sequence at cell index sIndex, in a specific of wells
|
||||||
|
//Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
|
||||||
|
public void assayWellsSequenceSWithReadDepth(Map<String, Integer> occupancyMap, Map<String, Integer> readCountMap,
|
||||||
|
int readDepth, double readErrorProb, double errorCollisionProb,
|
||||||
|
int n, int... sIndices) {
|
||||||
|
this.assayWellsSequenceSWithReadDepth(occupancyMap, readCountMap, readDepth, readErrorProb, errorCollisionProb, 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
|
||||||
//Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
|
//Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
|
||||||
public Map<String, Integer> assayWellsSequenceSWithReadDepth(int start, int end, int... sIndices) {
|
public void assayWellsSequenceSWithReadDepth(Map<String, Integer> occupancyMap, Map<String, Integer> readCountMap,
|
||||||
Map<String, Integer> assay = new HashMap<>();
|
int readDepth, double readErrorProb, double errorCollisionProb,
|
||||||
|
int start, int end, int... sIndices) {
|
||||||
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);
|
countSequencesWithReadDepth(occupancyMap, readCountMap, readDepth, readErrorProb, errorCollisionProb, 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
|
//For the sequences at cell indices sIndices, counts number of unique sequences in the given well into the given map
|
||||||
//Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
|
//Simulates read depth and read errors, counts the number of reads of a unique sequence into the given map.
|
||||||
|
|||||||
@@ -21,8 +21,12 @@ public class Simulator implements GraphModificationFunctions {
|
|||||||
//sourceVertexIndices and targetVertexIndices are indices within the cell to use as for the two sets of vertices
|
//sourceVertexIndices and targetVertexIndices are indices within the cell to use as for the two sets of vertices
|
||||||
//in the bipartite graph. "Source" and "target" are JGraphT terms for the two vertices an edge touches,
|
//in the bipartite graph. "Source" and "target" are JGraphT terms for the two vertices an edge touches,
|
||||||
//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, int readDepth, double readErrorRate, double errorCollisionRate, boolean verbose) {
|
||||||
Instant start = Instant.now();
|
Instant start = Instant.now();
|
||||||
|
Map<String, Integer> allAlphas;
|
||||||
|
Map<String, Integer> allBetas;
|
||||||
|
Map<String, Integer> alphaReadCounts = null;
|
||||||
|
Map<String, Integer> betaReadCounts = null;
|
||||||
List<String[]> 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()};
|
||||||
@@ -35,11 +39,21 @@ public class Simulator implements GraphModificationFunctions {
|
|||||||
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");}
|
||||||
|
if(readDepth == 1) {
|
||||||
|
allAlphas = new HashMap<>();
|
||||||
|
samplePlate.assayWellsSequenceS(allAlphas, alphaIndices);
|
||||||
|
allBetas = new HashMap<>();
|
||||||
|
samplePlate.assayWellsSequenceS(allBetas, betaIndices);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
allAlphas = new HashMap<>();
|
||||||
|
alphaReadCounts = new HashMap<>();
|
||||||
|
samplePlate.assayWellsSequenceSWithReadDepth(allAlphas, alphaReadCounts, readDepth, readErrorRate, errorCollisionRate, alphaIndices);
|
||||||
|
allBetas = new HashMap<>();
|
||||||
|
betaReadCounts = new HashMap<>();
|
||||||
|
samplePlate.assayWellsSequenceSWithReadDepth(allBetas, betaReadCounts, readDepth, readErrorRate, errorCollisionRate, 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();
|
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();
|
||||||
@@ -101,7 +115,13 @@ public class Simulator implements GraphModificationFunctions {
|
|||||||
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 (String seq : plateAtoVMap.keySet()) {
|
for (String seq : plateAtoVMap.keySet()) {
|
||||||
Vertex alphaVertex = new Vertex(SequenceType.CDR3_ALPHA, seq, alphaWellCounts.get(seq), plateAtoVMap.get(seq));
|
Vertex alphaVertex;
|
||||||
|
if (readDepth == 1) {
|
||||||
|
alphaVertex = new Vertex(SequenceType.CDR3_ALPHA, seq, alphaWellCounts.get(seq), plateAtoVMap.get(seq));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alphaVertex = new Vertex(SequenceType.CDR3_ALPHA, seq, alphaWellCounts.get(seq), plateAtoVMap.get(seq), alphaReadCounts.get(seq));
|
||||||
|
}
|
||||||
alphaVertices.add(alphaVertex);
|
alphaVertices.add(alphaVertex);
|
||||||
}
|
}
|
||||||
//Sort to make sure the order of vertices in list matches the order of the adjacency matrix
|
//Sort to make sure the order of vertices in list matches the order of the adjacency matrix
|
||||||
@@ -112,7 +132,13 @@ public class Simulator implements GraphModificationFunctions {
|
|||||||
//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 (String seq : plateBtoVMap.keySet()) {
|
for (String seq : plateBtoVMap.keySet()) {
|
||||||
Vertex betaVertex = new Vertex(SequenceType.CDR3_BETA, seq, betaWellCounts.get(seq), plateBtoVMap.get(seq));
|
Vertex betaVertex;
|
||||||
|
if (readDepth == 1) {
|
||||||
|
betaVertex = new Vertex(SequenceType.CDR3_BETA, seq, betaWellCounts.get(seq), plateBtoVMap.get(seq));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
betaVertex = new Vertex(SequenceType.CDR3_BETA, seq, betaWellCounts.get(seq), plateBtoVMap.get(seq), betaReadCounts.get(seq));
|
||||||
|
}
|
||||||
betaVertices.add(betaVertex);
|
betaVertices.add(betaVertex);
|
||||||
}
|
}
|
||||||
//Sort to make sure the order of vertices in list matches the order of the adjacency matrix
|
//Sort to make sure the order of vertices in list matches the order of the adjacency matrix
|
||||||
@@ -128,7 +154,7 @@ public class Simulator implements GraphModificationFunctions {
|
|||||||
Duration time = Duration.between(start, stop);
|
Duration time = Duration.between(start, stop);
|
||||||
|
|
||||||
//create GraphWithMapData object
|
//create GraphWithMapData object
|
||||||
GraphWithMapData output = new GraphWithMapData(graph, numWells, samplePlate.getPopulations(), distCellsMapAlphaKey, alphaCount, betaCount, time);
|
GraphWithMapData output = new GraphWithMapData(graph, numWells, samplePlate.getPopulations(), distCellsMapAlphaKey, alphaCount, betaCount, readDepth, time);
|
||||||
//Set source file name in graph to name of sample plate
|
//Set source file name in graph to name of sample plate
|
||||||
output.setSourceFilename(samplePlate.getFilename());
|
output.setSourceFilename(samplePlate.getFilename());
|
||||||
//return GraphWithMapData object
|
//return GraphWithMapData object
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class Vertex implements Serializable, Comparable<Vertex> {
|
|||||||
this.vertexLabel = vertexLabel;
|
this.vertexLabel = vertexLabel;
|
||||||
this.sequence = sequence;
|
this.sequence = sequence;
|
||||||
this.occupancy = occupancy;
|
this.occupancy = occupancy;
|
||||||
|
this.readCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vertex(SequenceType type, String sequence, Integer occupancy, Integer vertexLabel, Integer readCount) {
|
public Vertex(SequenceType type, String sequence, Integer occupancy, Integer vertexLabel, Integer readCount) {
|
||||||
|
|||||||
Reference in New Issue
Block a user