Skip to content

Commit

Permalink
Merge pull request #97 from natetrux/9_9fixes
Browse files Browse the repository at this point in the history
annotation documentation
  • Loading branch information
eaton-lab authored Sep 17, 2024
2 parents 0b2ee6a + 755b234 commit 5fb8f38
Show file tree
Hide file tree
Showing 4 changed files with 977 additions and 6 deletions.
276 changes: 274 additions & 2 deletions docs/docs-drafts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,23 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Distance & Dissimilarity Functions \n",
"# Distance & Dissimilarity Functions \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"The toytree _.distance_ subpackage has two main purposes: (1) to provide the user with efficient methods to measure or describe paths between nodes in a tree, and (2) to provide many methods of describing dissimilarities between two trees. All dissimilarity metrics currently implemented are quantified by quartet and bipartition differences, which are explained in [tree distances](/toytree/tree-distance/). \n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"## Node-level distances \n",
"\n",
Expand Down Expand Up @@ -1137,6 +1149,266 @@
"# toytree.distance.get_treedist_rfg_msi(tree1, tree2)\n",
"# toytree.distance.get_treedist_rfg_spi(tree1, tree2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Annotate subpackage Documentation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `.annotate` subpackage offers a clean, readable way to edit an existing tree as an alternative to modifying each argument in the `.draw()` method. The funcitons provided in this subpackage work by adding marks on top of the most recent `canvas` created by Toytree. It can be accessed direclty from a tree object (e.g., tree.annotate.{function}()), but some functions require additional arguments to specify axes, styles, etc. \n",
"\n",
"Since this subpackage contains very simple modifications that can be quickly added on top of existing trees, we encourage you to share with us any functions you make that may fit in this subpackage! These can be shared via Github at https://github.com/eaton-lab/toytree/discussions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Node and edge marks/labels \n",
"\n",
"- add_edge_labels\n",
"- add_edge_markers\n",
"- add_node_markers\n",
"- add_node_labels\n",
"- add_tip_markers\n",
"- add_node_bars\n",
"\n",
"## Axes annotations\n",
"\n",
"- add_axes_box_outline\n",
"- add_axes_scale_bar\n",
"\n",
"## Data/graph annotations\n",
"\n",
"- add_node_pie_charts\n",
"- add_edge_pie_charts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Quick examples"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import toytree\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_axes_box_outline\n",
"\n",
"tree = toytree.rtree.unittree(6, seed=123)\n",
"canvas, axes, m0 = tree.draw()\n",
"\n",
"\n",
"tree.annotate.add_axes_box_outline(axes=axes)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_edge_labels\n",
"\n",
"tree = toytree.rtree.unittree(6, seed=123)\n",
"canvas, axes, m0 = tree.draw()\n",
"m1 = tree.annotate.add_edge_labels(\n",
" axes,\n",
" labels=tree.get_node_data(\"idx\"),\n",
" color='blue',\n",
" style={'font-size': 16, 'baseline-shift': 8}\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_edge_markers\n",
"\n",
"tree = toytree.rtree.unittree(6, seed=123)\n",
"canvas, axes, m0 = tree.draw()\n",
"m1 = tree.annotate.add_edge_markers(\n",
" axes,\n",
" marker='s',\n",
" size=9,\n",
" color='red',\n",
" style={'stroke': 'white', 'stroke-width': 2.5}\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_node_markers\n",
"\n",
"tree = toytree.rtree.unittree(6, seed=123)\n",
"canvas, axes, m0 = tree.draw()\n",
"# add markers to all Nodes\n",
"m1 = tree.annotate.add_node_markers(\n",
" axes,\n",
" marker='s',\n",
" size=9,\n",
" color='red',\n",
" style={'stroke': 'white', 'stroke-width': 2.5}\n",
")\n",
"# add markers to only a few Nodes\n",
"m2 = tree.annotate.add_node_markers(\n",
" axes, marker=\">\", size=20, mask=tree.get_node_mask(9, 10)\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_node_labels\n",
"\n",
"tree = toytree.rtree.unittree(6, seed=123)\n",
"canvas, axes, m0 = tree.draw()\n",
"m1 = tree.annotate.add_node_labels(\n",
" axes,\n",
" labels=tree.get_node_data(\"idx\"),\n",
" color='blue',\n",
" style={'font-size': 16, 'baseline-shift': 8}\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_node_bars\n",
"\n",
"tree = toytree.rtree.unittree(10, treeheight=1e5)\n",
"c, a, m = tree.draw()\n",
"node_height = tree.get_node_data(\"height\").values\n",
"tree.annotate.add_node_bars(\n",
" axes=a,\n",
" bar_min=node_height * 0.5,\n",
" bar_max=node_height * 1.5,\n",
" size=0.33, z_index=-1, color='purple', opacity=0.4,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_tip_markers\n",
"\n",
"tree = toytree.rtree.unittree(6, seed=123)\n",
"canvas, axes, m0 = tree.draw()\n",
"# add markers to all Nodes\n",
"m1 = tree.annotate.add_tip_markers(\n",
" axes,\n",
" marker='s',\n",
" size=9,\n",
" color='red',\n",
" style={'stroke': 'white', 'stroke-width': 2.5}\n",
")\n",
"# add markers to only a few Nodes\n",
"m2 = tree.annotate.add_tip_markers(\n",
" axes, marker=\">\", size=20, mask=tree.get_node_mask(9)\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_axes_scale_bar\n",
"\n",
"import toytree\n",
"\n",
"tree = toytree.rtree.unittree(ntips = 10)\n",
"canvas, axes, mark = tree.draw()\n",
"tree.annotate.add_axes_scale_bar(axes)\n",
"\n",
"# orig = toytree.rtree.rtree(5, seed=123)\n",
"# orig.set_node_data(\"orig\", {i: i.idx for i in orig}, inplace=True)\n",
"# # orig.draw('p', node_labels=\"orig\");\n",
"# a, b = orig.mod.bisect(1)\n",
"# c, ax, m = a.draw()\n",
"# a.annotate.add_axes_scale_bar(ax)#scale_bar=True);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_node_pie_charts\n",
"tree = toytree.rtree.unittree(6, seed=123)\n",
"canvas, axes, m0 = tree.draw()\n",
"\n",
"# generate random pie-like (proportion) data array\n",
"ncategories = 3\n",
"arr = np.random.random(size=(tree.nnodes, ncategories))\n",
"arr = (arr.T / arr.sum(axis=1)).T\n",
"\n",
"# add pie charts to all internal Nodes\n",
"tree.annotate.add_node_pie_charts(\n",
" axes=axes, data=arr, size=20, mask=(0, 1, 1),\n",
" istroke_width=0.75, istroke=\"black\", rotate=-45,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#add_edge_pie_charts\n",
"tree = toytree.rtree.unittree(6, seed=123)\n",
"canvas, axes, m0 = tree.draw()\n",
"\n",
"# generate random pie-like (proportion) data array\n",
"ncategories = 3\n",
"arr = np.random.random(size=(tree.nnodes, ncategories))\n",
"arr = (arr.T / arr.sum(axis=1)).T\n",
"\n",
"# add pie charts to all internal Nodes\n",
"tree.annotate.add_edge_pie_charts(\n",
" axes=axes, data=arr, size=20, mask=(0, 1, 1),\n",
" istroke_width=0.75, istroke=\"black\", rotate=-45,\n",
")"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 5fb8f38

Please sign in to comment.