Skip to content

Commit e097c99

Browse files
committed
2 parents 8397321 + ac00306 commit e097c99

File tree

11 files changed

+44
-31
lines changed

11 files changed

+44
-31
lines changed

src/main/java/tudelft/ti2806/pl3/data/wrapper/WrappedGraphData.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,36 @@ public class WrappedGraphData {
2020

2121
private final List<Wrapper> nodeWrappers;
2222
private final int longestNodePath;
23+
private int genomeSize;
2324

2425
/**
2526
* Initialises an instance of {@link WrappedGraphData}.
2627
*
2728
* @param nodeWrappers
2829
* the nodes in the instance
30+
* @param genomeSize
31+
* genome count withing the graph data
2932
*/
30-
public WrappedGraphData(List<Wrapper> nodeWrappers) {
33+
public WrappedGraphData(List<Wrapper> nodeWrappers, int genomeSize) {
3134
this.nodeWrappers = nodeWrappers;
3235
this.longestNodePath = Wrapper.computeLongestPaths(this.nodeWrappers);
36+
this.genomeSize = genomeSize;
3337
init();
3438
}
3539

3640
private void init() {
3741
for (Wrapper wrapper : nodeWrappers) {
3842
wrapper.calculateX();
3943
}
40-
ComputeInterest.compute(nodeWrappers);
44+
ComputeInterest.compute(nodeWrappers, genomeSize);
4145
}
4246

43-
public WrappedGraphData(List<DataNode> nodes, List<Edge> edges) {
44-
this(DataNodeWrapper.newNodePositionList(nodes, edges));
47+
public WrappedGraphData(List<DataNode> nodes, List<Edge> edges, int genomeSize) {
48+
this(DataNodeWrapper.newNodePositionList(nodes, edges), genomeSize);
4549
}
4650

4751
public WrappedGraphData(AbstractGraphData gd) {
48-
this(gd.getNodes(), gd.getEdges());
52+
this(gd.getNodes(), gd.getEdges(), gd.getGenomes().size());
4953
}
5054

5155
public List<Wrapper> getPositionedNodes() {
@@ -56,4 +60,8 @@ public int getLongestNodePath() {
5660
return longestNodePath;
5761
}
5862

63+
public int getGenomeSize() {
64+
return genomeSize;
65+
}
66+
5967
}

src/main/java/tudelft/ti2806/pl3/data/wrapper/util/HorizontalWrapUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static WrappedGraphData collapseGraph(WrappedGraphData original, boolean
3838
if (newLayer == null) {
3939
return null;
4040
}
41-
return new WrappedGraphData(newLayer);
41+
return new WrappedGraphData(newLayer, original.getGenomeSize());
4242
}
4343

4444
/**

src/main/java/tudelft/ti2806/pl3/data/wrapper/util/SpaceWrapUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static WrappedGraphData collapseGraph(WrappedGraphData original) {
4444
if (newLayer == null) {
4545
return null;
4646
}
47-
return new WrappedGraphData(newLayer);
47+
return new WrappedGraphData(newLayer, original.getGenomeSize());
4848
}
4949

5050
/**

src/main/java/tudelft/ti2806/pl3/data/wrapper/util/VerticalWrapUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static WrappedGraphData collapseGraph(WrappedGraphData original) {
3737
if (newLayer == null) {
3838
return null;
3939
}
40-
return new WrappedGraphData(newLayer);
40+
return new WrappedGraphData(newLayer, original.getGenomeSize());
4141
}
4242

4343
/**

src/main/java/tudelft/ti2806/pl3/data/wrapper/util/WrapUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static WrappedGraphData applyFixNode(WrappedGraphData graph) {
115115

116116
FixWrapUtil.addFixNodesToGraph(nodes, startFix, endFix);
117117

118-
WrappedGraphData wrappedGraph = collapseGraphSpacial(new WrappedGraphData(nodes));
118+
WrappedGraphData wrappedGraph = collapseGraphSpacial(new WrappedGraphData(nodes, graph.getGenomeSize()));
119119

120120
startFix.setX(-1);
121121
endFix.setX(wrappedGraph.getPositionedNodes().get(0).getWidth() + 1);

src/main/java/tudelft/ti2806/pl3/data/wrapper/util/interest/ComputeInterest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,28 @@
66
import java.util.List;
77

88
public final class ComputeInterest {
9+
910
private ComputeInterest() {
1011
}
11-
12+
1213
/**
1314
* Compute the interest for the wrappers.
1415
*
1516
* @param wrappers
16-
* the wrappers to compute interest for
17+
* the wrappers to compute interest for
1718
*/
18-
public static void compute(List<Wrapper> wrappers) {
19+
public static void compute(List<Wrapper> wrappers, int genomeCount) {
1920
for (Wrapper wrapper : wrappers) {
21+
int wrapperGenomeCount = wrapper.getGenome().size();
22+
if (wrapperGenomeCount == genomeCount) {
23+
continue;
24+
}
2025
wrapper.addInterest((float) (Math.sqrt(wrapper.getBasePairCount()
21-
* wrapper.getGenome().size()) * computeRation(wrapper)));
26+
* wrapper.getGenome().size()) * computeRation(wrapper)
27+
* (wrapper.getLabels() != null ? 1 + wrapper.getLabels().size() : 1)));
2228
}
2329
}
24-
30+
2531
/**
2632
* Computes the ratio of N's in the {@link DataNode}s within the given wrapper.
2733
*

src/main/java/tudelft/ti2806/pl3/visualization/FilteredGraphModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void produceWrappedGraphData() {
8888
filter(resultNodes);
8989
List<Edge> resultEdges = originalGraphData.getEdgeListClone();
9090
EdgeUtil.removeAllDeadEdges(resultEdges, resultNodes);
91-
wrappedGraphData = new WrappedGraphData(resultNodes, resultEdges);
91+
wrappedGraphData = new WrappedGraphData(resultNodes, resultEdges, originalGraphData.getGenomes().size());
9292
EdgeUtil.removeAllEmptyEdges(wrappedGraphData);
9393
collapsedNode = WrapUtil.collapseGraph(wrappedGraphData).getPositionedNodes().get(0);
9494
positionNodeYOnGenomeSpace.calculate(collapsedNode, null);

src/test/java/tudelft/ti2806/pl3/data/wrapper/util/NodeCombineUtilTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,12 @@ public void cutHorizontalTest() throws IOException {
175175
WrappedGraphData original = new WrappedGraphData(gdr);
176176
List<List<Wrapper>> result = new ArrayList<>();
177177
HorizontalWrapUtil.cutHorizontalWrapper(original.getPositionedNodes(), result);
178-
assertEquals(1, result.size());
178+
assertEquals(2, result.size());
179179
result.clear();
180180
original = HorizontalWrapUtil.collapseGraph(original, true);
181181
HorizontalWrapUtil.cutHorizontalWrapper(original.getPositionedNodes(), result);
182182
assertEquals(1, result.size());
183183
original = HorizontalWrapUtil.collapseGraph(original, true);
184-
result.clear();
185-
HorizontalWrapUtil.cutHorizontalWrapper(original.getPositionedNodes(), result);
186-
original = HorizontalWrapUtil.collapseGraph(original, true);
187-
assertEquals(1, result.size());
188184
UnwrapOnCollapse unwrap = new UnwrapOnCollapse(-1);
189185
unwrap.compute(original.getPositionedNodes().get(0));
190186
assertEquals(4, unwrap.getWrapperClones().size());

src/test/java/tudelft/ti2806/pl3/util/EdgeWeightTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package tudelft.ti2806.pl3.util;
22

3+
import static org.junit.Assert.assertTrue;
4+
35
import org.junit.Before;
46
import org.junit.Test;
7+
58
import tudelft.ti2806.pl3.data.gene.GeneData;
69
import tudelft.ti2806.pl3.data.graph.GraphDataRepository;
710
import tudelft.ti2806.pl3.data.wrapper.WrappedGraphData;
@@ -13,8 +16,6 @@
1316
import java.io.File;
1417
import java.io.IOException;
1518

16-
import static org.junit.Assert.assertTrue;
17-
1819
/**
1920
* Created by Boris Mattijssen on 09-06-15.
2021
*/
@@ -36,8 +37,7 @@ public void before() throws IOException {
3637
GeneData geneData = GeneData.parseGenes("data/testdata/TestGeneAnnotationsFile");
3738
GraphDataRepository graphDataRepository = new GraphDataRepository();
3839
graphDataRepository.parseGraph(nodesFile, edgesFile, geneData);
39-
WrappedGraphData wrappedGraphData = new WrappedGraphData(graphDataRepository.getNodes(),
40-
graphDataRepository.getEdges());
40+
WrappedGraphData wrappedGraphData = new WrappedGraphData(graphDataRepository);
4141
Wrapper collapsedNode = WrapUtil.collapseGraph(wrappedGraphData)
4242
.getPositionedNodes().get(0);
4343
new CanUnwrapOperation().calculate(collapsedNode, null);

src/test/java/tudelft/ti2806/pl3/util/EmptyEdgesAbstract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void loadWrappedGraphData(String file) throws IOException {
2323
GeneData geneData = GeneData.parseGenes("data/testdata/TestGeneAnnotationsFile");
2424
GraphDataRepository graphDataRepository = new GraphDataRepository();
2525
graphDataRepository.parseGraph(nodesFile, edgesFile, geneData);
26-
wrappedGraphData = new WrappedGraphData(graphDataRepository.getNodes(), graphDataRepository.getEdges());
26+
wrappedGraphData = new WrappedGraphData(graphDataRepository);
2727
EdgeUtil.removeAllEmptyEdges(wrappedGraphData);
2828
nodes = wrappedGraphData.getPositionedNodes();
2929
}

src/test/java/tudelft/ti2806/pl3/visualisation/FilteredGraphModelTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package tudelft.ti2806.pl3.visualisation;
22

3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
5+
36
import org.junit.Before;
47
import org.junit.Test;
8+
59
import tudelft.ti2806.pl3.data.Genome;
610
import tudelft.ti2806.pl3.data.filter.Filter;
711
import tudelft.ti2806.pl3.data.filter.GenomeFilter;
@@ -21,14 +25,12 @@
2125
import java.util.ArrayList;
2226
import java.util.List;
2327

24-
import static org.junit.Assert.assertEquals;
25-
import static org.junit.Assert.assertTrue;
26-
2728
public class FilteredGraphModelTest {
2829

2930
private List<DataNode> resultNodes;
3031
private List<Edge> resultEdges;
3132
private final String genomeToFilter = "B";
33+
private int genomeCount;
3234

3335
@Before
3436
public void before() throws IOException {
@@ -48,6 +50,7 @@ public void before() throws IOException {
4850
resultNodes = graphDataRepository.getNodeListClone();
4951
filteredGraphModel.filter(resultNodes);
5052
resultEdges = graphDataRepository.getEdgeListClone();
53+
genomeCount = graphDataRepository.getGenomes().size();
5154
}
5255

5356
@Test
@@ -78,7 +81,7 @@ public void testDeadEdges() {
7881
@Test
7982
public void testEmptyEdges() {
8083
EdgeUtil.removeAllDeadEdges(resultEdges, resultNodes);
81-
WrappedGraphData wrappedGraphData = new WrappedGraphData(resultNodes, resultEdges);
84+
WrappedGraphData wrappedGraphData = new WrappedGraphData(resultNodes, resultEdges, genomeCount);
8285
EdgeUtil.removeAllEmptyEdges(wrappedGraphData);
8386
List<Wrapper> nodes = wrappedGraphData.getPositionedNodes();
8487
assertEquals(1, nodes.get(0).getOutgoing().size());
@@ -93,7 +96,7 @@ public void testEmptyEdges() {
9396
@Test
9497
public void testEmptyEdgesIncoming() {
9598
EdgeUtil.removeAllDeadEdges(resultEdges, resultNodes);
96-
WrappedGraphData wrappedGraphData = new WrappedGraphData(resultNodes, resultEdges);
99+
WrappedGraphData wrappedGraphData = new WrappedGraphData(resultNodes, resultEdges, genomeCount);
97100
EdgeUtil.removeAllEmptyEdges(wrappedGraphData);
98101
List<Wrapper> nodes = wrappedGraphData.getPositionedNodes();
99102
assertEquals(0, nodes.get(0).getIncoming().size());
@@ -108,7 +111,7 @@ public void testEmptyEdgesIncoming() {
108111
@Test
109112
public void testCollapse() {
110113
EdgeUtil.removeAllDeadEdges(resultEdges, resultNodes);
111-
WrappedGraphData wrappedGraphData = new WrappedGraphData(resultNodes, resultEdges);
114+
WrappedGraphData wrappedGraphData = new WrappedGraphData(resultNodes, resultEdges, genomeCount);
112115
EdgeUtil.removeAllEmptyEdges(wrappedGraphData);
113116
Wrapper collapsedNode = WrapUtil.collapseGraph(wrappedGraphData).getPositionedNodes().get(0);
114117
assertTrue(collapsedNode instanceof HorizontalWrapper);

0 commit comments

Comments
 (0)