cytoscape / py4cytoscape

Python library for calling Cytoscape Automation via CyREST
https://Py4Cytoscape.readthedocs.io
Other
72 stars 15 forks source link

Run notebook container side-by-side with cytoscape in docker servers. #119

Closed gmhhope closed 11 months ago

gmhhope commented 1 year ago

Hi Barry,

I am trying to wrap my whole workflow in a docker image but cytoscape GUI apparently cannot talk to notebook in docker container. I think this is what I should look for: https://github.com/cytoscape/docker-cytoscape-desktop.

However, I think this is probably pre-made docker containers include both cytoscape & jupyter notebook.

Is there a way I can use docker compose to have my notebook server together with cytoscape?

Here is my docker.yaml file:

Right now if I run this, it looks like only cyotscape was up but not the notebook. Hope you and your team can help out.

Thanks, Minghao Gong

version: '3.9'
services:
  R-notebook:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: R-notebook
    image: gongm/me-cfs-r-jupyter
    ports:
      - '8880:8888'
    volumes:
      - ../../../:/home/jovyan/
    environment:
      - JUPYTER_TOKEN=easy
      - PASSWORD=easy

  cytoscape-desktop:
    image: cytoscape/cytoscape-desktop:3.9.1
    ports:
      - '6080:6080'
gmhhope commented 1 year ago

This is the error:

In cyrest_get: Cannot find local or remote Cytoscape. Start Cytoscape and then proceed.
---------------------------------------------------------------------------
RequestException                          Traceback (most recent call last)
Cell In[8], line 1
----> 1 p4c.cytoscape_version_info()

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/py4cytoscape_logger.py:133, in cy_log.<locals>.wrapper_log(*args, **kwargs)
    131     return log_return(func, value)
    132 except Exception as e:
--> 133     log_exception(func, e)
    134 finally:
    135     log_finally()

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/py4cytoscape_logger.py:130, in cy_log.<locals>.wrapper_log(*args, **kwargs)
    128 log_incoming(func, *args, **kwargs)
    129 try:
--> 130     value = func(*args, **kwargs) # Call function being logged
    131     return log_return(func, value)
    132 except Exception as e:

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/cytoscape_system.py:81, in cytoscape_version_info(base_url)
     61 @cy_log
     62 def cytoscape_version_info(base_url=DEFAULT_BASE_URL):
     63     """Return the versions of the current Cytoscape and CyREST API.
     64 
     65     Args:
   (...)
     79         {'apiVersion': 'v1', 'cytoscapeVersion': '3.8.1', 'automationAPIVersion': '0.0.0', 'py4cytoscapeVersion': '0.0.2'}
     80     """
---> 81     versions = commands.cyrest_get('version', base_url=base_url)
     82     if len(versions) == 0:
     83         raise CyError('CyREST connection problem. py4cytoscape cannot continue!')

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/py4cytoscape_logger.py:133, in cy_log.<locals>.wrapper_log(*args, **kwargs)
    131     return log_return(func, value)
    132 except Exception as e:
--> 133     log_exception(func, e)
    134 finally:
    135     log_finally()

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/py4cytoscape_logger.py:130, in cy_log.<locals>.wrapper_log(*args, **kwargs)
    128 log_incoming(func, *args, **kwargs)
    129 try:
--> 130     value = func(*args, **kwargs) # Call function being logged
    131     return log_return(func, value)
    132 except Exception as e:

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/commands.py:159, in cyrest_get(operation, parameters, base_url, require_json, raw_get)
    157             return r.text
    158 except requests.exceptions.RequestException as e:
--> 159     _handle_error(e)

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/commands.py:149, in cyrest_get(operation, parameters, base_url, require_json, raw_get)
    147 try:
    148     url = build_url(base_url, operation)
--> 149     r = _do_request('GET', url, params=parameters, base_url=base_url, raw_request=raw_get)
    150     r.raise_for_status()
    151     try:

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/commands.py:695, in _do_request(method, url, base_url, raw_request, **kwargs)
    693 def _do_request(method, url, base_url=DEFAULT_BASE_URL, raw_request=False, **kwargs):
    694     # Determine whether actual call is local or remote
--> 695     requester, default_sandbox = _get_requester(base_url)
    697     if not raw_request:
    698         do_initialize_sandbox(requester, base_url=base_url) # make sure there's a sandbox before executing a command

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/commands.py:779, in _get_requester(base_url)
    777 def _get_requester(base_url):
    778     # Figure out whether CyREST available only via Jupyter-Bridge and what the default sandbox should be
--> 779     environment = _find_execution_environment(base_url)
    780     if environment == ExecutionEnvironment.REMOTE_JUPYTER_BRIDGE:
    781         default_sandbox = set_default_sandbox(**sandbox_initializer(sandboxName=PREDEFINED_SANDBOX_NAME))

File /opt/conda/lib/python3.11/site-packages/py4cytoscape/commands.py:803, in _find_execution_environment(base_url)
    801 environment = check_execution_environment(base_url)
    802 if environment == ExecutionEnvironment.UNKNOWN:
--> 803     raise requests.exceptions.RequestException('Cannot find local or remote Cytoscape. Start Cytoscape and then proceed.')
    804 return environment

RequestException: Cannot find local or remote Cytoscape. Start Cytoscape and then proceed.
bdemchak commented 1 year ago

I'm not much help with Docker issues. The expert is @kozo2 in Japan.

I'm hoping that with his assistance, you can get the right Docker.

I do know that there are people who have deployed py4cytoscape + Cytoscape successfully.

Anything you can help with, Kozo??

@AlexanderPico @yihangx

AlexanderPico commented 1 year ago

Here's a good place to start: https://hub.docker.com/r/cytoscape/cytoscape-desktop

bdemchak commented 1 year ago

Also, this is the nightly build that the developers believe has Layout Tools support for scaling and rotation. https://cytoscape-builds.ucsd.edu//Cytoscape-3.11.0/nightly/

I haven't had a chance to check it out yet, but you're welcome to.

For now, I'm trying to come up to speed on Docker, which will be a slow process. Per Alex, here's a Docker that contains Cytoscape 3.9.1 and py4cytoscape 1.2 ... kind of old, but a decent starting point for someone who knows Docker: https://hub.docker.com/r/cytoscape/cytoscape-desktop

kozo2 commented 1 year ago

Hi @gmhhope . Thank you for asking. After running docker-compose up -d on the file below,

version: '3.9'
services:
  R-notebook:
    image: jupyter/r-notebook
    ports:
      - '8888:8888'
    environment:
      - JUPYTER_TOKEN=easy
      - PASSWORD=easy
  cytoscape-desktop:
    image: cytoscape/cytoscape-desktop:3.9.1
    ports:
      - '6080:6080'
      - '1234:1234'

run curl http://cytoscape-desktop:1234 in the JupyterLab's terminal. By doing so, you can check you can access the Cytoscape container from the Jupyter container.

image

kozo2 commented 1 year ago

Hi @bdemchak @AlexanderPico

Could you inform @gmhhope about how to change the BaseURL in RCy3 / py4cytoscape ?

If @gmhhope use the above yml file, @gmhhope will need to set the BaseURL to http://cytoscape-desktop:1234/ instead of http://localhost:1234/.

kozo2 commented 1 year ago

By the way, I had forgotten to update that Docker image (cytoscape/cytoscape-desktop:3.9.1). I will upload the new image for version 3.10.1. I'll comment again if that's done.

gmhhope commented 1 year ago

Thanks @kozo2,

I will try it maybe this weekend! Thanks very much for helping out!

Best, MInghao Gong

AlexanderPico commented 1 year ago

Hi @bdemchak @AlexanderPico

Could you inform @gmhhope about how to change the BaseURL in RCy3 / py4cytoscape ?

If @gmhhope use the above yml file, @gmhhope will need to set the BaseURL to http://cytoscape-desktop:1234/ instead of http://localhost:1234/.

baseurl is a variable you can optionally pass in to any function. The defaults is 'http://127.0.0.1:1234/v1', so you'll probably want to try 'http://cytoscape-desktop:1234/v1'.

bdemchak commented 1 year ago

@AlexanderPico Thanks for this ... FYI, there's a document on this and related topics here. It shows an easier way than passing the base_url parameter on every call ... an environment variable will do the job.

AlexanderPico commented 1 year ago

Hmm... I just read that section twice and it says to set the base_url on every call. Where is the advice on the easier way?

bdemchak commented 1 year ago

Thanks for looking, @AlexanderPico ... this is what I think I'm talking about:

Is there a phrasing that would make this more clear?

AlexanderPico commented 1 year ago

Ah, third time did the trick! I thought we had something like this but couldn't find it. I was looking for a function... Thanks, @bdemchak!

bdemchak commented 1 year ago

@AlexanderPico Looking at this section and reading your comment, a few things occur to me:

1) This is written mainly for the case of setting a different port for Cytoscape, and then having base_url react to that. This is a valuable use case, but doesn't address the different use case of needing a completely different URL to accommodate Docker Cytoscape. Do you agree, and should I rewrite this section?

2) It seems like RCy3 and py4cytoscape should have the same mechanisms for setting the default URL. py4cytoscape has two methods: providing the URL on each API call or setting the URL via environment variable. It could also be that setting DEFAULT_BASE_URL immediately after importing py4cytoscape could work ... I can do it, but I haven't tested it. This would be the equivalent of providing a function call to do exactly this. What do you think of harmonizing between RCy3 and py4cytoscape, and (assuming harmony is good) what mechanisms should we support?

kozo2 commented 1 year ago

@gmhhope I have updated https://github.com/cytoscape/docker-cytoscape-desktop. The usage is https://github.com/cytoscape/docker-cytoscape-desktop?tab=readme-ov-file#an-example-of-how-to-use-this-docker-image. However, there is an issue https://github.com/cytoscape/RCy3/issues/212 for RCy3, which has not yet been resolved. On the other hand, as for py4cytoscape, you need to install version 1.9.0 with pip install git+https://github.com/cytoscape/py4cytoscape.git@1.9.0 . The reason is https://github.com/cytoscape/py4cytoscape/issues/113 .

bdemchak commented 1 year ago

Hi, @gmhhope ... Is this issue completely handled?? If not, can you report progress or failure? Thanks!

gmhhope commented 1 year ago

So busy that I cannot test this at this moment. Will let you know soon.

If I made it through and I will close this.

Thanks for checking out.

Best, Minghao

yihangx commented 1 year ago

The R version should work know. Please install RCy3 from GitHub by running:

install.packages("devtools") library(devtools) install_github('cytoscape/RCy3', build_vignettes=FALSE)