Convert a tree in the tree sequence to an object of the class phylo

  mode = c("index", "position"),
  labels = c("tskit", "pop"),
  quiet = FALSE



Tree sequence object of the class slendr_ts


Position of the tree in the tree sequence. If mode = "index", an i-th tree will be returned (in one-based indexing), if mode = "position", a tree covering an i-th base of the simulated genome will be returned.


How should the i argument be interpreted? Either "index" as an i-th tree in the sequence of genealogies, or "position" along the simulated genome.


What should be stored as node labels in the final phylo object? Options are either a population name or a tskit integer node ID (which is a different thing from a phylo class node integer index).


Should ape's internal phylo validity test be printed out?


Standard phylogenetic tree object implemented by the R package ape


check_dependencies(python = TRUE) # make sure dependencies are present

# load an example model with an already simulated tree sequence
slendr_ts <- system.file("extdata/models/introgression.trees", package = "slendr")
model <- read_model(path = system.file("extdata/models/introgression", package = "slendr"))

# load the tree-sequence object from disk
ts <- ts_load(slendr_ts, model, simplify = TRUE)

# extract the 1st tree from a given tree sequence, return ape object
tree <- ts_phylo(ts, i = 1, mode = "index", quiet = TRUE)
#> Phylogenetic tree with 26 tips and 25 internal nodes.
#> Tip labels:
#>   25 (EUR_5), 24 (EUR_5), 23 (EUR_4), 22 (EUR_4), 21 (EUR_3), 20 (EUR_3), ...
#> Node labels:
#>   67, 27, 26, 29, 30, 31, ...
#> Rooted; includes branch lengths.

# extract the tree at a 42th basepair in the given tree sequence
tree <- ts_phylo(ts, i = 42, mode = "position", quiet = TRUE)

# because the tree is a standard ape phylo object, we can plot it easily
plot(tree, use.edge.length = FALSE)