Browse code

update rm.singleton.newick

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

g.yu authored on 27/08/2015 08:02:12
Showing 2 changed files

  • NEWS index e7ae8bc9..01525190 100644
  • R/treeIO.R index 06b2da68..f4f0b6e3 100644
... ...
@@ -1,5 +1,6 @@
1 1
 CHANGES IN VERSION 1.1.17
2 2
 ------------------------
3
+ o bug fixed in rm.singleton.newick by adding support of scientific notation in branch length <2015-08-27, Thu>
3 4
  o bug fixed in gheatmap, remove inherit aes from ggtree <2015-08-27, Thu>
4 5
  o add 'width' parameter to add_legend, now user can specify the width of legend bar <2015-08-27, Thu>
5 6
  o add 'colnames_position' parameter to gheatmap, now colnames can be display on the top of heatmap <2015-08-27, Thu> 
... ...
@@ -57,9 +57,9 @@ rm.singleton.newick <- function(nwk, outfile = NULL) {
57 57
     tree <- readLines(nwk)
58 58
 
59 59
     ## remove singleton of tips
60
-    nodePattern <- "\\w+:[\\.0-9]+"
61
-    singletonPattern.with.nodename <- paste0(".*(\\(", nodePattern, "\\)\\w+:[\\.0-9]+).*")
62
-    singletonPattern.wo.nodename <- paste0(".*(\\(", nodePattern, "\\)[\\.0-9]+).*")
60
+    nodePattern <- "\\w+:[\\.0-9Ee\\+\\-]+"
61
+    singletonPattern.with.nodename <- paste0(".*(\\(", nodePattern, "\\)\\w+:[\\.0-9Ee\\+\\-]+).*")
62
+    singletonPattern.wo.nodename <- paste0(".*(\\(", nodePattern, "\\)[\\.0-9Ee\\+\\-]+).*")
63 63
     
64 64
     while(length(grep("\\([^,]+\\)", tree)) > 0) {
65 65
         singleton <- gsub(singletonPattern.with.nodename, "\\1", tree)
... ...
@@ -72,8 +72,8 @@ rm.singleton.newick <- function(nwk, outfile = NULL) {
72 72
 
73 73
         tip <- gsub("\\((\\w+).*", "\\1", singleton)
74 74
         
75
-        len1 <- gsub(".*[^\\.0-9]+([\\.0-9]+)", "\\1", singleton)
76
-        len2 <- gsub(".*:([.0-9]+)\\).*", "\\1", singleton)
75
+        len1 <- gsub(".*[^\\.0-9Ee\\+\\-]+([\\.0-9Ee\\+\\-]+)", "\\1", singleton)
76
+        len2 <- gsub(".*:([\\.0-9Ee\\+\\-]+)\\).*", "\\1", singleton)
77 77
         len <- as.numeric(len1) + as.numeric(len2)
78 78
         
79 79
         tree <- gsub(singleton, paste0(tip, ":", len), tree, fixed = TRUE)