This function combines information from the table of individuals and table of nodes into a single data frame which can be used in downstream analyses.

ts_nodes(x, sf = TRUE)

Arguments

x

Tree sequence object of the class slendr_ts or a phylo object extracted by ts_phylo

sf

Should spatial data be returned in an sf format? If FALSE, spatial geometries will be returned simply as x and y columns, instead of the standard POINT data type.

Value

Data frame with processed information from the tree sequence object. If the model which generated this data was spatial, result will be returned as a spatial object of the class sf.

Details

The source of data (tables of individuals and nodes recorded in the tree sequence generated by SLiM) are combined into a single data frame. If the model which generated the data was spatial, coordinates of nodes (which are pixel-based by default because SLiM spatial simulations occur on a raster), the coordinates are automatically converted to an explicit spatial object of the sf class unless spatial = FALSE. See https://r-spatial.github.io/sf/ for an extensive introduction to the sf package and the ways in which spatial data can be processed, analysed, and visualised.

See also

ts_table for accessing raw tree sequence tables without added metadata annotation. See also ts_ancestors to learn how to extract information about relationship beteween nodes in the tree sequence, and how to analysed data about distances between nodes in the spatial context.

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)

# extract an annotated table with (spatio-)temporal node information
ts_nodes(ts)
#> slendr 'nodes' object 
#> --------------------- 
#> times are expressed in a backward time direction
#> 
#> summary of the table data contents:
#>   CH - 1 'sampled', 1 'remembered', 1 'retained', 1 'alive' individuals
#>   AFR - 5 'sampled', 5 'remembered', 5 'retained', 5 'alive' individuals
#>   EUR - 5 'sampled', 5 'remembered', 5 'retained', 5 'alive' individuals
#>   NEA - 2 'sampled', 2 'remembered', NA 'retained', 0 'alive' individuals
#> 
#> total:
#>   - 13 'sampled' individuals
#>   - 13 'remembered' individuals
#>   - 42 'retained' individuals
#>   - 11 'alive' individuals
#> --------------------- 
#> oldest sampled individual: 70000 time units 'before present' 
#> youngest sampled individual: 0 time units 'before present' 
#> 
#> oldest node: 6000170 time units 'before present' 
#> youngest node: 0 time units 'before present' 
#> --------------------- 
#> overview of the underlying table object:
#> 
#> # A tibble: 68 × 12
#>    name  pop   node_id  time time_tskit sampled remembered retai…¹ alive pedig…²
#>    <chr> <fct>   <int> <dbl>      <dbl> <lgl>   <lgl>      <lgl>   <lgl>   <dbl>
#>  1 CH_1  CH         14     0          0 TRUE    TRUE       TRUE    TRUE  5520343
#>  2 CH_1  CH         15     0          0 TRUE    TRUE       TRUE    TRUE  5520343
#>  3 AFR_1 AFR         4     0          0 TRUE    TRUE       TRUE    TRUE  5520350
#>  4 AFR_1 AFR         5     0          0 TRUE    TRUE       TRUE    TRUE  5520350
#>  5 AFR_2 AFR         6     0          0 TRUE    TRUE       TRUE    TRUE  5520351
#>  6 AFR_2 AFR         7     0          0 TRUE    TRUE       TRUE    TRUE  5520351
#>  7 AFR_3 AFR         8     0          0 TRUE    TRUE       TRUE    TRUE  5520352
#>  8 AFR_3 AFR         9     0          0 TRUE    TRUE       TRUE    TRUE  5520352
#>  9 AFR_4 AFR        10     0          0 TRUE    TRUE       TRUE    TRUE  5520357
#> 10 AFR_4 AFR        11     0          0 TRUE    TRUE       TRUE    TRUE  5520357
#> # … with 58 more rows, 2 more variables: ind_id <dbl>, pop_id <int>, and
#> #   abbreviated variable names ¹​retained, ²​pedigree_id