Molecular Clock Dating of Influenza H3N2

Erik Volz

2019-01-16

Introduction

treedater fits a strict or relaxed molecular clock to a phylogenetic tree and estimates evolutionary rates and times of common ancestry. The calendar time of each sample must be specified (possibly with bounds of uncertainty) and the length of the sequences used to estimate the tree.

treedater uses heuristic search to optimise the TMRCAs of a phylogeny and the substitution rate. An uncorrelated relaxed molecular clock accounts for rate variation between lineages of the phylogeny which is parameterised using a Gamma-Poisson mixture model.

To cite:

The most basic usage is

dater( tre, sts, s)

where

Invoking treedater from the command line

You can also use treedater from the command line without starting R using the tdcl script:

./tdcl -h
Usage: ./tdcl [-[-help|h] [<logical>]] [-[-treefn|t] <character>] [-[-samplefn|s] <character>] [-[-sequenceLength|l] <double>] [-[-output|o] [<character>]]

-t <file> : file name of tree in newick format  
-s  <file> : should be a comma-separated-value file with sample times in format <taxon-id,sample-time> and no header
-l <length> :  the integer length of sequences in alignment used to construct the tree 
-o <file>: name of file for saving output 

Note that you may need to modify the first line of the tdcl script with the correct path to Rscript or littler.

Influenza H3N2 HA

This data set comprises 177 HA sequences collected over 35 years worldwide with known date of sampling. We estimated a maximum likelihood tree using iqtree. We will use the sample dates and ML tree to fit a molecular clock and estimate a dated phylogeny. First, load the tree (any method can be used to load a phylogeny into ape::phylo format):

require(treedater)
#> Loading required package: treedater
#> Loading required package: limSolve
(tre <- ape::read.tree( system.file( 'extdata', 'flu_h3n2_final_small.treefile', package='treedater') ))
#> 
#> Phylogenetic tree with 177 tips and 175 internal nodes.
#> 
#> Tip labels:
#>  HM628693_2010-03-03, KC883039_2011-04-04, KC882820_2011-01-04, GQ983548_2009-06-22, KF790184_2012-10-05, JX978746_2012-03-19, ...
#> 
#> Unrooted; includes branch lengths.

Note that this tree does not have a root, and in the process of fitting a molecular clock, we will estimate the best root location.

seqlen <- 1698 # the length of the HA sequences used to reconstruct the phylogeny

To fit the molecular clock, we will need the sample time for each lineage. Note that the date of sampling is incorporated into the name of each lineage, which is common in viral phylogenetics studies. The package includes a convenient function for extracting these dates:

sts <- sampleYearsFromLabels( tre$tip.label, delimiter='_' )
head(sts)
#> HM628693_2010-03-03 KC883039_2011-04-04 KC882820_2011-01-04 
#>            2010.167            2011.255            2011.008 
#> GQ983548_2009-06-22 KF790184_2012-10-05 JX978746_2012-03-19 
#>            2009.471            2012.760            2012.213

How are samples distributed through time?

hist( sts , main = 'Time of sequence sampling') 

The basic usage of the treedater algorithm is as follows:

(dtr <- dater( tre , sts, seqlen ))
#> Note: Minimum temporal branch length  (*minblen*) set to 0.0192816582316329. Increase *minblen* in the event of convergence failures. 
#> Tree is not rooted. Searching for best root position. Increase searchRoot to try harder.
#> 
#> Phylogenetic tree with 177 tips and 176 internal nodes.
#> 
#> Tip labels:
#>  HM628693_2010-03-03, KC883039_2011-04-04, KC882820_2011-01-04, GQ983548_2009-06-22, KF790184_2012-10-05, JX978746_2012-03-19, ...
#> 
#> Rooted; includes branch lengths.
#> 
#>  Time of common ancestor 
#> 1979.4372056481 
#> 
#>  Time to common ancestor (before most recent sample) 
#> 35.6066299683389 
#> 
#>  Mean substitution rate 
#> 0.00321644725184376 
#> 
#>  Strict or relaxed clock 
#> relaxed 
#> 
#>  Coefficient of variation of rates 
#> 0.406223621791838

This produces a rooted tree with branches in calendar time. Note that if we invoked dater with a rooted input tree, it would not estimate the root position. In this way, you can also set the root location in other ways, such as by using an outgroup.

Lets see how long it takes to run treedater:

rt0 <- Sys.time()
dtr <- dater( tre , sts, seqlen )
#> Note: Minimum temporal branch length  (*minblen*) set to 0.0192816582316329. Increase *minblen* in the event of convergence failures. 
#> Tree is not rooted. Searching for best root position. Increase searchRoot to try harder.
rt1 <- Sys.time()
rt1 - rt0 
#> Time difference of 2.312068 secs

Note the returned value includes estimated substition rates and TMRCAs. The dtr object extends ape::phylo, so most of the methods that you can use in other R packages that use that format can also be used with a dater object. Lets plot the tree.

plot( dtr , no.mar=T, cex = .2 )

It looks like there are a couple of recent lineages that dont seem to fit well with the ladder-like topology. We can further examine this by doing a root-to-tip regression using the fitted tree and estimated node times which also shows a couple of outliers:

rootToTipRegressionPlot( dtr )

#> Root-to-tip mean rate: 0.00422342495830628 
#> Root-to-tip p value: 2.01554002772221e-89 
#> Root-to-tip R squared (variance explained): 0.899994781482438 
#> Returning fitted linear model.

It is always a good idea to visualize these distances to ensure that there is enough ‘clock signal’ in the data to reliably estimate rates and dates. We will examine these outliers in the next section.

Detecting and removing outliers / testing for relaxed clock

To find lineages that dont fit the molecular clock model very well, run

This returns a table in ascending order showing the quality of the molecular clock model fit for each lineage. Now lineages could be selected for removal in various ways. Lets remove all tips that dont have a very high q-value :

Now we can rerun dater with the reduced tree:

After removing the outliers, the coefficient of variation of rates is much lower, suggesting that a strict clock model may be appropriate for the reduced tree. We can test the suitability of the strict clock with this test:

Note that the ncpu option enabled parallel computing to speed up this test.

This test indicates a relaxed clock. Nevertheless, lets re-fit the model to the reduced tree using a strict clock for comparison:

The rate is higher than the initial estimate with the relaxed clock and the recently-sampled outlying lineages have been removed.

Parametric bootstrap

Estimating confidence intervals for rates and dates is straightforward using a parametric bootstrap:

How fast was it? Note that the ncpu option would enable parallel computing.

We can also plot the estimated number of lineages through time with confidence intervals:

If the ggplot2 package is installed, we can use that instead:

Note repeated bottlenecks and seasonal peaks of LTT corresponding to when samples are taken during seasonal epidemics.

The package also includes methods for nonparametric bootstrapping if you have already computed a bootstrap distribution of phylogenies.

Missing sample times

Suppose we only know some of the sample times to the nearest month, a common occurance in viral phylogenetic studies. To simulate this, we will put uncertainty bounds on some sample times equal to a +/- 2-week window. We create the following data frame with columns lower and upper:

In this case, we constructed the data frame with bounds for the first 50 samples in the tree, but we could also manually construct a data frame for a few selected samples where times of sampling are uncertain, or for all of the samples.

Now re-run treedater with the uncertain sample times. The vector sts provided here gives an initial guess of the unknown sample times.

Note that the estimated rates and dates didnt change very much due to uncertain sample dates in this case.