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", network = 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 # convert those components to visual mapping # 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", "Boost SCC") # 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.", unlist(comps), "=255,0,0",sep="") mapping <- paste("cluster.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", "clusterColoring", props, "cluster") # 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.