Skip to content

Commit 3946717

Browse files
committed
Fix the scoring and show it in the pane.
Remove indepent mutation score. Fix the zooming.
1 parent cf87502 commit 3946717

12 files changed

Lines changed: 34 additions & 65 deletions

File tree

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/impl/command/AnalyzeCommand.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package nl.tudelft.dnainator.graph.impl.command;
22

3-
import java.util.Collections;
4-
import java.util.HashSet;
3+
import java.util.HashMap;
54
import java.util.Map;
6-
import java.util.Set;
75

86
import nl.tudelft.dnainator.graph.impl.NodeLabels;
97
import nl.tudelft.dnainator.graph.impl.RelTypes;
@@ -80,7 +78,6 @@ public void execute(GraphDatabaseService service) {
8078
) {
8179
for (Node n : topologicalOrder(service, processed)) {
8280
rankDest(n);
83-
scoreIndependentMutation(n);
8481
}
8582
scoreDRMutations(service);
8683
tx.success();
@@ -113,6 +110,7 @@ private void rankDest(Node n) {
113110
* @param service the graph service
114111
*/
115112
private void scoreDRMutations(GraphDatabaseService service) {
113+
Map<String, Object> params = new HashMap<>(1);
116114
service.findNodes(NodeLabels.DRMUTATION).forEachRemaining(drannotations ->
117115
drannotations.getRelationships(RelTypes.ANNOTATED).forEach(node -> {
118116
// From the startref of the annotation
@@ -122,7 +120,7 @@ private void scoreDRMutations(GraphDatabaseService service) {
122120
- (int) node.getStartNode().getProperty(SequenceProperties.STARTREF.name())
123121
+ (int) node.getStartNode().getProperty(SequenceProperties.BASE_DIST.name());
124122

125-
Map<String, Object> params = Collections.singletonMap("dist", basedist);
123+
params.put("dist", basedist);
126124
ResourceIterator<Node> mutations = service.execute(GET_NODES_BASEDIST, params)
127125
.columnAs(LABEL);
128126
mutations.forEachRemaining(m -> {
@@ -132,18 +130,4 @@ private void scoreDRMutations(GraphDatabaseService service) {
132130
})
133131
);
134132
}
135-
136-
/**
137-
* Scores the amount of independent mutations, using the phylogeny.
138-
* @param n the node representing the mutation.
139-
*/
140-
protected void scoreIndependentMutation(Node n) {
141-
Set<Node> ancestors = new HashSet<>();
142-
for (Relationship r : n.getRelationships(RelTypes.SOURCE)) {
143-
r.getEndNode().getRelationships(RelTypes.ANCESTOR_OF, Direction.INCOMING).forEach(e ->
144-
ancestors.add(e.getStartNode())
145-
);
146-
}
147-
n.setProperty(Scores.INDEP_MUT.name(), ancestors.size());
148-
}
149133
}

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/interestingness/InterestingnessStrategy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* is calculated.
66
*/
77
public interface InterestingnessStrategy {
8+
int RANGE_LOWER = 0;
9+
int RANGE_UPPER = 1000;
810

911
/**
1012
* Compute the interestingness at the given location.

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/interestingness/ScoreContainer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* Represents a location within the graph.
1010
*/
1111
public interface ScoreContainer {
12-
1312
/**
1413
* @param id the identifier of the property, which is used to get the score of
1514
* a particular property.

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/interestingness/Scores.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,26 @@
44
* All of the supported scores.
55
*/
66
public enum Scores implements ScoreIdentifier {
7-
SEQ_LENGTH("seqLength") {
8-
private static final int DENOMINATOR = 500;
7+
SEQ_LENGTH("Sequence Length Score") {
98
private static final int SEQ_LENGTH_THRESHOLD = 5000;
109

1110
@Override
1211
public int applyImportanceModifier(int rawScore) {
1312
if (rawScore < SEQ_LENGTH_THRESHOLD) {
14-
return rawScore / DENOMINATOR;
13+
return rawScore;
1514
} else {
16-
return (rawScore * rawScore) / DENOMINATOR;
15+
return rawScore * rawScore;
1716
}
1817
}
1918
},
20-
INDEP_MUT("independentMutation") {
21-
private static final int BASE = 8;
19+
DR_MUT("Drug Resistance Mutation Score") {
20+
private final int[] multipliers = { 0, 800, 1000 };
2221
@Override
2322
public int applyImportanceModifier(int rawScore) {
24-
return (int) Math.pow(BASE, rawScore);
25-
}
26-
},
27-
DR_MUT("drugResistanceMutation") {
28-
@Override
29-
public int applyImportanceModifier(int rawScore) {
30-
return rawScore * 100;
23+
if (rawScore >= multipliers.length) {
24+
return multipliers[multipliers.length - 1];
25+
}
26+
return multipliers[rawScore];
3127
}
3228
};
3329

dnainator-core/src/main/java/nl/tudelft/dnainator/graph/interestingness/impl/SummingScoresStrategy.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
* {@link Scores} together.
1111
*/
1212
public class SummingScoresStrategy implements InterestingnessStrategy {
13-
private static final int RANGE_LOWER = 0;
14-
private static final int RANGE_UPPER = 1000;
15-
1613
@Override
1714
public int compute(ScoreContainer container) {
1815
int sum = 0;

dnainator-core/src/test/java/nl/tudelft/dnainator/graph/impl/Neo4jGraphTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import nl.tudelft.dnainator.core.impl.SequenceNodeFactoryImpl;
1010
import nl.tudelft.dnainator.core.impl.SequenceNodeImpl;
1111
import nl.tudelft.dnainator.graph.impl.command.AnalyzeCommand;
12-
import nl.tudelft.dnainator.graph.interestingness.Scores;
1312
import nl.tudelft.dnainator.graph.query.GraphQueryDescription;
1413
import nl.tudelft.dnainator.parser.EdgeParser;
1514
import nl.tudelft.dnainator.parser.NodeParser;
@@ -284,19 +283,6 @@ public void testGetAnnotationsRangeInclusive() {
284283
assertTrue(as.contains(last));
285284
}
286285

287-
/**
288-
* Test the scoring of independent mutations.
289-
*/
290-
@Test
291-
public void testIndependentMutationScore() {
292-
EnrichedSequenceNode node11 = db.getNode("11");
293-
EnrichedSequenceNode node2 = db.getNode("2");
294-
EnrichedSequenceNode node9 = db.getNode("9");
295-
assertEquals(node11.getScore(Scores.INDEP_MUT), 2);
296-
assertEquals(node2.getScore(Scores.INDEP_MUT), 1);
297-
assertEquals(node9.getScore(Scores.INDEP_MUT), 1);
298-
}
299-
300286
private static void assertUnorderedIDEquals(Collection<String> expected,
301287
Collection<EnrichedSequenceNode> actual) {
302288
assertEquals(expected.stream().collect(Collectors.toSet()),

dnainator-core/src/test/java/nl/tudelft/dnainator/graph/interestingness/impl/SummingScoresStrategyTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
public class SummingScoresStrategyTest {
1515
private static final int TEST_SEQ_LENGTH = 5;
16-
private static final int TEST_INDEP_MUT = 3;
16+
private static final int TEST_DR_MUT = 1;
1717
private SummingScoresStrategy strategy;
1818
private ScoreContainer container;
1919

@@ -25,17 +25,17 @@ public void setUp() {
2525
this.strategy = new SummingScoresStrategy();
2626
this.container = Mockito.mock(ScoreContainer.class);
2727
Mockito.when(container.getScore(Scores.SEQ_LENGTH)).thenReturn(TEST_SEQ_LENGTH);
28-
Mockito.when(container.getScore(Scores.INDEP_MUT)).thenReturn(TEST_INDEP_MUT);
28+
Mockito.when(container.getScore(Scores.DR_MUT)).thenReturn(TEST_DR_MUT);
2929
}
3030

3131
/**
3232
* Tests whether it returns the sum of all scores.
3333
*/
3434
@Test
3535
public void testSum() {
36-
assertEquals(strategy.compute(container),
37-
Scores.SEQ_LENGTH.applyImportanceModifier(TEST_SEQ_LENGTH)
38-
+ Scores.INDEP_MUT.applyImportanceModifier(TEST_INDEP_MUT));
36+
int expected = Scores.SEQ_LENGTH.applyImportanceModifier(TEST_SEQ_LENGTH)
37+
+ Scores.DR_MUT.applyImportanceModifier(TEST_DR_MUT);
38+
assertEquals(expected, strategy.compute(container));
3939
}
4040

4141
}

dnainator-javafx/src/main/java/nl/tudelft/dnainator/javafx/controllers/PropertyPaneController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class PropertyPaneController {
1919
private SlidingAnimation animation;
2020
private static final int WIDTH = 300;
2121
private static final int ANIM_DURATION = 250;
22-
private static final int MAX_PROPERTY_SIZE = 750;
22+
private static final int MAX_PROPERTY_SIZE = 500;
2323

2424
@SuppressWarnings("unused") @FXML private VBox propertyPane;
2525

@@ -50,7 +50,7 @@ private void addLabel(PropertyType type, String value) {
5050
if (value != null && value.length() > MAX_PROPERTY_SIZE) {
5151
ScrollPane sp = new ScrollPane(label);
5252
sp.setFitToWidth(true);
53-
sp.setPrefHeight(WIDTH);
53+
sp.setPrefHeight(WIDTH / 2);
5454
label = sp;
5555
}
5656
propertyPane.getChildren().add(new VBox(description, label));

dnainator-javafx/src/main/java/nl/tudelft/dnainator/javafx/drawables/Thresholds.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* The amount corresponds to the level of scaling.
66
*/
77
public enum Thresholds {
8-
GRAPH(1.7),
8+
GRAPH(2.0),
99
CLUSTER(4.0);
1010

1111
private final double threshold;

dnainator-javafx/src/main/java/nl/tudelft/dnainator/javafx/drawables/strains/ClusterDrawable.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import nl.tudelft.dnainator.core.PropertyType;
55
import nl.tudelft.dnainator.core.SequenceNode;
66
import nl.tudelft.dnainator.core.impl.Cluster;
7-
import nl.tudelft.dnainator.graph.interestingness.Scores;
87
import nl.tudelft.dnainator.javafx.ColorServer;
98
import nl.tudelft.dnainator.javafx.drawables.Drawable;
109
import nl.tudelft.dnainator.javafx.views.AbstractView;
@@ -32,7 +31,8 @@ enum ClusterPropertyTypes implements PropertyType {
3231
ENDREF("End base on ref. strain"),
3332
SOURCES("Sources"),
3433
STARTRANK("Start rank"),
35-
BASEDIST("Start base");
34+
BASEDIST("Start base"),
35+
SCORE("Total interestingness score");
3636

3737
private String description;
3838
private ClusterPropertyTypes(String description) {
@@ -105,8 +105,10 @@ private void initSingletonProperties() {
105105
properties.put(ClusterPropertyTypes.BASEDIST, Integer.toString(sn.getBaseDistance()));
106106
properties.put(ClusterPropertyTypes.STARTREF, Integer.toString(sn.getStartRef()));
107107
properties.put(ClusterPropertyTypes.ENDREF, Integer.toString(sn.getEndRef()));
108-
properties.put(Scores.SEQ_LENGTH, Integer.toString(sn.getScore(Scores.SEQ_LENGTH)));
109108
properties.put(ClusterPropertyTypes.SEQUENCE, sn.getSequence());
109+
110+
properties.put(ClusterPropertyTypes.SCORE, Integer.toString(sn.getInterestingnessScore()));
111+
sn.getScores().forEach((k, v) -> properties.put(k, Integer.toString(v)));
110112
}
111113

112114
private void draw(ColorServer colorServer) {

0 commit comments

Comments
 (0)