Browse code

o unrooted layout support branch.length="none", fixed #114

guangchuang yu authored on 01/03/2017 08:49:58
Showing 7 changed files

... ...
@@ -1,5 +1,7 @@
1 1
 CHANGES IN VERSION 1.7.8
2 2
 ------------------------
3
+ o get_taxa_name now sorted by taxa position and also support whole tree <2017-03-01, Wed>
4
+ o unrooted layout support branch.length="none", fixed #114 <2017-03-01, Wed>
3 5
  o remove apeBootstrap and raxml object support as they were removed from treeio <2017-02-28, Tue>
4 6
 
5 7
 CHANGES IN VERSION 1.7.7
... ...
@@ -1,4 +1,4 @@
1
-##' get taxa name of a selected node
1
+##' get taxa name of a selected node (or tree if node=NULL) sorted by their position in plotting
2 2
 ##'
3 3
 ##'
4 4
 ##' @title get_taxa_name
... ...
@@ -7,16 +7,20 @@
7 7
 ##' @return taxa name vector
8 8
 ##' @export
9 9
 ##' @author Guangchuang Yu
10
-get_taxa_name <- function(tree_view=NULL, node) {
10
+get_taxa_name <- function(tree_view=NULL, node=NULL) {
11 11
     tree_view %<>% get_tree_view
12 12
 
13 13
     df <- tree_view$data
14
-    sp <- get.offspring.df(df, node)
15
-    res <- df[sp, "label"]
16
-    return(res[df[sp, "isTip"]])
17
-}
18
-
14
+    if (!is.null(node)) {
15
+        sp <- get.offspring.df(df, node)
16
+        df <- df[sp, ]
17
+    }
19 18
 
19
+    with(df, {
20
+        i = order(y, decreasing=T)
21
+        label[i][isTip[i]]
22
+    })
23
+}
20 24
 
21 25
 
22 26
 ##' view a clade of tree
... ...
@@ -494,7 +494,7 @@ fortify.phylo <- function(model, data, layout="rectangular",
494 494
 as.data.frame.phylo <- function(x, row.names, optional,
495 495
                                 layout="rectangular", ...) {
496 496
     if (layout == "unrooted") {
497
-        return(layout.unrooted(x))
497
+        return(layout.unrooted(x, ...))
498 498
     }
499 499
     as.data.frame.phylo_(x, layout, ...)
500 500
 }
... ...
@@ -159,7 +159,7 @@ reroot_node_mapping <- function(tree, tree2) {
159 159
 
160 160
 
161 161
 ##' @importFrom ape reorder.phylo
162
-layout.unrooted <- function(tree) {
162
+layout.unrooted <- function(tree, branch.length="branch.length", ...) {
163 163
     N <- getNodeNum(tree)
164 164
     root <- getRoot(tree)
165 165
 
... ...
@@ -198,7 +198,12 @@ layout.unrooted <- function(tree) {
198 198
             alpha <- (end - start) * ntip.child/curNtip
199 199
             beta <- start + alpha / 2
200 200
 
201
-            length.child <- df[child, "length"]
201
+            if (branch.length == "none") {
202
+                length.child <- 1
203
+            } else {
204
+                length.child <- df[child, "length"]
205
+            }
206
+
202 207
             df[child, "x"] <- df[curNode, "x"] + cospi(beta) * length.child
203 208
             df[child, "y"] <- df[curNode, "y"] + sinpi(beta) * length.child
204 209
             df[child, "angle"] <- -90 -180 * beta * sign(beta - 1)
... ...
@@ -1,8 +1,6 @@
1 1
 
2 2
 
3 3
 
4
-
5
-
6 4
 ##' @importFrom ggplot2 last_plot
7 5
 get_tree_view <- function(tree_view) {
8 6
     if (is.null(tree_view))
... ...
@@ -2,9 +2,9 @@
2 2
 ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data
3 3
 ===========================================================================================================================
4 4
 
5
-[![releaseVersion](https://img.shields.io/badge/release%20version-1.6.9-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.7.8-green.svg?style=flat)](https://github.com/GuangchuangYu/ggtree) [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [![total](https://img.shields.io/badge/downloads-22537/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1894/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) <img src="logo.png" align="right" />
5
+[![releaseVersion](https://img.shields.io/badge/release%20version-1.6.9-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.7.8-green.svg?style=flat)](https://github.com/GuangchuangYu/ggtree) [![Bioc](http://www.bioconductor.org/shields/years-in-bioc/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#since) [![total](https://img.shields.io/badge/downloads-22704/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1894/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) <img src="logo.png" align="right" />
6 6
 
7
-[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![codecov](https://codecov.io/gh/GuangchuangYu/ggtree/branch/master/graph/badge.svg)](https://codecov.io/gh/GuangchuangYu/ggtree) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--02--28-green.svg)](https://github.com/GuangchuangYu/ggtree/commits/master) [![GitHub forks](https://img.shields.io/github/forks/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/network) [![GitHub stars](https://img.shields.io/github/stars/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/stargazers) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-r.com/#awesome-r-graphic-displays)
7
+[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![codecov](https://codecov.io/gh/GuangchuangYu/ggtree/branch/master/graph/badge.svg)](https://codecov.io/gh/GuangchuangYu/ggtree) [![Last-changedate](https://img.shields.io/badge/last%20change-2017--03--01-green.svg)](https://github.com/GuangchuangYu/ggtree/commits/master) [![GitHub forks](https://img.shields.io/github/forks/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/network) [![GitHub stars](https://img.shields.io/github/stars/GuangchuangYu/ggtree.svg)](https://github.com/GuangchuangYu/ggtree/stargazers) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-r.com/#awesome-r-graphic-displays)
8 8
 
9 9
 [![platform](http://www.bioconductor.org/shields/availability/devel/ggtree.svg)](https://www.bioconductor.org/packages/devel/bioc/html/ggtree.html#archives) [![Build Status](http://www.bioconductor.org/shields/build/devel/bioc/ggtree.svg)](https://bioconductor.org/checkResults/devel/bioc-LATEST/ggtree/) [![Linux/Mac Travis Build Status](https://img.shields.io/travis/GuangchuangYu/ggtree/master.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/GuangchuangYu/ggtree) [![AppVeyor Build Status](https://img.shields.io/appveyor/ci/Guangchuangyu/ggtree/master.svg?label=Windows)](https://ci.appveyor.com/project/GuangchuangYu/ggtree) [![install with bioconda](https://img.shields.io/badge/install%20with-bioconda-green.svg?style=flat)](http://bioconda.github.io/recipes/bioconductor-ggtree/README.html)
10 10
 
... ...
@@ -51,7 +51,7 @@ For details, please visit our project website, <https://guangchuangyu.github.io/
51 51
 
52 52
 ### Download stats
53 53
 
54
-[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree) [![total](https://img.shields.io/badge/downloads-22537/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1894/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
54
+[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree) [![total](https://img.shields.io/badge/downloads-22704/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1894/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
55 55
 
56 56
          ++--------------------+--------------------+--------------------+--------------------+--------+
57 57
          |                                                                                        *    |
... ...
@@ -4,7 +4,7 @@
4 4
 \alias{get_taxa_name}
5 5
 \title{get_taxa_name}
6 6
 \usage{
7
-get_taxa_name(tree_view = NULL, node)
7
+get_taxa_name(tree_view = NULL, node = NULL)
8 8
 }
9 9
 \arguments{
10 10
 \item{tree_view}{tree view}
... ...
@@ -15,7 +15,7 @@ get_taxa_name(tree_view = NULL, node)
15 15
 taxa name vector
16 16
 }
17 17
 \description{
18
-get taxa name of a selected node
18
+get taxa name of a selected node (or tree if node=NULL) sorted by their position in plotting
19 19
 }
20 20
 \author{
21 21
 Guangchuang Yu