Skip to content

Commit

Permalink
Merge pull request #293 from biocore/flake8-again
Browse files Browse the repository at this point in the history
bump
  • Loading branch information
mortonjt authored Jul 8, 2021
2 parents 544ef2f + 4d25854 commit 5d253d6
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 132 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:
- name: Install conda packages
shell: bash -l {0}
run: conda install -c conda-forge statsmodels scikit-bio biom-format matplotlib flake8

- name: Install gneiss
shell: bash -l {0}
run: pip install -e .[dev]

- name: Run tests
shell: bash -l {0}
run: make all
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ help:
test:
$(TEST_COMMAND)
pep8:
pycodestyle gneiss setup.py
flake8 gneiss setup.py
flake8 gneiss setup.py --ignore E303,E731,E722

all: pep8 test
15 changes: 8 additions & 7 deletions gneiss/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ def _balance_basis(tree_node):
k = np.array([counts[n]['k'] for n in nds])
t = np.array([counts[n]['t'] for n in nds])

a = np.sqrt(s / (r*(r+s)))
b = -1*np.sqrt(r / (s*(r+s)))
a = np.sqrt(s / (r * (r + s)))
b = -1 * np.sqrt(r / (s * (r + s)))

basis = np.zeros((n_tips-1, n_tips))
basis = np.zeros((n_tips - 1, n_tips))
for i in range(len(nds)):
basis[i, :] = np.array([0]*k[i] + [a[i]]*r[i] + [b[i]]*s[i] + [0]*t[i])
basis[i, :] = np.array(
[0] * k[i] + [a[i]] * r[i] + [b[i]] * s[i] + [0] * t[i])
# Make sure that the basis is in level order
basis = basis[:, ::-1]
nds = [n.name for n in nds]
Expand Down Expand Up @@ -243,20 +244,20 @@ def sparse_balance_basis(tree):
row.append(i)
# consider tips in reverse order. May want to rethink
# this orientation in the future.
col.append(D-1-j)
col.append(D - 1 - j)
A = np.sqrt(n._s / (n._r * (n._s + n._r)))

value.append(A)

for j in range(n._k + n._r, n._k + n._r + n._s):
row.append(i)
col.append(D-1-j)
col.append(D - 1 - j)
B = -np.sqrt(n._r / (n._s * (n._s + n._r)))

value.append(B)
i += 1
nodes.append(n.name)

basis = coo_matrix((value, (row, col)), shape=(D-1, D))
basis = coo_matrix((value, (row, col)), shape=(D - 1, D))

return basis, nodes
2 changes: 1 addition & 1 deletion gneiss/cluster/tests/test_pba.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_correlation_linkage_1(self):
'(o3:0.574990173931,o4:0.574990173931)y2:0.773481312844)'
'y0;\n')
exp_tree = TreeNode.read([exp_str])
res_tree = correlation_linkage(table+0.1)
res_tree = correlation_linkage(table + 0.1)
# only check for tree topology since checking for floating point
# numbers on the branches is still tricky.
self.assertEqual(exp_tree.ascii_art(), res_tree.ascii_art())
Expand Down
7 changes: 3 additions & 4 deletions gneiss/composition/tests/test_variance.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ def test_varmat_larg(self):
np.random.seed(123)
D = 50
N = 100
mean = np.ones(D)*10
mean = np.ones(D) * 10
cov = np.eye(D)
X = pd.DataFrame(np.abs(np.random.multivariate_normal(mean, cov,
size=N)),
columns=np.arange(D).astype(np.str))
n__ = np.random.multivariate_normal(mean, cov, size=N)
X = pd.DataFrame(np.abs(n__), columns=np.arange(D).astype(np.str))
res = variation_matrix(X)

exp = DistanceMatrix.read(get_data_path('exp_varmat.txt'))
Expand Down
37 changes: 20 additions & 17 deletions gneiss/plot/_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import matplotlib.pyplot as plt
import pandas as pd
from gneiss.util import NUMERATOR, DENOMINATOR
import warnings


def balance_boxplot(balance_name, data, num_color='#FFFFFF',
Expand Down Expand Up @@ -49,6 +50,7 @@ def balance_boxplot(balance_name, data, num_color='#FFFFFF',
--------
seaborn.boxplot
"""
warnings.warn("This visualization are deprecated.", DeprecationWarning)
import seaborn as sns
if ax is None:
f, ax = plt.subplots()
Expand All @@ -57,9 +59,9 @@ def balance_boxplot(balance_name, data, num_color='#FFFFFF',
# resizing to make sure that there is separation between the
# edges of the plot, and the boxplot
pad = (data[balance_name].max() - data[balance_name].min()) / 20
ax.axvspan(data[balance_name].min()-pad, 0,
ax.axvspan(data[balance_name].min() - pad, 0,
facecolor=num_color, zorder=0)
ax.axvspan(0, data[balance_name].max()+pad,
ax.axvspan(0, data[balance_name].max() + pad,
facecolor=denom_color, zorder=0)

if 'hue' in kwargs.keys():
Expand Down Expand Up @@ -118,6 +120,7 @@ def balance_barplots(tree, balance_name, header, feature_metadata,
ax_denom : matplotlib axes object
Barplot of the features in the denominator of the balance.
"""
warnings.warn("This visualization are deprecated.", DeprecationWarning)
import seaborn as sns
if axes[0] is None or axes[1] is None:
f, (ax_num, ax_denom) = plt.subplots(2)
Expand Down Expand Up @@ -148,15 +151,15 @@ def balance_barplots(tree, balance_name, header, feature_metadata,
color=denom_color)
ax_denom.set_ylabel(ylabel)
ax_denom.set_xlabel(xlabel)
ax_denom.set_xlim([0, max([num_.max().values[1],
denom_.max().values[1]])])
ax_denom.set_xlim(
[0, max([num_.max().values[1], denom_.max().values[1]])])

ax_num = sns.barplot(y='index', x=header, data=num_, ax=ax_num,
color=num_color)
ax_num.set_ylabel(ylabel)
ax_num.set_xlabel(xlabel)
ax_num.set_xlim([0, max([num_.max().values[1],
denom_.max().values[1]])])
ax_num.set_xlim(
[0, max([num_.max().values[1], denom_.max().values[1]])])
return ax_num, ax_denom


Expand Down Expand Up @@ -238,6 +241,7 @@ def proportion_plot(table, metadata, category, left_group, right_group,
Since this method will return the raw matplotlib object, labels, titles,
ticks, etc can directly modified using this object.
"""
warnings.warn("This visualization are deprecated.", DeprecationWarning)
import seaborn as sns
if axes[0] is None or axes[1] is None:
f, (ax_num, ax_denom) = plt.subplots(1, 2)
Expand Down Expand Up @@ -268,16 +272,15 @@ def proportion_plot(table, metadata, category, left_group, right_group,
denom_data['part'] = 'denominator'
data = pd.concat((num_data, denom_data))
if feature_metadata is not None:
num_feature_metadata = feature_metadata.loc[num_df.columns,
label_col]
denom_feature_metadata = feature_metadata.loc[denom_df.columns,
label_col]
fm = feature_metadata
num_feature_metadata = fm.loc[num_df.columns, label_col]
denom_feature_metadata = fm.loc[denom_df.columns, label_col]
# order of the ids to plot
order = (list(num_feature_metadata.index) +
list(denom_feature_metadata.index))
n__ = list(num_feature_metadata.index)
d__ = list(denom_feature_metadata.index)
order = n__ + d__
else:
order = (list(num_df.columns) +
list(denom_df.columns))
order = list(num_df.columns) + list(denom_df.columns)

less_df = data.loc[data[category] == left_group].dropna()

Expand All @@ -296,9 +299,9 @@ def proportion_plot(table, metadata, category, left_group, right_group,
order=order,
ax=ax_num)
if feature_metadata is not None:
ax_denom.set(yticklabels=(list(num_feature_metadata.values) +
list(denom_feature_metadata.values)),
title=left_group)
n__ = list(num_feature_metadata.values)
d__ = list(denom_feature_metadata.values)
ax_denom.set(yticklabels=(n__ + d__), title=left_group)
else:
ax_denom.set(yticklabels=order, title=left_group)

Expand Down
6 changes: 3 additions & 3 deletions gneiss/plot/_dendrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def update_coordinates(self, s, x1, y1, a, da):
for child in self.children:
# calculate the arc that covers the subtree.
ca = child.leafcount * da
points += child.update_coordinates(s, x2, y2, a+ca/2, da)
points += child.update_coordinates(s, x2, y2, a + ca / 2, da)
a += ca
return points

Expand Down Expand Up @@ -375,14 +375,14 @@ class SquareDendrogram(RootedDendrogram):
def ycoords(self, scale, y1):
cys = [c.y1 for c in self.children]
if cys:
y2 = (cys[0]+cys[-1]) / 2.0
y2 = (cys[0] + cys[-1]) / 2.0
else:
y2 = y1 - 0.5 * scale.y
return (y2, y2)

def xcoords(self, scale, x1):
if self.is_tip():
return (x1, (scale.height-(self.height-self.length))*scale.x)
return (x1, (scale.height - (self.height - self.length)) * scale.x)
else:
# give some margins for internal nodes
dx = scale.x * self.length * 0.95
Expand Down
25 changes: 14 additions & 11 deletions gneiss/plot/_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
from gneiss.plot._dendrogram import SquareDendrogram
from gneiss.util import match_tips, NUMERATOR, DENOMINATOR
import warnings


def heatmap(table, tree, mdvar, highlights=None, cmap='viridis',
Expand Down Expand Up @@ -112,7 +113,7 @@ def heatmap(table, tree, mdvar, highlights=None, cmap='viridis',
# heatmap axes
hstart = xwidth + (h * hwidth)
[ax1_x, ax1_y, ax1_w, ax1_h] = [hstart, top_buffer,
cbar_pad-hstart, height]
cbar_pad - hstart, height]

# plot dendrogram
ax_dendrogram = fig.add_axes([axm_x, axm_y, axm_w, axm_h],
Expand Down Expand Up @@ -182,21 +183,21 @@ def _plot_highlights_dendrogram(ax_highlights, table, t, highlights):

ax_highlights.add_patch(
patches.Rectangle(
(i/num_h, k-offset), # x, y
1/num_h, # width
(i / num_h, k - offset), # x, y
1 / num_h, # width
r, # height
facecolor=highlights.iloc[i, 0]
))

ax_highlights.add_patch(
patches.Rectangle(
(i/num_h, k+r-offset), # x, y
1/num_h, # width
(i / num_h, k + r - offset), # x, y
1 / num_h, # width
l, # height
facecolor=highlights.iloc[i, 1]
))
hcoords.append((i+offset)/num_h)
ax_highlights.set_ylim([-offset, table.shape[0]-offset])
hcoords.append((i + offset) / num_h)
ax_highlights.set_ylim([-offset, table.shape[0] - offset])
ax_highlights.set_yticks([])
ax_highlights.set_xticks(hcoords)
ax_highlights.set_xticklabels(highlights.index, rotation=90)
Expand All @@ -219,8 +220,9 @@ def _plot_dendrogram(ax_dendrogram, table, edges, linewidth=1):
for i in range(len(edges.index)):
row = edges.iloc[i]
ax_dendrogram.plot([row.x0, row.x1],
[row.y0-offset, row.y1-offset], '-k', lw=linewidth)
ax_dendrogram.set_ylim([-offset, table.shape[0]-offset])
[row.y0 - offset, row.y1 - offset],
'-k', lw=linewidth)
ax_dendrogram.set_ylim([-offset, table.shape[0] - offset])
ax_dendrogram.set_yticks([])
ax_dendrogram.set_xticks([])
ax_dendrogram.axis('off')
Expand Down Expand Up @@ -278,6 +280,7 @@ def _plot_heatmap(ax_heatmap, table, mdvar, grid_col,
colorbar_ax : matplotlib axes object
The colorbar axis.
"""
warnings.warn("This visualization are deprecated.", DeprecationWarning)
# TODO add explicit test for this, since matplotlib orientation
# is from top to down (i.e. is backwards)
table, mdvar = _sort_table(table, mdvar)
Expand All @@ -293,13 +296,13 @@ def _plot_heatmap(ax_heatmap, table, mdvar, grid_col,

ticks = vcounts.sort_index().cumsum()
midpoints = ticks - (ticks - np.array([0] + list(ticks.values[:-1]))) / 2.0
ax_heatmap.set_xticks(ticks.values-0.5, minor=False)
ax_heatmap.set_xticks(ticks.values - 0.5, minor=False)
ax_heatmap.set_xticklabels([], minor=False)

ax_heatmap.xaxis.grid(True, which='major', color=grid_col,
linestyle='-', linewidth=grid_width)

ax_heatmap.set_xticks(midpoints-0.5, minor=True)
ax_heatmap.set_xticks(midpoints - 0.5, minor=True)
ax_heatmap.set_xticklabels(vcounts.index, minor=True)
ax_heatmap.set_xlabel(mdvar.name)
return colorbar_ax
16 changes: 10 additions & 6 deletions gneiss/plot/_radial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
# ----------------------------------------------------------------------------
import pandas as pd
from gneiss.plot._dendrogram import UnrootedDendrogram
from bokeh.models.glyphs import Circle, Segment
from bokeh.models import ColumnDataSource, DataRange1d, Plot
from bokeh.models import (HoverTool, BoxZoomTool, ResetTool,
WheelZoomTool, SaveTool, PanTool)
import warnings
try:
from bokeh.models.glyphs import Circle, Segment
from bokeh.models import ColumnDataSource, DataRange1d, Plot
from bokeh.models import (HoverTool, BoxZoomTool, ResetTool,
WheelZoomTool, SaveTool, PanTool)
except:
warnings.warn("Bokeh isn't installed - "
"the interactive visualizations won't work.")


def radialplot(tree, node_color='node_color', node_size='node_size',
Expand Down Expand Up @@ -56,8 +61,7 @@ def radialplot(tree, node_color='node_color', node_size='node_size',
--------
bifurcate
"""
# TODO: Add in example doc string

warnings.warn("This visualization are deprecated.", DeprecationWarning)
# This entire function was motivated by
# http://chuckpr.github.io/blog/trees2.html
t = UnrootedDendrogram.from_tree(tree.copy())
Expand Down
Loading

0 comments on commit 5d253d6

Please sign in to comment.