如何在Google Colab上安装Cytoscape?

时间:2020-06-17 03:27:48

标签: ubuntu google-colaboratory cytoscape

我想在Google Colab上使用Cytoscape.js(https://js.cytoscape.org/)。我在这里(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环境中端口的问题,但我不确定如何解决。

1 个答案:

答案 0 :(得分:0)

对于遇到此问题的其他任何人,我都知道,代替使用这种方法,一种更简单的方法是使用ipycytoscape,这使得使所有程序运行起来更加容易。

但是,这种方法以及我在问题中描述的方法都存在问题,即Cytoscape依赖某些ipywidget进行输出,而Google Colab尚不支持这些ipywidget。

您可以在此处跟踪此问题的进展:https://github.com/googlecolab/colabtools/issues/60