Skip to contents

Extract all descendants of a given tree-sequence node


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



Tree sequence object of the class slendr_ts


An integer node ID of the ancestral node


Report on the progress of ancestry path generation?


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.


A table of descendant nodes of a given tree-sequence node all the way down to the leaves of the tree sequence


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

#> 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, simplify = TRUE)

# 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: 2 × 12
#>   name  pop   node_id level child_id parent_id child_t…¹ paren…² child…³ paren…⁴
#>   <chr> <fct>   <dbl> <fct>    <int>     <int>     <dbl>   <dbl> <fct>   <fct>  
#> 1 NEA_1 NEA        62 1            0        62     70000   70040 NEA     NEA    
#> 2 NEA_1 NEA        62 1            1        62     70000   70040 NEA     NEA    
#> # … with 2 more variables: left_pos <dbl>, right_pos <dbl>, and abbreviated
#> #   variable names ¹​child_time, ²​parent_time, ³​child_pop, ⁴​parent_pop