Skip to content

Commit

Permalink
Fix 258 (#301)
Browse files Browse the repository at this point in the history
* started converting

* started converting rest

* finished empress.js

* convert node menu

* fixed tests/style

* fixed node select

* Update empress/support_files/js/empress.js

Co-authored-by: Marcus Fedarko <[email protected]>

* Update tests/python/test_core.py

Co-authored-by: Marcus Fedarko <[email protected]>

* addressed comments

* changed to camel case

* fixed barplot error

* Update empress/support_files/js/empress.js

Co-authored-by: Marcus Fedarko <[email protected]>

* Update empress/support_files/js/empress.js

Co-authored-by: Marcus Fedarko <[email protected]>

* Update empress/support_files/js/empress.js

Co-authored-by: Marcus Fedarko <[email protected]>

* removed appending attributes

* Update empress/support_files/js/empress.js

Co-authored-by: Marcus Fedarko <[email protected]>

* tojson

Co-authored-by: Marcus Fedarko <[email protected]>
  • Loading branch information
kwcantrell and fedarko authored Aug 6, 2020
1 parent 776910e commit 29d4563
Show file tree
Hide file tree
Showing 10 changed files with 673 additions and 621 deletions.
69 changes: 54 additions & 15 deletions empress/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,38 +266,76 @@ def _to_dict(self):
4020, 4020
)

tree_data = {}
# store node data in a postorder fashion.
# Note: currently, bp-tree uses 1-based index so the first element will
# start at 1. Thus, the 0th index is null. This will be fixed in
# #223
tree_data = [0]
td_to_ind = {
# note: color, isColored, visible, and inSample with be appended in
# empress constructor. They are not added here because all nodes
# will be initialized with the same value.
#
# all nodes
"name": 0,
"x2": 1,
"y2": 2,
"xr": 3,
"yr": 4,
"xc1": 5,
"yc1": 6,
"xc0": 7,
"yc0": 8,
"angle": 9,
# all internal nodes
"highestchildyr": 10,
"lowestchildyr": 11,
# non-root internal nodes
"arcx0": 12,
"arcy0": 13,
"arcstartangle": 14,
"arcendangle": 15
}
names_to_keys = {}
# Note: tree_data starts with index 1 because the bp tree uses 1 based
# indexing
for i, node in enumerate(self.tree.postorder(include_self=True), 1):
tree_data[i] = {
'name': node.name,
}
if node.is_tip():
# add one to account for 0-based index
tree_data.append([0] * (td_to_ind["angle"] + 1))
elif node.is_root():
# add 2 to account for highestchildyr and lowestchildyr
tree_data.append([0] * (td_to_ind["angle"] + 2 + 1))
else:
tree_data.append([0] * len(td_to_ind))
tree_data[i][td_to_ind["name"]] = node.name
# Add coordinate data from all layouts for this node
for layoutsuffix in layout_to_coordsuffix.values():
xcoord = "x" + layoutsuffix
ycoord = "y" + layoutsuffix
tree_data[i][xcoord] = getattr(node, xcoord)
tree_data[i][ycoord] = getattr(node, ycoord)
tree_data[i][td_to_ind[xcoord]] = getattr(node, xcoord)
tree_data[i][td_to_ind[ycoord]] = getattr(node, ycoord)
# Hack: it isn't mentioned above, but we need start pos info for
# circular layout. The start pos for the other layouts is the
# parent xy coordinates so we need only need to specify the start
# for circular layout.
tree_data[i]["xc0"] = node.xc0
tree_data[i]["yc0"] = node.yc0
tree_data[i]["angle"] = node.clangle
tree_data[i][td_to_ind["xc0"]] = node.xc0
tree_data[i][td_to_ind["yc0"]] = node.yc0
tree_data[i][td_to_ind["angle"]] = node.clangle

# Also add vertical bar coordinate info for the rectangular layout,
# and start point & arc coordinate info for the circular layout
if not node.is_tip():
tree_data[i]["highestchildyr"] = node.highest_child_yr
tree_data[i]["lowestchildyr"] = node.lowest_child_yr
tree_data[i][td_to_ind["highestchildyr"]] = \
node.highest_child_yr
tree_data[i][td_to_ind["lowestchildyr"]] = node.lowest_child_yr
if not node.is_root():
tree_data[i]["arcx0"] = node.arcx0
tree_data[i]["arcy0"] = node.arcy0
tree_data[i]["arcstartangle"] = node.highest_child_clangle
tree_data[i]["arcendangle"] = node.lowest_child_clangle
tree_data[i][td_to_ind["arcx0"]] = node.arcx0
tree_data[i][td_to_ind["arcy0"]] = node.arcy0
tree_data[i][td_to_ind["arcstartangle"]] = \
node.highest_child_clangle
tree_data[i][td_to_ind["arcendangle"]] = \
node.lowest_child_clangle

if node.name in names_to_keys:
names_to_keys[node.name].append(i)
Expand Down Expand Up @@ -326,6 +364,7 @@ def _to_dict(self):
'tree': shifting(self._bp_tree),
'lengths': lengths,
'tree_data': tree_data,
'td_to_ind': td_to_ind,
'names': names,
'names_to_keys': names_to_keys,
# feature table
Expand Down
4 changes: 2 additions & 2 deletions empress/support_files/js/canvas-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ define(["glMatrix", "SelectedNodeMenu"], function (gl, SelectedNodeMenu) {
// margin of error for mouse click to still register a node sel
var epsilon = 10;
var closestDist = Infinity;
var closestNode = null;
var closeNode = null;
var xDist, yDist, closeNodeKey;

// Go through all the nodes in the tree and find the node
// closest to the (x, y) point that was clicked
for (var i = 1; i <= empress._tree.size; i++) {
var node = empress._treeData[i];
if (!node.visible) continue;
if (!empress.getNodeInfo(node, "visible")) continue;
var nodeX = empress.getX(node);
var nodeY = empress.getY(node);
xDist = x - nodeX;
Expand Down
Loading

0 comments on commit 29d4563

Please sign in to comment.