What is the "VizMap automation command" to apply preferred VisualStyle to specific sub-network in multiple network collections?

32 views
Skip to first unread message

Waan

unread,
Sep 20, 2019, 4:01:07 PM9/20/19
to cytoscape-helpdesk
Dear All, 

Could anyone help me to figure out what is the VizMap automation command to apply my own VisualStyle (*.xml) to the specific network in the multiple network collections? 

I am developing a Cytoscape app to automate some pathway analysis methods that will highlight the nodes in different colours. 

However, by using the command "vizmap apply styles="myownstyle", I couldn't get it to paint the network that I need when I have > 1 network or network collection in my workspace. I have to close the Cytoscape and re-open it again in order to run my app + get the nodes coloured. 

I found some posts related to my question but still not sure whether it's really the right one since it doesn't seem to be a way to automate the app. 
https://groups.google.com/forum/#!searchin/cytoscape-helpdesk/VizMapper$20with$20multiple$20networks%7Csort:date/cytoscape-helpdesk/Z0aJj8533sI/t4k-BLroAAkJ


Below please see my codes.
(credit to Scooter's codes: https://groups.google.com/forum/#!topic/cytoscape-app-dev/kXOmppHCsqQ). 

===================
1. Create method to execute the command: 
===================
public void executeCommand(String namespace, String command, Map<String, Object> args, TaskObserver observer) {
if (commandTaskFactory == null)
   commandTaskFactory = getService(CommandExecutorTaskFactory.class);
if (taskManager == null)
  taskManager = getService(SynchronousTaskManager.class);
  TaskIterator ti = commandTaskFactory.createTaskIterator(namespace, command, args, observer);
  taskManager.execute(ti);
}

===================
2. Then, call the method
===================
Map<String, Object>visualStyle_args = new HashMap<>();
visualStyle_args.put("styles","myownstyle");
executeCommand("vizmap","apply",visualStyle_args,null);


Thank you so much for any help in advance!
Waan. 

Scooter Morris

unread,
Sep 26, 2019, 10:37:49 AM9/26/19
to cytoscape-helpdesk
Hi Waan,
    Actually, from a Cytoscape app it's even easier.  Use the CyNetworkViewManager to get a list of the current views, then for each view simply:

    VisualMappingManager vmm = manager.getService(VisualMappingManager.class);
    vmm.setCurrentVisualStyle(stringStyle);

    if (netView != null) {
      vmm.setVisualStyle(stringStyle, netView);
      manager.getService(CyNetworkViewManager.class).addNetworkView(netView);
      manager.getService(CyApplicationManager.class).setCurrentNetworkView(netView);
    }

This assumes that you have already created and/or read your visual style.  I typically create my style programmatically rather than using an XML file.  If you want to see an example, take a look at the StringApp's ViewUtils.createStyle() method: https://github.com/RBVI/stringApp/blob/master/src/main/java/edu/ucsf/rbvi/stringApp/internal/utils/ViewUtils.java#109

-- scooter

Nardnisa Sintupisut

unread,
Oct 17, 2019, 11:37:58 AM10/17/19
to cytoscape...@googlegroups.com
Hi Scooter,

I really apologize for my super late reply!! I have been stuck in some other projects and have not tried the codes yet. I will try and keep you updated very soon as this might be beneficial for the others. As usual, your codes look very well constructed and easy to understand for such a new developer like me. Thank you very much again and again.

All the best,
Waan



--
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/76e5e926-3450-4115-92c9-7b7a63e925c8%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages