Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete unconnected short paths from a graph in igraph

Tags:

graph

r

igraph

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 enter image description here

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.

like image 591
Saad Avatar asked Oct 19 '16 14:10

Saad


1 Answers

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.

like image 196
paqmo Avatar answered Oct 03 '22 04:10

paqmo