Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

## Overview

Tskit enables performant storage, manipulation, and analysis of ancestral
`Tskit` enables performant storage, manipulation, and analysis of ancestral
recombination graphs (ARGs) using succinct tree sequence encoding.
See https://tskit.dev for project news, documentation, and tutorials.
Tskit provides Python, C, and Rust APIs. The Python API can be called from R
via the `reticulate` R package to seamlessly load and analyse a tree sequence,
as described at https://tskit.dev/tutorials/RcppTskit.html.
`Tskit` provides Python, C, and Rust application programming interfaces (APIs).
The Python API can be called from R via the `reticulate` R package to
seamlessly load and analyse a tree sequence, as described at
https://tskit.dev/tutorials/RcppTskit.html.
`RcppTskit` provides R access to the `tskit` C API for use cases where the
`reticulate` option is not optimal. For example, for high-performance and
low-level work with tree sequences. Currently, `RcppTskit` provides a limited
Expand Down Expand Up @@ -91,10 +92,11 @@ By contributing to this project, you agree to abide by its terms.

### Clone

First clone the repository:
First clone the repository and step into the directory:

```
git clone https://github.com/HighlanderLab/RcppTskit.git
cd RcppTskit
```

### Pre-commit install
Expand Down
2 changes: 2 additions & 0 deletions RcppTskit/.Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
^\.covrignore$
^\.github$
^codecov\.yaml$
^cran-comments\.md$
^inst/examples/create_test\.trees\.R$
^inst/examples/create_test\.trees\.py$
^LICENSE.md$
^notes_pkg_dev\.Rmd$
^pkg_dev_notes\.md$
^tests/testthat/_snaps$
Expand Down
40 changes: 22 additions & 18 deletions RcppTskit/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
Type: Package
Package: RcppTskit
Title: R access to the tskit C API
Title: R Access to the Tskit C API
Version: 0.1.0
Date: 2026-01-2607
Authors@R:
person("Gregor", "Gorjanc", , "gregor.gorjanc@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8008-2787"))
Description: Tskit enables performant storage, manipulation, and analysis
of ancestral recombination graphs (ARGs) using succinct tree sequence
encoding. See https://tskit.dev for project news, documentation, and
tutorials. Tskit provides Python, C, and Rust APIs. The Python API
can be called from R via the `reticulate` R package to seamlessly load
and analyse a tree sequence as described at
https://tskit.dev/tutorials/RcppTskit.html. `RcppTskit` provides R
access to the `tskit` C API for use cases where the `reticulate`
Date: 2026-01-27
Authors@R: c(
person("Gregor", "Gorjanc", , "gregor.gorjanc@gmail.com", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8008-2787")),
person("Tskit Developers", role = "cph",
comment = "Authors of included tskit C library")
)
Description: 'Tskit' enables performant storage, manipulation, and
analysis of ancestral recombination graphs (ARGs) using succinct tree
sequence encoding. See <https://tskit.dev> for project news,
documentation, and tutorials. 'Tskit' provides Python, C, and Rust
application programming interfaces (APIs). The Python API can be
called from R via the 'reticulate' R package to seamlessly load and
analyse a tree sequence as described at
<https://tskit.dev/tutorials/tskitr.html>. 'RcppTskit' provides R
access to the 'tskit' C API for use cases where the 'reticulate'
option is not optimal. For example, for high-performance and low-level
work with tree sequences. Currently, `RcppTskit` provides a limited
work with tree sequences. Currently, 'RcppTskit' provides a limited
number of R functions due to the availability of extensive Python API
and the `reticulate` option.
and the 'reticulate' option.
License: MIT + file LICENSE
URL: https://github.com/HighlanderLab/RcppTskit
BugReports: https://github.com/HighlanderLab/RcppTskit/issues
Expand All @@ -26,16 +30,16 @@ Depends:
Imports:
methods,
R6,
Rcpp (>= 1.1.0),
reticulate
Rcpp (>= 0.12.10),
reticulate (>= 1.41.0)
Suggests:
covr,
knitr,
quarto,
spelling,
testthat (>= 3.0.0)
LinkingTo:
Rcpp
Rcpp (>= 0.12.10)
VignetteBuilder:
quarto
Config/testthat/edition: 3
Expand Down
2 changes: 1 addition & 1 deletion RcppTskit/LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2025
YEAR: 2026
COPYRIGHT HOLDER: Gregor Gorjanc
21 changes: 21 additions & 0 deletions RcppTskit/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2026 Gregor Gorjanc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions RcppTskit/LICENSE.note
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The tskit C library is distributed under the MIT license.
Full copies of the license are included in `inst/include/tskit/LICENSE` and `src/tskit/LICENSE.
1 change: 1 addition & 0 deletions RcppTskit/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(TreeSequence)
export(check_tskit_py)
export(get_tskit_py)
export(kastore_version)
export(ts_load)
Expand Down
75 changes: 54 additions & 21 deletions RcppTskit/R/Class-TreeSequence.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ TreeSequence <- R6Class(
},

#' @description Alias for \code{\link[=TreeSequence]{TreeSequence$dump}}.
#' @param file see
#' @param options see
#' @param file see \code{\link[=TreeSequence]{TreeSequence$dump}}.
#' @param options see \code{\link[=TreeSequence]{TreeSequence$dump}}.
write = function(file, options = 0L) {
self$dump(file = file, options = options)
},
Expand Down Expand Up @@ -106,11 +106,14 @@ TreeSequence <- R6Class(
#' ts_r$num_samples() # 160
#'
#' # Transfer the tree sequence to reticulate Python and use tskit Python API
#' ts_py <- ts_r$r_to_py()
#' is(ts_py)
#' ts_py$num_samples # 160
#' ts2_py <- ts_py$simplify(samples = c(0L, 1L, 2L, 3L))
#' ts2_py$num_samples # 4
#' tskit <- get_tskit_py()
#' if (check_tskit_py(tskit)) {
#' ts_py <- ts_r$r_to_py()
#' is(ts_py)
#' ts_py$num_samples # 160
#' ts2_py <- ts_py$simplify(samples = c(0L, 1L, 2L, 3L))
#' ts2_py$num_samples # 4
#' }
r_to_py = function(tskit_module = get_tskit_py(), cleanup = TRUE) {
ts_r_to_py_ptr(
self$pointer,
Expand All @@ -120,107 +123,137 @@ TreeSequence <- R6Class(
},

#' @description Get the number of provenances in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_provenances(ts)
#' ts$num_provenances()
num_provenances = function() {
ts_num_provenances_ptr(self$pointer)
},

#' @description Get the number of populations in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_populations(ts)
#' ts$num_populations()
num_populations = function() {
ts_num_populations_ptr(self$pointer)
},

#' @description Get the number of migrations in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_migrations(ts)
#' ts$num_migrations()
num_migrations = function() {
ts_num_migrations_ptr(self$pointer)
},

#' @description Get the number of individuals in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_individuals(ts)
#' ts$num_individuals()
num_individuals = function() {
ts_num_individuals_ptr(self$pointer)
},

#' @description Get the number of samples (of nodes) in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_samples(ts)
#' ts$num_samples()
num_samples = function() {
ts_num_samples_ptr(self$pointer)
},

#' @description Get the number of nodes in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_nodes(ts)
#' ts$num_nodes()
num_nodes = function() {
ts_num_nodes_ptr(self$pointer)
},

#' @description Get the number of edges in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_edges(ts)
#' ts$num_edges()
num_edges = function() {
ts_num_edges_ptr(self$pointer)
},

#' @description Get the number of trees in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_trees(ts)
#' ts$num_trees()
num_trees = function() {
ts_num_trees_ptr(self$pointer)
},

#' @description Get the number of sites in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_sites(ts)
#' ts$num_sites()
num_sites = function() {
ts_num_sites_ptr(self$pointer)
},

#' @description Get the number of mutations in a tree sequence.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_num_mutations(ts)
#' ts$num_mutations()
num_mutations = function() {
ts_num_mutations_ptr(self$pointer)
},

#' @description Get the sequence length.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_sequence_length(ts)
#' ts$sequence_length()
sequence_length = function() {
ts_sequence_length_ptr(self$pointer)
},

#' @description Get the time units string.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts_time_units(ts)
#' ts$time_units()
time_units = function() {
ts_time_units_ptr(self$pointer)
},

#' @description Get the min time in node table and mutation table.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts$min_time()
min_time = function() {
ts_min_time_ptr(self$pointer)
},

#' @description Get the max time in node table and mutation table.
#' @examples
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#' ts$max_time()
max_time = function() {
ts_max_time_ptr(self$pointer)
},

#' @description Get the length of metadata in a tree sequence and its tables.
#' @return A named list with the length of metadata.
#' @examples
#'ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts_file <- system.file("examples/test.trees", package = "RcppTskit")
#' ts <- ts_load(ts_file)
#'ts$metadata_length()
#' ts$metadata_length()
metadata_length = function() {
ts_metadata_length_ptr(self$pointer)
}
Expand Down
4 changes: 0 additions & 4 deletions RcppTskit/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ ts_metadata_length_ptr <- function(ts) {
.Call(`_RcppTskit_ts_metadata_length_ptr`, ts)
}

ts_grow <- function(ts) {
.Call(`_RcppTskit_ts_grow`, ts)
}

test_tsk_bug_assert_c <- function() {
invisible(.Call(`_RcppTskit_test_tsk_bug_assert_c`))
}
Expand Down
9 changes: 5 additions & 4 deletions RcppTskit/R/RcppTskit-package.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Contains the package description and .onLoad() function

#' @description
#' Tskit enables performant storage, manipulation, and analysis of
#' `Tskit` enables performant storage, manipulation, and analysis of
#' ancestral recombination graphs (ARGs) using succinct tree sequence encoding.
#' See https://tskit.dev for project news, documentation, and tutorials.
#' Tskit provides Python, C, and Rust APIs. The Python API can be called from R
#' via the `reticulate` R package to seamlessly load and analyse a tree sequence
#' as described at https://tskit.dev/tutorials/tskitr.html.
#' `Tskit` provides Python, C, and Rust application programming interfaces (APIs).
#' The Python API can be called from R via the `reticulate` R package to
#' seamlessly load and analyse a tree sequence as described at
#' https://tskit.dev/tutorials/tskitr.html.
#' `RcppTskit` provides R access to the `tskit` C API for use cases where the
#' `reticulate` option is not optimal. For example, for high-performance
#' and low-level work with tree sequences. Currently, `RcppTskit` provides a
Expand Down
Loading
Loading