Browse code

read.nhx support newick file

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/ggtree@122503 bc3139a8-67e5-0310-9ffc-ced21a209358

Guangchuang Yu authored on 17/10/2016 03:02:06
Showing 4 changed files

  • DESCRIPTION index 4c1a1a6b..08bfb177 100644
  • NEWS index c2110837..dcfbba2c 100644
  • R/NHX.R index 82f6ccd3..5f9913cf 100644
  • README.md index 51ead079..fad55913 100644
... ...
@@ -1,7 +1,7 @@
1 1
 Package: ggtree
2 2
 Type: Package
3 3
 Title: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data
4
-Version: 1.5.16
4
+Version: 1.5.17
5 5
 Author: Guangchuang Yu and Tommy Tsan-Yuk Lam
6 6
 Maintainer: Guangchuang Yu <guangchuangyu@gmail.com>
7 7
 Description: 'ggtree' extends the 'ggplot2' plotting system which implemented the grammar of graphics.
... ...
@@ -1,3 +1,8 @@
1
+CHANGES IN VERSION 1.5.17
2
+------------------------
3
+ o read.nhx support newick file <2016-10-17, Mon>
4
+   + https://github.com/GuangchuangYu/ggtree/issues/79
5
+
1 6
 CHANGES IN VERSION 1.5.16
2 7
 ------------------------
3 8
  o read.phyloT for parsing newick format of phyloT output <2016-10-11, Tue>
... ...
@@ -15,7 +15,7 @@ read.nhx <- function(file) {
15 15
         treetext <- paste0(treetext, collapse = '')
16 16
     }
17 17
     treetext %<>% gsub(" ", "",. )
18
-    
18
+
19 19
     phylo <- read.tree(text=treetext)
20 20
     nnode <- phylo$Nnode + Ntip(phylo)
21 21
     nlab <- paste("X", 1:nnode, sep="")
... ...
@@ -32,25 +32,29 @@ read.nhx <- function(file) {
32 32
     nhx.matches <- gregexpr("(\\w+)?(:?\\d*\\.?\\d*[Ee]?[\\+\\-]?\\d*)?\\[&&NHX.*?\\]", treetext)
33 33
     matches <- nhx.matches[[1]]
34 34
     match.pos <- as.numeric(matches)
35
-    match.len <- attr(matches, 'match.length')
36
-    
37
-    nhx_str <- substring(treetext, match.pos, match.pos+match.len-1)
35
+    if (length(match.pos) == 1 && (match.pos == -1)) {
36
+        nhx_stats <- data.frame(node = treeinfo$node)
37
+    } else {
38
+        match.len <- attr(matches, 'match.length')
39
+
40
+        nhx_str <- substring(treetext, match.pos, match.pos+match.len-1)
38 41
 
39
-    ## nhx_features <- gsub("^(\\w+)?:?\\d*\\.?\\d*[Ee]?[\\+\\-]?\\d*", "", nhx_str) %>%
40
-    nhx_features <- gsub("^[^\\[]*", "", nhx_str) %>%
41
-        gsub("\\[&&NHX:", "", .) %>%
42
+        ## nhx_features <- gsub("^(\\w+)?:?\\d*\\.?\\d*[Ee]?[\\+\\-]?\\d*", "", nhx_str) %>%
43
+        nhx_features <- gsub("^[^\\[]*", "", nhx_str) %>%
44
+            gsub("\\[&&NHX:", "", .) %>%
42 45
             gsub("\\]", "", .)
43
-    
44
-    nhx_stats <- get_nhx_feature(nhx_features)
45
-    fields <- names(nhx_stats)
46
-    for (i in ncol(nhx_stats)) {
47
-        if(any(grepl("\\D+", nhx_stats[,i])) == FALSE) {
48
-            ## should be numerical varialbe
49
-            nhx_stats[,i] <- as.numeric(nhx_stats[,i])
46
+
47
+        nhx_stats <- get_nhx_feature(nhx_features)
48
+        fields <- names(nhx_stats)
49
+        for (i in ncol(nhx_stats)) {
50
+            if(any(grepl("\\D+", nhx_stats[,i])) == FALSE) {
51
+                ## should be numerical varialbe
52
+                nhx_stats[,i] <- as.numeric(nhx_stats[,i])
53
+            }
50 54
         }
55
+        nhx_stats$node <- node
51 56
     }
52
-    nhx_stats$node <- node
53
-    
57
+
54 58
     new("nhx",
55 59
         file = filename(file),
56 60
         fields = fields,
... ...
@@ -1,9 +1,9 @@
1 1
 ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data
2 2
 ===========================================================================================================================
3 3
 
4
-[![releaseVersion](https://img.shields.io/badge/release%20version-1.4.20-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.5.16-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-14940/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1678/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
4
+[![releaseVersion](https://img.shields.io/badge/release%20version-1.4.20-green.svg?style=flat)](https://bioconductor.org/packages/ggtree) [![develVersion](https://img.shields.io/badge/devel%20version-1.5.17-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-15283/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1678/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
5 5
 
6
-[![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-2016--10--11-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)
6
+[![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-2016--10--17-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 7
 
8 8
 [![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)
9 9
 
... ...
@@ -17,7 +17,7 @@ Please cite the following article when using `ggtree`:
17 17
 
18 18
 **G Yu**, DK Smith, H Zhu, Y Guan, TTY Lam<sup>\*</sup>. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data. ***Methods in Ecology and Evolution***. *accepted*
19 19
 
20
-[![doi](https://img.shields.io/badge/doi-10.1111/2041--210X.12628-green.svg?style=flat)](http://dx.doi.org/10.1111/2041-210X.12628) [![citation](https://img.shields.io/badge/cited%20by-1-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627) [![Altmetric](https://img.shields.io/badge/Altmetric-125-green.svg?style=flat)](https://www.altmetric.com/details/10533079)
20
+[![doi](https://img.shields.io/badge/doi-10.1111/2041--210X.12628-green.svg?style=flat)](http://dx.doi.org/10.1111/2041-210X.12628) [![citation](https://img.shields.io/badge/cited%20by-1-green.svg?style=flat)](https://scholar.google.com.hk/scholar?oi=bibs&hl=en&cites=7268358477862164627) [![Altmetric](https://img.shields.io/badge/Altmetric-187-green.svg?style=flat)](https://www.altmetric.com/details/10533079)
21 21
 
22 22
 ------------------------------------------------------------------------
23 23
 
... ...
@@ -50,7 +50,7 @@ For details, please visit our project website, <https://guangchuangyu.github.io/
50 50
 
51 51
 ### Download stats
52 52
 
53
-[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree/) [![total](https://img.shields.io/badge/downloads-14940/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1678/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
53
+[![download](http://www.bioconductor.org/shields/downloads/ggtree.svg)](https://bioconductor.org/packages/stats/bioc/ggtree/) [![total](https://img.shields.io/badge/downloads-15283/total-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree) [![month](https://img.shields.io/badge/downloads-1678/month-blue.svg?style=flat)](https://bioconductor.org/packages/stats/bioc/ggtree)
54 54
 
55 55
          +-------------------------+------------------------+-------------------------+----------------+
56 56
          |                                                                                         *   |