knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 8,
  fig.height = 6,
  fig.path = "figs/",
  echo = TRUE
)

Installing the package

To install the development version of the package, type:

devtools::install_github("thibautjombart/quicksim")

Note that this requires the package devtools installed.

What does it do?

As it currently stands, the package does not implement the process generating the transmission tree, but it does provide functions to create cases given known transmission events.

The main features of the package include:

Demo

A basic example

We start from the following transmission tree:

tree <- matrix(c(1, 2, 2, 3, 3, 4, 2, 5, 5, 6), ncol = 2, byrow = TRUE)
colnames(tree) <- c("from", "to")
tree

## dates of infection for cases 1-6
infection_dates <- c(0, 2, 5, 6, 7, 10)

library(igraph)
plot(graph.data.frame(tree), vertex.color = "#e0ccff")

We load the package, examine the default settings, make custom config, and generate an index case:

library(quicksim)

## see default config
new_config()

## use custom config
conf <- new_config(genome_length = 1e4,
                   mutation_rate = 1e-4,
                   separation_lineages = 10)

## create index case
index <- new_case(config = conf)
index

We create new cases according to the transmission tree:

set.seed(1)

cases <- vector(mode = "list", length = 6)
cases[[1]] <- index

for (i in seq_len(nrow(tree))) {
  infector <- tree[i, 1]
  infectee <- tree[i, 2]
  cases[[infectee]] <- new_case(cases[[infector]],
                                date = infection_dates[infectee],
                                config = conf)
}

cases

Some further analyses

library(ape)

dna <- lapply(cases, function(e) e$dna)
locations <- matrix(unlist(lapply(cases, function(e) e$location)),
                    ncol = 2, byrow = TRUE)

## genetic distances
D_dna <- dist_dna(dna)
D_dna

plot(nj(D_dna), "unrooted", main = "Unrooted NJ tree, Hamming distances",
     show.tip.label = FALSE)

tiplabels(frame = "circ", col = "#f9ecf2", bg = "#602040", cex = 1.5)

## spatial distances
D_geo <- dist(locations)
D_geo
plot(locations, pch = paste(1:6), xlab = "x", ylab = "y", cex = 2)

Using custom spatial kernel

Customised spatial kernels can be specified as part of the config through the argument spatial_kernel. The behaviour of new_location is as follows:

  1. by default, a Normal kernel with standard deviation 1 is used
  2. if provided, sd_spatial is used for the standard deviation of the Normal kernel
  3. if provided, the alternative spatial kernel spatial_kernel is used instead, in which case sd_spatial is ignored.

If provided, the argument spatial_kernel should be a function of x, a vector of spatial coordinates, and return a similarly sized vector of new coordinates.

We can repeat the previous example with a new spatial kernel:

## new custom config
custom_kernel <- function(x) {
  out <- x + runif(length(x), min = 1, max = 3)
  out
}

new_conf <- new_config(genome_length = 1e4,
                       mutation_rate = 1e-4,
                       separation_lineages = 10,
                       spatial_kernel = custom_kernel)

set.seed(1)

for (i in seq_len(nrow(tree))) {
  infector <- tree[i, 1]
  infectee <- tree[i, 2]
  cases[[infectee]] <- new_case(cases[[infector]],
                                date = infection_dates[infectee],
                                config = new_conf)
}


## look at the new spatial distribution
locations <- matrix(unlist(lapply(cases, function(e) e$location)),
                    ncol = 2, byrow = TRUE)

plot(locations, pch = paste(1:6), xlab = "x", ylab = "y", cex = 2)

Resources

Vignettes

Vignettes are not currently available for this package.

Websites

The following websites are available:

Getting help online

Bug reports and feature requests should be posted on github using the issue system. All other questions should be posted on the RECON forum:
http://www.repidemicsconsortium.org/forum/

A quick overview

The following worked example provides a brief overview of the package's functionalities.

Contributors (by alphabetic order):

See details of contributions on:
https://github.com/thibautjombart/quicksim/graphs/contributors

Contributions are welcome via pull requests.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Maintainer: Thibaut Jombart (thibautjombart@gmail.com)



thibautjombart/quicksim documentation built on May 5, 2019, 2:42 a.m.