【问题标题】:vertex sequences from igraph来自 igraph 的顶点序列
【发布时间】:2014-07-01 16:43:23
【问题描述】:

我已经使用 igraph 提取了所有最短路径并将其保存在一个列表文件中(命名为 best)。首先,所有节点都是数字,我向它们添加了基因符号。结果是:

library(igraph)
adjacency <- structure(list(source = structure(c(3L, 5L, 1L, 3L, 2L, 4L), 
  .Label = c("ANXA7", "CAV1", "FLNA", "GRB7", "PRKCA"), class = "factor"), 
  Target = structure(c(5L, 2L, 1L, 3L, 4L, 1L), 
  .Label = c("A1BG", "ANXA7", "CAV1", "GRB7", "PRKCA"), class = "factor")), 
  .Names = c("source", "Target"), 
  class = "data.frame",row.names = c(NA, -6L)) 

graph <- graph.data.frame(adjacency, directed = FALSE)

graph
# IGRAPH UN-- 6 6 -- 
# + attr: name (v/c)
plot(graph)

然后实现最短路径:

rest <- best <- list()
rest[[1]] <- get.all.shortest.paths(graph, 1, 3, mode = c("all"))$res
names <- V(graph)
best <- lapply(rest[[1]], function(rest) { names[rest]})

然后

[[1]]
Vertex sequence:
[1] "FLNA"  "PRKCA" "ANXA7"

您可能还需要 dput 和 unlist 输出:

dput(best)
list(list(structure(c(1, 2, 3), class = "igraph.es", env = <environment>)))

unlist(best[[1]])
[1] 1 2 3

但我需要的只是提取/计算节点名称。顺序也很重要。

names(best[[1]])
NULL     # I need to just list the names
length(best)
[1] 1   # number of shortest paths
> length(best[[1]])
[1] 1 # I need to count nodes in each shortest path

谢谢

【问题讨论】:

  • 此代码生成错误:Error in `[.igraph.vs`(names, rest) : invalid indexing of vertex seq
  • 我已经检查并修改了它。谢谢

标签: list graph igraph


【解决方案1】:

只需将此代码 (names 替换为:

names<-V(graph)$name

这会起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-19
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2018-07-29
    相关资源
    最近更新 更多