如何在 Google Colab 上安装 Cytoscape?

How do I install Cytoscape on Google Colab?

我想使用 Cytoscape.js (https://js.cytoscape.org/) on Google Colab. I found here (https://py2cytoscape.readthedocs.io/en/latest/) 这可以在 Jupyter Notebooks 中完成,但文档不是很详尽。

这是我 运行 尝试设置 Cytoscape 和 CyREST 的代码(将此处的每个代码块粘贴到 Google Colab 中的单独单元格中):

%%shell
# Install dependencies
pip install py2cytoscape
pip install dash dash-html-components
pip install dash-cytoscape
apt install g++ make libxml2-dev python-dev python3-dev zlib1g-dev

# Clone Cytoscape from Git and install
cd /usr/local/envs/cytoscape
wget https://github.com/cytoscape/cytoscape/releases/download/3.8.0/Cytoscape_3_8_0_unix.sh
chmod u+x  Cytoscape_3_8_0_unix.sh
sudo sh Cytoscape_3_8_0_unix.sh -q

# Run Cytoscape to check that everything was installed correctly
Cytoscape &
# Start Cytoscape
!Cytoscape &

from py2cytoscape.data.cyrest_client import CyRestClient

cy = CyRestClient()
network = cy.network.create(name='My Network', collection='My network collection')
print(network.get_id())

这给了我以下错误:

---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/urllib3/connection.py in _new_conn(self)
    158             conn = connection.create_connection(
--> 159                 (self._dns_host, self.port), self.timeout, **extra_kw)
    160 

23 frames
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

NewConnectionError                        Traceback (most recent call last)
NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f822bd80860>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
MaxRetryError: HTTPConnectionPool(host='localhost', port=1234): Max retries exceeded with url: /v1/styles/visualproperties (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f822bd80860>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    514                 raise SSLError(e, request=request)
    515 
--> 516             raise ConnectionError(e, request=request)
    517 
    518         except ClosedPoolError as e:

ConnectionError: HTTPConnectionPool(host='localhost', port=1234): Max retries exceeded with url: /v1/styles/visualproperties (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f822bd80860>: Failed to establish a new connection: [Errno 111] Connection refused',))

我在某个地方发现了这段代码,它应该有助于启动 CyREST,但是 运行 它给了我与上面完全相同的错误(我不太明白)

REST_PORT = '1234' # Set to whatever rest.port is in Cytoscape preferences
REST_ENDPOINT = "http://localhost:{}/v1".format(REST_PORT)
import requests
import json
import os
from urllib.request import urlretrieve
from IPython.display import Image, display, HTML

response = requests.get(REST_ENDPOINT)
js_resp = response.json()
assert js_resp['apiVersion'] == 'v1', \
    "This notebook uses CyREST API v1, but version {} was found.".format(js_resp['apiVersion'])

print("CyREST v1 is running!")

我猜这是 Google Colab Ubuntu 环境中的端口问题,但我不确定如何解决它。

对于遇到此问题的任何其他人,我了解到,与其使用这种方法,更简单的方法是使用 ipycytoscape,这样可以更容易地获得所有内容 运行。

但是,这种方法和我在问题中描述的方法的问题是 Cytoscape 依赖于一些 ipywidgets 进行输出,而 Google Colab 尚不支持这些。

你可以在这里关注这个问题的进展:https://github.com/googlecolab/colabtools/issues/60