Question: Network generation from adjacency matrix of zeroes and ones
0
gravatar for alptaciroglu
3.8 years ago by
alptaciroglu50
Turkey
alptaciroglu50 wrote:

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     

mirna R adjacency matrix • 751 views
ADD COMMENTlink modified 3.8 years ago • written 3.8 years ago by alptaciroglu50
Answer: Network generation from adjacency matrix of zeroes and ones
2
gravatar for Robert Castelo
3.8 years ago by
Robert Castelo2.3k
Spain/Barcelona/Universitat Pompeu Fabra
Robert Castelo2.3k wrote:

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 COMMENTlink written 3.8 years ago by Robert Castelo2.3k

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 REPLYlink written 3.8 years ago by alptaciroglu50
1

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 REPLYlink written 3.8 years ago by Robert Castelo2.3k
Answer: Network generation from adjacency matrix of zeroes and ones
0
gravatar for alptaciroglu
3.8 years ago by
alptaciroglu50
Turkey
alptaciroglu50 wrote:

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 COMMENTlink written 3.8 years ago by alptaciroglu50
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 16.09
Traffic: 162 users visited in the last hour