cytoscape / py4cytoscape

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

Clear the label rotation bypass #117

Closed gmhhope closed 1 year ago

gmhhope commented 1 year ago

Hi Barry,

I have to reopen this as I still want to figure out how to clear the bypass of node label...

Trying to reset the wrongly assigned rotation/label. See the following screenshot:

Screenshot 2023-08-30 at 6 17 12 PM

Here is my command:

node_names = list(p4c.get_table_columns(columns='name')['name'])
p4c.clear_node_property_bypass(node_names = node_names,visual_property='NODE_LABEL_POSITION')

But this gives me an error:

In cyrest_delete(): Bypass Visual Property does not exist: NODE_LABEL_POSITION
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File ~/mambaforge/envs/yoda/lib/python3.11/site-packages/py4cytoscape/commands.py:109, in cyrest_delete(operation, parameters, base_url, require_json)
    108 r = _do_request('DELETE', url, params=parameters, base_url=base_url)
--> 109 r.raise_for_status()
    110 try:

File ~/mambaforge/envs/yoda/lib/python3.11/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
   1020 if http_error_msg:
-> 1021     raise HTTPError(http_error_msg, response=self)

HTTPError: 404 Client Error: Not Found for url: http://127.0.0.1:1234/v1/networks/2221/views/2673/nodes/2306/NODE_LABEL_POSITION/bypass

During handling of the above exception, another exception occurred:

CyError                                   Traceback (most recent call last)
Cell In[299], line 2
      1 node_names = list(p4c.get_table_columns(columns='name')['name'])
----> 2 p4c.clear_node_property_bypass(node_names = node_names,visual_property='NODE_LABEL_POSITION')

File ~/mambaforge/envs/yoda/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 ~/mambaforge/envs/yoda/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 ~/mambaforge/envs/yoda/lib/python3.11/site-packages/py4cytoscape/style_bypasses.py:219, in clear_node_property_bypass(node_names, visual_property, network, base_url)
    217 else:
    218     for suid in node_suids:
--> 219         res = commands.cyrest_delete(f'networks/{net_suid}/views/{view_suid}/nodes/{suid}/{visual_property}/bypass',
    220                                      base_url=base_url)
    222 return res

File ~/mambaforge/envs/yoda/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 ~/mambaforge/envs/yoda/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 ~/mambaforge/envs/yoda/lib/python3.11/site-packages/py4cytoscape/commands.py:118, in cyrest_delete(operation, parameters, base_url, require_json)
    116             return r.text
    117 except requests.exceptions.RequestException as e:
--> 118     _handle_error(e)

File ~/mambaforge/envs/yoda/lib/python3.11/site-packages/py4cytoscape/commands.py:683, in _handle_error(e, force_cy_error)
    681     else:
    682         show_error(f'In {caller}: {e}\n{content}')
--> 683 raise e

CyError: In cyrest_delete(): Bypass Visual Property does not exist: NODE_LABEL_POSITION

I just have some crunching time and cannot plunge myself to look for answers from what you told me about all the other alternatives.

Hope you can help!

Best, Minghao

Originally posted by @gmhhope in https://github.com/cytoscape/py4cytoscape/issues/111#issuecomment-1699922286

bdemchak commented 1 year ago

Hi --

Fair question ...

I think the problem you're running into is that some nodes have the bypass and some don't. And when Cytoscape is asked to clear a bypass that doesn't exist, it gives an error.

Both py4cytoscape and RCy3 require a list of nodes for the bypass clear. It loops through the nodes, but if there's an error, it terminates the loop.

So, it will clear bypasses until it finds one that doesn't exist.

One could argue that Cytoscape shouldn't throw an error, as the end state is what the caller intends.

One could make the same point about py4cytoscape and RCy3.

At this point, though, you have two choices:

1) attempt to clear only bypasses you have set

2) get this behavior changed in py4cytoscape and RCy3

If #1 is convenient, I'd take it.

If you'd rather take #2, I can float this to the group, but can't guarantee the result or time frame. If the group can quickly agree, I can make this change in hours. However, on a Labor Day weekend, I'm not sure that agreement would be quick.

Sorry that I can't give a better answer, but it's actionable at least.