Package 'Rtskit'

Title: Native Access to Succinct Tree Sequences
Description: Provides a native R interface to the 'tskit' C API for loading, inspecting, traversing, and writing succinct tree sequences. Tree sequences remain owned by native external pointers while typed R functions expose selected tables, opaque metadata, tree intervals, and declared source-population ancestry without a Python runtime.
Authors: Sounkou Mahamane Toure [aut, cre], Tskit Developers [cph] (Bundled tskit C library)
Maintainer: Sounkou Mahamane Toure <[email protected]>
License: GPL (>= 2)
Version: 0.0.0.9000
Built: 2026-09-20 11:23:30 UTC
Source: https://github.com/RGenomicsETL/Rtskit

Help Index


A native succinct tree sequence

Description

TreeSequence owns one tsk_treeseq_t value through a native external pointer. IDs returned by table accessors retain tskit's zero-based indexing.

Usage

TreeSequence(ptr = NULL, source = character(0))

Arguments

ptr

Internal live native pointer.

source

Source path or "<memory>".


Extract source-population ancestry intervals

Description

For every focal sample and marginal tree, this function walks toward the root and records the first node whose population is one of source_populations. Adjacent tree intervals with the same source are merged. This is exact ancestry truth only when the simulation's population and node-retention semantics make those source populations authoritative.

Usage

tskit_ancestry_intervals(
  x,
  source_populations,
  samples = NULL,
  require_resolved = TRUE
)

Arguments

x

A TreeSequence.

source_populations

A non-empty vector of zero-based source-population IDs. Names, when supplied, become the returned source labels and should be dataset-qualified.

samples

Zero-based focal sample-node IDs. NULL uses every sample.

require_resolved

Whether to fail if a focal lineage reaches a root without encountering a declared source population.

Value

A data frame of sample IDs, half-open intervals, source labels, and source-population IDs, grouped by sample and ordered by coordinate.

References

Haller et al. (2019), Tree-sequence recording in SLiM opens new horizons for forward-time simulation of whole genomes, doi:10.1111/1755-0998.12968. The published local-ancestry example is pinned at SLiMTreeSeqPub commit ⁠6715c28b02942bc4757c9f8bcab133ad4a0bfcfb⁠.


Write a succinct tree sequence

Description

Write a succinct tree sequence

Usage

tskit_dump(x, path, overwrite = FALSE)

Arguments

x

A TreeSequence.

path

Destination .trees path. Its parent directory must exist.

overwrite

Whether to replace an existing file.

Value

The normalized destination path, invisibly.


Materialize the edge table

Description

Metadata remains native and is not decoded by this initial accessor.

Usage

tskit_edges(x)

Arguments

x

A TreeSequence.

Value

A data frame with zero-based IDs and edge coordinates and nodes.


Create deterministic example tree-sequence data

Description

The example contains two sample nodes from one individual and two source ancestors spanning adjacent trees over a sequence of length 10. Population and individual metadata, one site, and one mutation exercise the native constructor without external software.

Usage

tskit_example()

Value

An in-memory TreeSequence.


Materialize the individual table

Description

Ragged locations and parent IDs are returned as list columns. Individual metadata remains opaque and is available through tskit_metadata().

Usage

tskit_individuals(x)

Arguments

x

A TreeSequence.

Value

A data frame with zero-based individual IDs, flags, location and parent list columns, and metadata lengths.


Load a succinct tree sequence

Description

Load a succinct tree sequence

Usage

tskit_load(path)

Arguments

path

Existing .trees file.

Value

A TreeSequence owning the loaded native value.


Read opaque metadata bytes

Description

Rtskit deliberately returns raw bytes and does not infer a codec from a schema. Row tables return a list of raw vectors in the requested ID order. Top-level tree-sequence and reference-sequence metadata return one raw vector and do not accept id.

Usage

tskit_metadata(x, table, id = NULL)

Arguments

x

A TreeSequence.

table

One of "tree_sequence", "reference_sequence", "individuals", "nodes", "edges", "migrations", "sites", "mutations", or "populations".

id

Optional zero-based row IDs. NULL requests every row of a row table.

Value

A raw vector for top-level metadata or a list of raw vectors for a row table.


Read an opaque metadata schema

Description

The schema is returned exactly as stored. Convert or decode it explicitly only when the declared codec is understood by the caller.

Usage

tskit_metadata_schema(x, table)

Arguments

x

A TreeSequence.

table

One of "tree_sequence", "reference_sequence", "individuals", "nodes", "edges", "migrations", "sites", "mutations", or "populations".

Value

A raw vector containing the table metadata schema.


Materialize the node table

Description

Metadata remains native and is not decoded by this initial accessor.

Usage

tskit_nodes(x)

Arguments

x

A TreeSequence.

Value

A data frame with zero-based IDs, flags, time, population, and individual columns.


Materialize the population table

Description

Population metadata remains opaque. Use tskit_metadata() to request its bytes explicitly.

Usage

tskit_populations(x)

Arguments

x

A TreeSequence.

Value

A data frame with zero-based population IDs and metadata lengths.


Return sample node IDs

Description

Return sample node IDs

Usage

tskit_samples(x)

Arguments

x

A TreeSequence.

Value

An integer vector of zero-based node IDs.


Summarize a succinct tree sequence

Description

Summarize a succinct tree sequence

Usage

tskit_summary(x)

Arguments

x

A TreeSequence.

Value

A named list of sequence length and table/tree counts. Counts are doubles because tskit sizes can exceed R's integer range.


Traverse tree intervals

Description

Traverse tree intervals

Usage

tskit_trees(x)

Arguments

x

A TreeSequence.

Value

A data frame containing each tree index, half-open interval, root count, and active edge count.