Network generation from adjacency matrix of zeroes and ones
2
0
Entering edit mode
alptaciroglu ▴ 50
@alptaciroglu-8859
Last seen 4.5 years ago
Turkey

Dear All,

I have an adjacency matrix as follows:

 

                Gene1       Gene2         Gene3     Gene4     Gene5    Gene6      Gene7   Gene8    Gene9  Gene10 Gene11
miRNA1          0          0                  0              0              0             0            1            0            0        0                2     
miRNA2          0          0                  0              0              0             0            1            0            0        0                2     
miRNA3          0          0                  0              0              0             0            1            0            0        0                2      
miRNA4          0          0                  0              0              0             0            1            0            0        0                2      
miRNA5          0          0                  0              0              0             0            1            0            0        0                2      
miRNA6          0          0                   0              0              0             0            1            0            0        0                2

 

I want to generate a miRNA-gene interaction network from this data (there are of course more columns and rows, showing only a portion here). I tried several packages like igraph, Rgraphviz etc.. but the thing is more data is not square so they gave me an error. I would appreciate any help     

R adjacency matrix mirna • 2.1k views
ADD COMMENT
2
Entering edit mode
Robert Castelo ★ 3.4k
@rcastelo
Last seen 4 weeks ago
Barcelona/Universitat Pompeu Fabra

hi,

if you use the Bioconductor package graph you could do the following:

library(graph)

## generate a random matrix of 0s and 1s
m <- matrix(sample(0:1, size=40, replace=TRUE), nrow=4, ncol=10)

## extract the row and column indices of cells with value 1
wh <- which(m == 1, arr.ind=TRUE)

## build a graphBAM object for a directed graph
g <- graphBAM(data.frame(from=wh[, 1], to=wh[, 2], weight=1), edgemode="directed")
g
A graphBAM graph with directed edges
Number of Nodes = 10
Number of Edges = 18

## plot it
plot(g)

## etc

from this point, you should consult the documentation of the graph package to figure out how to handle graphBAM objects. You can interact from R with Cytoscape using the Bioconductor package RCytoscape.

 

cheers,

robert.

ADD COMMENT
0
Entering edit mode

That was great. Thank you. Do you know how to put labels on nodes? Right now, it is only showing me with numbers 1,2 etc..

I am sorry posted that as an answer

ADD REPLY
1
Entering edit mode

Just use the indices returned by which() to fetch the desired labels. Following my previous example:

rowlabs <- paste0("R", 1:4)
collabs <- paste0("C", 1:10)
g <- graphBAM(data.frame(from=rowlabs[wh[, 1]], to=collabs[wh[, 2]], weight=1), edgemode="directed")

consider looking at introductory materials on how learn programming with R.

ADD REPLY
0
Entering edit mode
alptaciroglu ▴ 50
@alptaciroglu-8859
Last seen 4.5 years ago
Turkey

That was great. Thank you. Do you know how to put labels on nodes? Right now, it is only showing me with numbers 1,2 etc..

ADD COMMENT

Login before adding your answer.

Traffic: 592 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