Browse code

fix bug of layoutEqualAngle

xiangpin authored on 06/07/2022 13:33:17
Showing5 changed files

... ...
@@ -62,5 +62,5 @@ BugReports: https://github.com/YuLab-SMU/ggtree/issues
62 62
 Packaged: 2014-12-03 08:16:14 UTC; root
63 63
 biocViews: Alignment, Annotation, Clustering, DataImport,
64 64
     MultipleSequenceAlignment, Phylogenetics, ReproducibleResearch, Software, Visualization
65
-RoxygenNote: 7.1.2
65
+RoxygenNote: 7.2.0
66 66
 Roxygen: list(markdown = TRUE)
... ...
@@ -81,7 +81,7 @@ layoutEqualAngle <- function(model, branch.length = "branch.length"){
81 81
     ## Get number of tips for each node in tree.
82 82
   ## nb.sp <- sapply(1:N, function(i) length(get.offspring.tip(tree, i)))
83 83
   ## self_include = TRUE to return itself if the input node is a tip
84
-  nb.sp <- vapply(1:N, function(i) length(offspring(tree, i, tiponly = TRUE, self_include = TRUE)), numeric(1))
84
+  nb.sp <- vapply(1:N, function(i) length(suppressMessages(offspring(tree, i, tiponly = TRUE, self_include = TRUE))), numeric(1))
85 85
     ## Get list of node id's.
86 86
     nodes <- getNodes_by_postorder(tree)
87 87
 
... ...
@@ -97,6 +97,9 @@ layoutEqualAngle <- function(model, branch.length = "branch.length"){
97 97
         end <- df[curNode, "end"]
98 98
         cur_x = df[curNode, "x"]
99 99
         cur_y = df[curNode, "y"]
100
+
101
+        total_angle = end - start
102
+
100 103
         for (child in children) {
101 104
             ## Get the number of tips for child node.
102 105
             ntip.child <- nb.sp[child]
... ...
@@ -104,7 +107,8 @@ layoutEqualAngle <- function(model, branch.length = "branch.length"){
104 107
             ## Calculated in half radians.
105 108
             ## alpha: angle of segment for i-th child with ntips_ij tips.
106 109
             ## alpha = (left_angle - right_angle) * (ntips_ij)/(ntips_current)
107
-            alpha <- (end - start) * ntip.child / curNtip
110
+            ## alpha <- (end - start) * ntip.child / curNtip
111
+            alpha <- total_angle * ntip.child / curNtip
108 112
             ## beta = angle of line from parent node to i-th child.
109 113
             beta <- start + alpha / 2
110 114
 
... ...
@@ -68,7 +68,5 @@ For demonstration of this function, please refer to chapter 8.3 of
68 68
 \url{http://yulab-smu.top/treedata-book/index.html} by Guangchuang Yu.
69 69
 }
70 70
 \author{
71
-Guangchuang Yu
72
-
73 71
 Guangchuang Yu
74 72
 }
... ...
@@ -21,12 +21,14 @@ tree as data.frame with equal angle layout.
21 21
 }
22 22
 \references{
23 23
 The following aglorithm aims to implement the vague description of the "Equal-daylight Algorithm"
24
-in "Inferring Phylogenies" pp 582-584 by Joseph Felsenstein.\preformatted{Leafs are subtrees with no children
24
+in "Inferring Phylogenies" pp 582-584 by Joseph Felsenstein.
25
+
26
+\if{html}{\out{<div class="sourceCode">}}\preformatted{Leafs are subtrees with no children
25 27
 Initialise tree using equal angle algorithm
26 28
 tree_df = equal_angle(tree)
27 29
 
28 30
 nodes = get list of nodes in tree_df breadth-first
29 31
 nodes = remove tip nodes.
30 32
 
31
-}
33
+}\if{html}{\out{</div>}}
32 34
 }
... ...
@@ -52,6 +52,6 @@ below to see their documentation.
52 52
 
53 53
   \item{magrittr}{\code{\link[magrittr:pipe]{\%>\%}}}
54 54
 
55
-  \item{tidytree}{\code{\link[tidytree]{MRCA}}, \code{\link[tidytree]{groupClade}}, \code{\link[tidytree]{groupOTU}}, \code{\link[tidytree]{nodeid}}, \code{\link[tidytree]{nodelab}}}
55
+  \item{tidytree}{\code{\link[tidytree]{groupClade}}, \code{\link[tidytree]{groupOTU}}, \code{\link[tidytree]{MRCA}}, \code{\link[tidytree]{nodeid}}, \code{\link[tidytree]{nodelab}}}
56 56
 }}
57 57