Auto apply preexisting layout

196 views
Skip to first unread message

Adam Miller

unread,
Mar 15, 2013, 8:32:05 PM3/15/13
to cytoscap...@googlegroups.com
So, I have an app under development where I load some data from a file and create the graph from that programmatically. Its based off of a MenuAction sample, where it adds a menuitem to the top bar for the program, and then sets an action performed function to be called when its clicked. The MenuAction class extends from AbstracCyAction, and I'm pretty sure that its available in the samples.

The problem is, whenever the graph is finished being created, it is nothing but a bunch of nodes stacked upon one another. I'm really confused as to why this is, because when I got to apply this hierarchical layout that already exists, it seems to apply the VisualStyle settings that I have specified in the actionPerformed function; before the layout is applied, nodes don't have labels. After the layout is done, the nodes do have labels, and I don't understand why that is. (In a previous email, over the course of a number of messages I explained that I found that you had to use the VisualStyleFunctionFactory in conjunction with VisualStyle and VisualMappingManager classes to configure styles. After I found this out, I followed samples 15 & 16 to a T, but it doesn't apply these settings that I'm configuring with the VisualStyle class until after the layout.

 I always layout this graph in hierarchical, from the Layout menu that already exists in cytoscape. My thinking is, if I can have it automatically perform this layout, its a time saver, and it will also solve the other problem (for now, but I really want to understand why it doesn't get applied immediately). How can I programmatically make it perform this same layout?

Peng-Liang Wang

unread,
Mar 28, 2013, 2:01:30 PM3/28/13
to cytoscap...@googlegroups.com
Sorry for late reply. To apply layout automatically, you can insert a
layout task after your current task. You can use some code like this.


public void run(TaskMonitor taskMonitor) throws Exception {
...
// Apply layout
final CyLayoutAlgorithm layout =
adapter.getCyLayouts().getLayout("hierarchical");
layout.setNetworkView(view);
insertTasksAfterCurrentTask(layout.getTaskIterator());
...
}


Peng
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Dan

unread,
Mar 29, 2013, 5:10:13 PM3/29/13
to cytoscap...@googlegroups.com
Hi Peng.

Where do you get the getCyLayouts() method?

Dan

unread,
Mar 29, 2013, 5:13:14 PM3/29/13
to cytoscap...@googlegroups.com
I mean. Is this "adapter" the equivalent to BundleContext?

Kenneth Adam Miller

unread,
Mar 29, 2013, 5:14:07 PM3/29/13
to cytoscap...@googlegroups.com
In the CyActivator, you can do getService(CyLayoutAlgorithmManager.class...
and then use the resulting object to call getLayouts, match the desired layout name for a given CyLayoutAlgorithm, and apply the rest of the code.


You received this message because you are subscribed to a topic in the Google Groups "cytoscape-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cytoscape-discuss/5To4DAMoA3g/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to cytoscape-disc...@googlegroups.com.

Peng-Liang Wang

unread,
Mar 29, 2013, 5:36:28 PM3/29/13
to cytoscap...@googlegroups.com
Hi Dan,

The adapter is the CySwingAppAdapter or CyAppAdapter, if you develop simple app, you always get the reference of this adapter, where you get access to all of Cytoscape services. If you develop bundle app, then you can do what Kenneth said, to get the access to CyLayoutManager at your CyActivator


Peng

Dan

unread,
Mar 29, 2013, 6:07:15 PM3/29/13
to cytoscap...@googlegroups.com
Thanks guys, i'll try it and soon i'll post the results.

Dan.

James Grammatikos

unread,
Apr 30, 2013, 4:42:13 PM4/30/13
to cytoscap...@googlegroups.com
I also had this problem, but the CyLayoutAlgorithm class doesn't have a setNetworkView method in my jar or in the javadocs for 3.0.1 or 3.1.0 (http://chianti.ucsd.edu/cytoscape-3.0.1/API/org/cytoscape/view/layout/CyLayoutAlgorithm.html and http://code.cytoscape.org/jenkins/job/cytoscape-3-javadoc/javadoc/. How would I go about assigning a layout to a view?

Jason Montojo

unread,
May 1, 2013, 10:38:29 AM5/1/13
to cytoscap...@googlegroups.com
Hi James,

That sample code is actually a bit outdated.  You can use CyLayoutAlgorithm.createTaskIterator() to accomplish the same thing:

CyLayoutAlgorithm layout = ...;
CyNetworkView view = ...;
Set<View<CyNode>> nodes = null; // If nodes is null, layout is applied to all nodes.  Otherwise, it will be applied to given nodes.
String attribute = null; // For attribute-weighted layouts, specify name here.  For unweighted, use null.
insertTasksAfterCurrentTask(layout.createTaskIterator(view, context, nodes, attribute);


Hope this helps,
Jason

James Grammatikos

unread,
May 1, 2013, 4:21:18 PM5/1/13
to cytoscap...@googlegroups.com
Hi Jason,
Running the task iterator from the algorithm works exactly as hoped, although I'd clarify that it doesn't work with null, but instead only for an empty set.
Thanks a lot,
James

Jason Montojo

unread,
May 1, 2013, 4:23:07 PM5/1/13
to cytoscap...@googlegroups.com
Hi James,

Thanks for the clarification!  We'll need to update the Javadocs to indicate what should be allowed.  Thanks!

Jason

victor

unread,
Jun 4, 2013, 9:53:21 AM6/4/13
to cytoscap...@googlegroups.com
Hi Jason, 

I was able to get it to work via the tips you just gave. However, now that I'm not running the app I'm working on as a 'task' I don't know what course of action to pursue. 

Is there any class that can allow me to simply 'set' my own layout?

Jason Montojo

unread,
Jun 4, 2013, 10:54:15 AM6/4/13
to cytoscap...@googlegroups.com
Hi Victor,

I'm not sure what you're asking.  What do you mean by "'set' my own layout"?  Do you mean you've implemented a layout and are trying to apply it to a network?

Thanks,
Jason

victor

unread,
Jun 4, 2013, 11:18:42 AM6/4/13
to cytoscap...@googlegroups.com
Hi Jason, 

It's not a custom layout. It's one of the pre-existing ones. This is how my code looks like:

CyLayoutAlgorithm layout = 'get my desired layout'

and from here I don't know what to do because the class i'm doing this in does not extend AbstractTask and therefore doesn't possess an insertTasksAfterCurrentTasks method to call. 

I was just wondering if there was a service/manager that I could use to do something like this service.setLayout(layout).

Jason Montojo

unread,
Jun 4, 2013, 11:58:05 AM6/4/13
to cytoscap...@googlegroups.com
Hi Victor,

Ahh!  CyLayoutAlgorithms are a sort of task factory.  So you can do this:

Object context = layout.createLayoutContext();
String layoutAttribute = null; // This means don't use an attribute-weighted variation of the layout
TaskIterator iterator = layout.createTaskIterator(networkView, context, CyLayoutAlgorithm.ALL_NODE_VIEWS, layoutAttribute);
taskManager.execute(iterator);

Hope this helps,
Jason

victor

unread,
Jun 4, 2013, 12:16:37 PM6/4/13
to cytoscap...@googlegroups.com
Hi Jason,

Thanks! Works like a charm!

Thanks, 

Victor
Reply all
Reply to author
Forward
0 new messages