-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Radialplot #112
WIP: Radialplot #112
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jamie always does a great job!
|
||
else: | ||
self.height = self.length | ||
self.leafcount = self.edgecount = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know this double-"=" works!
if children: | ||
for c in children: | ||
c.update_geometry(use_lengths, self.depth) | ||
self.height = max([c.height for c in children]) + self.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are height
and length
? Are they describing tree branches? In FigTree height and length have some different and statistical meanings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
height
is the total height of the subtree. length
is the branch length connecting to that subtree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update the docstring for it and specify it in the attributes
from bokeh.models.glyphs import Circle, Segment | ||
from bokeh.models import ColumnDataSource, DataRange1d, Plot | ||
from bokeh.models import HoverTool, BoxZoomTool, ResetTool | ||
except ImportError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering in this situation, ImportError
and/or ImportWarning
will be raised eventually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to avoid my dependencies blowing up - so all of the visualization code that I'm using will be based on optional dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I also wonder how to set up Travis to test both scenarios. Can one install / not install a package simultaneously in .travis.yaml?
gneiss/plot/_radial.py
Outdated
node_hue : str | ||
Name of variable in `tree` to color nodes. | ||
node_size : str | ||
Name of variable in `tree` that species the radius of nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: species
=> specifies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
gneiss/plot/_radial.py
Outdated
---------- | ||
tree : instance of skbio.TreeNode | ||
Input tree for plotting. | ||
node_hue : str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the usage of term "hue" here isn't right. You actually passed the entire RGB value to hue
. But to be strict hue is a single number that should be used with saturation and brightness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced hue
with color
. What are your thoughts?
gneiss/plot/_radial.py
Outdated
nodes = t.coords(figsize[0], figsize[1]) | ||
|
||
# fill in all of the node attributes | ||
default_node_hue = '#D3D3D3' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consider putting a comment here what color (in English) does '#D3D3D3' mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
gneiss/plot/_radial.py
Outdated
default_node_hue) | ||
for n in t.levelorder(include_self=True)}) | ||
|
||
default_node_size = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to zip these two iterations into one? (I don't know I am just asking)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about something like as follows
def _retreive(tree, x, default):
return pd.Series({n.name: getattr(n, x, default)
for n in tree.levelorder()})
nodes[node_hue] = _retreive(t, node_hue, '#D3D3D3')
I think it is ok to only install bokeh on travis.
…On Mon, Feb 27, 2017 at 12:13 PM, Qiyun Zhu ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In gneiss/plot/_radial.py
<#112 (comment)>:
> @@ -0,0 +1,144 @@
+# ----------------------------------------------------------------------------
+# Copyright (c) 2016--, gneiss development team.
+#
+# Distributed under the terms of the GPLv3 License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+# ----------------------------------------------------------------------------
+import pandas as pd
+from gneiss.plot._dendrogram import UnrootedDendrogram
+
+try:
+ from bokeh.models.glyphs import Circle, Segment
+ from bokeh.models import ColumnDataSource, DataRange1d, Plot
+ from bokeh.models import HoverTool, BoxZoomTool, ResetTool
+except ImportError:
Sounds good. I also wonder how to set up Travis to test both scenarios.
Can one install / not install a package simultaneously in .travis.yaml?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#112 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AD_a3RFEf5B3d-8WCZj-5H79BOotfsxQks5rgy57gaJpZM4L-SJq>
.
|
@qiyunzhu all of the comments have been addressed. Would you like to clone it and try this out yourself?
And there's the following commands that you can run to test within a notebook. # import stuff
from gneiss.plot import radialplot
import numpy as np
from scipy.cluster.hierarchy import ward
from skbio import TreeNode, DistanceMatrix
from bokeh.io import output_notebook, show
from gneiss.plot._dendrogram import UnrootedDendrogram
import bokeh.plotting as plt
output_notebook()
# create random tree
np.random.seed(0)
num_otus = 3 #otus
x = np.random.rand(num_otus)
dm = DistanceMatrix.from_iterable(x, lambda x, y: np.abs(x-y))
lm = ward(dm.condensed_form())
t = TreeNode.from_linkage_matrix(lm, np.arange(len(x)).astype(np.str))
t = UnrootedDendrogram.from_tree(t)
# populate tree with colors and stuff
for i, n in enumerate(t.postorder(include_self=True)):
if not n.is_tip():
n.name = "y%d" % i
n.color='#00FF00'
n.edge_color='#FF0000'
n.node_size=10
else:
n.color='#0000FF'
n.edge_color='#00FF00'
n.node_size=10
n.length = np.random.rand()*3
n.edge_width = 2
# plot and show
p = radialplot(t, node_hue='color', edge_hue='edge_color',
node_size='node_size', edge_width='edge_width')
show(p) |
I tested the code and it worked. The plot looks cool. @mortonjt Ready to ship. |
Depends on #110
This creates unrooted radial tree visualizations using bokeh.
Right now, this creates an interactive tree, with zoom, reset and name highlighting capabilities.
This is attempting to follow the seaborn paradigm, using the tree and the internal data structure for plotting instead of a pandas dataframe.
In the future, we'll need to create methods that'll make it easy to perform bulk operations to append values to scikit-bio trees. Maybe some methods that take in
pd.DataFrame
and decorates all of the nodes and edges in the tree with those attributes. That is a future PR.There are a couple of concerns that will need to be addressed here.