Refactor Vertex class to use SequenceRecords

This commit is contained in:
eugenefischer
2022-09-28 00:58:44 -05:00
parent 9973473cc6
commit 610da68262
2 changed files with 22 additions and 66 deletions

View File

@@ -105,8 +105,7 @@ public class Simulator implements GraphModificationFunctions {
//the list of alpha vertices
List<Vertex> alphaVertices = new ArrayList<>();
for (String seq : plateAtoVMap.keySet()) {
Vertex alphaVertex = new Vertex(SequenceType.CDR3_ALPHA, seq, alphaSequences.get(seq).getOccupancy(),
plateAtoVMap.get(seq), alphaSequences.get(seq).getReadCount());
Vertex alphaVertex = new Vertex(alphaSequences.get(seq), plateAtoVMap.get(seq));
alphaVertices.add(alphaVertex);
}
//Sort to make sure the order of vertices in list matches the order of the adjacency matrix
@@ -116,8 +115,7 @@ public class Simulator implements GraphModificationFunctions {
//the list of beta vertices
List<Vertex> betaVertices = new ArrayList<>();
for (String seq : plateBtoVMap.keySet()) {
Vertex betaVertex = new Vertex(SequenceType.CDR3_BETA, seq, betaSequences.get(seq).getOccupancy(),
plateBtoVMap.get(seq), betaSequences.get(seq).getReadCount());
Vertex betaVertex = new Vertex(betaSequences.get(seq), plateBtoVMap.get(seq));
betaVertices.add(betaVertex);
}
//Sort to make sure the order of vertices in list matches the order of the adjacency matrix

View File

@@ -1,76 +1,43 @@
import org.jheaps.AddressableHeap;
import java.io.Serializable;
import java.util.Map;
public class Vertex implements Serializable, Comparable<Vertex> {
private SequenceType type;
private Integer vertexLabel;
private String sequence;
private Integer occupancy;
private Integer readCount;
private Double potential;
private SequenceRecord record;
private Integer vertexLabel;
private Double potential;
private AddressableHeap queue;
public Vertex(Integer vertexLabel) {
public Vertex(SequenceRecord record, Integer vertexLabel) {
this.record = record;
this.vertexLabel = vertexLabel;
}
public Vertex(String vertexLabel) {
this.vertexLabel = Integer.parseInt((vertexLabel));
}
public Vertex(SequenceType type, String sequence, Integer occupancy, Integer vertexLabel) {
this.type = type;
this.vertexLabel = vertexLabel;
this.sequence = sequence;
this.occupancy = occupancy;
this.readCount = 1;
}
public SequenceRecord getRecord() { return record; }
public Vertex(SequenceType type, String sequence, Integer occupancy, Integer vertexLabel, Integer readCount) {
this.type = type;
this.vertexLabel = vertexLabel;
this.sequence = sequence;
this.occupancy = occupancy;
this.readCount = readCount;
}
public SequenceType getType() {
return type;
}
public void setType(String type) {
this.type = SequenceType.valueOf(type);
}
public SequenceType getType() { return record.getSequenceType(); }
public Integer getVertexLabel() {
return vertexLabel;
}
public void setVertexLabel(String label) {
this.vertexLabel = Integer.parseInt(label);
}
public String getSequence() {
return sequence;
}
public void setSequence(String sequence) {
this.sequence = sequence;
return record.getSequence();
}
public Integer getOccupancy() {
return occupancy;
return record.getOccupancy();
}
public void setOccupancy(String occupancy) {
this.occupancy = Integer.parseInt(occupancy);
}
public Integer getReadCount() { return record.getReadCount(); }
public Map<Integer, Integer> getWellOccupancies() { return record.getWellOccupancies(); }
@Override //adapted from JGraphT example code
public int hashCode()
{
return (sequence == null) ? 0 : sequence.hashCode();
return (this.getSequence() == null) ? 0 : this.getSequence().hashCode();
}
@Override //adapted from JGraphT example code
@@ -83,22 +50,21 @@ public class Vertex implements Serializable, Comparable<Vertex> {
if (getClass() != obj.getClass())
return false;
Vertex other = (Vertex) obj;
if (sequence == null) {
return other.sequence == null;
if (this.getSequence() == null) {
return other.getSequence() == null;
} else {
return sequence.equals(other.sequence);
return this.getSequence().equals(other.getSequence());
}
}
@Override //adapted from JGraphT example code
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("(").append(vertexLabel)
.append(", Type: ").append(type.name())
.append(", Sequence: ").append(sequence)
.append(", Occupancy: ").append(occupancy).append(")");
.append(", Type: ").append(this.getType().name())
.append(", Sequence: ").append(this.getSequence())
.append(", Occupancy: ").append(this.getOccupancy()).append(")");
return sb.toString();
}
@@ -106,12 +72,4 @@ public class Vertex implements Serializable, Comparable<Vertex> {
public int compareTo(Vertex other) {
return this.vertexLabel - other.getVertexLabel();
}
public Integer getReadCount() {
return readCount;
}
public void setReadCount(Integer readCount) {
this.readCount = readCount;
}
}