Skip to content

Commit cedb5c8

Browse files
docs(r): add some extra docs in Newick utils (#156)
* doc(r): add some extra doc for newick utils * style: pre-commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 15e8b28 commit cedb5c8

File tree

10 files changed

+81
-5
lines changed

10 files changed

+81
-5
lines changed

docs/development.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,29 @@ pixi run -e py-phylo2vec profile matrix 10000
103103
Although not currently implemented in the CI pipeline, we used the following
104104
packages to monitor test coverage:
105105

106-
* Rust: [cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov)
106+
- Rust: [cargo-llvm-cov](https://github.com/taiki-e/cargo-llvm-cov)
107+
107108
```bash
108109
cargo install cargo-llvm-cov
109110

110111
cargo llvm-cov
111112
```
112-
* Python: [pytest-cov](https://github.com/pytest-dev/pytest-cov)
113+
114+
- Python: [pytest-cov](https://github.com/pytest-dev/pytest-cov)
115+
113116
```bash
114117
pixi add pytest-cov
115118

116119
pixi run -e py-phylo2vec pytest ./py-phylo2vec/tests --cov=./py-phylo2vec/
117120
```
118-
* R: [covr](https://covr.r-lib.org/)
121+
122+
- R: [covr](https://covr.r-lib.org/)
123+
119124
```r
120125
install.packages("covr")
121126
rcov <- package_coverage("./r-phylo2vec", quiet = FALSE)
122127
```
123128

124-
125129
## Python: py-phylo2vec
126130

127131
This directory contains the phylo2vec Python codebase, which includes Rust

r-phylo2vec/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ License: GPL-3 + file LICENSE
88
Encoding: UTF-8
99
Roxygen: list(markdown = TRUE)
1010
RoxygenNote: 7.3.2
11-
Config/rextendr/version: 0.4.0.9000
11+
Config/rextendr/version: 0.4.2
1212
Suggests:
1313
testthat (>= 3.0.0),
1414
ape (>= 5.0)

r-phylo2vec/R/extendr-wrappers.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ add_leaf <- function(vector, leaf, branch) .Call(wrap__add_leaf, vector, leaf, b
2424
#'
2525
#' Note 2: the parent nodes are removed from the output,
2626
#' but the branch lengths/annotations are kept.
27+
#'
28+
#' @param newick Newick representation of a tree with integer labels
29+
#' @param label_mapping_list A vector where the index corresponds to the integer label
30+
#' @return Newick with string labels
2731
#' @export
2832
apply_label_mapping <- function(newick, label_mapping_list) .Call(wrap__apply_label_mapping, newick, label_mapping_list)
2933

@@ -51,12 +55,18 @@ cophenetic_from_vector <- function(vector, unrooted) .Call(wrap__cophenetic_from
5155
#'
5256
#' Note 2: the parent nodes are removed from the output,
5357
#' but the branch lengths/annotations are kept.
58+
#'
59+
#' @param newick Newick representation of a tree with string labels
60+
#' @return A list with two elements:
61+
#' - `newick`: Newick with integer labels
62+
#' - `mapping`: A vector where the index corresponds to the integer label
5463
#' @export
5564
create_label_mapping <- function(newick) .Call(wrap__create_label_mapping, newick)
5665

5766
#' Find the number of leaves in a Newick string
5867
#'
5968
#' @param newick Newick representation of a tree
69+
#' @return Number of leaves
6070
#' @export
6171
find_num_leaves <- function(newick) .Call(wrap__find_num_leaves, newick)
6272

@@ -76,6 +86,8 @@ from_pairs <- function(pairs) .Call(wrap__from_pairs, pairs)
7686
get_common_ancestor <- function(vector, node1, node2) .Call(wrap__get_common_ancestor, vector, node1, node2)
7787

7888
#' Check if a newick string has branch lengths
89+
#'
90+
#' @param newick Newick representation of a tree
7991
#' @export
8092
has_branch_lengths <- function(newick) .Call(wrap__has_branch_lengths, newick)
8193

@@ -120,10 +132,16 @@ pre_precision_from_vector <- function(vector) .Call(wrap__pre_precision_from_vec
120132
queue_shuffle <- function(vector, shuffle_cherries) .Call(wrap__queue_shuffle, vector, shuffle_cherries)
121133

122134
#' Remove parent labels from the Newick string
135+
#'
136+
#' @param newick Newick representation of a tree with branch lengths
137+
#' @return Newick string without branch lengths
123138
#' @export
124139
remove_branch_lengths <- function(newick) .Call(wrap__remove_branch_lengths, newick)
125140

126141
#' Remove parent labels from the Newick string
142+
#'
143+
#' @param newick Newick representation of a tree with parent labels
144+
#' @return Newick string without parent labels
127145
#' @export
128146
remove_parent_labels <- function(newick) .Call(wrap__remove_parent_labels, newick)
129147

r-phylo2vec/man/apply_label_mapping.Rd

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r-phylo2vec/man/create_label_mapping.Rd

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r-phylo2vec/man/find_num_leaves.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r-phylo2vec/man/has_branch_lengths.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r-phylo2vec/man/remove_branch_lengths.Rd

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r-phylo2vec/man/remove_parent_labels.Rd

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r-phylo2vec/src/rust/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ fn queue_shuffle(vector: Vec<i32>, shuffle_cherries: bool) -> List {
262262
}
263263

264264
/// Check if a newick string has branch lengths
265+
///
266+
/// @param newick Newick representation of a tree
265267
/// @export
266268
#[extendr]
267269
fn has_branch_lengths(newick: &str) -> bool {
@@ -271,6 +273,7 @@ fn has_branch_lengths(newick: &str) -> bool {
271273
/// Find the number of leaves in a Newick string
272274
///
273275
/// @param newick Newick representation of a tree
276+
/// @return Number of leaves
274277
/// @export
275278
#[extendr]
276279
fn find_num_leaves(newick: &str) -> usize {
@@ -285,6 +288,11 @@ fn find_num_leaves(newick: &str) -> usize {
285288
///
286289
/// Note 2: the parent nodes are removed from the output,
287290
/// but the branch lengths/annotations are kept.
291+
///
292+
/// @param newick Newick representation of a tree with string labels
293+
/// @return A list with two elements:
294+
/// - `newick`: Newick with integer labels
295+
/// - `mapping`: A vector where the index corresponds to the integer label
288296
/// @export
289297
#[extendr]
290298
fn create_label_mapping(newick: &str) -> List {
@@ -309,6 +317,10 @@ fn create_label_mapping(newick: &str) -> List {
309317
///
310318
/// Note 2: the parent nodes are removed from the output,
311319
/// but the branch lengths/annotations are kept.
320+
///
321+
/// @param newick Newick representation of a tree with integer labels
322+
/// @param label_mapping_list A vector where the index corresponds to the integer label
323+
/// @return Newick with string labels
312324
/// @export
313325
#[extendr]
314326
fn apply_label_mapping(newick: &str, label_mapping_list: Vec<String>) -> String {
@@ -323,13 +335,19 @@ fn apply_label_mapping(newick: &str, label_mapping_list: Vec<String>) -> String
323335
}
324336

325337
/// Remove parent labels from the Newick string
338+
///
339+
/// @param newick Newick representation of a tree with branch lengths
340+
/// @return Newick string without branch lengths
326341
/// @export
327342
#[extendr]
328343
fn remove_branch_lengths(newick: &str) -> String {
329344
newick::remove_branch_lengths(newick)
330345
}
331346

332347
/// Remove parent labels from the Newick string
348+
///
349+
/// @param newick Newick representation of a tree with parent labels
350+
/// @return Newick string without parent labels
333351
/// @export
334352
#[extendr]
335353
fn remove_parent_labels(newick: &str) -> String {

0 commit comments

Comments
 (0)