ts_segregating: Calculate the density of segregating sites for the given sets...

ts_segregatingR Documentation

Calculate the density of segregating sites for the given sets of individuals

Description

Calculate the density of segregating sites for the given sets of individuals

Usage

ts_segregating(
  ts,
  sample_sets,
  mode = c("site", "branch", "node"),
  windows = NULL,
  span_normalise = FALSE
)

Arguments

ts

Tree sequence object of the class slendr_ts

sample_sets

A list (optionally a named list) of character vectors with individual names (one vector per set). If a simple vector is provided, it will be interpreted as as.list(sample_sets), meaning that a given statistic will be calculated for each individual separately.

mode

The mode for the calculation ("sites" or "branch")

windows

Coordinates of breakpoints between windows. The first coordinate (0) and the last coordinate (equal to ts$sequence_length) are added automatically)

span_normalise

Divide the result by the span of the window? Default TRUE, see the tskit documentation for more detail.

Value

For each set of individuals either a single diversity value or a vector of diversity values (one for each window)

Examples


init_env()

# 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) %>% ts_mutate(mutation_rate = 1e-8, random_seed = 42)

# collect sampled individuals from all populations in a list
sample_sets <- ts_samples(ts) %>%
  split(., .$pop) %>%
  lapply(function(pop) pop$name)

ts_segregating(ts, sample_sets)

bodkan/slendr documentation built on Dec. 19, 2024, 11:41 p.m.