Question: R: How to convert graphNEL object into Adjacency Matrix
0
gravatar for urwa
19 months ago by
urwa0
urwa0 wrote:

This is my graphNEL object

>mergedPathways_d

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.

Thanks!

R • 946 views
ADD COMMENTlink modified 8 months ago by Biostar ♦♦ 20 • written 19 months ago by urwa0

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

ADD REPLYlink written 19 months ago by Jean-Karim Heriche17k

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 19 months ago • written 19 months ago by urwa0
1

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 19 months ago by Jean-Karim Heriche17k

Thanks a lot! This was helpful!

ADD REPLYlink written 19 months ago by urwa0
Please log in to add an answer.

Help
Access

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