Skip to contents

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

Usage

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, quit = TRUE) # dependencies must be present

init_env()
#> The interface to all required Python modules has been activated.

# 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)

# 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: 95 × 12
#>    name  pop   node_id level child_id parent_id child_time parent_time child_pop
#>    <chr> <fct>   <int> <fct>    <int>     <int>      <dbl>       <dbl> <fct>    
#>  1 EUR_1 EUR        16 1           16        37          0        2690 EUR      
#>  2 EUR_1 EUR        16 1           16        38          0        2930 EUR      
#>  3 EUR_1 EUR        16 1           16        40          0        4250 EUR      
#>  4 EUR_1 EUR        16 2           37        38       2690        2930 EUR      
#>  5 EUR_1 EUR        16 2           38        42       2930        6440 EUR      
#>  6 EUR_1 EUR        16 2           38        47       2930        7730 EUR      
#>  7 EUR_1 EUR        16 2           38        48       2930        8210 EUR      
#>  8 EUR_1 EUR        16 2           38        49       2930        8300 EUR      
#>  9 EUR_1 EUR        16 2           38        52       2930       10280 EUR      
#> 10 EUR_1 EUR        16 2           40        42       4250        6440 EUR      
#> # ℹ 85 more rows
#> # ℹ 3 more variables: parent_pop <fct>, left_pos <dbl>, right_pos <dbl>