YuLab-SMU / treeio

:seedling: Base Classes and Functions for Phylogenetic Tree Input and Output
https://yulab-smu.top/treedata-book/
94 stars 24 forks source link

update spt and as.phylo.igraph consider edge attributes and add find.hclust.igraph #105

Closed xiangpin closed 1 year ago

xiangpin commented 1 year ago

Description

Related Issue

https://github.com/YuLab-SMU/ProjectYulab/issues/10

Example

update spt with edge attribute

library(igraph)
library(treeio)
library(ggplot2)
library(ggtree)
set.seed(123)
g <- igraph::sample_gnp(100, .1) %>%
        set_edge_attr(name='weight', value=abs(rnorm(E(.),3)))
tr1 <- spt(g, from = 6, to=V(g), weights = 'weight')

tr2 <- spt(g, from = 6, to = V(g), weights = NA)

p1 <- ggtree(tr1,layout='circ') + geom_point(color='orange', size= 4) + geom_nodelab(node='all')
p2 <- ggtree(tr2, layout='circ')  + geom_point(color='orange', size= 4) + geom_nodelab(node='all')
p1/p2

image

update as.phylo.igraph with edge attribute

library(treeio)
library(igraph)
library(ggtree)
set.seed(123)
g <- igraph::sample_gnp(18, .3) %>%
      igraph::mst() %>%
      igraph::set_edge_attr(name='weight', value=abs(rnorm(length(igraph::E(.)))))
tr1 <- as.phylo(g, branch.length = weight)
tr2 <- as.phylo(g)
p1 <- ggtree(tr1) + geom_point(color='orange', size= 4) + geom_nodelab(node='all')
p2 <-  ggtree(tr2)  + geom_point(color='orange', size= 4) + geom_nodelab(node='all')
p1/p2

image

find.hclust.igraph

tr3 <- find.hclust(g, weight='weight')
tr4 <- find.hclust(g, weight=NA)
p3 <- ggtree(tr3) + geom_tippoint(color='orange', size=4) + geom_tiplab()
p4 <- ggtree(tr4) + geom_tippoint(color='orange', size=4) + geom_tiplab()
p3/p4

image

GuangchuangYu commented 1 year ago

@xiangpin 有conflict,解决一下。

xiangpin commented 1 year ago

ok, 已解决