| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/untangle.R |
| 3 |
\name{untangle_step_rotate_both_side} |
| 4 |
\alias{untangle_step_rotate_both_side} |
| 5 |
\title{Stepwise untangle two trees at the same time} |
| 6 |
\usage{ |
| 7 |
untangle_step_rotate_both_side( |
| 8 |
dend1, |
| 9 |
dend2, |
| 10 |
L = 1.5, |
| 11 |
max_n_iterations = 10L, |
| 12 |
print_times = dendextend_options("warn"), |
| 13 |
... |
| 14 |
) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{dend1}{a dendrogram object. The one we will rotate to best fit |
| 18 |
dend2.} |
| 19 |
|
| 20 |
\item{dend2}{a dendrogram object. The one we will rotate to best fit |
| 21 |
dend1.} |
| 22 |
|
| 23 |
\item{L}{the distance norm to use for measuring the distance between the |
| 24 |
two trees. It can be any positive number, |
| 25 |
often one will want to use 0, 1, 1.5, 2 (see 'details' in \link{entanglement}).} |
| 26 |
|
| 27 |
\item{max_n_iterations}{integer. The maximal number of times to switch between optimizing one tree with another.} |
| 28 |
|
| 29 |
\item{print_times}{logical (TRUE), should we print how many times we executed steps 1 and 2?} |
| 30 |
|
| 31 |
\item{...}{not used} |
| 32 |
} |
| 33 |
\value{ |
| 34 |
A list with two dendrograms (dend1/dend2), |
| 35 |
after they are rotated to best fit one another. |
| 36 |
} |
| 37 |
\description{ |
| 38 |
This is a greedy forward selection algorithm for rotating the tree and |
| 39 |
looking for a better match. |
| 40 |
|
| 41 |
This is useful for finding good trees for a \link{tanglegram}. |
| 42 |
|
| 43 |
It goes through simultaneously rotating branches of dend1 and dend2 |
| 44 |
until a locally optimal solution is found. |
| 45 |
|
| 46 |
|
| 47 |
Step 1: The algorithm begins by executing the 'step2side' operation on the pair |
| 48 |
of dendograms. |
| 49 |
|
| 50 |
Step 2: The algorithm generates new alternative tanglegrams by simultaneously |
| 51 |
rotating one branch from tree 1 and one branch from tree 2. This rotation is |
| 52 |
applied to every possible combination of branches between tree 1 and tree 2, |
| 53 |
resulting in a set of new alternative tanglegrams. The tanglegram with the lowest |
| 54 |
entanglement is retained. |
| 55 |
|
| 56 |
Step 3: Steps 1 and 2 are repeated until either a locally optimal solution is |
| 57 |
found or the maximum number of iterations is reached. |
| 58 |
} |
| 59 |
\examples{ |
| 60 |
|
| 61 |
\dontrun{ |
| 62 |
# Figures recreated from 'Shuffle & untangle: novel untangle |
| 63 |
# methods for solving the tanglegram layout problem' (Nguyen et al. 2022) |
| 64 |
library(tidyverse) |
| 65 |
example_labels <- c("Versicolor 90", "Versicolor 54", "Versicolor 81", |
| 66 |
"Versicolor 63", "Versicolor 72", "Versicolor 99", "Virginica 135", |
| 67 |
"Virginica 117", "Virginica 126", "Virginica 108", "Virginica 144", |
| 68 |
"Setosa 27", "Setosa 18", "Setosa 36", "Setosa 45", "Setosa 9") |
| 69 |
|
| 70 |
iris_modified <- |
| 71 |
iris \%>\% |
| 72 |
mutate(Row = row_number()) \%>\% |
| 73 |
mutate(Label = paste(str_to_title(Species), Row)) \%>\% |
| 74 |
filter(Label \%in\% example_labels) |
| 75 |
iris_numeric <- iris_modified[,1:4] |
| 76 |
rownames(iris_numeric) <- iris_modified$Label |
| 77 |
|
| 78 |
# Single Linkage vs. Complete Linkage comparison (Fig. 1) |
| 79 |
dend1 <- as.dendrogram(hclust(dist(iris_numeric), method = "single")) |
| 80 |
dend2 <- as.dendrogram(hclust(dist(iris_numeric), method = "complete")) |
| 81 |
tanglegram(dend1, dend2, |
| 82 |
color_lines = TRUE, |
| 83 |
lwd = 2, |
| 84 |
margin_inner = 6) # Good. |
| 85 |
entanglement(dend1, dend2, L = 2) # 0.207 |
| 86 |
|
| 87 |
# The step2side algorithm (Fig. 2) |
| 88 |
result <- untangle_step_rotate_2side(dend1, dend2) |
| 89 |
tanglegram(result[[1]], result[[2]], |
| 90 |
color_lines = TRUE, |
| 91 |
lwd = 2, |
| 92 |
margin_inner = 6) # Better... |
| 93 |
entanglement(result[[1]], result[[2]], L = 2) # 0.185 |
| 94 |
|
| 95 |
# The stepBothSides algorithm (Fig. 4) |
| 96 |
result <- untangle_step_rotate_both_side(dend1, dend2) |
| 97 |
tanglegram(result[[1]], result[[2]], |
| 98 |
color_lines = TRUE, |
| 99 |
lwd = 2, |
| 100 |
margin_inner = 6, |
| 101 |
lty = 1) # PERFECT. |
| 102 |
entanglement(result[[1]], result[[2]], L = 2) # 0.000 |
| 103 |
} |
| 104 |
} |
| 105 |
\references{ |
| 106 |
Nghia Nguyen, Kurdistan Chawshin, Carl Fredrik Berg, Damiano Varagnolo, Shuffle & untangle: novel untangle methods for solving the tanglegram layout problem, Bioinformatics Advances, Volume 2, Issue 1, 2022, vbac014, https://doi.org/10.1093/bioadv/vbac014 |
| 107 |
} |
| 108 |
\seealso{ |
| 109 |
\link{tanglegram}, \link{match_order_by_labels}, |
| 110 |
\link{entanglement}, \link{flip_leaves}, \link{all_couple_rotations_at_k}. |
| 111 |
\link{untangle_step_rotate_1side}, \link{untangle_step_rotate_2side}. |
| 112 |
} |