subsetting data in ggtree

Subsetting is commonly used in ggtree as we would like to for example separating internal nodes from tips. We may also want to display annotation to specific node(s)/tip(s).

Some software may stored clade information (e.g. bootstrap value) as internal node labels. Indeed we want to manipulate such information and taxa labels separately.

In current ggplot2 (version=1.0.1, access date:2015-09-23), it support subset. For instance:

Continue reading

subview

I implemented a function, subview, in ggtree that make it easy to embed a subplot in ggplot.

An example is shown below:

library(ggplot2)
library(ggtree)

dd <- data.frame(x=LETTERS[1:3], y=1:3)
pie <- ggplot(dd, aes(x=1, y, fill=x)) + 
	geom_bar(stat="identity", width=1) + 
	coord_polar(theta="y") + theme_tree() + 
	xlab(NULL) + ylab(NULL) + 
	theme_transparent()

x <- sample(2:9)
y <- sample(2:9)
width <- sample(seq(0.05, 0.15, length.out=length(x)))
height <- width

p <- ggplot(data=data.frame(x=c(0, 10), y=c(0, 10)), aes(x, y))+geom_blank()
print(p)
for (i in seq_along(x)) {
	p %<>% subview(pie, x[i], y[i], width[i], height[i])
	print(p)
}

Continue reading

I found a Bioconductor package, seq2pathway, that can apply functional analysis to NGS data. It consists of two components, seq2gene and gene2pathway. seq2gene converts genomic coordination to genes while gene2pathway performs functional analysis at gene level.

I think it would be interesting to incorporate seq2gene with clusterProfiler. But it fail to run due to it call absolute path of python installed in the author’s computer.

Continue reading

递归

递归正如‘盗梦空间’中的场景:

PS: 使用《windows用户, 截屏新手段》可以一句for循环生成类似这种效果的图。

简言之就是不断调用自己,

经常我们会拿fibonacci数来讲解递归,正如在Rabbits and Recurrence Relations一题中所实现的,我使用了静态变量来缓存,以加快运行速度。R版本的实现可以参考tricky things in R一文,相对应于C的静态变量,在R中使用了局部的全局变量,这需要用<<-来赋值。

在开发ggtree时,unrooted layout最早的版本就是使用递归实现,但BiocCheck会把<<-报出来,而Bioconductor的人不喜欢看到这个赋值符,于是我改成了现在的版本,使用for loop。递归和循环一样,都只是程序的一种控制机制,某些递归实现代码非常短的同时,可读性非常强。

Example 1

比如我们要写writeSequence这样的函数:

Call                    Output
writeSequence(1);   1
writeSequence(2);   1 1
writeSequence(3);   2 1 2
writeSequence(4);   2 1 1 2
writeSequence(5);   3 2 1 2 3
writeSequence(6);   3 2 1 1 2 3
public void writeSequence(int n) {
    if (n < 1)
    throw new IllegalArgumentException();

    if (n == 1) {
    System.out.print(1);
    return;
    }

    if (n == 2) {
    System.out.print("1 1");
    return;
    }

    int x = (int) Math.ceil(n/2.0);
    
    System.out.print(x + " ");
    writeSequence(n-2);
    System.out.print(" " + x);
}

Continue reading

Author's picture

Guangchuang Yu

Bioinformatics Professor @ SMU

Bioinformatics Professor

Guangzhou