Skip to content

Commit

Permalink
Merge pull request #288 from ProgrammingLife2017/snp
Browse files Browse the repository at this point in the history
Detect if children can be SNP'ed together
  • Loading branch information
MeAmAnUsername authored Jun 22, 2017
2 parents 5cf55c4 + 45b5a07 commit e3288ad
Show file tree
Hide file tree
Showing 14 changed files with 811 additions and 211 deletions.
2 changes: 1 addition & 1 deletion ProgrammingLife.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.github.uphy:javafx-console:ce9860eb36" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.5" level="project" />
<orderEntry type="library" name="Maven: com.diffplug.durian:durian:3.4.0" level="project" />
<orderEntry type="library" name="Maven: com.github.uphy:javafx-console:ce9860eb36" level="project" />
<orderEntry type="library" name="Maven: org.mapdb:mapdb:3.0.4" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.0.7" level="project" />
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-runtime:1.0.7" level="project" />
Expand Down
85 changes: 41 additions & 44 deletions src/main/java/programminglife/gui/controller/GraphController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.LinkedList;

/**
* Created by Martijn van Meerten on 8-5-2017.
* Controller for drawing the graph.
*/
public class GraphController {
Expand All @@ -32,6 +31,7 @@ public class GraphController {
private double zoomLevel = 1;

private int centerNodeInt;
private boolean drawSNP = false;

/**
* Initialize controller object.
Expand All @@ -49,55 +49,45 @@ public int getCenterNodeInt() {
return this.centerNodeInt;
}

/**
* Utility function for benchmarking purposes.
* @param description the description to print
* @param r the {@link Runnable} to run/benchmark
*/
private void time(String description, Runnable r) {
long start = System.nanoTime();
r.run();
Console.println(String.format("%s: %d ms", description, (System.nanoTime() - start) / 1000000));
}

/**
* Method to draw the subGraph decided by a center node and radius.
* @param center the node of which the radius starts.
* @param radius the amount of layers to be drawn.
*/
public void draw(int center, int radius) {
long startTimeProgram = System.nanoTime();
GraphicsContext gc = canvas.getGraphicsContext2D();

long startTimeSubGraph = System.nanoTime();

DrawableSegment centerNode = new DrawableSegment(graph, center);
centerNodeInt = centerNode.getIdentifier();
subGraph = new SubGraph(centerNode, radius);

long finishTimeSubGraph = System.nanoTime();

long startLayoutTime = System.nanoTime();
subGraph.layout();
long finishTimeLayout = System.nanoTime();

long startTimeColorize = System.nanoTime();
colorize();
long finishTimeColorize = System.nanoTime();


long startTimeDrawing = System.nanoTime();
draw(gc);
long finishTimeDrawing = System.nanoTime();

highlightNode(center, Color.DARKORANGE);
centerOnNodeId(center);

long finishTime = System.nanoTime();
long differenceTimeProgram = finishTime - startTimeProgram;
long differenceTimeDrawing = finishTimeDrawing - startTimeDrawing;
long differenceTimeLayout = finishTimeLayout - startLayoutTime;
long differenceTimeSubGraph = finishTimeSubGraph - startTimeSubGraph;
long differenceTimeColorize = finishTimeColorize - startTimeColorize;
long msDifferenceTimeProgram = differenceTimeProgram / 1000000;
long millisecondTimeDrawing = differenceTimeDrawing / 1000000;
long msDifferenceTimeLayout = differenceTimeLayout / 1000000;
long msDifferenceTimeSubGraph = differenceTimeSubGraph / 1000000;
long msDifferenceTimeColorize = differenceTimeColorize / 1000000;
Console.println("time of SubGraph: " + msDifferenceTimeSubGraph);
Console.println("Time of layout: " + msDifferenceTimeLayout);
Console.println("Time of Colorize: " + msDifferenceTimeColorize);
Console.println("Time of Drawing: " + millisecondTimeDrawing);
Console.println("Time of Total Program: " + msDifferenceTimeProgram);
time("Total drawing", () -> {
DrawableSegment centerNode = new DrawableSegment(graph, center);
centerNodeInt = centerNode.getIdentifier();
GraphicsContext gc = canvas.getGraphicsContext2D();

time("Find subgraph", () -> subGraph = new SubGraph(centerNode, radius));

if (drawSNP) {
time("Replace SNPs", subGraph::replaceSNPs);
}
time("Layout subgraph", subGraph::layout);

time("Colorize", this::colorize);

time("Calculate genomes through edges", subGraph::calculateGenomes);
time("Drawing", () -> {
draw(gc);
});

centerOnNodeId(center);
highlightNode(center, Color.DARKORANGE);
});
}

/**
Expand Down Expand Up @@ -357,6 +347,13 @@ public void highlightByGenome(int genomeID) {
highlightNodes(drawNodeList, Color.YELLOW);
}

/**
* Sets if the glyph snippets will be drawn or not.
*/
void setSNP() {
drawSNP = !drawSNP;
}

/**
* Returns the node clicked on else returns null.
* @param x position horizontally where clicked
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/programminglife/gui/controller/GuiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.scene.canvas.Canvas;
import jp.uphy.javafx.console.ConsoleView;
import programminglife.ProgrammingLife;
import programminglife.controller.MiniMapController;
Expand Down Expand Up @@ -65,8 +66,11 @@ public class GuiController implements Observer {
@FXML private MenuItem btnInstructions;
@FXML private Menu menuRecentGFA;
@FXML private Menu menuRecentGFF;
@FXML private RadioMenuItem btnToggle;

@FXML private RadioMenuItem btnSNP;
@FXML private RadioMenuItem btnConsole;
@FXML private RadioMenuItem btnMiniMap;

@FXML private Button btnZoomReset;
@FXML private Button btnTranslateReset;
@FXML private Button btnDraw;
Expand All @@ -84,7 +88,7 @@ public class GuiController implements Observer {
@FXML private AnchorPane anchorLeftControlPanel;
@FXML private AnchorPane anchorGraphPanel;
@FXML private AnchorPane anchorGraphInfo;
@FXML private javafx.scene.canvas.Canvas miniMap;
@FXML private Canvas miniMap;

private double orgSceneX, orgSceneY;

Expand Down Expand Up @@ -276,18 +280,24 @@ private void fileChooser(ExtensionFilter filter, boolean isGFA) {
*/
private void initMenuBar() {
btnOpenGFA.setOnAction((ActionEvent event) -> fileChooser(extFilterGFA, true));
btnOpenGFF.setOnAction((ActionEvent event) -> fileChooser(extFilterGFF, false));

btnOpenGFA.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCodeCombination.CONTROL_DOWN));
btnOpenGFF.setOnAction((ActionEvent event) -> fileChooser(extFilterGFF, false));

btnMiniMap.setOnAction(event -> miniMapController.toggleVisibility());
btnMiniMap.setAccelerator(new KeyCodeCombination(KeyCode.M, KeyCodeCombination.CONTROL_DOWN));
btnQuit.setOnAction(event -> Alerts.quitAlert());
btnQuit.setAccelerator(new KeyCodeCombination(KeyCode.E, KeyCodeCombination.CONTROL_DOWN));
btnQuit.setAccelerator(new KeyCodeCombination(KeyCode.Q, KeyCodeCombination.CONTROL_DOWN));

btnAbout.setOnAction(event -> Alerts.infoAboutAlert());
btnAbout.setAccelerator(new KeyCodeCombination(KeyCode.I, KeyCodeCombination.CONTROL_DOWN));
btnInstructions.setOnAction(event -> Alerts.infoInstructionAlert());
btnInstructions.setAccelerator(new KeyCodeCombination(KeyCode.H, KeyCodeCombination.CONTROL_DOWN));

btnMiniMap.setOnAction(event -> miniMapController.toggleVisibility());
btnMiniMap.setAccelerator(new KeyCodeCombination(KeyCode.M, KeyCodeCombination.CONTROL_DOWN));
btnSNP.setOnAction(event -> {
graphController.setSNP();
Platform.runLater(this::draw);
});
btnSNP.setAccelerator(new KeyCodeCombination(KeyCode.G, KeyCodeCombination.CONTROL_DOWN));
}


Expand Down Expand Up @@ -533,17 +543,17 @@ private void initConsole() {
AnchorPane.setRightAnchor(console, 0.d);
AnchorPane.setLeftAnchor(console, 0.d);

btnToggle.setOnAction(event -> {
if (btnToggle.isSelected()) {
btnConsole.setOnAction(event -> {
if (btnConsole.isSelected()) {
st.show();
} else {
st.close();
}
});

st.show();
btnToggle.setSelected(true);
root.visibleProperty().bind(btnToggle.selectedProperty());
btnConsole.setSelected(true);
root.visibleProperty().bind(btnConsole.selectedProperty());

Console.setOut(console.getOut());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public String details() {
return toString();
}

@Override
public DrawableSNP createSNPIfPossible(SubGraph subGraph) {
return null;
}

@Override
public void colorize(SubGraph sg) {
double genomeFraction = 0.d;
Expand All @@ -97,6 +102,7 @@ public void colorize(SubGraph sg) {

this.setStrokeWidth(strokeWidth);
this.setStrokeColor(strokeColor);

}

/**
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/programminglife/model/drawing/DrawableNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ public DrawableNode(GenomeGraph graph, int id) {
}
}


@Override
public final boolean equals(Object o) {
if (this == o) {
return true;
}

if (!this.getClass().equals(o.getClass())) {
return false;
}
return this.getIdentifier() == ((DrawableNode) o).getIdentifier();
}

@Override
public final int hashCode() {
int result = getGraph().hashCode();
result = 31 * result + getIdentifier();
return result;
}

/**
* Get the ID.
* @return the ID
*/
public final int getIdentifier() {
return this.id;
}

/**
* Get the {@link GenomeGraph}.
* @return the graph
Expand Down Expand Up @@ -110,6 +138,13 @@ private boolean isDrawDimensionsUpToDate() {
*/
public abstract String details();

/**
* Checks if the children of this {@link DrawableNode} can be merged as a SNP.
* @param subGraph the {@link SubGraph} this {@link DrawableNode} is in
* @return null if children cannot be SNP'ed, SNP with (parent, child and mutation) otherwise
*/
public abstract DrawableSNP createSNPIfPossible(SubGraph subGraph);

/**
* Color this according to contents.
* @param subGraph {@link SubGraph} to colorize.
Expand Down Expand Up @@ -188,10 +223,6 @@ final XYCoordinate getRightBorderCenter() {
return new XYCoordinate(location.getX() + getWidth(), location.getY() + 0.5 * getHeight());
}

public final int getIdentifier() {
return id;
}

public final XYCoordinate getLocation() {
return location;
}
Expand Down
Loading

0 comments on commit e3288ad

Please sign in to comment.