prefuse force directe layout from python

342 views
Skip to first unread message

David M

unread,
Feb 8, 2017, 8:38:25 AM2/8/17
to cytoscape-helpdesk
Dear All,

I am trying to programatically create networks in python using networkx, then send them over to cytoscape to apply a layout, edit some visual properties and create an image (png for example), which I can then save to disc. I do not want to do this in a notebook.

I can create an xml file from python, open that in cytoscape manually, and apply the layout settings and other visual settings I want. However, I am having trouble finding how to apply the same effects via the cyrest api.

For example: How can I apply the "Prefuse Force Directed Layout" algorithm?

This:
res = requests.get("http://localhost:1234/v1/apply/layouts")
Gives me a list of available layout algorithms:
['attribute-circle', 'stacked-node-layout', 'degree-circle', 'circular', 'attributes-layout', 'kamada-kawai', 'force-directed', 'grid', 'hierarchical', 'fruchterman-rheingold', 'isom']

Once I have the name of the layout, I should be able to apply it by using a command like:
requests.get(BASE + 'apply/layouts/force-directed/' + str(new_suid))


In cytoscape, if I am manually applying the layout, I need to select the "Edge attribute that contains the weights". How can this be included in a get call?

Many thanks in advance,
D.

David Otasek

unread,
Feb 9, 2017, 11:14:41 AM2/9/17
to cytoscape-helpdesk

Hello David,


Your first observation is correct; unfortunately, there is an incongruity between the name of the layout in the GUI, and its layout in command-line and consequently CyREST. This means ‘Prefuse Force Directed Layout’ appears as ‘force-directed’ to CyREST.


To access the column parameter, you can add it to the URL as follows (for an example network ’52’ with an edge column ‘EdgeBetweenness’):


/v1/apply/layouts/force-directed/52?column=EdgeBetweenness


All other parameters can be set by sending a PUT request with a JSON payload to the following URL:


/v1/apply/layouts/force-directed/parameters


An example payload can be the following, where the Default Spring Length is set to 100:


[

  {

    "name": "numIterations",

    "description": "Number of Iterations:",

    "type": "int",

    "value": 100

  },

  {

    "name": "defaultSpringCoefficient",

    "description": "Default Spring Coefficient:",

    "type": "double",

    "value": 0.0001

  },

  {

    "name": "defaultSpringLength",

    "description": "Default Spring Length:",

    "type": "double",

    "value": 100

  },

  {

    "name": "defaultNodeMass",

    "description": "Default Node Mass:",

    "type": "double",

    "value": 3

  },

  {

    "name": "isDeterministic",

    "description": "Force deterministic layouts (slower):",

    "type": "boolean",

    "value": false

  },

  {

    "name": "singlePartition",

    "description": "Don't partition graph before layout:",

    "type": "boolean",

    "value": false

  }

]


Let me know if this is helpful.


Sincerely,


David Otasek

David Otasek

unread,
Feb 10, 2017, 4:58:23 PM2/10/17
to cytoscape-helpdesk
In addition, if you want to find the GUI name for a layout, it can be found under 'longName' if you initiate a get request using this URL pattern:

http://localhost:1234/v1/apply/layouts/force-directed/


On Wednesday, February 8, 2017 at 8:38:25 AM UTC-5, David M wrote:

David M

unread,
Feb 13, 2017, 9:38:08 AM2/13/17
to cytoscape-helpdesk

Dear David Otasek,

Thank you so much for the reply.
Your answer is exactly what I was looking for.

I have now been able to create a .png image without having to interact with the GUI. :)

Regards,
Dave.

David M

unread,
Feb 15, 2017, 9:09:34 AM2/15/17
to cytoscape-helpdesk
Changing tack a little: I started out with this approach to try and show something, and I am not sure its being shown as I expected - most likely because I don't know how to control Cytoscape. I will describe the problem I wish to solve, and maybe you can offer advice on if it can be achieved with Cytoscape.

I start with 2 .fasta files. Imagine these are my sequences and a friends sequences (red and green). I perform clustering on each .fasta file, grouping them into sub-populations.
For each sub-population I create a node in networkX. I then calculate the distance between each node, and each other node, and fill in edges on the network with weights being the distance between the nodes / clusters. I then draw this network in Cytoscape.
The size of the node is proportional to the size of the cluster.
I initially chose to use a prefuse force directed layout, but have since convinced myself that the Edge-weighted Spring Embedded Layout is actually the one I should have been using all along. But I may be wrong again.

And it is here, interpreting the networks, that I get a little unravelled. I was under the impression (most likely an incorrect assumed one) that if two nodes had exactly the same edge weights to every other node, and with no distance between one another, they would be placed on top of one another. Showing that they are equally distant from every other cluster. But, it appears, that my understanding of how these these layouts place nodes is incorrect. So, my aim is to have nodes overlap exactly if they are exactly the same, and be further away from one another based on the edge weight between them.

I can't seem to find any user manual describing in detail how these layouts work, or how each property in the settings GUI alters the behaviour.

Any suggestions, advice or assistance would be welcomed.

Regards,
Dave.
Reply all
Reply to author
Forward
0 new messages