Question: Adjacency to network using R
0
gravatar for pankaj borah
7.7 years ago by
pankaj borah120
pankaj borah120 wrote:
Hi All, Can anyone help me with how to convert an adjacency matrix of (NxM) dimension  to cytoscape input file (edge list, SIF etc) using R ? Consider an adjacency of  5x10 dimension , where rows are genes and columns are metabolite(or vice versa). Now if I want to import it to any network visualization software how can I do that ? Thanks, Pankaj [[alternative HTML version deleted]]
visualization network convert • 2.0k views
ADD COMMENTlink modified 7.7 years ago by Tim Triche4.2k • written 7.7 years ago by pankaj borah120
Answer: Adjacency to network using R
0
gravatar for Tim Triche
7.7 years ago by
Tim Triche4.2k
United States
Tim Triche4.2k wrote:
doesn't RCytoscape take a graphNEL object as input for some routines? In Paul Shannon's workshop I seemed to remember this being the case (look at the materials from Bioc2011, there should be a bunch of examples). Adjacency matrices are almost always much smaller when represented as adjacency lists, and a graphAM can be coerced to a graphNEL for the purpose you wish. R> library(graph) R> class?graphAM R> class?graphNEL # say your adj. matrix is in matrix 'mat' R> graphmat <- new("graphAM", adjMat=mat, edgemode='directed') R> graphlist <- as(graphmat, 'graphNEL') # now from the vignette: R> library(RCytoscape) R> cw <- new.CytoscapeWindow ('vignette', graph=graphlist) R> displayGraph(cw) Is that the sort of thing you were thinking of ? On Sat, Mar 24, 2012 at 8:46 AM, pankaj borah <pankajborah2k3@yahoo.co.in>wrote: > Hi All, > > > Can anyone help me with how to convert an adjacency matrix of (NxM) > dimension to cytoscape > input file (edge list, SIF etc) using R ? > > > Consider an adjacency of 5x10 dimension , where rows are genes > and columns are metabolite(or vice versa). Now if I want to import it to > any network visualization software how can I do that ? > > > Thanks, > > Pankaj > [[alternative HTML version deleted]] > > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > > -- *A model is a lie that helps you see the truth.* * * Howard Skipper<http: cancerres.aacrjournals.org="" content="" 31="" 9="" 1173.full.pdf=""> [[alternative HTML version deleted]]
ADD COMMENTlink written 7.7 years ago by Tim Triche4.2k
Thanks Tim, Yes you are true if the adjacency matrix is a square matrix (NxN). But my adjacency is non square NxM matrix. Regards, Pankaj ________________________________ From: "Tim Triche, Jr." <tim.triche@gmail.com> Cc: "bioconductor@r-project.org" <bioconductor@r-project.org> Sent: Saturday, 24 March 2012 6:16 PM Subject: Re: [BioC] Adjacency to network using R doesn't RCytoscape take a graphNEL object as input for some routines? In Paul Shannon's workshop I seemed to remember this being the case (look at the materials from Bioc2011, there should be a bunch of examples).  Adjacency matrices are almost always much smaller when represented as adjacency lists, and a graphAM can be coerced to a graphNEL for the purpose you wish. R> library(graph) R> class?graphAM R> class?graphNEL # say your adj. matrix is in matrix 'mat' R> graphmat <- new("graphAM", adjMat=mat, edgemode='directed') R> graphlist <- as(graphmat, 'graphNEL') # now from the vignette: R> library(RCytoscape) R> cw <- new.CytoscapeWindow ('vignette', graph=graphlist) R> displayGraph(cw) Is that the sort of thing you were thinking of ? wrote: Hi All, > > >Can anyone help me with how to convert an adjacency matrix of (NxM) dimension  to cytoscape >input file (edge list, SIF etc) using R ? > > >Consider an adjacency of  5x10 dimension , where rows are genes and columns are metabolite(or vice versa). Now if I want to import it to any network visualization software how can I do that ? > > >Thanks, > >Pankaj >       [[alternative HTML version deleted]] > > >_______________________________________________ >Bioconductor mailing list >Bioconductor@r-project.org >https://stat.ethz.ch/mailman/listinfo/bioconductor >Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > > -- A model is a lie that helps you see the truth. Howard Skipper [[alternative HTML version deleted]]
ADD REPLYlink written 7.7 years ago by pankaj borah120
How have you ended up with a non-square adjacency matrix? (can it be made square by adding additional columns/rows set to 0?) Alternatively, why not enumerate and add the edges between nodes for all [N,M] such that mat[n,m] != 0. (see the RCytoscape vignette for more on this and export functions) On Sat, Mar 24, 2012 at 12:33 PM, pankaj borah <pankajborah2k3@yahoo.co.in>wrote: > Thanks Tim, > Yes you are true if the adjacency matrix is a square matrix (NxN). But my > adjacency is non square NxM matrix. > > Regards, > Pankaj > > ------------------------------ > *From:* "Tim Triche, Jr." <tim.triche@gmail.com> > *To:* pankaj borah <pankajborah2k3@yahoo.co.in> > *Cc:* "bioconductor@r-project.org" <bioconductor@r-project.org> > *Sent:* Saturday, 24 March 2012 6:16 PM > *Subject:* Re: [BioC] Adjacency to network using R > > doesn't RCytoscape take a graphNEL object as input for some routines? In > Paul Shannon's workshop I seemed to remember this being the case (look at > the materials from Bioc2011, there should be a bunch of examples). > Adjacency matrices are almost always much smaller when represented as > adjacency lists, and a graphAM can be coerced to a graphNEL for the purpose > you wish. > > R> library(graph) > R> class?graphAM > R> class?graphNEL > # say your adj. matrix is in matrix 'mat' > R> graphmat <- new("graphAM", adjMat=mat, edgemode='directed') > R> graphlist <- as(graphmat, 'graphNEL') > > # now from the vignette: > R> library(RCytoscape) > R> cw <- new.CytoscapeWindow ('vignette', graph=graphlist) > R> displayGraph(cw) > > Is that the sort of thing you were thinking of ? > > > > On Sat, Mar 24, 2012 at 8:46 AM, pankaj borah <pankajborah2k3@yahoo.co.in>wrote: > > Hi All, > > > Can anyone help me with how to convert an adjacency matrix of (NxM) > dimension to cytoscape > input file (edge list, SIF etc) using R ? > > > Consider an adjacency of 5x10 dimension , where rows are genes > and columns are metabolite(or vice versa). Now if I want to import it to > any network visualization software how can I do that ? > > > Thanks, > > Pankaj > [[alternative HTML version deleted]] > > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > > > > > -- > *A model is a lie that helps you see the truth.* > * > * > Howard Skipper<http: cancerres.aacrjournals.org="" content="" 31="" 9="" 1173.full.pdf=""> > > > > -- *A model is a lie that helps you see the truth.* * * Howard Skipper<http: cancerres.aacrjournals.org="" content="" 31="" 9="" 1173.full.pdf=""> [[alternative HTML version deleted]]
ADD REPLYlink written 7.7 years ago by Tim Triche4.2k
How have I ended up with a non-square adjacency matrix: It is something like this - > m<-matrix(rnorm(1000),nrow=100,ncol=10,dimnames=list(paste("met",c(1 :100)))) > g<-matrix(rnorm(10000),nrow=1000,ncol=10,dimnames=list(paste("gen",c (1:1000)))) > cm<-cm <- cor(t(m),t(g)) > cm<-cor(t(m),t(g)) > ADJ<-ifelse(c(cm)>0.75,1,0) > dim(ADJ)<-dim(cm) > str(ADJ)  num [1:100, 1:1000] 0 0 0 0 0 0 0 0 0 0 ... Now need to convert the ADJ to a edge list or sif. I have tried igraph package. But, it can convert square Adjacency matrix to edge list or a graphNEL object. Is there a way that I can convert my non square AM to a graph object or edge list ? Pankaj ________________________________ From: "Tim Triche, Jr." <tim.triche@gmail.com> Cc: "bioconductor@r-project.org" <bioconductor@r-project.org> Sent: Saturday, 24 March 2012 9:08 PM Subject: Re: [BioC] Adjacency to network using R How have you ended up with a non-square adjacency matrix?  (can it be made square by adding additional columns/rows set to 0?) Alternatively, why not enumerate and add the edges between nodes for all [N,M] such that mat[n,m] != 0. (see the RCytoscape vignette for more on this and export functions) wrote: Thanks Tim, > >Yes you are true if the adjacency matrix is a square matrix (NxN). But my adjacency is non square NxM matrix. > > >Regards, Pankaj > > > >________________________________ > From: "Tim Triche, Jr." <tim.triche@gmail.com> >Cc: "bioconductor@r-project.org" <bioconductor@r-project.org> >Sent: Saturday, 24 March 2012 6:16 PM >Subject: Re: [BioC] Adjacency to network using R > > > >doesn't RCytoscape take a graphNEL object as input for some routines? In Paul Shannon's workshop I seemed to remember this being the case (look at the materials from Bioc2011, there should be a bunch of examples).  Adjacency matrices are almost always much smaller when represented as adjacency lists, and a graphAM can be coerced to a graphNEL for the purpose you wish. > > >R> library(graph) >R> class?graphAM >R> class?graphNEL ># say your adj. matrix is in matrix 'mat' >R> graphmat <- new("graphAM", adjMat=mat, edgemode='directed') >R> graphlist <- as(graphmat, 'graphNEL') > > ># now from the vignette: >R> library(RCytoscape) >R> cw <- new.CytoscapeWindow ('vignette', graph=graphlist) >R> displayGraph(cw) > > >Is that the sort of thing you were thinking of ? > > > > > wrote: > >Hi All, >> >> >>Can anyone help me with how to convert an adjacency matrix of (NxM) dimension  to cytoscape >>input file (edge list, SIF etc) using R ? >> >> >>Consider an adjacency of  5x10 dimension , where rows are genes and columns are metabolite(or vice versa). Now if I want to import it to any network visualization software how can I do that ? >> >> >>Thanks, >> >>Pankaj >>       [[alternative HTML version deleted]] >> >> >>_______________________________________________ >>Bioconductor mailing list >>Bioconductor@r-project.org >>https://stat.ethz.ch/mailman/listinfo/bioconductor >>Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> > > > >-- >A model is a lie that helps you see the truth. > > >Howard Skipper > > > -- A model is a lie that helps you see the truth. Howard Skipper [[alternative HTML version deleted]]
ADD REPLYlink written 7.7 years ago by pankaj borah120
so here's a cheesy way to do it (as if I ever do things any other way), picking up where you left off: R> rownames(ADJ) = paste('met', 1:NROW(ADJ), sep='') R> colnames(ADJ) = paste('gen', 1:NCOL(ADJ), sep='') R> edges = which(ADJ==1, arr.ind=TRUE) R> mets = unique(rownames(ADJ)[edges[,1]]) R> gens = unique(colnames(ADJ)[edges[,2]]) R> nodes = c(mets, gens) R> gNEL = new('graphNEL', nodes=nodes) R> for(i in seq_along(rownames(edges))) { x = edges[i,] gNEL <- graph::addEdge(rownames(ADJ)[x[1]], colnames(ADJ)[x[2]], gNEL) } R> gNEL A graphNEL graph with undirected edges Number of Nodes = 566 Number of Edges = 646 Now the thing that bothers me about this is, what about tight correlations between metabolites or between genes? Might not you want to have a within-type graph for each, and a map from cliques in the metabolite graph to cliques in the gene graph? I do not know the answer to this, mind you, but it would concern me a little -- it almost seems like what you really might prefer would be to treat it as 100 variable selection problems (gene -> metabolite) and/or 10000 variable selection problems (metabolite -> gene) using something like SparseNet or glmnet, but that's just my take on the problem. Moving right along, then... # make sure Cytoscape is running with the CytoscapeRPC plugin v1.7 or higher, listening on port 9000 R> library(RCytoscape) R> cw <- new.CytoscapeWindow('ADJ', graph=gNEL) R> displayGraph(cw) So now the graph is in Cytoscape. More stuff is in the RCytoscape vignette. Don't forget to press the "apply force-directed layout" button to expand it. --t On Sat, Mar 24, 2012 at 4:00 PM, pankaj borah <pankajborah2k3@yahoo.co.in>wrote: > How have I ended up with a non-square adjacency matrix: > It is something like this - > > > > m<-matrix(rnorm(1000),nrow=100,ncol=10,dimnames=list(paste("met",c(1 :100)))) > > > g<-matrix(rnorm(10000),nrow=1000,ncol=10,dimnames=list(paste("gen",c (1:1000)))) > > cm<-cm <- cor(t(m),t(g)) > > cm<-cor(t(m),t(g)) > > ADJ<-ifelse(c(cm)>0.75,1,0) > > dim(ADJ)<-dim(cm) > > str(ADJ) > num [1:100, 1:1000] 0 0 0 0 0 0 0 0 0 0 ... > > Now need to convert the ADJ to a edge list or sif. I have tried igraph > package. But, it can convert square Adjacency matrix to edge list or a > graphNEL object. Is there a way that I can convert my non square AM to a > graph object or edge list ? > > Pankaj > ------------------------------ > *From:* "Tim Triche, Jr." <tim.triche@gmail.com> > *To:* pankaj borah <pankajborah2k3@yahoo.co.in> > *Cc:* "bioconductor@r-project.org" <bioconductor@r-project.org> > *Sent:* Saturday, 24 March 2012 9:08 PM > > *Subject:* Re: [BioC] Adjacency to network using R > > How have you ended up with a non-square adjacency matrix? (can it be made > square by adding additional columns/rows set to 0?) > > Alternatively, why not enumerate and add the edges between nodes for all > [N,M] such that mat[n,m] != 0. > (see the RCytoscape vignette for more on this and export functions) > > > On Sat, Mar 24, 2012 at 12:33 PM, pankaj borah <pankajborah2k3@yahoo.co.in> > wrote: > > Thanks Tim, > Yes you are true if the adjacency matrix is a square matrix (NxN). But my > adjacency is non square NxM matrix. > > Regards, > Pankaj > > ------------------------------ > *From:* "Tim Triche, Jr." <tim.triche@gmail.com> > *To:* pankaj borah <pankajborah2k3@yahoo.co.in> > *Cc:* "bioconductor@r-project.org" <bioconductor@r-project.org> > *Sent:* Saturday, 24 March 2012 6:16 PM > *Subject:* Re: [BioC] Adjacency to network using R > > doesn't RCytoscape take a graphNEL object as input for some routines? In > Paul Shannon's workshop I seemed to remember this being the case (look at > the materials from Bioc2011, there should be a bunch of examples). > Adjacency matrices are almost always much smaller when represented as > adjacency lists, and a graphAM can be coerced to a graphNEL for the purpose > you wish. > > R> library(graph) > R> class?graphAM > R> class?graphNEL > # say your adj. matrix is in matrix 'mat' > R> graphmat <- new("graphAM", adjMat=mat, edgemode='directed') > R> graphlist <- as(graphmat, 'graphNEL') > > # now from the vignette: > R> library(RCytoscape) > R> cw <- new.CytoscapeWindow ('vignette', graph=graphlist) > R> displayGraph(cw) > > Is that the sort of thing you were thinking of ? > > > > On Sat, Mar 24, 2012 at 8:46 AM, pankaj borah <pankajborah2k3@yahoo.co.in>wrote: > > Hi All, > > > Can anyone help me with how to convert an adjacency matrix of (NxM) > dimension to cytoscape > input file (edge list, SIF etc) using R ? > > > Consider an adjacency of 5x10 dimension , where rows are genes > and columns are metabolite(or vice versa). Now if I want to import it to > any network visualization software how can I do that ? > > > Thanks, > > Pankaj > [[alternative HTML version deleted]] > > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > > > > > -- > *A model is a lie that helps you see the truth.* > * > * > Howard Skipper<http: cancerres.aacrjournals.org="" content="" 31="" 9="" 1173.full.pdf=""> > > > > > > > -- > *A model is a lie that helps you see the truth.* > * > * > Howard Skipper<http: cancerres.aacrjournals.org="" content="" 31="" 9="" 1173.full.pdf=""> > > > > -- *A model is a lie that helps you see the truth.* * * Howard Skipper<http: cancerres.aacrjournals.org="" content="" 31="" 9="" 1173.full.pdf=""> [[alternative HTML version deleted]]
ADD REPLYlink written 7.7 years ago by Tim Triche4.2k
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: 194 users visited in the last hour