Lets say
> y <- matrix(rnorm(50), 10, 5, dimnames=list(paste("g", 1:10, sep=""), paste("g", 1:5, sep="")))
> y
g1 g2 g3 g4 g5
g1 0.3074333 -0.27050232 -0.3779216 -2.49669225 0.09672238
g2 -1.4595533 1.33653556 -0.6434152 0.69457288 0.12146522
g3 0.7390419 -0.75854672 0.6254186 0.33169744 -1.01592252
g4 0.4479730 -0.55661946 0.2709066 -0.04312139 0.83234461
g5 0.6056811 -0.68056140 0.3908853 0.65742583 -1.64629457
g6 -0.4503781 -0.01651466 0.7885615 -0.76685821 0.74624990
g7 1.3214891 -0.78996628 -0.6776208 -1.23106417 -1.43658047
g8 0.3922689 1.37774633 0.5571683 -1.05571200 0.32167027
g9 -0.1545101 -0.61269863 0.5805345 -1.01307431 -0.45720747
g10 -0.2896233 1.16499032 -0.5502498 0.25729953 0.38061157
> a.matrix=ifelse(c(y)>0,1,0)
> dim(a.matrix)<-dim(y)
> a.matrix
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0 0 0 1
[2,] 0 1 0 1 1
[3,] 1 0 1 1 0
[4,] 1 0 1 0 1
[5,] 1 0 1 1 0
[6,] 0 0 1 0 1
[7,] 1 0 0 0 0
[8,] 1 1 1 0 1
[9,] 0 0 1 0 0
[10,] 0 1 0 1 1
Notice that this is a non square matrix and I want to view this in cytoscape. Now I want to flatten it, ie convert it into a .sif format. (it would be better if I could get three columns with one of the columns having the corresponding '0' or '1', and the other two specifying rows and columns).
eg:
g1 g1 1
g1 g2 0
g1 g3 0
g1 g4 0
g1 g5 1
g2 g1 0
g2 g2 1
etc...
Also, this is not a bipartite graph (some of the genes might be same in rows and columns). It can be represented like that but thats not the goal.
Thanks for help!