Skip to contents

Extract all descendants of a given tree-sequence node

Usage

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

Arguments

ts

Tree sequence object of the class slendr_ts

x

An integer node ID of the ancestral node

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 descendant nodes of a given tree-sequence node all the way down to the leaves of the tree sequence

Examples

init_env()
#> Python virtual environment for slendr has been activated.

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

# load the tree-sequence object from disk
ts <- ts_read(slendr_ts, model)

# find the complete descendancy information for a given individual
ts_descendants(ts, x = 62, verbose = TRUE)
#> 
#> Generating data about spatial relationships of nodes...
#> # A tibble: 18 × 12
#>    name  pop   node_id level child_id parent_id child_time parent_time child_pop
#>    <chr> <fct>   <dbl> <fct>    <int>     <int>      <dbl>       <dbl> <fct>    
#>  1 EUR_4 NEA        62 1           22        62          0       51800 EUR      
#>  2 NA    NEA        62 1           35        62      11000       51800 EUR      
#>  3 NA    NEA        62 1           36        62      12110       51800 EUR      
#>  4 NA    NEA        62 1           38        62      14060       51800 EUR      
#>  5 NA    NEA        62 1           48        62      24530       51800 EUR      
#>  6 NA    NEA        62 1           50        62      30560       51800 EUR      
#>  7 NA    NEA        62 1           56        62      40580       51800 NEA      
#>  8 EUR_2 NEA        62 2           18        35          0       11000 EUR      
#>  9 EUR_4 NEA        62 2           22        35          0       11000 EUR      
#> 10 EUR_3 NEA        62 2           21        36          0       12110 EUR      
#> 11 NA    NEA        62 2           36        38      12110       14060 EUR      
#> 12 EUR_5 NEA        62 2           25        48          0       24530 EUR      
#> 13 NA    NEA        62 2           35        48      11000       24530 EUR      
#> 14 NA    NEA        62 2           39        48      14750       24530 EUR      
#> 15 NEA_2 NEA        62 2            2        56      40000       40580 NEA      
#> 16 NEA_2 NEA        62 2            3        56      40000       40580 NEA      
#> 17 NA    NEA        62 3           34        39      10040       14750 EUR      
#> 18 EUR_2 NEA        62 4           19        34          0       10040 EUR      
#> # ℹ 3 more variables: parent_pop <fct>, left_pos <dbl>, right_pos <dbl>