Delete unconnected short paths from a graph in igraph

北城以北 提交于 2019-12-10 19:12:27

问题


I am working with networks in igraph, I have a network where there are short connected nodes that overlap eachother and so we donot exaclt see the edge. I want to delete al such short connected nodes as they are not connected to the main network. The degree thing doesnt work here as the nodes are not 0 degree., they are either connected to 1 or more genes but still not in the main network.Even the main network shows some overlapping genes, I want to correct that too.

 net <- simplify(InnatedGraph, remove.multiple = T, remove.loops = T, ) 
 bad.vs<-V(net)[degree(net) == 0] 
 net <-delete.vertices(net, bad.vs)
 plot(net,vertex.label=NA, edge.curved=.1, edge.width = 1,edge.arrow.width = 0.3,vertex.size = 3,asp=-1,edge.arrow.size = 0.5,vertex.label.cex = 0.3)

After doing all this i get a network like this

The genes you see around the main network are not isolated nodes but connected to other nodes that are overlapped. Is there are way to delete these genes and prevent overlapping in the main network.


回答1:


You want the main component. First, find the components and then subset the graph based on those components. Where g is your network:

V(g)$comp <- components(g)$membership
main <- induced_subgraph(g,V(g)$comp==1)

As far as overlapping nodes, check out the different layouts available in igraph. ?igraph::layout.

NOTE: check out @hermidalc’s answer. The largest component is not necessarily the first extracted component.




回答2:


You want the main/largest component, which is not necessarily the first component with id == 1

main <- induced_subgraph(
  g, V(g)[components(g)$membership == which.max(components(g)$csize)]
)


来源:https://stackoverflow.com/questions/40133971/delete-unconnected-short-paths-from-a-graph-in-igraph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!