Question: R: How to convert graphNEL object into Adjacency Matrix
gravatar for urwa
2.1 years ago by
urwa0 wrote:

This is my graphNEL object


A graphNEL graph with undirected edges

Number of Nodes = 41

Number of Edges = 102

I have tried coerce. It did not work out. It asks to pre-define the matrix and To and From didnot work correctly, I had NA as entries in my adj matrix

I tried using edgeL. It did not work out. The edge list I got had numbers as edges and not the names of the genes. And I don't know how to map genes onto those numbers.

I tried converting it into igraph using igraph.from.graphNEL and then using as_adjacency_matrix. It did not work out. I got a dgCMatrix and not a normal matrix with accessible rows and columns and I am unable to convert it into a data frame either.

So right now an adjacency matrix (41 x 41) with rows ans columns being 41 gene names from the graphNEL object. OR an edge list with 2 columns and 102 rows. Each edge on one row.

Any help would be highly appreciated. It has been whole day trying to extract data from KEGG and now trying to manipulate into desired form for further application.


R • 1.2k views
ADD COMMENTlink modified 14 months ago by Biostar ♦♦ 20 • written 2.1 years ago by urwa0

Have you tried coerce(mergedPathways_d,to="matrix") ?

ADD REPLYlink written 2.1 years ago by Jean-Karim Heriche19k

Error in as.character.default(from) : no method for coercing this S4 class to a vector In addition: Warning message: In coerce(mergedPathways_d, to = "matrix") : direct use of coerce() is deprecated: use as(from, class(to)) instead

ADD REPLYlink modified 2.1 years ago • written 2.1 years ago by urwa0

You should probably post on the Bioconductor support site. I just noticed that you get a sparse matrix (dgCMatrix) from igraph so it seems that the igraph conversion is working. To get a normal matrix use as_adjacency_matrix(..., sparse = FALSE) or use as.matrix() on the dgCMatrix.

ADD REPLYlink written 2.1 years ago by Jean-Karim Heriche19k

Thanks a lot! This was helpful!

ADD REPLYlink written 2.1 years ago by urwa0
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 668 users visited in the last hour