Import multiple networks from data frame in R and apply Glay clustering algorithm

202 views
Skip to first unread message

Giovanni Urgo

unread,
Jan 5, 2021, 12:19:47 PM1/5/21
to cytoscape-helpdesk
Hi all, 

I know it's a quite complex question but hope you'll be able to help me!
I'm quite new to Cytoscape and coding.

What I would like to do is to create an R script to do the following:
  • Import a network from a data frame in R
  • Run the Glay clustering algorithm from ClusterMaker on this network
  • Save the table with the new cluster column from Glay as csv file
  • Destroy network
Is this doable with Rcy3? 
I've found some documentation about importing the network but none about running Glay trhough an R script.

My data frame has the following format:

patient A     disease A     patient B.   disease B   Score

and I would like for them to be respectively:

SourceNode     SourceNoteAttribute    TargetNode    TargetNodeAttribute   EdgeAttribute

Thank you very much for your help!

Giovanni


Giovanni Urgo

unread,
Jan 5, 2021, 12:25:41 PM1/5/21
to cytoscape...@googlegroups.com

Ruth Isserlin

unread,
Jan 5, 2021, 12:44:39 PM1/5/21
to cytoscape...@googlegroups.com
Hi Giovanni,
Have you seen the example notebooks here: https://github.com/cytoscape/cytoscape-automation/wiki#r-notebooks-and-scripts .  There are a lot of them and they show how to do some of the things you would like to do. 
Collection of scripts that include programmatic io and control of Cytoscape - cytoscape/cytoscape-automation

To run the GLay algorithm you will need to use the function in RCy3 commandsRun (http://cytoscape.org/RCy3/reference/commandsRun.html) as cluster maker is app and not part of the core.  You can run something like:
RCy3::commandsRun("cluster glay") - for all the parameters you can specify you will have see the specifications.  I find the easiest way to do this by going to the command line in cytoscape and typing "help cluster glay".  You can also go to Help-> automation -> Cyrest commands API to see a graphical version of the help.   (this link might work on your computer if you have cytoscape open http://localhost:1234/v1/swaggerUI/swagger-ui/index.html?url=http%3A%2F%2Flocalhost%3A1234%2Fv1%2Fcommands%2Fswagger.json#!/cluster/cluster_glay otherwise you have to go to it from the cytoscape help menu) 

You can export the node table after you have run the command but you can also just read the table directly into R if that is where you want to use it (see getTableColumns - https://rdrr.io/bioc/RCy3/man/getTableColumns.html).

 To destroy the network you can then run  deleteNetwork (https://rdrr.io/bioc/RCy3/man/deleteNetwork.html)

Ruth 

From: cytoscape...@googlegroups.com <cytoscape...@googlegroups.com> on behalf of Giovanni Urgo <urgogi...@gmail.com>
Sent: Tuesday, January 5, 2021 12:19 PM
To: cytoscape-helpdesk <cytoscape...@googlegroups.com>
Subject: [cytoscape-helpdesk] Import multiple networks from data frame in R and apply Glay clustering algorithm
 
EXTERNAL EMAIL:
--
You received this message because you are subscribed to the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpd...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cytoscape-helpdesk/42d0592d-4337-46bb-b8b6-ea52f4797c0fn%40googlegroups.com.

Giovanni Urgo

unread,
Jan 5, 2021, 1:37:10 PM1/5/21
to cytoscape-helpdesk
Hi Ruth, 

Thank you so much for your help. That's very useful!
Sorry I'm quite new to this.
I had a look at athe documentation but I haven't find the right example for me just yet using the attributes like in the example.

patient A     disease A     patient B.   disease B   Score

and I would like for them to be respectively:

SourceNode     SourceNoteAttribute    TargetNode    TargetNodeAttribute   EdgeAttribute

Sorry it might be there somewhere but I just didn't find it yet.

Than what I would like to do is to then use a style that I've already saved, and that uses these attributes to define the colors and labels of the network.

Thank you so much for your help!
Giovanni

Ruth Isserlin

unread,
Jan 5, 2021, 1:47:51 PM1/5/21
to cytoscape...@googlegroups.com
Hi Giovanni, 
The easiest way is to restructure your data in R.  break out your data frame into two dataframes.  One for the nodes and one for the edges and use the createNetworkFromDataFrame function https://rdrr.io/bioc/RCy3/man/createNetworkFromDataFrames.html
Takes data frames for nodes and edges, as well as naming parameters to generate the JSON data format required by the "networks" POST operation via CyREST. Returns the network.suid and applies the perferred layout set in Cytoscape preferences.


if your dataframe is called df then

nodesA <- data.frame(id = df$patientA, disease = df$diseaseA)
nodesB <-  data.frame(id= df$patientB, disease = df$diseaseB)
nodes <- rbind(nodesA, nodesB)

edges <- data.frame(source = df$patientA, target= df$patientB, score = df$score)

createNetworkFromDataFrame(nodes, edges)

Thanks, 
Ruth 



Sent: Tuesday, January 5, 2021 1:37 PM
To: cytoscape-helpdesk <cytoscape...@googlegroups.com>
Subject: Re: [cytoscape-helpdesk] Import multiple networks from data frame in R and apply Glay clustering algorithm
 
EXTERNAL EMAIL:

Giovanni Urgo

unread,
Jan 5, 2021, 4:34:43 PM1/5/21
to cytoscape-helpdesk
Thank you so much Ruth! :)

I've managed to import the network and change the style as I want. I was now trying to understand how to use Glay. 
The problem I'm finding is that I used the Glay from ClusterMaker in my previous analysis and in that case I don't have to specify anything else in order to get the cluster column I need.
Since I'm now trying to automate this same process is there any way to use it through that?

Thank you so much!

Giovanni

Ruth Isserlin

unread,
Jan 5, 2021, 4:41:14 PM1/5/21
to cytoscape...@googlegroups.com
HI Giovanni.

From R if you run:
commandsRun('cluster glay')

it should run the layout with the default options just like in Cytoscape.  Does that work for you?

You then have to get the Nodetable to get the newly added "__glayCluster" attribute.
nodetable <- getTableColumns('node')

Thanks, 
Ruth 

Sent: Tuesday, January 5, 2021 4:34 PM
 
EXTERNAL EMAIL:

Giovanni Urgo

unread,
Jan 5, 2021, 5:01:58 PM1/5/21
to cytoscape-helpdesk
Thank you so much Ruth, 

I've just tried 


and I get the nodetable but there is no __glayCluster column unfortuntelly.


I don't know why unfortunatelly.

Thanks, 
Giovanni

Ruth Isserlin

unread,
Jan 5, 2021, 5:04:42 PM1/5/21
to cytoscape...@googlegroups.com
unfortunately, the screenshots you included won't show up for me.  

Are you getting any errors for your commands?  If you go to the cytoscape network that you are trying to issue the command on is there a column __glayCluster ?

Ruth 

Sent: Tuesday, January 5, 2021 5:01 PM

To: cytoscape-helpdesk <cytoscape...@googlegroups.com>
Subject: Re: [cytoscape-helpdesk] Import multiple networks from data frame in R and apply Glay clustering algorithm
 
EXTERNAL EMAIL:
--
You received this message because you are subscribed to the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpd...@googlegroups.com.

Giovanni Urgo

unread,
Jan 5, 2021, 5:08:20 PM1/5/21
to cytoscape-helpdesk
Screenshot 2021-01-05 at 22.03.23.png

No unortunatelly the column doesn't show on Cytoscape neither. I don't get a proper error but a list of possible Glay attributes. 
I hope the screenshot will load this time sorry

Giovanni
Screenshot 2021-01-05 at 22.03.23.png

Alex Pico

unread,
Jan 5, 2021, 10:01:09 PM1/5/21
to cytoscape-helpdesk
Small interjection:  Try commandsPOST instead of commandRun. The arg list result suggests the GET help command, which is not what you want. You might also have to provide at least one argument, for example, network=“current”.

 - Alex



To view this discussion on the web visit https://groups.google.com/d/msgid/cytoscape-helpdesk/69f82f4b-a183-456c-b0c8-56d5d7a42dc0n%40googlegroups.com.
<Screenshot 2021-01-05 at 22.03.23.png><Screenshot 2021-01-05 at 22.03.23.png>

Ruth Isserlin

unread,
Jan 6, 2021, 9:29:24 AM1/6/21
to cytoscape-helpdesk
Hi Giovanni, 
It works for me if I specify the network.  Try running but specify to use the current network:
RCy3::commandsRun('cluster glay network="current"')

Ruth 


Giovanni Urgo

unread,
Jan 6, 2021, 10:06:38 AM1/6/21
to cytoscape-helpdesk
Hi both Alex and Ruth, 

it finally worked! Thank you so much both for your help!

May I ask you one last question? I'vre tried saving the network as suggested in the documentation

full.path=paste(getwd(),'vignette_image',sep='/')

exportImage(full.path, 'PNG', zoom=200)

and changing the zoom but I always get a cutted image. Would you please suggest how to get the full image and remove the interacts with (edge) label?

Thank you so so much for your help.

Giovanni

 Screenshot 2021-01-06 at 14.57.52.png

Ruth Isserlin

unread,
Jan 6, 2021, 10:13:07 AM1/6/21
to cytoscape...@googlegroups.com
HI Giovanni, 
try running fitContent before exporting your image - https://rdrr.io/bioc/RCy3/man/fitContent.html
Zoom and pan network view to maximize either height or width of current network window.

Ruth 

Sent: Wednesday, January 6, 2021 10:06 AM
 
EXTERNAL EMAIL:

Giovanni Urgo

unread,
Jan 6, 2021, 10:40:28 AM1/6/21
to cytoscape-helpdesk
That worked perfectly thank you!

What about removing the 'intersect with' label? 
Sorry for the too many question and thank you so so much again!
I thought it was saved in my style but when I create the image they keep showing

Giovanni

Ruth Isserlin

unread,
Jan 6, 2021, 11:18:17 AM1/6/21
to cytoscape...@googlegroups.com
Hi Giovanni, 
Sorry, I don't know how to fix that one 🙂. 
Ruth

Sent: Wednesday, January 6, 2021 10:40 AM
 
EXTERNAL EMAIL:

Giovanni Urgo

unread,
Jan 6, 2021, 12:03:06 PM1/6/21
to cytoscape-helpdesk
Hi Ruth, 

thank you so much again for your help! :)

Giovanni

Scooter Morris

unread,
Jan 14, 2021, 11:45:15 AM1/14/21
to cytoscape-helpdesk
HI Giovanni,
   You can remove the "interacts with" label using the style methods.  There is a default edge style that is adding a passthrough mapping from the Interaction column to the edge label.  If you remove that mapping, the label will go away.

-- scooter
Reply all
Reply to author
Forward
0 new messages