2

How can we reflect Fruchterman-Reingold layout using Cytoscape? I cannot replicate the Fruchterman-Reingold layout figure from igraph using Cytoscape.

 library(RCy3)
 library(igraph)
 library(ggraph)
 library(tidygraph)
 library(RColorBrewer)

actors <- data.frame(name=c("Alice", "Bob", "Cecil", "David",
                        "Esmeralda"),
                 age=c(48,33,45,34,21),
                 gender=c("F","M","F","M","F"))
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
                           "David", "Esmeralda"),
                    to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
                    same.dept=c(FALSE,FALSE,TRUE,FALSE,FALSE,TRUE),
                    weight=c(4,5,5,2,1,1), advice=c(4,5,5,4,2,3))
 ig <- graph_from_data_frame(relations, directed=F, vertices=actors)

coul  <- brewer.pal(2, "Set1") 
my_color <- coul[as.numeric(as.factor(V(ig)$gender))]
coords <- layout.fruchterman.reingold(ig)
plot(ig,layout=coords, vertex.color=my_color)


cytoscapePing()


createNetworkFromIgraph(ig,"myIgraph")
layoutNetwork('fruchterman-rheingold gravity_multiplier=1 nIterations=100')
Stephan T.
  • 5,843
  • 3
  • 20
  • 42
user224050
  • 317
  • 3
  • 10

1 Answers1

0

I'm not sure it is the correct answer to your question, but I don't think you need to specify gravity multiplier in your layoutNetwork command. I did not check in detail the Fruchterman-reingold algorithm but as I understand your question, you want to apply the same algorithm between igraph and Cytoscape.

For that, I first take a look at the parameters passed by default to the function layout.fruchterman.reingold which is basically calling the function layout_with_fr (wrote layout_with_fr in R console to see the function parameters).

Checking the code of this function, you can see that based on how you write it, only two parameters are set. The first one is number of iteration (set by default to 500) and the second is the temperature start (start.temp eqault to he sqrt of vcount of your graph). So, here start.temp = sqrt(5).

Then, you can check attributes of the Fruchterman-reingold algorithm in Cytoscape by using:

getLayoutPropertyNames("fruchterman-rheingold")

[1] "Available arguments for 'layout fruchterman-rheingold':"
 [1] "attraction_multiplier" "conflict_avoidance"    "defaultEdgeWeight"    
 [4] "edgeAttribute"         "gravity_multiplier"    "layout3D"             
 [7] "max_distance_factor"   "maxWeightCutoff"       "minWeightCutoff"      
[10] "network"               "nIterations"           "nodeAttribute"        
[13] "nodeList"              "randomize"             "repulsion_multiplier" 
[16] "singlePartition"       "spread_factor"         "temperature"          
[19] "type"                  "update_iterations"   

So, I think based on your example, we should use only nIterations and temperature arguments:

createNetworkFromIgraph(ig,"myIgraph")
setNodeShapeDefault("ELLIPSE")
setNodeSizeDefault(30)
setNodeColorMapping("gender", c("F","M"), c( "#E41A1C", "#377EB8"), mapping.type = "d")
setLayoutProperties("fruchterman-rheingold", 
                    list(nIterations=500,
                         temperature = sqrt(5)))
layoutNetwork("fruchterman-rheingold")

And you get such representation: enter image description here

Empirically, I found that if you are using gravity_multiplier=1, you need to also pass the argument repulsion_multiplier = 1 to compensate and make your network more appealing.

Hope it will help you to figure it out the solution to your question.

dc37
  • 15,840
  • 4
  • 15
  • 32
  • Hi, thank you for your comment. I still cannot replicate in my own data with 100 samples. It looks like Biolayout...... – user224050 Feb 23 '20 at 23:27
  • 1
    Sorry to hear that, my knowledge are quite limited on this subject. Maybe you can contact directly developpers of Cytoscape – dc37 Feb 24 '20 at 06:13