Tutorial introducing the R package TransPhylo Xavier Didelot January 16, 2017

Introduction Welcome to this quick tutorial on TransPhylo. TransPhylo is a R package that can reconstruct infectious disease transmission using genomic data. The input is a dated phylogeny, where leaves correspond to pathogens sampled from the known infected hosts. The main output is a transmission tree which indicates who infected whom, including the potential existence of unsampled individuals who may have acted as missing transmission links. TransPhylo works by colouring the branches of the phylogeny using a separate colour for each host, sampled or not. Each section of the tree coloured in a unique colour represents the pathogen evolution happening within a distinct host. Changes of colours on branches therefore correspond to transmission events from one host to another. In the first part of this tutorial we will simulate a dataset. In the second part we will analyse the dataset simulated in the first part. If you already have a dataset on which you want to apply TransPhylo you can skip the first part, although you might still find it useful to read as it introduces some of the concepts in our model. If you have not already done so, you can install TransPhylo using the following R command: devtools::install_github('xavierdidelot/TransPhylo') You should then be able to load TransPhylo using: library('TransPhylo') ## Loading required package:

ape

Finally, if you want to reproduce exactly the same results as the ones shown in this tutorial, you should set the seed of your random number generator to the same as mine: set.seed(0)

1

Simulation

A pathogen has an effective within-host population size of Ne = 100 and a generation time g = 1 day, so that Ne g = 100/365 year. The offspring distribution is negative binomial with mean equal to the basic reproduction number R = 5. Both the generation time and the sampling time are Gamma distributed with parameters (10,0.1) which has a mean of 1 year. The density of sampling is π = 0.25. The following commands specify these parameters: neg=100/365 off.r=5 w.shape=10 w.scale=0.1 pi=0.25 We simulate an outbreak that starts in 2005 and which and is observed up to 2008:

1

simu <- simulateOutbreak(neg=neg,pi=pi,off.r=off.r,w.shape=w.shape, w.scale=w.scale,dateStartOutbreak=2005,dateT=2008) This simulation contains both the transmission tree between infected hosts and the within-host phylogenetic tree of each host. This can be visualised as a colored phlogenetic tree, where each host is represented by a unique color:

plotCTree(simu)

2 6 3 5 1 4

2005.0

2006.0

2007.0

2008.0

The transmission tree can be extracted and plotted separately from the phylogeny: ttree<-extractTTree(simu) plotTTree(ttree,w.shape,w.scale)

2

6 2 3 5 1 4

2005.0

2006.0

2007.0

2008.0

The phylogenetic tree can be extracted and converted into a phylo object from the ape package: library(ape) ptree<-extractPTree(simu) p<-phyloFromPTree(ptree) plot(p) axisPhylo()

4

1

5

3

6

2 2.5

2

1.5

1

0.5

0

Let us save this tree into a Newick file so that we can use it as input in the second part.

3

write.tree(p,'tree.nwk',append = F) Note that this phylogeny is scaled in years, but time is measured only relatively to the date of the last sample which is at 0 on the x-axis of the figure above. To use this tree in the second part we also need to know exactly when was the last sample taken: print(max(simu$ctree[,1])) ## [1] 2007.964

2

Inference of transmission tree given a phylogeny

This second part is independent from the first part, so we start by erasing the workspace and resetting the seed of the random number generator: rm(list=ls()) set.seed(0) Our starting point is a timed phylogenetic tree such as the one created in the previous part and that we stored in the tree.nwk file. Because such a phylogeny is timed relatively and not absolutely, we also need to indicate when the last sample was taken, which in the simulation above was equal to 2007.964. However, if you are using your own dataset, you should set this equal to the date at which the last sample was taken. ptree<-ptreeFromPhylo(read.tree('tree.nwk'),dateLastSample=2007.964) TransPhylo also needs to know the parameters of the Gamma distribution representing the generation time. In the simulation above we assumed that these parameters were equal to (10,0.1), and so this is what we specify below. However, if you are using your own data, you should set these values to something sensible for your pathogen of interest. w.shape=10 w.scale=0.1 Finally TransPhylo needs to know the time at which observation of cases stopped. In the simulation above this was equal to 2008, and so this is what we specify below. However, if you are using your own data, you should set this equal to the date when observation stopped for your outbreak of interest. It might be today’s date if you are doing a real-time genomic epidemiology investigation. It can even be set equal to Inf if you are confident that the outbreak is finished and that there will be no cases in the future, for example if you are analysing an old outbreak which is clearly finished. dateT=2008 The MCMC procedure to infer the transmission tree given the phylogenetic tree can be run as follows: record<-inferTTree(ptree,mcmcIterations=100,w.shape=w.shape,w.scale=w.scale,dateT=dateT) This returns a record of all MCMC iterations. This is what the transmission tree looks like at the end of the MCMC: lastIteration<-record[[length(record)]] plotCTree(lastIteration$ctree)

4

2 6 3 5 1 4

2005.0

2006.0

2007.0

2008.0

Traces of the MCMC can be plotted as follows: par(mfrow=c(2,2)) plot(sapply(record,function(x) x$pTTree+x$pPTree),ylab='Posterior probability', xlab='MCMC iterations',type='l') plot(sapply(record,function(x) x$pi),ylab='Sampling proportion pi', xlab='MCMC iterations',type='l') plot(sapply(record,function(x) x$neg),ylab='Within-host coalescent rate Ne*g', xlab='MCMC iterations',type='l') plot(sapply(record,function(x) x$off.r),ylab='Basic reproduction number R', xlab='MCMC iterations',type='l')

5

20 40 60 80

0.50 0.35 0.20

Sampling proportion pi

−20 −30

Posterior probability

0

0

0

20 40 60 80

2.0 1.0

1.5

Basic reproduction number R

MCMC iterations

0.5

Within−host coalescent rate Ne*g

MCMC iterations

20 40 60 80

MCMC iterations

0

20 40 60 80 MCMC iterations

A consensus transmission tree can be built as follows: cons=consTTree(record) plotTTree(cons,w.shape,w.scale)

4 5 1

6 2 3

2005

2006

6

2007

2008

Tutorial introducing the R package TransPhylo - GitHub

Jan 16, 2017 - disease transmission using genomic data. The input is a dated phylogeny, ... In the second part we will analyse the dataset simulated in the first ...

278KB Sizes 26 Downloads 392 Views

Recommend Documents

Package 'TransPhylo' - GitHub
Jan 16, 2017 - Shape parameter of the Gamma probability density function ... makeTTree(off.r, off.p, pi, w.shape, w.scale, ws.shape, ws.scale, maxTime,.

Package 'hcmr' - GitHub
Effective green time to cycle length ratio. P ... Two-Lane Highway - Base Percent Time Spent Following .... Passenger-Car Equivalent of Recreational Vehicles:.

Package 'CaseCrossover' - GitHub
Apr 21, 2017 - strategies for picking the exposure will be tested in the analysis, a named list of .... A data frame of subjects as generated by the function ...

Package 'SelfControlledCaseSeries' - GitHub
Mar 27, 2017 - 365, minAge = 18 * 365, maxAge = 65 * 365, minBaselineRate = 0.001,. maxBaselineRate = 0.01 .... Modeling and Computer Simulation 23, 10 .... function ggsave in the ggplot2 package for supported file formats. Details.

package management.key - GitHub
Which version of Faker did our app depend on? If we run our app in a year and on a different machine, will it work? If we are developing several apps and they each require different versions of Faker, will our apps work? Page 6. Gem Management with B

Package 'MethodEvaluation' - GitHub
Feb 17, 2017 - effects in real data based on negative control drug-outcome pairs. Further included are .... one wants to nest the analysis within the indication.

Package 'CohortMethod' - GitHub
Jun 23, 2017 - in an observational database in the OMOP Common Data Model. It extracts the ..... Create a CohortMethod analysis specification. Description.

Package 'deGPS' - GitHub
Sep 9, 2014 - The package also contains function to generate GP distrbuted data to be an ... apply deGPS on fly data with the empirical T stats downloaded at.

Package 'fishhook' - GitHub
April 18, 2017. Title R Package for performing Gamma-Poisson regression on somatic mutation count data. Version 0.1. Description Package for performing Gamma-Poisson regression on somatic mutation count data with covariates to identify mutational enr

Package 'fishhook' - GitHub
Apr 18, 2017 - count data with covariates to identify mutational enrichment or depletion in a .... $signature interval covariates: fraction of bases overlapping feature .... toggles between creating a pdf (FALSE) or an interactive html widget ...

Package 'cmgo' - GitHub
Aug 21, 2017 - blue all Voronoi segments, b) in red all segments fully within the channel polygon, c) in green all ..... if [TRUE] the plot will be saved as pdf.

Package 'EmpiricalCalibration' - GitHub
study setup. This empirical null distribution can be used to compute a .... Description. Odds ratios from a case-control design. Usage data(caseControl). Format.

Package 'OhdsiRTools' - GitHub
April 7, 2017. Type Package. Title Tools for Maintaining OHDSI R Packages. Version 1.3.0. Date 2017-4-06. Author Martijn J. Schuemie [aut, cre],. Marc A.

Package 'FeatureExtraction' - GitHub
deleteCovariatesSmallCount = 100, longTermDays = 365, ..... Description. Uses a bag-of-words approach to construct covariates based on free-text. Usage.

Package 'EvidenceSynthesis' - GitHub
Mar 19, 2018 - This includes functions for performing meta-analysis and forest plots. Imports ggplot2 (>= 2.0.0),. gridExtra, meta,. EmpiricalCalibration. License Apache License 2.0. URL https://github.com/OHDSI/EvidenceSynthesis. BugReports https://

Package 'IcTemporalPatternDiscovery' - GitHub
Nov 25, 2015 - exposureOutcomePairs = data.frame(outcomeId = c(196794, ... strategies for picking the exposure will be tested in the analysis, a named list of.

SKAT Package - CRAN-R
Jul 21, 2017 - When the trait is binary and the sample size is small, SKAT can produce conservative results. We developed a moment matching adjustment (MA) that adjusts the asymptotic null distribution by estimating empirical variance and kurtosis. B

Package 'SelfControlledCohort' - GitHub
If multiple strategies for picking the exposure will be tested in the analysis, a named list of ... studyStartDate Date for minimum allowable data for index exposure.

Package 'DatabaseConnector' - GitHub
Aug 14, 2017 - connect creates a connection to a database server .There are four ways to call this function: • connect(dbms, user, domain, password, server, ...

Package 'CaseControl' - GitHub
control analyses in an observational database in the OMOP Common Data .... multiple strategies for picking the nesting cohort will be tested in the analysis, a.

CryptRndTest: An R Package for Testing the ... - The R Journal
on the package Rmpfr. By this way, included tests are applied precisely for ... alternative tests for the evaluation of cryptographic randomness available ..... Call. Test. GCD.test(). GCD.test(x,KS = TRUE,CSQ = TRUE,AD = TRUE,JB = TRUE, ..... In:Pro

CryptRndTest: An R Package for Testing the ... - The R Journal
To the best of our knowledge, the adaptive chi-square, topological binary, .... rate of the theoretical Poisson distribution (λ), and the number of classes (k) that is ...... passes the GCD test with CS goodness-of-fit test for k at (8, I), (8, II)

Single studies using the CaseControl package - GitHub
Jun 29, 2016 - Loading data on the cases and potential controls from the database .... for which no matching control was found be removed from the analysis.

Single studies using the SelfControlledCaseSeries package - GitHub
Transforming the data into a format suitable for an SCCS study. .... Now we can tell SelfControlledCaseSeries to extract all necessary data for our analysis:.