cytoscape / py4cytoscape

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

In cyrest_put(): Could not parse the input JSON for updating view because: HTTP 404 Not Found #52

Closed StefanR-github closed 3 years ago

StefanR-github commented 3 years ago

Hi, I am trying to set the border colour of my nodes to a bluegreen colour. I only want the significant nodes to be coloured, for which I have a list. Unfortunately, I keep getting the same error. I tried it with different pathways and different gene lists as well, but I recieve the same error. Also, in cytoscape, some of the significant nodes are given the correct node colour, yet some are not. For example, GSR is coloured, regardless of the error message, and CXCL10 is not......

Code and output is below. I am coding in Jupyter notebooks. Any help is much appreciated. I am relatively new to coding so please use simple words :)

col_one_list = dfSigGene['nodes'].tolist() print(f"\ncol_one_list:\n{col_one_list}\ntype:{type(col_one_list)}")

col_one_list: ['NFIX', 'GSR', 'MT1X', 'XDH', 'GPX3', 'MAOA', 'CAT', 'GCLC', 'SOD2', 'MAPK10', 'NFE2L2', 'NFKBIE', 'NFKBIA', 'ATF4', 'ITPR3', 'ITPR1', 'ITPR1', 'ITPR3', 'CAMK2D', 'CAMK2D', 'CALML3', 'CALML3', 'CALML3', 'IL1RN', 'IL36A', 'TNF', 'CXCL10', 'MMP9', 'IL23A', 'CXCL1', 'CCL28', 'CCL20', 'MMP1', 'CSF2', 'CXCL3', 'CXCL6', 'CSF1', 'CSF3', 'IL15', 'LIF', 'VEGFA', 'IL33', 'CXCL14', 'CXCL2', 'CTGF', 'CXCL5', 'NFKB1', 'MAP2K6', 'IL36G', 'IL6', 'SMAD3', 'IL1B', 'IL1A', 'TGFBR2', 'IL17C', 'CXCL16', 'PTGES', 'IRF7', 'TLL2', 'COL8A1', 'TLL1', 'ATP6AP2', 'MME', 'CES1', 'COL12A1', 'PPIB'] type:<class 'list'>

p4c.set_node_border_color_bypass(col_one_list,'#2AFFD8')

In cyrest_put(): Could not parse the input JSON for updating view because: HTTP 404 Not Found

HTTPError Traceback (most recent call last) ~\anaconda3\lib\site-packages\py4cytoscape\commands.py in cyrest_put(operation, parameters, body, base_url, require_json) 226 r = _do_request('PUT', url, params=parameters, json=body, headers = {'Content-Type': 'application/json'}, base_url=base_url) --> 227 r.raise_for_status() 228 try:

~\anaconda3\lib\site-packages\requests\models.py in raise_for_status(self) 940 if http_error_msg: --> 941 raise HTTPError(http_error_msg, response=self) 942

HTTPError: 500 Server Error: Internal Server Error for url: http://127.0.0.1:1234/v1/networks/78/views/1044/nodes?bypass=True

During handling of the above exception, another exception occurred:

CyError Traceback (most recent call last)

in ----> 1 p4c.set_node_border_color_bypass(col_one_list,'#2AFFD8') ~\anaconda3\lib\site-packages\py4cytoscape\py4cytoscape_logger.py in 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() ~\anaconda3\lib\site-packages\py4cytoscape\py4cytoscape_logger.py in 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: ~\anaconda3\lib\site-packages\py4cytoscape\style_bypasses.py in set_node_border_color_bypass(node_names, new_colors, network, base_url) 1112 verify_hex_colors(new_colors) 1113 -> 1114 res = set_node_property_bypass(node_names, new_colors, 'NODE_BORDER_PAINT', network=network, base_url=base_url) 1115 return res 1116 ~\anaconda3\lib\site-packages\py4cytoscape\py4cytoscape_logger.py in 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() ~\anaconda3\lib\site-packages\py4cytoscape\py4cytoscape_logger.py in 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: ~\anaconda3\lib\site-packages\py4cytoscape\style_bypasses.py in set_node_property_bypass(node_names, new_values, visual_property, bypass, network, base_url) 126 zip(node_suids, new_values)] 127 --> 128 res = commands.cyrest_put(f'networks/{net_suid}/views/{view_suid}/nodes', 129 parameters={'bypass': bypass}, body=body_list, base_url=base_url, require_json=False) 130 return res ~\anaconda3\lib\site-packages\py4cytoscape\py4cytoscape_logger.py in 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() ~\anaconda3\lib\site-packages\py4cytoscape\py4cytoscape_logger.py in 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: ~\anaconda3\lib\site-packages\py4cytoscape\commands.py in cyrest_put(operation, parameters, body, base_url, require_json) 234 return r.text 235 except requests.exceptions.RequestException as e: --> 236 _handle_error(e) 237 238 ~\anaconda3\lib\site-packages\py4cytoscape\commands.py in _handle_error(e, force_cy_error) 676 else: 677 show_error(f'In {caller}: {e}\n{content}') --> 678 raise e 679 680 CyError: In cyrest_put(): Could not parse the input JSON for updating view because: HTTP 404 Not Found
bdemchak commented 3 years ago

@StefanR-github Very strange. There are lots of unit tests around this topic, and they're all well behaved. So, there must be some unexpected context.

First, thanks for trying py4cytoscape and letting me know about this problem!

This error appears to be occurring in the HTTP python library. And the URL ( http://127.0.0.1:1234/v1/networks/78/views/1044/nodes?bypass=True ) looks plausible. I wish I could see what body= parameter was being passed to the library.

My tests are using both Cytoscape 3.8.2 and the nightly Cytoscape 3.9.0 build. I'm also using py4cytoscape 0.0.9 (just released on PyPI). I'm executing from PyCharm.

It looks like you're using Anaconda ... I'm guessing you're executing from a command line ... maybe on a Mac or Linux? What version of py4cytoscape and Cytoscape are you using?

Your log snippet is helpful, but doesn't tell the whole story. Are you aware of the py4cytoscape-specific logs? I think you might find them in the "logs" folder in your python working directory. The later entries would be very helpful here. They look something like the log at the end of this post .... for "set_node_border_color_bypass(['YGL035C', 'YLR044C', 'YNL216W', 'YIL162W'], '#2AFFD8')". The most important line is in bold (near the end).

Can you send me a log that shows the failure? ... or at least the part of the log that shows the failure?

Also, are you able to execute the sanity test described here? https://py4cytoscape.readthedocs.io/en/latest/install.html#testing-command-line ... a good point of reference.

Is there more of your code you can share with me? If I can reproduce the problem here, we'd be better off.

One thing to consider ... py4cytoscape can execute within Google Colab and it communicates with the Cytoscape on your PC. If you'd like to share your code with me, putting it into a Google Colab notebook might be a good way (though might be a distraction if you're just trying to get something working). I'll leave it to you ... here's an existing Google Colab notebook to give you a flavor: https://colab.research.google.com/github/bdemchak/cytoscape-jupyter/blob/main/gangsu/basic%20protocol%201.ipynb

Are you current on all of your python library modules? Same for Cytoscape ... are you at 3.8.2 or later, and have you updated all of your apps?

Would you be interested in trying the Cytoscape 3.9.0 nightly build? https://cytoscape-builds.ucsd.edu/cytoscape-builds/Cytoscape-3.9.0/nightly/

2021-06-04 11:16:08,768 [DEBUG] py4...: -------------------- 2021-06-04 11:16:22,713 [DEBUG] py4...: Calling set_node_border_color_bypass(['YGL035C', 'YLR044C', 'YNL216W', 'YIL162W'], '#2AFFD8') 2021-06-04 11:16:22,713 [DEBUG] py4...: ǀCalling set_node_property_bypass(['YGL035C', 'YLR044C', 'YNL216W', 'YIL162W'], ['#2AFFD8'], 'NODE_BORDER_PAINT', network=None, base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,713 [DEBUG] py4...: ǀǀCalling get_network_suid(None, base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,713 [DEBUG] py4...: ǀǀǀCalling commands_post('network get attribute network="current" namespace="default" columnList="SUID"', base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,713 [DEBUG] py4...: ǀǀǀHTTP POST(http://127.0.0.1:1234/v1/commands/network/get%20attribute), json: {'network': 'current', 'namespace': 'default', 'columnList': 'SUID'} 2021-06-04 11:16:22,725 [DEBUG] py4...: ǀǀǀOK[200], content: { "data": [ { "SUID": 4317 } ], "errors":[] } 2021-06-04 11:16:22,725 [DEBUG] py4...: ǀǀǀReturning 'commands_post': [{'SUID': 4317}] 2021-06-04 11:16:22,725 [DEBUG] py4...: ǀǀReturning 'get_network_suid': 4317 2021-06-04 11:16:22,725 [DEBUG] py4...: ǀǀCalling get_network_views(4317, base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,725 [DEBUG] py4...: ǀǀǀCalling get_network_suid(4317, base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,725 [DEBUG] py4...: ǀǀǀǀCalling cyrest_get('networks', base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,725 [DEBUG] py4...: ǀǀǀǀHTTP GET(http://127.0.0.1:1234/v1/networks) 2021-06-04 11:16:22,757 [DEBUG] py4...: ǀǀǀǀOK[200], content: [4317] 2021-06-04 11:16:22,757 [DEBUG] py4...: ǀǀǀǀReturning 'cyrest_get': [4317] 2021-06-04 11:16:22,757 [DEBUG] py4...: ǀǀǀReturning 'get_network_suid': 4317 2021-06-04 11:16:22,757 [DEBUG] py4...: ǀǀǀCalling cyrest_get('networks/4317/views', base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,757 [DEBUG] py4...: ǀǀǀHTTP GET(http://127.0.0.1:1234/v1/networks/4317/views) 2021-06-04 11:16:22,773 [DEBUG] py4...: ǀǀǀOK[200], content: [5033] 2021-06-04 11:16:22,773 [DEBUG] py4...: ǀǀǀReturning 'cyrest_get': [5033] 2021-06-04 11:16:22,773 [DEBUG] py4...: ǀǀReturning 'get_network_views': [5033] 2021-06-04 11:16:22,773 [DEBUG] py4...: ǀǀCalling get_table_columns('node', ['name'], 'default', None, base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,773 [DEBUG] py4...: ǀǀǀCalling get_network_suid(None, 'http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,773 [DEBUG] py4...: ǀǀǀǀCalling commands_post('network get attribute network="current" namespace="default" columnList="SUID"', base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,773 [DEBUG] py4...: ǀǀǀǀHTTP POST(http://127.0.0.1:1234/v1/commands/network/get%20attribute), json: {'network': 'current', 'namespace': 'default', 'columnList': 'SUID'} 2021-06-04 11:16:22,799 [DEBUG] py4...: ǀǀǀǀOK[200], content: { "data": [ { "SUID": 4317 } ], "errors":[] } 2021-06-04 11:16:22,799 [DEBUG] py4...: ǀǀǀǀReturning 'commands_post': [{'SUID': 4317}] 2021-06-04 11:16:22,799 [DEBUG] py4...: ǀǀǀReturning 'get_network_suid': 4317 2021-06-04 11:16:22,799 [DEBUG] py4...: ǀǀǀCalling get_table_column_types('node', namespace='default', network=None, base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,799 [DEBUG] py4...: ǀǀǀǀCalling get_network_suid(None, base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,799 [DEBUG] py4...: ǀǀǀǀǀCalling commands_post('network get attribute network="current" namespace="default" columnList="SUID"', base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,799 [DEBUG] py4...: ǀǀǀǀǀHTTP POST(http://127.0.0.1:1234/v1/commands/network/get%20attribute), json: {'network': 'current', 'namespace': 'default', 'columnList': 'SUID'} 2021-06-04 11:16:22,825 [DEBUG] py4...: ǀǀǀǀǀOK[200], content: { "data": [ { "SUID": 4317 } ], "errors":[] } 2021-06-04 11:16:22,825 [DEBUG] py4...: ǀǀǀǀǀReturning 'commands_post': [{'SUID': 4317}] 2021-06-04 11:16:22,825 [DEBUG] py4...: ǀǀǀǀReturning 'get_network_suid': 4317 2021-06-04 11:16:22,825 [DEBUG] py4...: ǀǀǀǀCalling cyrest_get('networks/4317/tables/defaultnode/columns', base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,825 [DEBUG] py4...: ǀǀǀǀHTTP GET(http://127.0.0.1:1234/v1/networks/4317/tables/defaultnode/columns) 2021-06-04 11:16:22,857 [DEBUG] py4...: ǀǀǀǀOK[200], content: [{"name":"SUID","type":"Long","immutable":true,"primaryKey":true}, {"name":"shared name","type":"String","immutable":true,"primaryKey":false}, ... {"name":"isExcludedFromPaths","type":"Boolean","immutable":false,"primaryKey":false}] 2021-06-04 11:16:22,857 [DEBUG] py4...: ǀǀǀǀReturning 'cyrest_get': [{'name': 'SUID', 'type': 'Long', 'immutable': True, 'primaryKey': True}, {'name': 'shared name', 'type': 'String', 'immutable': True, 'primaryKey': False}, ..., {'name': 'isExcludedFromPaths', 'type': 'Boolean', 'immutable': False, 'primaryKey': False}] 2021-06-04 11:16:22,857 [DEBUG] py4...: ǀǀǀReturning 'get_table_column_types': {'SUID': 'Long', 'shared name': 'String', 'name': 'String', ..., 'isExcludedFromPaths': 'Boolean'} 2021-06-04 11:16:22,857 [DEBUG] py4...: ǀǀǀCalling cyrest_get('networks/4317/tables/defaultnode/columns/SUID', base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,857 [DEBUG] py4...: ǀǀǀHTTP GET(http://127.0.0.1:1234/v1/networks/4317/tables/defaultnode/columns/SUID) 2021-06-04 11:16:22,874 [DEBUG] py4...: ǀǀǀOK[200], content: {"name":"SUID","values":[4608,4609,...,4607]} 2021-06-04 11:16:22,874 [DEBUG] py4...: ǀǀǀReturning 'cyrest_get': {'name': 'SUID', 'values': [4608, 4609, ..., 4607]} 2021-06-04 11:16:22,874 [DEBUG] py4...: ǀǀǀCalling cyrest_get('networks/4317/tables/defaultnode/columns/name', base_url='http://127.0.0.1:1234/v1') 2021-06-04 11:16:22,874 [DEBUG] py4...: ǀǀǀHTTP GET(http://127.0.0.1:1234/v1/networks/4317/tables/defaultnode/columns/name) 2021-06-04 11:16:22,896 [DEBUG] py4...: ǀǀǀOK[200], content: {"name":"name","values":["YER074W","YBR093C",......,"YIL069C"]} 2021-06-04 11:16:22,896 [DEBUG] py4...: ǀǀǀReturning 'cyrest_get': {'name': 'name', 'values': ['YER074W', 'YBR093C', ..., 'YIL069C']} 2021-06-04 11:16:22,931 [DEBUG] py4...: ǀǀReturning 'get_table_columns': name 4608 YER074W 4609 YBR093C ... 4606 YOL127W 4607 YIL069C

[330 rows x 1 columns] 2021-06-04 11:16:22,947 [DEBUG] py4...: ǀǀCalling cyrest_put('networks/4317/views/5033/nodes', parameters={'bypass': True}, body=[{'SUID': '4566', 'view': [{'visualProperty': 'NODE_BORDER_PAINT', 'value': '#2AFFD8'}]}, {'SUID': '4614', 'view': [{'visualProperty': 'NODE_BORDER_PAINT', 'value': '#2AFFD8'}]}, {'SUID': '4619', 'view': [{'visualProperty': 'NODE_BORDER_PAINT', 'value': '#2AFFD8'}]}, {'SUID': '4440', 'view': [{'visualProperty': 'NODE_BORDER_PAINT', 'value': '#2AFFD8'}]}], base_url='http://127.0.0.1:1234/v1', require_json=False) 2021-06-04 11:16:22,947 [DEBUG] py4...: ǀǀHTTP PUT(http://127.0.0.1:1234/v1/networks/4317/views/5033/nodes), params: {'bypass': True}, json: [{'SUID': '4566', 'view': [{'visualProperty': 'NODE_BORDER_PAINT', 'value': '#2AFFD8'}]}, {'SUID': '4614', 'view': [{'visualProperty': 'NODE_BORDER_PAINT', 'value': '#2AFFD8'}]}, {'SUID': '4619', 'view': [{'visualProperty': 'NODE_BORDER_PAINT', 'value': '#2AFFD8'}]}, {'SUID': '4440', 'view': [{'visualProperty': 'NODE_BORDER_PAINT', 'value': '#2AFFD8'}]}] 2021-06-04 11:16:23,081 [DEBUG] py4...: ǀǀOK[200], content: 2021-06-04 11:16:23,081 [DEBUG] py4...: ǀǀReturning 'cyrest_put': '' 2021-06-04 11:16:23,081 [DEBUG] py4...: ǀReturning 'set_node_property_bypass': '' 2021-06-04 11:16:23,081 [DEBUG] py4...: Returning 'set_node_border_color_bypass': '' 2021-06-04 11:16:23,081 [DEBUG] py4...: --------------------

StefanR-github commented 3 years ago

Thank you for your reply!

I am using Anaconda (v.1.10.0), Cytoscape (v.3.8.2), Jupyter Notebooks (v. 2.2.6) and py4cytoscape (v.0.0.8) and a Windows 10 laptop. All apps are updated in Cytoscape.

I will try out the sanity test and Cytoscape nightly build 3.9.0 right now.

I have made a google drive folder that includes my code in the google colab file. In the folder there is also the log, datafile and cytoscape file.

StefanR-github commented 3 years ago

Fixed

I tried using the suggested sanity test. This one I used: https://github.com/bdemchak/cytoscape-jupyter/tree/main/sanity-test

This repository already gave an error at the code : p4c.cytoscape_version_info()

A similar cy_rest() error. I reinstalled the FileTransfer App in cytoscape. The sanity test also reinstalled my py4cytoscape version. It went from version v.0.0.8. to v.0.0.9.

I think reinstalling py4cytoscape or reinstalling the FileTransfer App or both have somehow fixed the problem.

p4c.set_node_border_color_bypass(col_one_list,'#2AFFD8') Now works correctly

bdemchak commented 3 years ago

Nice ... thanks! I don't know what the problem was, and I'm glad it's gone. I can imagine something like this coming up with other users, and I'll suggest your path. Still, it nags at me that this happened at all, and I apologize for your lost time. I'll be watchful for possible issues of this sort.

bdemchak commented 3 years ago

@StefanR-github Hi, Stefan ... I have taken a look at your notebook, and I like what I see ... thanks for exercising these functions. Would you be interested in a few observations about it? I have a few thoughts that might make your life a little easier.