nodeColorStyle <- function(nodes, colors, style_name) { # First, get the visual mapping manager and its catalog vmm <- .jcall("cytoscape/Cytoscape", "Lcytoscape/visual/VisualMappingManager;", "getVisualMappingManager") catalog <- .jcall(vmm, "Lcytoscape/visual/CalculatorCatalog;", "getCalculatorCatalog") # Create a new visual style from the currently active one oldStyle <- .jcall(vmm, "Lcytoscape/visual/VisualStyle;", "getVisualStyle") style <- .jnew("cytoscape/visual/VisualStyle", oldStyle) .jcall(style, "S", "setName", style_name) # Create a mapping from "canonicalName" to color, according to cluster # We build a Java properties object describing the mapping type <- paste("type", "DiscreteMapping", sep="=") attr <- paste("controller", "canonicalName", sep="=") # red for the clusters, white for the rest colors <- paste("map.", nodes, "=", colors, sep="") mapping <- paste("nodes.mapping", c(type, attr, colors), sep=".", collapse="\n") props <- .jnew("java/util/Properties") .jcall(props, , "load", .jcast(.jnew("java/io/StringBufferInputStream", mapping), "java/io/InputStream")) # Place the mapping inside a node color calculator fillColor <- .jnew("cytoscape/visual/calculators/GenericNodeColorCalculator", "nodeColoring", props, "nodes") # That calculator needs to be in a node apperance calculator set on the style nodeAppearance <- .jcall(style, "Lcytoscape/visual/NodeAppearanceCalculator;", "getNodeAppearanceCalculator") .jcall(nodeAppearance, , "setNodeFillColorCalculator", .jcast(fillColor, "cytoscape/visual/calculators/NodeColorCalculator")) #.jcall(style, "Lcytoscape/visual/NodeAppearanceCalculator;", # "setNodeAppearanceCalculator", nodeAppearance) # Finally, add the visual style to a calculator and set it to active #.jcall(catalog, , "addVisualStyle", style) #.jcall(vmm, "Lcytoscape/visual/VisualStyle;", "setVisualStyle", style) #.jcall(vmm, , "applyNodeAppearances") # Make the network visual update # Don't know how to do this yet - probably need to get the Swing component # and repaint it. style } require(rmetnet) require(RBGL) #.jinit("/home/daisy/research/cytoscape-v2.3/cytoscape.jar") # ok, now get the network cy_network <- .jcall("cytoscape/Cytoscape", "Lcytoscape/CyNetwork;", "getCurrentNetwork") print("got a cy network") # and create our graph object network <- new("graphCytoscape", cy_network) print("got a network") # now pass to RBGL to find strongly connected components comps <- strongComp(network) print("analyzed") comps <- comps[sapply(comps, length)>1] # get rid of all the singletons #vmm <- .jcall("cytoscape/Cytoscape", "Lcytoscape/visual/VisualMappingManager;", # "getVisualMappingManager") #oldStyle <- .jcall(vmm, "Lcytoscape/visual/VisualStyle;", "getVisualStyle") animation <- .jnew("edu/iastate/cytoscape/animation/SimpleAnimation") sapply(comps, function(comp) { #frame <- .jnew("edu/iastate/cytoscape/animation/SimpleFrame", # nodeColorStyle(comp, "255,0,0", "boost scc"), 3) rules <- paste("node canonicalName =", comp, "-> fill color = 255,0,0", collapse=";") #style <- .jnew("cytoscape/visual/VisualStyle", oldStyle, "scc frame") #sapply(rules, function(rule) .jcall("edu/iastate/cytoscape/mapping/MappingRuleParser", # "V", "mergeRule", rule, style)) frame <- .jnew("edu/iastate/cytoscape/animation/SimpleFrame", rules, 0.5) #animation$addFrame(frame) .jcall(animation, "V", "addFrame", .jcast(frame, "edu/iastate/cytoscape/animation/Frame")) }) .jcall("Animator", "V", "playAnimation", .jcast(animation, "edu/iastate/cytoscape/animation/Animation"))