Skip to content

Commit 62af7ec

Browse files
authored
FirstMatchingSplit() (#247)
1 parent a69c8fe commit 62af7ec

File tree

14 files changed

+277
-6
lines changed

14 files changed

+277
-6
lines changed

.github/workflows/R-CMD-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ jobs:
9595
- {os: windows-latest, r: "release"}
9696
- {os: macos-15-intel, r: "release"} # Until Intel architecture retired 2027-11
9797
- {os: macOS-latest, r: "release"}
98-
- {os: ubuntu-24.04-arm, r: "release", rspm: "https://packagemanager.posit.co/cran/__linux__/noble/latest"}
9998
- {os: ubuntu-24.04, r: "3.6", rspm: "https://packagemanager.posit.co/cran/2022-10-11"}
10099
- {os: ubuntu-24.04, r: "4.0", rspm: "https://packagemanager.posit.co/cran/2022-10-11"}
100+
- {os: ubuntu-24.04-arm, r: "release", rspm: "https://packagemanager.posit.co/cran/__linux__/noble/latest"}
101101
- {os: ubuntu-24.04, r: "devel", rspm: "https://packagemanager.posit.co/cran/__linux__/noble/latest"}
102102

103103
env:

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: TreeTools
22
Title: Create, Modify and Analyse Phylogenetic Trees
3-
Version: 2.0.0.9006
3+
Version: 2.0.0.9007
44
Authors@R: c(
55
person("Martin R.", 'Smith', role = c("aut", "cre", "cph"),
66
email = "martin.smith@durham.ac.uk",

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ S3method(Pruningwise,list)
116116
S3method(Pruningwise,multiPhylo)
117117
S3method(Pruningwise,phylo)
118118
S3method(RenumberTips,"NULL")
119+
S3method(RenumberTips,Splits)
119120
S3method(RenumberTips,list)
120121
S3method(RenumberTips,multiPhylo)
121122
S3method(RenumberTips,phylo)
@@ -294,6 +295,7 @@ export(EdgeAncestry)
294295
export(EdgeDistances)
295296
export(EndSentence)
296297
export(ExtractTaxa)
298+
export(FirstMatchingSplit)
297299
export(Hamming)
298300
export(IC1Spr)
299301
export(ImposeConstraint)

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# TreeTools 2.0.0.9006 (development) #
1+
# TreeTools 2.0.0.9007 (development) #
22
- `FirstMatchingSplit()`...
3+
- Add method `RenumberTips.Splits()`.
34
- Support logical `pole` in `PolarizeSplits()`.
45
- `RenumberTree()` supports numeric `tipOrder` input.
56

R/RcppExports.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ descendant_tips <- function(parent, child, postorder) {
4141
.Call(`_TreeTools_descendant_tips`, parent, child, postorder)
4242
}
4343

44+
first_matching_split_pair <- function(x, table) {
45+
.Call(`_TreeTools_first_matching_split_pair`, x, table)
46+
}
47+
48+
first_matching_split_index <- function(x, table) {
49+
.Call(`_TreeTools_first_matching_split_index`, x, table)
50+
}
51+
4452
num_to_parent <- function(n, nTip) {
4553
.Call(`_TreeTools_num_to_parent`, n, nTip)
4654
}

R/match.R

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,31 @@ setMethod("%in%",
218218
signature(x = "phylo", table = "phylo"),
219219
function(x, table) all.equal(x, table))
220220

221+
#' @rdname match.Splits
222+
#' @param x,table Splits objects
223+
#' @param return Which index to return: in `x`, in `table`, or both
224+
#' @return `FirstMatchingSplit()` returns an integer
225+
#' (or length-2 integer if `return = "both"`) specifying the first split in `x`
226+
#' to have a match in `table` (`return = "x"`),
227+
#' or the index of that match (`return = "table"`).
228+
#' `nomatch` (default `0`) is returned in the absence of a match.
229+
#' @export
230+
FirstMatchingSplit <- function(x, table, nomatch,
231+
return = c("x", "table", "both")) {
232+
if (!inherits(x, "Splits")) {
233+
x <- as.Splits(x)
234+
}
235+
table <- as.Splits(table, x)
236+
ij <- first_matching_split_pair(x, table)
237+
238+
if (!missing(nomatch)) {
239+
ij[ij == 0] <- nomatch
240+
}
241+
242+
# Return:
243+
return <- match.arg(return)
244+
switch(return,
245+
x = ij[[1L]],
246+
table = ij[[2L]],
247+
both = ij)
248+
}

R/tree_numbering.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,16 @@ RenumberTips.phylo <- function(tree, tipOrder) {
650650
tree
651651
}
652652

653+
#' @rdname RenumberTips
654+
#' @export
655+
RenumberTips.Splits <- function(tree, tipOrder) {
656+
if (is.character(tipOrder)) {
657+
as.Splits(tree, tipOrder)
658+
} else if (is.numeric(tipOrder)) {
659+
as.Splits(tree, TipLabels(tree)[tipOrder])
660+
}
661+
}
662+
653663
#' @rdname RenumberTips
654664
#' @export
655665
RenumberTips.multiPhylo <- function(tree, tipOrder) {

man/RenumberTips.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.

man/match.Splits.Rd

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RcppExports.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ BEGIN_RCPP
138138
return rcpp_result_gen;
139139
END_RCPP
140140
}
141+
// first_matching_split_pair
142+
IntegerVector first_matching_split_pair(const RawMatrix x, const RawMatrix table);
143+
RcppExport SEXP _TreeTools_first_matching_split_pair(SEXP xSEXP, SEXP tableSEXP) {
144+
BEGIN_RCPP
145+
Rcpp::RObject rcpp_result_gen;
146+
Rcpp::RNGScope rcpp_rngScope_gen;
147+
Rcpp::traits::input_parameter< const RawMatrix >::type x(xSEXP);
148+
Rcpp::traits::input_parameter< const RawMatrix >::type table(tableSEXP);
149+
rcpp_result_gen = Rcpp::wrap(first_matching_split_pair(x, table));
150+
return rcpp_result_gen;
151+
END_RCPP
152+
}
153+
// first_matching_split_index
154+
int first_matching_split_index(const RawMatrix x, const RawMatrix table);
155+
RcppExport SEXP _TreeTools_first_matching_split_index(SEXP xSEXP, SEXP tableSEXP) {
156+
BEGIN_RCPP
157+
Rcpp::RObject rcpp_result_gen;
158+
Rcpp::RNGScope rcpp_rngScope_gen;
159+
Rcpp::traits::input_parameter< const RawMatrix >::type x(xSEXP);
160+
Rcpp::traits::input_parameter< const RawMatrix >::type table(tableSEXP);
161+
rcpp_result_gen = Rcpp::wrap(first_matching_split_index(x, table));
162+
return rcpp_result_gen;
163+
END_RCPP
164+
}
141165
// num_to_parent
142166
IntegerVector num_to_parent(const IntegerVector n, const IntegerVector nTip);
143167
RcppExport SEXP _TreeTools_num_to_parent(SEXP nSEXP, SEXP nTipSEXP) {
@@ -458,6 +482,8 @@ static const R_CallMethodDef CallEntries[] = {
458482
{"_TreeTools_descendant_edges", (DL_FUNC) &_TreeTools_descendant_edges, 3},
459483
{"_TreeTools_descendant_edges_single", (DL_FUNC) &_TreeTools_descendant_edges_single, 5},
460484
{"_TreeTools_descendant_tips", (DL_FUNC) &_TreeTools_descendant_tips, 3},
485+
{"_TreeTools_first_matching_split_pair", (DL_FUNC) &_TreeTools_first_matching_split_pair, 2},
486+
{"_TreeTools_first_matching_split_index", (DL_FUNC) &_TreeTools_first_matching_split_index, 2},
461487
{"_TreeTools_num_to_parent", (DL_FUNC) &_TreeTools_num_to_parent, 2},
462488
{"_TreeTools_random_parent", (DL_FUNC) &_TreeTools_random_parent, 2},
463489
{"_TreeTools_edge_to_num", (DL_FUNC) &_TreeTools_edge_to_num, 3},

0 commit comments

Comments
 (0)