Debian Codegraph @

docs/source/tutorials/timetree.rst

raw
1
2 Estimation of time scaled phylogenies
3 -------------------------------------
4
5 The principal functionality of TreeTime is estimating time trees from an initial tree topology, a set of date constraints (e.g. tip dates), and an alignment (optional).
6 This tutorial uses data provided in the github repository `github.com/neherlab/treetime_examples <https://github.com/neherlab/treetime_examples>`_.
7
8 .. code-block:: bash
9
10 treetime --tree data/h3n2_na/h3n2_na_20.nwk --dates data/h3n2_na/h3n2_na_20.metadata.csv --aln data/h3n2_na/h3n2_na_20.fasta --outdir h3n2_timetree
11
12 The tree can be in newick or nexus format, the alignment in fasta or phylip, and the dates should be given as a tsv or csv file.
13 TreeTime will attempt to parse dates, preferred formats are "%Y-%m-%d" or numerical as in YYYY.F (where 'F' is the fraction of the year that has passed, in days. For example 2016.04918 means that 18/366 days of 2016 have passed).
14 This command will estimate an GTR model, a molecular clock model, and a time-stamped phylogeny.
15 The results are saved to several files in the directory specified as `outdir` and printed to standard out:
16
17 .. code-block:: bash
18
19 Inferred GTR model:
20 Substitution rate (mu): 1.0
21
22 Equilibrium frequencies (pi_i):
23 A: 0.2983
24 C: 0.1986
25 G: 0.2353
26 T: 0.2579
27 -: 0.01
28
29 Symmetrized rates from j->i (W_ij):
30 A C G T -
31 A 0 0.8273 2.8038 0.4525 1.031
32 C 0.8273 0 0.5688 2.8435 1.0561
33 G 2.8038 0.5688 0 0.6088 1.0462
34 T 0.4525 2.8435 0.6088 0 1.0418
35 - 1.031 1.0561 1.0462 1.0418 0
36
37 Actual rates from j->i (Q_ij):
38 A C G T -
39 A 0 0.2468 0.8363 0.135 0.3075
40 C 0.1643 0 0.1129 0.5646 0.2097
41 G 0.6597 0.1338 0 0.1432 0.2462
42 T 0.1167 0.7332 0.157 0 0.2686
43 - 0.0103 0.0106 0.0105 0.0104 0
44
45 Root-Tip-Regression:
46 --rate: 2.613e-03
47 --chi^2: 22.16
48
49 --r^2: 0.98
50
51 --- saved tree as
52 h3n2_timetree/timetree.pdf
53
54 --- alignment including ancestral nodes saved as
55 h3n2_timetree/ancestral_sequences.fasta
56
57 --- saved divergence times in
58 h3n2_timetree/dates.tsv
59
60 --- tree saved in nexus format as
61 h3n2_timetree/timetree.nexus
62
63 --- root-to-tip plot saved to
64 h3n2_timetree/root_to_tip_regression.pdf
65
66 Other output files include an alignment with reconstructed ancestral sequences, an annotated tree in nexus format in which branch length correspond to years and mutations and node dates (in the numeric format detailed above) are added as comments to each node.
67 In addition, the root-to-tip vs time regression and the tree are drawn and saved to file.
68
69
70 .. image:: figures/timetree.png
71 :target: figures/timetree.png
72 :alt: rtt
73
74
75 Accounting for phylogenetic covariance
76 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77
78 The root-to-tip distances of samples are expected to increase with sampling date and TreeTime uses this behavior to estimate clock rates.
79 However, these root-to-tip distances are correlated due to shared ancestry.
80 This can be efficiently accounted if the sequence data set is consistent with a simple strict molecular clock model, but can give misleading results when the molecular clock model is violated.
81 This feature is hence off by default and can be switched on using the flag
82
83 .. code-block:: bash
84
85 --covariation
86
87
88 Fixed evolutionary rate
89 ^^^^^^^^^^^^^^^^^^^^^^^
90
91 If the temporal signal in the data is weak and the clock rate can't be estimated confidently from the data, it is advisable to specify the rate explicitly.
92 This can be done using the argument
93
94 .. code-block:: bash
95
96 --clock-rate <rate>
97
98
99 Divergence times inference methods
100 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101
102 TimeTree estimates optimal time trees by chosing node positions/ divergence times that optimize the joint or marginal likelihood.
103
104 The **joint maximum-likelihood** assignment corresponds to the global configuration with the highest likelihood, however it gives no information about the confidence of divergence time estimates.
105 The **marginal maximum-likelihood** assignment assigns nodes to their most likely divergence time after integrating over all possible configurations of the other nodes, it enables the computation of divergence time confidence intervals.
106
107 Which 'method' of divergence time estimation is used can be specified with the flag:
108
109 .. code-block:: bash
110
111 --time-marginal <method>
112
113 It is possible to run iterations of TreeTime using different methods.
114 If ``‘false’`` or ``‘never’``, TreeTime uses the jointly most likely values for the divergence times. If ``‘true’`` or ``‘always’`` TreeTime uses the marginal inference mode at every
115 round of optimization, ``‘only-final’`` (or ``‘assign’`` for compatibility with previous versions) only uses the marginal distribution in the final round.
116
117
118 In versions 0.9 and higher the marginal-likelihood assignment was sped up by using the Fast Fourier Transform to calculate convolution integrals. Now the time complexity of marginal and joint likelihood calculations is comparable,
119 whereas in versions prior to 0.9 the joint likelihood assignment was 2-3 times faster. To maintain compatibility with previous versions the joint maximum-likelihood assignment is still
120 preformed as a default, however the marginal-likelihood assignment is now recommended.
121
122
123 Confidence intervals
124 ^^^^^^^^^^^^^^^^^^^^
125
126 In its default setting, TreeTime does not estimate confidence intervals of divergence times.
127 Such estimates require calculation of the marginal probability distributions of the dates of the internal nodes.
128 To switch on confidence estimation, pass the flag ``--confidence``.
129 If the ``--time-marginal`` method is in ``['false', 'never']`` TreeTime will run another round of marginal timetree reconstruction to calculate the marginal probability distribution of the nodes. Otherwise, TreeTime will use the marginal
130 probability distribution calculated in the last round of time tree reconstruction and determine the region that contains 90% of the marginal probability distribution of the node dates.
131 These intervals are drawn into the tree graph and written to the dates file.
132
133
134 Specify or estimate coalescent models
135 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
136
137 TreeTime can be run either without a tree prior or with a Kingman coalescent tree prior.
138 The later is parameterized by a time scale 'Tc' which can vary in time.
139 This time scale is often called 'effective population size' Ne, but the appropriate Tc has very little to do with census population sizes.
140 To activate the Kingman Coalescent model in TreeTime, you need to add the flag
141
142 .. code-block:: bash
143
144 --coalescent <arg>
145
146 where the argument is either a floating point number giving the time scale of coalescence in units of divergence, 'const' to have TreeTime estimate a constant merger rate, or 'skyline'.
147 In the latter case, TreeTime will estimate a piece-wise linear merger rate trajectory and save this in files ending on ``skyline.tsv`` and ``skyline.pdf``
148
149 The following command will run TreeTime on the ebola example data set and estimate a time tree along with a skyline (this will take a few minutes).
150
151 .. code-block:: bash
152
153 treetime --tree data/ebola/ebola.nwk --dates data/ebola/ebola.metadata.csv --aln data/ebola/ebola.fasta --outdir ebola --coalescent skyline
154
155 The number of grid points in the skyline model can be additionally specified using the flag
156
157 .. code-block:: bash
158
159 --n-skyline <n_skyline_grid_points>
160
161 .. image:: figures/ebola_skyline.png
162 :target: figures/ebola_skyline.png
163 :alt: ebola_skyline
164
165 The coalescent model requires the number of lineages in the tree at any given time for estimating the probability of a coalecent event. In the default
166 setting the current estimates of divergence times are used for calculating the number of lineages, if the certainty of these estimates should be accounted for
167 the posterior probability distributions of divergence times can be used by adding the flag
168
169 .. code-block:: bash
170
171 --n-branches-posterior
172
173 this should smooth the coalescence likelihood distributions.
174
175 VCF files as input
176 ^^^^^^^^^^^^^^^^^^
177
178 In addition to standard fasta files, TreeTime can ingest sequence data in form of vcf files which is common for bacterial data sets where short reads are mapped against a reference and only variable sites are reported.
179 The following example with a set of MtB sequences uses a fixed evolutionary rate of 1e-7 per site and year.
180
181 .. code-block:: bash
182
183 treetime --aln data/tb/lee_2015.vcf.gz --vcf-reference data/tb/tb_ref.fasta --tree data/tb/lee_2015.nwk --clock-rate 1e-7 --dates data/tb/lee_2015.metadata.tsv
184
185 For many bacterial data sets where the temporal signal in the data is weak, it is advisable to fix the rate of the molecular clock explicitly.
186 Divergence times, however, will depend on this choice.
187
188
189