Copy & Save Visual Styles

Any collection of vizmap rules, created in R or interactively in the Cytoscape GUI can be given a name and, with a little care, saved for later reuse. Unless you take extra steps, however, vizmap rules go into a visual style named default and are lost (to Cytoscape) when you close your Cytoscape session. (Note however that the recommended approach to visual style in RCytoscape is to save all your vizmap rules and overrides as an R function.)

In addition, all RCytoscape visual mapping rules belong to the default style.

This recipe explains how you can save your vizmap rules into a style with a name of your choosing.

Save your vizmap Rules along with your network into a Cytoscape session file

When you save a network via the Cytoscape File->Save menu, your vizmap style will be lost unless you take these steps to rename it, and then specify it.
  cy = CytoscapeConnection () # you can also use any existing CytoscapeWindow object you already have
  new.style.name = 'glioblastoma study #5'
  copyVisualStyle (cy, 'default', new.style.name)
  setVisualStyle  (cy, new.style.name)

Use different visual styles in different windows

RCytoscape's vizmap-setting rules always apply to the default style. So if you have one set of rules for you first network in one window, and you want to apply different rules to a different network in a second window, here is what you should do:
  1. Create the first network in the first window, with vizmap rules which implicitly belong to the default visual style.
  2. Execute these lines of code to save those rules in a new style:
      new.style.name = 'style 1'
      copyVisualStyle (cy, 'default', new.style.name)
      setVisualStyle  (cy, new.style.name)
    
  3. Now create the second network in the second window, implicitly (as always) writing vizmap rules to the default visual style
To summarize: if you want to save a visual style to a Cytoscape session file, or if you want to protect it against changes made in a subsequent window, be sure to copy the style to one with a new name.