cytoscape / py4cytoscape

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

Editing base_url leads to cyrest_get errors #113

Closed jackhart591 closed 1 year ago

jackhart591 commented 1 year ago

I am attempting to change the port I'm using with py4cytoscape. In my Python script, I start Cytoscape like this:

subprocess.Popen(['Cytoscape', '-R', str(_port)])

where _port is user-specified, but defaults to 1234. After this, I run this function:

connected = False
_url = f"http://127.0.0.1:{_port}/v1"

# Try this until cytoscape is open (we get a successful ping)
for i in range(num_retries):
    try:
        p4c.cytoscape_ping(_url)
    except:
        continue

    connected = True
    break

if not connected:
    raise RuntimeError("Failed to connect to Cytoscape!")
else: 
    print("Successfully connected to Cytoscape!")
    _cytoscape_connected = True

After I get the success message, I try to send Cytoscape my NetworkX graph using this line:

p4c.create_network_from_networkx(_graph.graph, base_url=_url)

When this is run, my network does appear in Cytoscape, however, it is not positioned and I begin to receive this error repeatedly: In cyrest_get: HTTPConnectionPool(host='127.0.0.1', port=1234): Max retries exceeded with url: /v1/networks (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa6d4196bc0>: Failed to establish a new connection: [Errno 111] Connection refused')) And my traceback will point back to the line mentioned above, however when I print the _url, I still get the correct URL (URL in this example is http://127.0.0.1:8124/v1). This code will all run successfully if my port is set to 1234.

System

bdemchak commented 1 year ago

Hi --

First, thanks for using py4cytoscape, and we're very sorry for the trouble you're having.

Based on your description (which was quite helpful), we narrowed the problem down to the network layout that occurs after the network is first loaded and displayed. The problem is also present in create_network_from_data_frames().

This base_url problem comes up from time to time, but very infrequently these days. Sorry you spent time working against it.

The problem is now addressed and no regression tests fail. Would you mind trying it out and letting me know??

You can find the development version on the py4cytoscape 1.9.0 branch ... the only difference between the release and the development version (right now) is this fix and the removal of a warning in set_visual_property_default()

jackhart591 commented 1 year ago

Thank you for getting back to me so quickly! I tested and it worked perfectly. Thanks for the help!

bdemchak commented 1 year ago

Excellent! Thanks for your patience and the report ... closing this now.