Skip to content

Commit ac18e1b

Browse files
committed
Merge pull request #42 from maartentbm/mutations
All sprint 7 progress.
2 parents 6a09bb4 + 2f62a7b commit ac18e1b

60 files changed

Lines changed: 2952 additions & 626 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
*.nwk
1111
*.graph
1212
*.classpath
13+
resistanceCausingMutations.tsv
1314
resistanceCausingMutations.txt
15+
Gene_annotations.tsv
1416

1517
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1618
hs_err_pid*
Binary file not shown.
144 KB
Binary file not shown.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>ContextPL1</groupId>
44
<artifactId>ContextPL1</artifactId>
5-
<version>0.0.1-SNAPSHOT</version>
5+
<version>7.1-SNAPSHOT</version>
66
<name>Programming Life</name>
77
<description>Context project of programming life</description>
88
<dependencies>

src/main/java/Start.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
import javax.swing.SwingUtilities;
42

53
import nl.tudelft.ti2806.pl1.gui.Window;
@@ -22,6 +20,7 @@ private Start() {
2220
*/
2321
public static void main(final String[] args) {
2422
SwingUtilities.invokeLater(new Runnable() {
23+
@Override
2524
public void run() {
2625
new Window();
2726
}

src/main/java/nl/tudelft/ti2806/pl1/DGraph/ConvertDGraph.java

Lines changed: 82 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,111 @@
11
package nl.tudelft.ti2806.pl1.DGraph;
22

3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
7+
import nl.tudelft.ti2806.pl1.gui.contentpane.ViewArea;
8+
39
import org.graphstream.graph.Graph;
10+
import org.graphstream.graph.Node;
411
import org.graphstream.graph.implementations.SingleGraph;
512

613
/**
7-
* Converts a DGraph into a graphstream graph.
14+
* Contains methods to create a visual graph from a data graph.
815
*
9-
* @author mark
16+
* @author Mark, Maarten, Justin
1017
*
18+
* @see Graph
19+
* @see DGraph
1120
*/
1221
public final class ConvertDGraph {
1322

1423
/**
15-
* When this threshold is surpassed, the length instead of the label will be
16-
* shown.
24+
* When this threshold is surpassed, the length instead of the content of a
25+
* node will be displayed on or next to the node.
1726
*/
1827
private static final int LABEL_LENGTH_THRESHOLD = 10;
1928

2029
/**
21-
* Converts a DGraph into a graphstream graph.
30+
*/
31+
private ConvertDGraph() {
32+
}
33+
34+
/**
35+
* Converts a data graph into a visual graph.
36+
*
2237
*
2338
* @param dgraph
24-
* The dgraph to be converted
25-
* @return Graphstream graph
39+
* The data graph to convert.
40+
* @return The visual graph containing all the nodes from the data graph.
2641
*/
2742
public static Graph convert(final DGraph dgraph) {
28-
Graph graph = new SingleGraph("DNApp");
29-
for (DNode n : dgraph.getNodes().values()) {
43+
return convert(dgraph, new ViewArea(Integer.MIN_VALUE,
44+
Integer.MAX_VALUE));
45+
}
46+
47+
/**
48+
* Converts a part of a data graph into a visual graph.
49+
*
50+
* @param dgraph
51+
* The data graph to convert.
52+
* @param va
53+
* The area of the graph to convert.
54+
* @return The visual graph containing the nodes positioned in the given
55+
* view area of the data graph.
56+
*/
57+
public static Graph convert(final DGraph dgraph, final ViewArea va) {
58+
Graph graph = new SingleGraph("");
59+
Set<DEdge> edges = new HashSet<DEdge>();
60+
for (DNode n : dgraph.getDNodes(va)) {
61+
edges.addAll(n.getAllEdges());
3062
String id = String.valueOf(n.getId());
31-
graph.addNode(id);
32-
graph.getNode(id).addAttribute("x", n.getX());
33-
graph.getNode(id).addAttribute("y", n.getY());
34-
graph.getNode(id).addAttribute("ui.label",
35-
checkLabelLength(n.getContent()));
36-
graph.getNode(id).addAttribute("ui.class", "common");
37-
graph.getNode(id).addAttribute("ui.color", 1 - n.getPercUnknown());
63+
Node gn = graph.addNode(id);
64+
gn.addAttribute("x", n.getX());
65+
gn.addAttribute("y", n.getY());
66+
gn.addAttribute("ui.label", checkLabelLength(n.getContent()));
67+
gn.addAttribute("ui.class", "common");
68+
gn.addAttribute("ui.color", 1 - n.getPercUnknown());
69+
gn.addAttribute("contentsize", n.getContent().length());
70+
gn.addAttribute("collapsed",
71+
new HashSet<Integer>(Arrays.asList(n.getId())));
3872
}
39-
for (DEdge edge : dgraph.getEdges()) {
40-
String src = String.valueOf(edge.getStartNode().getId());
41-
String target = String.valueOf(edge.getEndNode().getId());
42-
graph.addEdge(src + target, src, target, true);
73+
for (DEdge edge : edges) {
74+
String from = String.valueOf(edge.getStartNode().getId());
75+
String to = String.valueOf(edge.getEndNode().getId());
76+
if (graph.getNode(from) == null) {
77+
addNodeToGraph(graph, from, dgraph);
78+
} else if (graph.getNode(to) == null) {
79+
addNodeToGraph(graph, to, dgraph);
80+
}
81+
graph.addEdge(from + to, from, to, true);
4382
}
4483
return graph;
4584
}
4685

86+
/**
87+
* Creates a visual node object, extracts the needed data from a data graph
88+
* and adds it to a visual graph.
89+
*
90+
* @param g
91+
* The graph to add the new node to.
92+
* @param id
93+
* The id for the new node.
94+
* @param dg
95+
* The data graph where the node is defined.
96+
* @return
97+
*/
98+
private static void addNodeToGraph(final Graph g, final String id,
99+
final DGraph dg) {
100+
Node gn = g.addNode(id);
101+
DNode n = dg.getDNode(Integer.parseInt(id));
102+
gn.addAttribute("x", n.getX());
103+
gn.addAttribute("y", n.getY());
104+
gn.addAttribute("ui.label", checkLabelLength(n.getContent()));
105+
gn.addAttribute("ui.class", "common");
106+
gn.addAttribute("ui.color", 1 - n.getPercUnknown());
107+
}
108+
47109
/**
48110
* Compares the label with a threshold length and returns the label if it's
49111
* smaller than the threshold, otherwise it returns the length.

src/main/java/nl/tudelft/ti2806/pl1/DGraph/DEdge.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,9 @@ public int hashCode() {
111111
result += PRIME_37 * result + getEndNode().getId();
112112
return result;
113113
}
114+
115+
@Override
116+
public String toString() {
117+
return "<Edge[" + startNode + "->" + endNode + "]>";
118+
}
114119
}

src/main/java/nl/tudelft/ti2806/pl1/DGraph/DGraph.java

Lines changed: 92 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,30 @@
66
import java.util.Map;
77

88
import nl.tudelft.ti2806.pl1.geneAnnotation.ReferenceGeneStorage;
9+
import nl.tudelft.ti2806.pl1.gui.contentpane.ViewArea;
10+
import nl.tudelft.ti2806.pl1.mutation.DeletionMutation;
11+
import nl.tudelft.ti2806.pl1.mutation.InsertionMutation;
12+
import nl.tudelft.ti2806.pl1.mutation.MutatedGraph;
13+
import nl.tudelft.ti2806.pl1.mutation.PointMutation;
914

1015
/**
1116
* The DGraph class for representing our data.
1217
*
1318
* @author Mark
1419
*
1520
*/
16-
public class DGraph {
21+
public class DGraph implements MutatedGraph, DynamicGraph {
1722

18-
/**
19-
* The nodes in the graph.
20-
*/
23+
/** The nodes in the graph. */
2124
private final Map<Integer, DNode> nodes;
2225

23-
/**
24-
* A map storing a collection nodes per genome reference.
25-
*/
26+
/** A map storing a collection nodes per genome reference. */
2627
private HashMap<String, Collection<DNode>> references;
2728

28-
/**
29-
* The edges in the graph.
30-
*/
29+
/** The edges in the graph. */
3130
private Collection<DEdge> edges;
3231

33-
/**
34-
* The start node and end node of the graph.
35-
*/
32+
/** The start node and end node of the graph. */
3633
private DNode start, end;
3734

3835
/** Storage of all the genes in the reference genome. */
@@ -45,6 +42,15 @@ public class DGraph {
4542
// private static final String MUTATION_FILE =
4643
// "resistanceCausingMutations.txt";
4744

45+
/** All the point mutations in the graph. */
46+
private Collection<PointMutation> pointMutations;
47+
48+
/** All the deletion mutations in the graph. */
49+
private Collection<DeletionMutation> delmutations;
50+
51+
/** All the insertion mutations in the graph. */
52+
private Collection<InsertionMutation> insmutations;
53+
4854
/**
4955
* Creates a new DGraph.
5056
*/
@@ -266,4 +272,77 @@ public final void setEnd(final DNode e) {
266272
this.end = e;
267273
}
268274

275+
/** {@inheritDoc} */
276+
@Override
277+
public Collection<PointMutation> getAllPointMutations() {
278+
return pointMutations;
279+
}
280+
281+
@Override
282+
public Collection<PointMutation> getAllInDelMutations() {
283+
return pointMutations;
284+
}
285+
286+
/** {@inheritDoc} */
287+
@Override
288+
public Collection<DNode> getDNodes(final ViewArea va) {
289+
ArrayList<DNode> ret = new ArrayList<DNode>();
290+
for (DNode n : getNodes().values()) {
291+
if (va.isContained(n)) {
292+
ret.add(n);
293+
}
294+
}
295+
return ret;
296+
}
297+
298+
@Override
299+
public String toString() {
300+
return nodes + " " + edges;
301+
}
302+
303+
/**
304+
* @param newPointMutations
305+
* pointMutations to set.
306+
*/
307+
public void setPointMutations(
308+
final Collection<PointMutation> newPointMutations) {
309+
this.pointMutations = newPointMutations;
310+
}
311+
312+
/**
313+
* @param deletionMutationsIn
314+
* deletion mutations to set.
315+
*/
316+
public void setDeletionMutations(
317+
final Collection<DeletionMutation> deletionMutationsIn) {
318+
delmutations = deletionMutationsIn;
319+
}
320+
321+
/** @return the deletion mutations. */
322+
public Collection<DeletionMutation> getDelmutations() {
323+
return delmutations;
324+
}
325+
326+
/**
327+
* @return the insmutations
328+
*/
329+
public Collection<InsertionMutation> getInsmutations() {
330+
return insmutations;
331+
}
332+
333+
/**
334+
* @param insmutationsIn
335+
* the insmutations to set
336+
*/
337+
public void setInsertionmutations(
338+
final Collection<InsertionMutation> insmutationsIn) {
339+
this.insmutations = insmutationsIn;
340+
}
341+
342+
/**
343+
* @return the referenceGeneStorage
344+
*/
345+
public final ReferenceGeneStorage getReferenceGeneStorage() {
346+
return referenceGeneStorage;
347+
}
269348
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
*
3+
*/
4+
package nl.tudelft.ti2806.pl1.DGraph;
5+
6+
/**
7+
* @author Maarten, Justin
8+
* @since 4-6-2015
9+
*
10+
*/
11+
public interface DGraphInterface {
12+
13+
}

src/main/java/nl/tudelft/ti2806/pl1/DGraph/DNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,9 @@ public final boolean equals(final Object o) {
397397
public final int hashCode() {
398398
return getId();
399399
}
400+
401+
@Override
402+
public String toString() {
403+
return "<Node[" + id + "]>";
404+
}
400405
}

0 commit comments

Comments
 (0)