Question: Network visualization from a matrix (filled with 0 &1 values only) using R/bioconductor.
2
6.2 years ago by
Abdul Rawoof60
United States
Abdul Rawoof60 wrote:

Hello everyone,

I have a matrix based on binary concept as follows,

T1 T2 T3
Gene1 0 1 1
Gene2 1 0 1
.. 0 0 0
.. 0 1 0
Gene nth 0 0 1

I want to make a network using this matrix in R/bioconductor. Please suggest me some package.

Any help will be appreciated.

Thanks..

modified 6.2 years ago by mikhail.shugay3.4k • written 6.2 years ago by Abdul Rawoof60
1
6.2 years ago by
Jimbou770
Germany
Jimbou770 wrote:

Take a look at http://igraph.org/r/ You can find also many tutorials out there.

1
6.2 years ago by
Alex Reynolds31k
Seattle, WA USA
Alex Reynolds31k wrote:

You could use the igraph R package. For example, given your input matrix, you could turn it into a set of vertices and edges and then plot its network:

> install.packages("igraph")
> library("igraph")
> verts <- data.frame(name=c("Gene1", "Gene2", "Gene3", "Gene4", "Gene5", "T1", "T2", "T3"))
> edges <- data.frame(from=c("Gene1", "Gene1", "Gene2", "Gene2", "Gene4", "Gene5"), to=c("T2", "T3", "T1", "T3", "T2", "T3"))
> g <- graph.data.frame(edges, directed=TRUE, vertices=verts)
> png("graph.png")
> plot(g)
> dev.off()

The file graph.png might look something like this:

if values are between 0 to 1, then what will be the script. can we mention the edge distance.

0
6.2 years ago by
mikhail.shugay3.4k
Czech Republic, Brno, CEITEC
mikhail.shugay3.4k wrote:

Essentially the same solution as above, but allows parsing arbitrary tables

install.packages("igraph", "reshape")
library(igraph); library(reshape)

input <- "gene\tT1\tT2\tT3\nG1\t0\t1\t1\nG2\t1\t0\t0\nG3\t0\t0\t0\nG4\t0\t1\t0\nG5\t0\t0\t1"

# collapse table, select existing edges
df <- melt(df)
df <- df[,df\$value>0]

# build graph
e <- data.frame(from = df\$gene, to = df\$variable)
g <- graph.data.frame(e)

plot(g)