This function computes the AFS with respect to the given set of individuals

## Usage

ts_afs(
ts,
sample_sets = NULL,
mode = c("site", "branch", "node"),
windows = NULL,
span_normalise = FALSE,
polarised = 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 NULL, allele frequency spectrum for all individuals in the tree sequence will be computed.

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 Argument passed to tskit's allele_frequency_spectrum method polarised When FALSE (the default) the allele frequency spectrum will be folded (i.e. the counts will not depend on knowing which allele is ancestral) ## Value Allele frequency spectrum values for the given sample set ## Details For more information on the format of the result and dimensions, in particular the interpretation of the first and the last element of the AFS, please see the tskit manual at https://tskit.dev/tskit/docs/stable/python-api.html ## Examples check_dependencies(python = TRUE) # make sure dependencies are 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, mutate = TRUE, mutation_rate = 1e-8, random_seed = 42) samples <- ts_samples(ts) %>% .[.$pop %in% c("AFR", "EUR"), ]

# compute AFS for the given set of individuals
ts_afs(ts, sample_sets = list(samples\$name))
#>  [1]  4  2  0  0  1  0  0  1  0 20  0  0  0  0  0  0  0  0  0  0