Skip to content

Commit 52bbe88

Browse files
committed
add fortify_matrix method for phylo object
1 parent de233eb commit 52bbe88

9 files changed

+54
-8
lines changed

Diff for: NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ S3method(fortify_matrix,MAF)
138138
S3method(fortify_matrix,default)
139139
S3method(fortify_matrix,formula)
140140
S3method(fortify_matrix,matrix)
141+
S3method(fortify_matrix,phylo)
141142
S3method(fortify_matrix,waiver)
142143
S3method(fortify_upset,list)
143144
S3method(fortify_upset,matrix)

Diff for: R/align-phylo.R

+19
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ AlignPhylo <- ggproto("AlignPhylo", Align,
181181
summary_align = function(self) c(TRUE, FALSE)
182182
)
183183

184+
#' @inherit fortify_matrix title
185+
#' @description This method allows a [`phylo`][ape::as.phylo] object to be
186+
#' directly input into `stack_discrete()` or `circle_discrete()`. This makes it
187+
#' possible to add [`align_phylo()`] to the stack independently, as
188+
#' [`align_phylo()`] requires the layout to have labels.
189+
#' @return A one-column matrix where the tip labels are the values, and the row
190+
#' names will also be the tip labels.
191+
#' @family fortify_matrix methods
192+
#' @export
193+
fortify_matrix.phylo <- function(data, ...) {
194+
rlang::check_dots_empty()
195+
if (is.null(labels <- data$tip_labels)) {
196+
cli_abort(
197+
"{.arg data} {.cls phylo} object must have tip labels to match the layout data"
198+
)
199+
}
200+
as.matrix(vec_set_names(labels, labels))
201+
}
202+
184203
#' @inherit fortify_data_frame.default title description
185204
#' @inheritParams rlang::args_dots_empty
186205
#' @inheritParams fortify_data_frame.dendrogram

Diff for: R/fortify-matrix.R

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#' - [`fortify_matrix.default()`]
1313
#' - [`fortify_matrix.MAF()`]
1414
#' - [`fortify_matrix.GISTIC()`]
15+
#' - [`fortify_matrix.phylo()`]
1516
#' @export
1617
fortify_matrix <- function(data, ...) {
1718
UseMethod("fortify_matrix")

Diff for: man/fortify_matrix.GISTIC.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/fortify_matrix.MAF.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/fortify_matrix.Rd

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/fortify_matrix.default.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/fortify_matrix.phylo.Rd

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: man/patch_titles.Rd

+1-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)