
Get the table of individuals/nodes/edges/mutations from the tree sequence
Source:R/tree-sequences.R
ts_table.Rd
This function extracts data from a given tree sequence table. All times are converted to model-specific time units from tskit's "generations backwards" time direction.
Usage
ts_table(ts, table = c("individuals", "edges", "nodes", "mutations"))
Value
Data frame with the information from the give tree-sequence table (can be either a table of individuals, edges, nodes, or mutations).
Details
For further processing and analyses, the output of the function
ts_nodes
might be more useful, as it merges the information in
node and individual tables into one table and further annotates it with
useful information from the model configuration data.
Examples
# 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, mutate = TRUE,
mutation_rate = 1e-8, random_seed = 42)
# get the 'raw' tskit table of individuals
ts_table(ts, "individuals")
#> # A tibble: 55 × 11
#> ind_id time pedigree_id raste…¹ raste…² pop_id alive remem…³ retai…⁴ sampled
#> <dbl> <dbl> <dbl> <dbl> <dbl> <int[> <lgl> <lgl> <lgl> <lgl>
#> 1 0 -10 5520343 0 0 0 TRUE TRUE TRUE TRUE
#> 2 1 -10 5520350 0 0 1 TRUE TRUE TRUE TRUE
#> 3 2 -10 5520351 0 0 1 TRUE TRUE TRUE TRUE
#> 4 3 -10 5520352 0 0 1 TRUE TRUE TRUE TRUE
#> 5 4 -10 5520357 0 0 1 TRUE TRUE TRUE TRUE
#> 6 5 -10 5520358 0 0 1 TRUE TRUE TRUE TRUE
#> 7 6 -10 5520506 0 0 3 TRUE TRUE TRUE TRUE
#> 8 7 -10 5520601 0 0 3 TRUE TRUE TRUE TRUE
#> 9 8 -10 5520655 0 0 3 TRUE TRUE TRUE TRUE
#> 10 9 -10 5520773 0 0 3 TRUE TRUE TRUE TRUE
#> # … with 45 more rows, 1 more variable: time_tskit <dbl[1d]>, and abbreviated
#> # variable names ¹raster_x, ²raster_y, ³remembered, ⁴retained
# get the 'raw' tskit table of edges
ts_table(ts, "edges")
#> # A tibble: 133 × 5
#> id child parent left right
#> <dbl> <int> <int> <dbl> <dbl>
#> 1 0 14 26 0 500000
#> 2 1 15 26 0 500000
#> 3 2 6 27 0 500000
#> 4 3 13 27 0 500000
#> 5 4 7 28 0 500000
#> 6 5 8 28 0 500000
#> 7 6 11 29 0 500000
#> 8 7 12 29 0 500000
#> 9 8 5 30 0 500000
#> 10 9 29 30 0 500000
#> # … with 123 more rows
# get the 'raw' tskit table of nodes
ts_table(ts, "nodes")
#> # A tibble: 68 × 5
#> node_id ind_id pop_id time time_tskit
#> <int> <int[1d]> <int> <dbl> <dbl[1d]>
#> 1 0 18 2 70010 2334
#> 2 1 18 2 70010 2334
#> 3 2 20 2 40010 1334
#> 4 3 20 2 40010 1334
#> 5 4 1 1 -10 0
#> 6 5 1 1 -10 0
#> 7 6 2 1 -10 0
#> 8 7 2 1 -10 0
#> 9 8 3 1 -10 0
#> 10 9 3 1 -10 0
#> # … with 58 more rows
# get the 'raw' tskit table of mutations
ts_table(ts, "mutations")
#> # A tibble: 2,187 × 5
#> id site node time time_tskit
#> <dbl> <int> <int> <dbl> <dbl[1d]>
#> 1 0 0 66 757010. 25234.
#> 2 1 1 64 575160. 19172.
#> 3 2 2 26 3622440. 120748.
#> 4 3 3 66 693873. 23129.
#> 5 4 4 63 220620. 7354.
#> 6 5 5 66 5179605. 172654.
#> 7 6 6 66 5212483. 173750.
#> 8 7 7 66 2373328. 79111.
#> 9 8 8 64 477414. 15914.
#> 10 9 9 26 1158846. 38629.
#> # … with 2,177 more rows