Skip to content

Commit

Permalink
tried to modularise the code and caused 1000 test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
KatyBrown committed Nov 28, 2024
1 parent 6f57d0f commit 33f8bb1
Show file tree
Hide file tree
Showing 143 changed files with 592 additions and 480 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__
.coverage
*~
dist
man/_build
*egg*
Binary file added _basic_tree.pickle
Binary file not shown.
Binary file added _big_tree.pickle
Binary file not shown.
File renamed without changes.
50 changes: 5 additions & 45 deletions plot_phylo/amend_tree.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,8 @@
#!/usr/bin/env python3
def get_boxes(ax, texts):
'''
Converts a list of text objects to their co-ordinates on the axis in
axis units.
Parameters
----------
ax : matplotlib.axes._axes.Axes,
An open matplotlib ax object where the tree will be plotted.
texts : list
A list of matplotlib.pyplot.text objects representing the tip
labels from the tree and their metadata.
Returns
-------
boxpos : dict
A dictionary of dictionaries where the top level keys are the tip
labels. Within each subdictionary the key value pairs are
index (position in the tree starting from the top) and the minimum,
maximum and central position of the text box on the x and y axis,
as index, xmin, xmid, xmax and ymin, ymid and ymax.
'''
boxpos = dict()
# Iterate through the tip labels
for i, txt in enumerate(texts):
# Get the position of the boxes containing the labels, convert to axis
# units
box = ax.transData.inverted().transform(txt.get_window_extent(
ax.figure.canvas.get_renderer()))
nam = txt.get_text().strip()
# Build the dictionary
boxpos[nam] = dict()
boxpos[nam]['index'] = i
boxpos[nam]['xmin'] = box[0][0].round(3)
boxpos[nam]['xmax'] = box[1][0].round(3)
boxpos[nam]['ymin'] = box[0][1].round(3)
boxpos[nam]['ymax'] = box[1][1].round(3)
boxpos[nam]['ymid'] = (box[0][1] + ((
box[1][1] - box[0][1]) / 2)).round(3)
boxpos[nam]['xmid'] = (
box[0][0] + ((box[1][0] - box[0][1]) / 2)).round(3)

return (boxpos)
try:
from plot_phylo import get_boxes
except ImportError:
import get_boxes


def auto_axis(ax, textobj, xpos, ypos, width, height, depth, scale_bar,
Expand Down Expand Up @@ -87,7 +47,7 @@ def auto_axis(ax, textobj, xpos, ypos, width, height, depth, scale_bar,
ymin -= yint + (yint * 0.2)
ax.set_ylim(ymin, ymax)
xmin = xpos - xint
nboxes = get_boxes(ax, textobj)
nboxes = get_boxes.get_boxes(ax, textobj)
xmaxes = [nboxes[x]['xmax'] for x in nboxes]
xmax = xint + max(xmaxes)
ax.set_xlim(xmin, xmax)
Expand Down
Loading

0 comments on commit 33f8bb1

Please sign in to comment.