Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pause needed after network creation #106

Open
AlexanderPico opened this issue Sep 24, 2020 · 5 comments
Open

Pause needed after network creation #106

AlexanderPico opened this issue Sep 24, 2020 · 5 comments
Assignees
Labels

Comments

@AlexanderPico
Copy link
Member

I think we have a synchronicity issue (see cytoscape/RCy3#98).

Can you help me diagnose if the issue is with CyREST or Cytoscape? Ideas for how to fix this?

@AlexanderPico
Copy link
Member Author

Additional details. This line throws an error sometimes...

https://github.com/cytoscape/RCy3/blob/master/R/Networks.R#L992

The prior call to CyREST occurs on this line:

https://github.com/cytoscape/RCy3/blob/master/R/Networks.R#L956

I suspect that CyREST is returning before the network view is actually ready.

@AlexanderPico
Copy link
Member Author

AlexanderPico commented Sep 24, 2020

And here's a little troubleshooting script in R. Run this with RCy3 loaded and it should throw an error, usually in the first or second attempt.

https://www.dropbox.com/s/q61hg6bqk15d085/cyrest.R?dl=0

Note that adding a sleep function before attempting to apply the visual style will completely "fix" the problem.

@AlexanderPico
Copy link
Member Author

Confirmed error in 3.8.0 and 3.8.1.

@AlexanderPico
Copy link
Member Author

@dotasek Any ideas on this one? Would be great to include a simple fix in 3.8.2.

@dotasek
Copy link
Contributor

dotasek commented Dec 18, 2020

I added a tunable to set the network for the apply style endpoint. This goes around the issue of selectedNetworkViews. The committed code is on this branch of cytoscape-impl: https://github.com/cytoscape/cytoscape-impl/tree/cyrest-106

Your original code needs a slight modification to work without a pause:

## Troubleshooting for https://github.com/cytoscape/cyREST/issues/106

# This script will create a network and then attempt to apply a visual style.
# If the network view is not ready yet, then it will throw an error. This
# behavior is inconsistent to repeated attempts may be needed to throw error.

library(RCy3)

## parameters
base.url <- 'http://127.0.0.1:1234/v1'
title <- "test network"
collection <- "test collection"
nodes <- data.frame(id=c("node 0","node 1","node 2","node 3"),
                    group=c("A","A","B","B"), 
                    score=as.integer(c(20,10,15,5)))

.nodeSet2JSON <- function(node.set, node.id.list = 'id') {
  counter <- 0
  size <- 1
  json_set <- c()
  
  for (i in seq_len(dim(node.set)[1])) {
    rest <- list()
    for (j in seq_len(dim(node.set)[2])) {
      rest[[colnames(node.set)[j]]] = node.set[i, j]
    }
    current_node = list("data" = rest)
    counter <- counter + 1
    json_set[[counter]] <- current_node
  }
  return(json_set[seq_len(counter)])
}

json_nodes <- .nodeSet2JSON(nodes["id"])


json_edges <- "[]"
json_network <- list(data = list(name = title),
                     elements = c(
                       nodes = list(json_nodes),
                       edges = list(json_edges)
                     ))

for(n in 1:5){
  ## create network
  network.suid <- cyrestPOST('networks',
                             parameters = list(
                               title = title, 
                               collection = collection),
                             body = json_network,
                             base.url = base.url)
  
  ## NOTE: A LITTLE SLEEP WILL "FIX" THE PROBLEM
  #commandSleep(2)
  
  ## apply style
  commandsPOST('vizmap apply network="CURRENT" styles="default"', base.url = base.url)
}
closeSession(F, base.url = base.url)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants