RCytoscape- Non-square adjacency matrix

297 views
Skip to first unread message

Chirag Gupta

unread,
Nov 18, 2013, 12:44:02 PM11/18/13
to cytoscap...@googlegroups.com
Hi
I have a non square adjacency matrix with rows representing genes and columns as Transcription Factors in R. Each cell value is a score of either 0 or 1. I want to view this in cytoscape. All the available functions ask for a square matrix. I am stuck up in this situation for days now. 
Any help is appreciated.


Thanks. 

Tim Kacprowski

unread,
Nov 19, 2013, 3:15:45 AM11/19/13
to cytoscap...@googlegroups.com
hello,

that sounds like you are dealing with a bi-partite graph represented by that matrix.
you can, e.g.,  represent this graph with an usual square adjacency matrix, as well.

cheers
tim

________________________________________

Tim Kacprowski
Molecular Networks in Medical Bioinformatics
Max Planck Institute for Informatics
Campus E1.4, 66123 Saarbrücken, Germany
________________________________________


--
You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-disc...@googlegroups.com.
To post to this group, send email to cytoscap...@googlegroups.com.
Visit this group at http://groups.google.com/group/cytoscape-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Paul Shannon

unread,
Nov 19, 2013, 8:50:07 AM11/19/13
to chiraggup...@gmail.com, Paul Shannon, cytoscap...@googlegroups.com
Can you give me a small example -- as small as it can be but sufficient to demonstrate your difficulty?

I'd be glad then to help out.

- Paul

Chirag Gupta

unread,
Nov 19, 2013, 9:25:29 AM11/19/13
to cytoscap...@googlegroups.com
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!  

Paul Shannon

unread,
Nov 19, 2013, 11:57:11 PM11/19/13
to Chirag Gupta, Paul Shannon, cytoscap...@googlegroups.com
Hi Chirag,

My solution, shown below, starts with your matrix, adds empty columns to make it square, constructs a graphAM using the matrix, converts to a graphNEL, and then displays the result using RCytoscape:

y <- matrix(rnorm(50), 10, 5, dimnames=list(paste("g", 1:10, sep=""), paste("g", 1:5, sep="")))
x <- matrix(0, 10, 5, dimnames=list(paste("g", 1:10, sep=""), paste("g", 6:10, sep="")))
xy <- cbind(y,x)
xy[xy <=0 ] <- 0
xy[xy >0 ] <- 1
library(RCytoscape)
g1 <- graphAM(xy, edgemode="directed")
g2 <- as(g1, "graph")
cw <- new.CytoscapeWindow("from adjacency matrix", g2, overwrite=TRUE)
displayGraph(cw)
setNodeLabelRule(cw, "label")
redraw(cw)

With this (rather hasty) result.  Is this helpful?

 - Paul

-- 
Thanks and regards,
Chirag Gupta
+1479-799-7136

Tim Kacprowski

unread,
Nov 20, 2013, 11:30:23 AM11/20/13
to cytoscap...@googlegroups.com
i see.
following some quick thoughts, you could do:

cat( paste( apply( which(a.matrix == 1, arr.ind = T), 1,
  function (x) {
paste(x[1], x[2], a.matrix[x[1],x[2]],
 sep ='\t')
  }
),
collapse = '\n'))


but there may also be some more elegenat formulation if you think about it for a while...

cheers
tim

________________________________________

Tim Kacprowski
Molecular Networks in Medical Bioinformatics
Max Planck Institute for Informatics
Campus E1.4, 66123 Saarbrücken, Germany
________________________________________


--

Tim Kacprowski

unread,
Nov 20, 2013, 11:32:42 AM11/20/13
to cytoscap...@googlegroups.com
to get 'g1' instead of 1, replace x[1] by rownames(y)[x[1]] in the inner paste...

________________________________________

Tim Kacprowski
Molecular Networks in Medical Bioinformatics
Max Planck Institute for Informatics
Campus E1.4, 66123 Saarbrücken, Germany
________________________________________


Reply all
Reply to author
Forward
0 new messages