ts_tracts | R Documentation |
Extract a data frame with coordinates of ancestry tracts from a given tree sequence.
ts_tracts(
ts,
census,
squashed = TRUE,
source = NULL,
target = NULL,
quiet = FALSE
)
ts |
Tree sequence object of the class |
census |
Census time. See the documentation linked in the Details for more
information. If a slendr-specific tree sequence was provided as |
squashed |
Should ancestry tracts be squashed (i.e., should continuous
tracts that can be traced to different ancestral nodes be merged)? Default
is |
source |
From which source population to extract tracts for? if |
target |
Similar purpose as |
quiet |
Should the default summary output of the |
This function implements an R-friendly interface to an algorithm for extracting ancestry tracts provided by the Python module tspop https://tspop.readthedocs.io/en/latest/ and developed by Georgia Tsambos. Please make sure to cite the paper which describes the algorithm in detail: https://academic.oup.com/bioinformaticsadvances/article/3/1/vbad163/7429395. For more technical details, see also the tutorial at: https://tspop.readthedocs.io/en/latest/basicusage.html.
In general, when using this function on a slendr-generated tree sequence,
please be aware that the output changes slightly to what you would get by
running the pure tspop.get_pop_ancestry()
in Python. First,
ts_tracts()
populates the output data frame with additional metadata
(such as names of individuals or populations). Additionally, for slendr models,
it is specifically designed to only return ancestry tracts originating to a
an ancestral population which contributed its ancestry during a gene-flow
event which started at a specific time (i.e., scheduled in a model via
the gene_flow()
) function. It does not return every single ancestry
tracts present in the tree sequence for every single sample node (and every
single potential ancestry population) as does the tspop.get_pop_ancestry()
Python method.
That said, when run on a tree sequence which does not originate from a slendr
simulation, the behavior of ts_tracts()
is identical to that of the
underlying tspop.get_pop_ancestry()
.
As of the current version of slendr, ts_tracts()
only works for
slendr/msprime sequences but not on slendr/SLiM tree sequences. Support for
slendr-generated SLiM tree sequences is in development. Tracts from tree
sequences originating from non-slendr msprime and SLiM simulations are not
restricted in any way and, as mentioned in the previous paragraph,
ts_tracts()
in this situation effectively reduces to the standard
tspop.get_pop_ancestry()
call.
A data frame containing coordinates of ancestry tracts
init_env(quiet = TRUE)
# load an example model with an already simulated tree sequence
slendr_ts <- system.file("extdata/models/introgression_msprime.trees", package = "slendr")
model <- read_model(path = system.file("extdata/models/introgression", package = "slendr"))
# load the tree-sequence object from disk
ts <- ts_load(file = slendr_ts, model = model)
# extract Neanderthal ancestry tracts (i.e. those corresponding to the
# census event at the gene-flow time at 55000 kya as scheduled by
# the simulation which produced the tree sequence)
nea_tracts <- ts_tracts(ts, census = 55000, source = "NEA")
nea_tracts
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.