Style

  • Default

    • Get

      • There are so many options, so I will pick some of them up and I will write a typical workflow. For users, it will be useful and if they want to know more about it or more complex one, they can use if as example.
    • Set

      • Same as above
  • Direct

    • Get
      • same as above
    • Set
      • same as above
  • Rule

    • Get

      • same as above
    • Set

      • same as above
  • Change style by attribute

    • Nodes
    • Edges

Style


In this section, you can learn how to apply default style or your original style. And you can also understand how to apply descrete or continuous mapping.

Table of contents


  • Get the default Style and apply it
  • Get visual propeties
  • Create original Style and apply it
  • Create passthrough mapping
  • Create continuous mapping
  • Create descrete mapping

In [ ]:

Prepare network data


To execute this cookbook's example, first you prepare network data.


In [2]:
# import library
library(RCy3)
library(igraph)

# import utility
source("../../utility/import.R")

# first, delete existing windows to save memory:
deleteAllWindows(CytoscapeConnection())

# create graph class
g <- new ('graphNEL', edgemode='directed')

edgeDataDefaults(g, attr = "edgeType") <- "undefined"
attr(edgeDataDefaults(g, attr = "edgeType"), "class") <- "STRING"

# Load Data
gal.matrix <- sifDataToMatrix('../sampleData/galFiltered.sif')

# Get NodesVec
gal.table.nodevec <- unique(c(gal.matrix[,1], gal.matrix[,3]))

# add nodes to graph
for(node in gal.table.nodevec){
    g <- graph::addNode(node, g)
}

# get EdgeList and type
gal.table.fromvec <- gal.matrix[,1]
gal.table.type <- gal.matrix[,2]
gal.table.tovec <-  gal.matrix[,3]

for (index in 1:length(gal.table.fromvec)){
    g <- graph::addEdge (gal.table.fromvec[[index]] ,gal.table.tovec[[index]], g)
    edgeData(g, gal.table.fromvec[[index]] ,gal.table.tovec[[index]], "edgeType") <- gal.table.type[[index]]
}

# show it in cytescape
cw <- CytoscapeWindow('vignette', graph=g, overwrite=TRUE)
displayGraph (cw)
layoutNetwork (cw, layout.name='degree-circle')


Loading required package: graph
Loading required package: httr
Warning message:
: package ‘httr’ was built under R version 3.2.5Loading required package: RJSONIO
Loading required package: RCurl
Warning message:
: package ‘RCurl’ was built under R version 3.2.4Loading required package: bitops

Attaching package: ‘igraph’

 以下のオブジェクトは ‘package:graph’ からマスクされています: 

     degree, edges, intersection, union 

 以下のオブジェクトは ‘package:stats’ からマスクされています: 

     decompose, spectrum 

 以下のオブジェクトは ‘package:base’ からマスクされています: 

     union 

Warning message:
:  使われていないコネクション 4 (../sampleData/galFiltered.sif) を閉じます Warning message:
In .local(from, to, graph): edges replaced: ‘YPL248C|YML051W’
[1] "label"
[1] "edgeType"

Get the default Style and apply it


In Cytoscape, there are several useful default styles. You can get the list of the style and apply the style that you want.

Get the default Style


First, to know the available default style, let's get all of the default style in Cytoscape. If you add some original style, you can get that style by this method. However, now we don't make any style, so we can only get the default style here.


In [3]:
getVisualStyleNames(cw)


  1. 'default'
  2. 'Sample3'
  3. 'Minimal'
  4. 'Gradient1'
  5. 'Universe'
  6. 'Marquee'
  7. 'Nested Network Style'
  8. 'Sample1'
  9. 'Sample2'
  10. 'Solid'
  11. 'Curved'
  12. 'BioPAX'
  13. 'BioPAX_SIF'
  14. 'Directed'
  15. 'Ripple'
  16. 'default black'
  17. 'Big Labels'

Apply default style network


Now, we know the available style, so let's apply the default style network.


In [4]:
# apply 'Minimal' style
setVisualStyle(cw, 'Minimal')

# Show it 
# TODO : I don't know why this method is not available. So I have to find it.
# print(saveImage(cw, 'sampleImage', 'pdf', 2.0))
# The following code is available
file.name <- paste (getwd (), 'resultImage' ,'applyMinimalStyle' , sep= '/' )
image.type <- 'png'

resource.uri <- paste(cw@uri, 
                      pluginVersion(cw), "networks", as.character(cw@window.id), 
                      paste0("views/first.", image.type), 
                      sep="/")
request.res <- GET(resource.uri, write_disk(paste0(file.name,".", image.type), overwrite = TRUE))


In [5]:
# apply 'Gradient1' style
setVisualStyle(cw, 'Gradient1')

# Show it 
# TODO : I don't know why this method is not available. So I have to find it.
# print(saveImage(cw, 'sampleImage', 'pdf', 2.0))

# The following code is available
file.name <- paste (getwd (), 'resultImage' ,'applyGradient1Style' , sep= '/' )
image.type <- 'png'

resource.uri <- paste(cw@uri, 
                      pluginVersion(cw), "networks", as.character(cw@window.id), 
                      paste0("views/first.", image.type), 
                      sep="/")
request.res <- GET(resource.uri, write_disk(paste0(file.name,".", image.type), overwrite = TRUE))

Get visual propeties


To create your original style, we have to set value to visual propeties. First, we should know the kind of visual propeties and there are several visual propeties in each node, edge and network.

Get all visual propeties


We can get all visual propeties.


In [6]:
# Get all visual propeties
print(getDirectlyModifiableVisualProperties(cw))


  [1] "COMPOUND_NODE_PADDING"              "COMPOUND_NODE_SHAPE"               
  [3] "DING_RENDERING_ENGINE_ROOT"         "EDGE"                              
  [5] "EDGE_BEND"                          "EDGE_CURVED"                       
  [7] "EDGE_LABEL"                         "EDGE_LABEL_COLOR"                  
  [9] "EDGE_LABEL_FONT_FACE"               "EDGE_LABEL_FONT_SIZE"              
 [11] "EDGE_LABEL_TRANSPARENCY"            "EDGE_LABEL_WIDTH"                  
 [13] "EDGE_LINE_TYPE"                     "EDGE_PAINT"                        
 [15] "EDGE_SELECTED"                      "EDGE_SELECTED_PAINT"               
 [17] "EDGE_SOURCE_ARROW_SELECTED_PAINT"   "EDGE_SOURCE_ARROW_SHAPE"           
 [19] "EDGE_SOURCE_ARROW_UNSELECTED_PAINT" "EDGE_STROKE_SELECTED_PAINT"        
 [21] "EDGE_STROKE_UNSELECTED_PAINT"       "EDGE_TARGET_ARROW_SELECTED_PAINT"  
 [23] "EDGE_TARGET_ARROW_SHAPE"            "EDGE_TARGET_ARROW_UNSELECTED_PAINT"
 [25] "EDGE_TOOLTIP"                       "EDGE_TRANSPARENCY"                 
 [27] "EDGE_UNSELECTED_PAINT"              "EDGE_VISIBLE"                      
 [29] "EDGE_WIDTH"                         "NETWORK"                           
 [31] "NETWORK_BACKGROUND_PAINT"           "NETWORK_CENTER_X_LOCATION"         
 [33] "NETWORK_CENTER_Y_LOCATION"          "NETWORK_CENTER_Z_LOCATION"         
 [35] "NETWORK_DEPTH"                      "NETWORK_EDGE_SELECTION"            
 [37] "NETWORK_HEIGHT"                     "NETWORK_NODE_SELECTION"            
 [39] "NETWORK_SCALE_FACTOR"               "NETWORK_SIZE"                      
 [41] "NETWORK_TITLE"                      "NETWORK_WIDTH"                     
 [43] "NODE"                               "NODE_BORDER_PAINT"                 
 [45] "NODE_BORDER_STROKE"                 "NODE_BORDER_TRANSPARENCY"          
 [47] "NODE_BORDER_WIDTH"                  "NODE_CUSTOMGRAPHICS_1"             
 [49] "NODE_CUSTOMGRAPHICS_2"              "NODE_CUSTOMGRAPHICS_3"             
 [51] "NODE_CUSTOMGRAPHICS_4"              "NODE_CUSTOMGRAPHICS_5"             
 [53] "NODE_CUSTOMGRAPHICS_6"              "NODE_CUSTOMGRAPHICS_7"             
 [55] "NODE_CUSTOMGRAPHICS_8"              "NODE_CUSTOMGRAPHICS_9"             
 [57] "NODE_CUSTOMGRAPHICS_POSITION_1"     "NODE_CUSTOMGRAPHICS_POSITION_2"    
 [59] "NODE_CUSTOMGRAPHICS_POSITION_3"     "NODE_CUSTOMGRAPHICS_POSITION_4"    
 [61] "NODE_CUSTOMGRAPHICS_POSITION_5"     "NODE_CUSTOMGRAPHICS_POSITION_6"    
 [63] "NODE_CUSTOMGRAPHICS_POSITION_7"     "NODE_CUSTOMGRAPHICS_POSITION_8"    
 [65] "NODE_CUSTOMGRAPHICS_POSITION_9"     "NODE_CUSTOMGRAPHICS_SIZE_1"        
 [67] "NODE_CUSTOMGRAPHICS_SIZE_2"         "NODE_CUSTOMGRAPHICS_SIZE_3"        
 [69] "NODE_CUSTOMGRAPHICS_SIZE_4"         "NODE_CUSTOMGRAPHICS_SIZE_5"        
 [71] "NODE_CUSTOMGRAPHICS_SIZE_6"         "NODE_CUSTOMGRAPHICS_SIZE_7"        
 [73] "NODE_CUSTOMGRAPHICS_SIZE_8"         "NODE_CUSTOMGRAPHICS_SIZE_9"        
 [75] "NODE_CUSTOMPAINT_1"                 "NODE_CUSTOMPAINT_2"                
 [77] "NODE_CUSTOMPAINT_3"                 "NODE_CUSTOMPAINT_4"                
 [79] "NODE_CUSTOMPAINT_5"                 "NODE_CUSTOMPAINT_6"                
 [81] "NODE_CUSTOMPAINT_7"                 "NODE_CUSTOMPAINT_8"                
 [83] "NODE_CUSTOMPAINT_9"                 "NODE_DEPTH"                        
 [85] "NODE_FILL_COLOR"                    "NODE_HEIGHT"                       
 [87] "NODE_LABEL"                         "NODE_LABEL_COLOR"                  
 [89] "NODE_LABEL_FONT_FACE"               "NODE_LABEL_FONT_SIZE"              
 [91] "NODE_LABEL_POSITION"                "NODE_LABEL_TRANSPARENCY"           
 [93] "NODE_LABEL_WIDTH"                   "NODE_NESTED_NETWORK_IMAGE_VISIBLE" 
 [95] "NODE_PAINT"                         "NODE_SELECTED"                     
 [97] "NODE_SELECTED_PAINT"                "NODE_SHAPE"                        
 [99] "NODE_SIZE"                          "NODE_TOOLTIP"                      
[101] "NODE_TRANSPARENCY"                  "NODE_VISIBLE"                      
[103] "NODE_WIDTH"                         "NODE_X_LOCATION"                   
[105] "NODE_Y_LOCATION"                    "NODE_Z_LOCATION"                   

Get node visual propeties



In [7]:
# Get node visual propeties
all_visual_propeties = getDirectlyModifiableVisualProperties(cw)

# Show it
print(all_visual_propeties[grep("^NODE.*", all_visual_propeties)])


 [1] "NODE"                              "NODE_BORDER_PAINT"                
 [3] "NODE_BORDER_STROKE"                "NODE_BORDER_TRANSPARENCY"         
 [5] "NODE_BORDER_WIDTH"                 "NODE_CUSTOMGRAPHICS_1"            
 [7] "NODE_CUSTOMGRAPHICS_2"             "NODE_CUSTOMGRAPHICS_3"            
 [9] "NODE_CUSTOMGRAPHICS_4"             "NODE_CUSTOMGRAPHICS_5"            
[11] "NODE_CUSTOMGRAPHICS_6"             "NODE_CUSTOMGRAPHICS_7"            
[13] "NODE_CUSTOMGRAPHICS_8"             "NODE_CUSTOMGRAPHICS_9"            
[15] "NODE_CUSTOMGRAPHICS_POSITION_1"    "NODE_CUSTOMGRAPHICS_POSITION_2"   
[17] "NODE_CUSTOMGRAPHICS_POSITION_3"    "NODE_CUSTOMGRAPHICS_POSITION_4"   
[19] "NODE_CUSTOMGRAPHICS_POSITION_5"    "NODE_CUSTOMGRAPHICS_POSITION_6"   
[21] "NODE_CUSTOMGRAPHICS_POSITION_7"    "NODE_CUSTOMGRAPHICS_POSITION_8"   
[23] "NODE_CUSTOMGRAPHICS_POSITION_9"    "NODE_CUSTOMGRAPHICS_SIZE_1"       
[25] "NODE_CUSTOMGRAPHICS_SIZE_2"        "NODE_CUSTOMGRAPHICS_SIZE_3"       
[27] "NODE_CUSTOMGRAPHICS_SIZE_4"        "NODE_CUSTOMGRAPHICS_SIZE_5"       
[29] "NODE_CUSTOMGRAPHICS_SIZE_6"        "NODE_CUSTOMGRAPHICS_SIZE_7"       
[31] "NODE_CUSTOMGRAPHICS_SIZE_8"        "NODE_CUSTOMGRAPHICS_SIZE_9"       
[33] "NODE_CUSTOMPAINT_1"                "NODE_CUSTOMPAINT_2"               
[35] "NODE_CUSTOMPAINT_3"                "NODE_CUSTOMPAINT_4"               
[37] "NODE_CUSTOMPAINT_5"                "NODE_CUSTOMPAINT_6"               
[39] "NODE_CUSTOMPAINT_7"                "NODE_CUSTOMPAINT_8"               
[41] "NODE_CUSTOMPAINT_9"                "NODE_DEPTH"                       
[43] "NODE_FILL_COLOR"                   "NODE_HEIGHT"                      
[45] "NODE_LABEL"                        "NODE_LABEL_COLOR"                 
[47] "NODE_LABEL_FONT_FACE"              "NODE_LABEL_FONT_SIZE"             
[49] "NODE_LABEL_POSITION"               "NODE_LABEL_TRANSPARENCY"          
[51] "NODE_LABEL_WIDTH"                  "NODE_NESTED_NETWORK_IMAGE_VISIBLE"
[53] "NODE_PAINT"                        "NODE_SELECTED"                    
[55] "NODE_SELECTED_PAINT"               "NODE_SHAPE"                       
[57] "NODE_SIZE"                         "NODE_TOOLTIP"                     
[59] "NODE_TRANSPARENCY"                 "NODE_VISIBLE"                     
[61] "NODE_WIDTH"                        "NODE_X_LOCATION"                  
[63] "NODE_Y_LOCATION"                   "NODE_Z_LOCATION"                  

Get edge visual propeties



In [10]:
# Get edge visual propeties
all_visual_propeties = getDirectlyModifiableVisualProperties(cw)

# Show it
print(all_visual_propeties[grep("^EDGE.*", all_visual_propeties)])


 [1] "EDGE"                               "EDGE_BEND"                         
 [3] "EDGE_CURVED"                        "EDGE_LABEL"                        
 [5] "EDGE_LABEL_COLOR"                   "EDGE_LABEL_FONT_FACE"              
 [7] "EDGE_LABEL_FONT_SIZE"               "EDGE_LABEL_TRANSPARENCY"           
 [9] "EDGE_LABEL_WIDTH"                   "EDGE_LINE_TYPE"                    
[11] "EDGE_PAINT"                         "EDGE_SELECTED"                     
[13] "EDGE_SELECTED_PAINT"                "EDGE_SOURCE_ARROW_SELECTED_PAINT"  
[15] "EDGE_SOURCE_ARROW_SHAPE"            "EDGE_SOURCE_ARROW_UNSELECTED_PAINT"
[17] "EDGE_STROKE_SELECTED_PAINT"         "EDGE_STROKE_UNSELECTED_PAINT"      
[19] "EDGE_TARGET_ARROW_SELECTED_PAINT"   "EDGE_TARGET_ARROW_SHAPE"           
[21] "EDGE_TARGET_ARROW_UNSELECTED_PAINT" "EDGE_TOOLTIP"                      
[23] "EDGE_TRANSPARENCY"                  "EDGE_UNSELECTED_PAINT"             
[25] "EDGE_VISIBLE"                       "EDGE_WIDTH"                        

Get network visual propeties



In [11]:
# Get network visual propeties
all_visual_propeties = getDirectlyModifiableVisualProperties(cw)

# Show it
print(all_visual_propeties[grep("^NETWORK.*", all_visual_propeties)])


 [1] "NETWORK"                   "NETWORK_BACKGROUND_PAINT" 
 [3] "NETWORK_CENTER_X_LOCATION" "NETWORK_CENTER_Y_LOCATION"
 [5] "NETWORK_CENTER_Z_LOCATION" "NETWORK_DEPTH"            
 [7] "NETWORK_EDGE_SELECTION"    "NETWORK_HEIGHT"           
 [9] "NETWORK_NODE_SELECTION"    "NETWORK_SCALE_FACTOR"     
[11] "NETWORK_SIZE"              "NETWORK_TITLE"            
[13] "NETWORK_WIDTH"            

Create original Style and apply it


Now, we know the all of the visual propeties, so let's create your original style and apply it.

Create original Style


To create original style, the first step is to create style object. Then, add the value to each visual propeties that you want to change from default.


In [ ]:

Apply original style



In [ ]:

Create passthrough mapping


The "passthrough" means that vizual propetiy connect with the table column. So, if you set the 'NODE_LABEL' in visual propety as 'lable' data of the table's column, you can bind these data and will appear it as graph in Cytoscape.


In [ ]:

Create continuous mapping


The continuous mapping is to map the network value to visual style. For example, you can map the color gradient from the node value.


In [ ]:

Create descrete mapping


The descrete mapping is to map the network value to visual style. For example, you can map the color from the edge value and change the edge color by the edge's value.


In [ ]: