This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Network visualization from a matrix (filled with 0 &1 values only) using R/bioconductor.

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..

r bioconductor packages network gene

3 answers

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

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.

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

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

# read input
# could also read from file with read.delim(file_name)
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"
df <- read.delim(text = input)

# 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)

Log in to answer this question.