Extract (spatio-)temporal ancestral history for given nodes/individuals

ts_ancestors(ts, x, verbose = FALSE, complete = TRUE)

Arguments

ts

Tree sequence object of the class slendr_ts

x

Either an individual name or an integer node ID

verbose

Report on the progress of ancestry path generation?

complete

Does every individual in the tree sequence need to have complete metadata recorded? If TRUE, only individuals/nodes with complete metadata will be included in the reconstruction of ancestral relationships. For instance, nodes added during the coalescent recapitation phase will not be included because they don't have spatial information associated with them.

Value

A table of ancestral nodes of a given tree-sequence node all the way up to the root of the tree sequence

Examples

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)

# find the complete ancestry information for a given individual
ts_ancestors(ts, "EUR_1", verbose = TRUE)
#> Collecting ancestors of EUR_1 [1/1]...
#> 
#> Generating data about spatial relationships of nodes...
#> # A tibble: 93 × 12
#>    name  pop   node_id level child_id parent_id child_…¹ paren…² child…³ paren…⁴
#>    <chr> <fct>   <int> <fct>    <int>     <int>    <dbl>   <dbl> <fct>   <fct>  
#>  1 EUR_1 EUR        16 1           16        37        0    2690 EUR     EUR    
#>  2 EUR_1 EUR        16 1           16        38        0    2930 EUR     EUR    
#>  3 EUR_1 EUR        16 1           16        40        0    4250 EUR     EUR    
#>  4 EUR_1 EUR        16 2           37        38     2690    2930 EUR     EUR    
#>  5 EUR_1 EUR        16 2           38        42     2930    6440 EUR     EUR    
#>  6 EUR_1 EUR        16 2           38        47     2930    7730 EUR     EUR    
#>  7 EUR_1 EUR        16 2           38        48     2930    8210 EUR     EUR    
#>  8 EUR_1 EUR        16 2           38        49     2930    8300 EUR     EUR    
#>  9 EUR_1 EUR        16 2           38        52     2930   10280 EUR     EUR    
#> 10 EUR_1 EUR        16 2           40        42     4250    6440 EUR     EUR    
#> # … with 83 more rows, 2 more variables: left_pos <dbl>, right_pos <dbl>, and
#> #   abbreviated variable names ¹​child_time, ²​parent_time, ³​child_pop,
#> #   ⁴​parent_pop