The State of Trees in MicrobeTrace
By: Tony Boyles
Tags: Phylogeny, Phylogenetics, D3js, Epidemiology

One popular analysis tool in Molecular Epidemiology is the phylogenetic tree. Trees give you an estimation of the evolutionary structure of a genetically diverse population. This is super useful for tracing evolution, if you have reason to be concerned about it (e.g., if you’re following propagation of drug-resistance mutations).

However, for analysis of outbreak clusters, trees don’t resemble the transmission processes very much. Networks, however, do. Accordingly, MicrobeTrace is built with the expectation that epidemiologists can get a lot more analytic leverage from networks. This is why the 2D network is the first visualization MicrobeTrace renders (by default). However, we recognize that analysis workflow changes don’t happen spontaneously, so MicrobeTrace enables users to build a phylogenetic tree if they need it.

There are a lot of Phylogenetic Tree libraries out there. Most are OK, a few are good, and none is perfect. Recognizing this, we had to build a new Phylogenetic Tree library starting from scratch to get the complete set of features that our users required. (Well, almost from scratch.) Over the course of just a few weeks, we were able to build up a library (and stand-alone web application) that met our needs.

…Until last month. One of our partners discovered that there’s a bug in TidyTree’s underlying data model, patristic. When you re-root the tree on a given node, patristic distances across the root branch will become inconsistent. This is a complex and subtle bug, but it led me to think for awhile about what is actually happening when the tree is rerooted. You basically pick the new root node and pull it to the top of the tree, and all the branches between the old and new root invert. Everything else stays the same. Thinking in this visual way made me realize that if we could just rely on physics, correct rerooting would simply be a consequence thereof. One thing led to another, and…

Introducing Physics Trees

MicrobeTrace now includes a view devoted to building Phylogenetic Trees in a dynamic physics model. This is similar to the 2D Network, only with the data which constructs trees, rather than networks. So, for example, you can drag nodes in the tree around the screen, and the tree adjusts to compensate for the changes. (By contrast, there’s no way to directly drag nodes around a TidyTree.) To build a Physics Tree:

Navigate to https://devmicrobetrace.herokuapp.com/ Load some sequence data. For this demo, we’ll use the MicrobeTrace default demo FASTA file. Click View > Physics Tree. The screen will go nuts for a second, and then settle down to something that looks like this:

Our fist Physics Tree!

It’s not especially interpretable this way. In the settings menu (see the gear button at the top-left), under the “Tree” tab, Let’s reduce the lateral strength, which is the degree to which MicrobeTrace attempts to force nodes to stick to the horizontal center-line of the screen. (If the layout is vertical, then the lateral strength forces nodes to the vertical center of the screen, and if the layout is radial, lateral force keeps nodes to specific bands around the screen’s centerpoint).

The Physics Tree, improved by decreasing the lateral force.

To validate this, I’ve configured a TidyTree using the same data to resemble the the Physics Tree:

A MicrobeTrace TidyTree, showing the same tree

(The settings to do this are Tree > Type = Tree and Branch > Type = Straight). You can tease out the fact that the structure of the two trees is identical.

Physics tree is a very early-stage feature to MicrobeTrace, but I’m introducing it here and now because I believe it will become the primary means of rendering Phylogenetic trees in MicrobeTrace. TidyTree will remain in MicrobeTrace for the forseeable future, but once we square away the re-rooting bug, it probably won’t receive much more development attention.