R: How to convert graphNEL object into Adjacency Matrix
0
0
Entering edit mode
7.6 years ago
urwa • 0

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 • 3.1k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY
1
Entering edit mode

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 REPLY
0
Entering edit mode

Thanks a lot! This was helpful!

ADD REPLY

Login before adding your answer.

Traffic: 1240 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6