Browse code

Commit made by the Bioconductor Git-SVN bridge. Consists of 1 commit.

Commit information:

Commit id: 4e97e602c3e032f680bc3da4b47209dd77c97f36

phylopic

Committed by: GuangchuangYu
Author Name: GuangchuangYu
Commit date: 2015-01-30 17:47:29 +0800
Author date: 2015-01-30 17:47:29 +0800


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

g.yu authored on 30/01/2015 09:48:19
Showing 6 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: ggtree
2 2
 Type: Package
3 3
 Title: a phylogenetic tree viewer for different types of tree annotations
4
-Version: 0.99.7
4
+Version: 0.99.8
5 5
 Author: Guangchuang Yu
6 6
 Maintainer: Guangchuang Yu <guangchuangyu@gmail.com>
7 7
 Description: ggtree extends the ggplot2 plotting system which implemented the
... ...
@@ -18,6 +18,8 @@ Imports:
18 18
     jsonlite,
19 19
     magrittr,
20 20
     methods,
21
+    png,
22
+    RCurl,
21 23
     reshape2,
22 24
     stats4
23 25
 Suggests:
... ...
@@ -22,6 +22,7 @@ export(geom_tippoint)
22 22
 export(geom_tree)
23 23
 export(get.fields)
24 24
 export(get.offspring.tip)
25
+export(get.phylopic)
25 26
 export(get.placements)
26 27
 export(get.subs)
27 28
 export(get.tipseq)
... ...
@@ -65,6 +66,7 @@ exportMethods(show)
65 66
 importFrom(Biostrings,GENETIC_CODE)
66 67
 importFrom(Biostrings,readBStringSet)
67 68
 importFrom(Biostrings,toString)
69
+importFrom(RCurl,getURLContent)
68 70
 importFrom(ape,Ntip)
69 71
 importFrom(ape,drop.tip)
70 72
 importFrom(ape,extract.clade)
... ...
@@ -100,6 +102,9 @@ importFrom(ggplot2,theme_bw)
100 102
 importFrom(ggplot2,xlab)
101 103
 importFrom(ggplot2,xlim)
102 104
 importFrom(ggplot2,ylab)
105
+importFrom(grDevices,col2rgb)
106
+importFrom(grDevices,rgb)
107
+importFrom(grid,rasterGrob)
103 108
 importFrom(grid,unit)
104 109
 importFrom(gridExtra,grid.arrange)
105 110
 importFrom(jsonlite,fromJSON)
... ...
@@ -108,5 +113,6 @@ importFrom(magrittr,"%>%")
108 113
 importFrom(magrittr,add)
109 114
 importFrom(magrittr,equals)
110 115
 importFrom(methods,show)
116
+importFrom(png,readPNG)
111 117
 importFrom(reshape2,melt)
112 118
 importFrom(stats4,plot)
... ...
@@ -1,3 +1,8 @@
1
+CHANGES IN VERSION 0.99.8
2
+------------------------
3
+ o add get.phylopic function to read the online phylo pic and convert it to grob object,
4
+   which can be use to annotate ggplot figure using annotation_custom <2015-01-30, Fri>
5
+ 
1 6
 CHANGES IN VERSION 0.99.7
2 7
 ------------------------
3 8
  o add angle information for 'fan' & 'unrooted' layout <2015-01-29, Thu>
4 9
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+##' download phylopic and convert to grob object
2
+##'
3
+##' 
4
+##' @title get.phylopic
5
+##' @param id phylopic id
6
+##' @param size size of the phylopic
7
+##' @param color color
8
+##' @param alpha alpha
9
+##' @return grob object
10
+##' @importFrom grDevices rgb
11
+##' @importFrom grDevices col2rgb
12
+##' @importFrom RCurl getURLContent
13
+##' @importFrom png readPNG
14
+##' @importFrom grid rasterGrob
15
+##' @export
16
+##' @author Guangchuang Yu
17
+##' @references https://github.com/sckott/rphylopic/blob/master/R/add_phylopic.r
18
+get.phylopic <- function(id, size=512, color="black", alpha=1) {
19
+    size %<>% as.character %>% match.arg(c("64", "128", "256", "512", "1024"))
20
+    img <- paste0("http://phylopic.org/assets/images/submissions/", id, ".", size, ".png") %>%
21
+        getURLContent %>%
22
+            readPNG
23
+
24
+    color %<>% col2rgb
25
+    n <- length(img[,,1])
26
+    
27
+    matrix(ifelse(img[,,4] > 0,
28
+                  rgb(red   = rep(color[1,1], n),
29
+                      green = rep(color[2,1], n),
30
+                      blue  = rep(color[3,1], n),
31
+                      alpha = img[,,4] * 255 * alpha, maxColorValue = 255),
32
+                  rgb(red   = rep(1, n),
33
+                      green = rep(1, n),
34
+                      blue  = rep(1, n),
35
+                      alpha = img[,,4] * alpha)), 
36
+           nrow = nrow(img)) %>%
37
+               rasterGrob
38
+}
... ...
@@ -160,8 +160,8 @@ layout.unrooted <- function(tree) {
160 160
     df$angle <- NA
161 161
     df[root, "x"] <- 0
162 162
     df[root, "y"] <- 0
163
-    df[root, "start"] <- -1
164
-    df[root, "end"]   <- 1
163
+    df[root, "start"] <- 0
164
+    df[root, "end"]   <- 2
165 165
     df[root, "angle"] <- 0
166 166
     
167 167
     nb.sp <- sapply(1:N, function(i) length(get.offspring.tip(tree, i)))
... ...
@@ -190,7 +190,7 @@ layout.unrooted <- function(tree) {
190 190
             length.child <- df[child, "length"]
191 191
             df[child, "x"] <- df[curNode, "x"] + cospi(beta) * length.child
192 192
             df[child, "y"] <- df[curNode, "y"] + sinpi(beta) * length.child
193
-            df[child, "angle"] <- -180 * abs(beta)
193
+            df[child, "angle"] <- -90 -180 * beta * sign(beta - 1)
194 194
             df[child, "start"] <- start
195 195
             df[child, "end"] <- start + alpha
196 196
             start <- start + alpha
197 197
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+% Generated by roxygen2 (4.1.0): do not edit by hand
2
+% Please edit documentation in R/phylopic.R
3
+\name{get.phylopic}
4
+\alias{get.phylopic}
5
+\title{get.phylopic}
6
+\usage{
7
+get.phylopic(id, size = 512, color = "black", alpha = 1)
8
+}
9
+\arguments{
10
+\item{id}{phylopic id}
11
+
12
+\item{size}{size of the phylopic}
13
+
14
+\item{color}{color}
15
+
16
+\item{alpha}{alpha}
17
+}
18
+\value{
19
+grob object
20
+}
21
+\description{
22
+download phylopic and convert to grob object
23
+}
24
+\author{
25
+Guangchuang Yu
26
+}
27
+\references{
28
+https://github.com/sckott/rphylopic/blob/master/R/add_phylopic.r
29
+}
30
+