dinesh kumar
2008-Dec-12 01:10 UTC
[R] i graph library: how can generates a fully connected graph from a similarity matrix
Dear R users I have a similarity matrix 100X100. I used this matrix as adjacency matrix to generate igraph graph object. Its a fully connected graph. The similarity score is the weight of the edge. Now I want to remove all possible lowest scores (edges) but I want to get back a fully connected graph (dont want any isolated vertex).How can I do it? Also is there any possibility that I can remove the edges which dont pass a threshold (below 70% similarity score). I attached the similarity matrix. I would appreciate the reply Thanks in advance Dinesh -- Dinesh Kumar Barupal Junior Specialist Metabolomics Fiehn Lab UCD Genome Center 451 East Health Science Drive GBSF Builidng University of California DAVIS 95616 http://fiehnlab.ucdavis.edu/staff/kumar -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: pubchem-sim.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20081211/7151a6e6/attachment.txt>
Gábor Csárdi
2008-Dec-12 08:46 UTC
[R] i graph library: how can generates a fully connected graph from a similarity matrix
On Fri, Dec 12, 2008 at 2:10 AM, dinesh kumar <barupal at gmail.com> wrote:> Dear R users > > I have a similarity matrix 100X100. I used this matrix as adjacency matrix > to generate igraph graph object. Its a fully connected graph. The similarity > score is the weight of the edge. Now I want to remove all possible lowest > scores (edges) but I want to get back a fully connected graph (dont want any > isolated vertex).How can I do it?Actually your matrix is only 87x87. If you mean that you want a graph with 87 vertices, and some edge weights being zero, then you can simply do (assuming there are no negative edge weights) G <- graph.adjacency(adjmat+1, mode="undirected", weighted=TRUE) E(G)$weight <- E(G)$weight - 1 If you mean that you want to remove isolate vertices after creating the graph, that would be: G <- graph.adjacency(adjmat, mode="undirected", weighted=TRUE) G <- remove.vertices(G, V(G)[ degree(G)==0 ]) (For your data nothing really happens, there are no isolate vertices.)> Also is there any possibility that I can remove the edges which dont pass a > threshold (below 70% similarity score).You can remove it initially, from the matrix: adjmat2 <- adjmat adjmat2[ adjmat2 < 0.7 ] <- 0 G <- graph.adjacency(adjmat2, mode="undirected", weighted=TRUE) or after, from the graph itself: G <- graph.adjacency(adjmat+1, mode="undirected", weighted=TRUE) E(G)$weight <- E(G)$weight - 1 G2 <- delete.edges(G, E(G)[ weight < 0.7 ]) Gabor ps. there is also an igraph mailing list, you can find it from the igraph homepage. Just in case I miss your messages here.> I attached the similarity matrix. > > I would appreciate the reply > > Thanks in advance > > Dinesh > > > > -- > Dinesh Kumar Barupal > Junior Specialist > Metabolomics Fiehn Lab > UCD Genome Center > 451 East Health Science Drive > GBSF Builidng > University of California > DAVIS > 95616 > http://fiehnlab.ucdavis.edu/staff/kumar > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >-- Gabor Csardi <Gabor.Csardi at unil.ch> UNIL DGM