cytoscape / cytoscape-automation

Collection of scripts that include programmatic io and control of Cytoscape
Creative Commons Zero v1.0 Universal
81 stars 58 forks source link

ipython example does not work with modern citoscape? #78

Open Kreijstal opened 2 months ago

Kreijstal commented 2 months ago

https://github.com/cytoscape/cytoscape-automation/blob/c938ab4dd06602e1c2075969e7ab6007bc9a7f4d/for-scripters/Python/Overview-of-py4cytoscape.ipynb#L284

I am using

{'apiVersion': 'v1',
 'cytoscapeVersion': '3.10.2',
 'automationAPIVersion': '1.9.0',
 'py4cytoscapeVersion': '1.9.0'}

and on that line I get the following error:

 ---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[~/scoop/apps/msys2/2023-01-27/tmp/ipykernel_22224/3096295504.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/tmp/ipykernel_22224/3096295504.py) in ?()
      1 from py4cytoscape import gen_node_color_map
      2 from py4cytoscape import gen_edge_arrow_map
----> 3 p4c.set_node_color_mapping(**gen_node_color_map('group', mapping_type='d', style_name=style_name)) #'d' means 'discrete' mapping
      4 p4c.set_edge_target_arrow_shape_mapping(**gen_edge_arrow_map('interaction', style_name=style_name))

[~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/py4cytoscape_logger.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/py4cytoscape_logger.py) in ?(*args, **kwargs)
    131             return log_return(func, value)
    132         except Exception as e:
    133             log_exception(func, e)
    134         finally:
--> 135             log_finally()

[~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/py4cytoscape_logger.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/py4cytoscape_logger.py) in ?(*args, **kwargs)
    131             return log_return(func, value)
    132         except Exception as e:
    133             log_exception(func, e)
    134         finally:
--> 135             log_finally()

[~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/style_auto_mappings.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/style_auto_mappings.py) in ?(table_column, palette, mapping_type, default_color, style_name, network, base_url)
    801 
    802     See Also:
    803         `Value Generators <https://py4cytoscape.readthedocs.io/en/0.0.9/concepts.html#value-generators>`_ in the Concepts section in the py4cytoscape User Manual.
    804     """
--> 805     return _gen_color_map('node', table_column, palette, mapping_type, default_color, style_name, network, base_url)

~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/style_auto_mappings.py in ?(table, table_column, palette, mapping_type, default_value, style_name, network, base_url)
   1446         else:
   1447             raise CyError(f'Palette dictionary does not contain entry for "{mapping_type}" mapping')
   1448 
   1449     if mapping_type == 'd':
-> 1450         return _gen_d_color_map(table, table_column, palette, default_value, style_name, network, base_url)
   1451     else:
   1452         return _gen_c_color_map(table, table_column, palette, default_value, style_name, network, base_url)

[~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/style_auto_mappings.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/style_auto_mappings.py) in ?(table, table_column, palette, default_value, style_name, network, base_url)
   1468 
   1469     if 'qualitative' not in palette_type:
   1470         narrate(f'Warning: {palette_func_name} is not a qualitative palette and may give poor results for a discrete mapping.')
   1471 
-> 1472     return _map_values(table, table_column, palette_func, 'colors', 'default_color', default_value, style_name, network, base_url)

[~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/style_auto_mappings.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/py4cytoscape/style_auto_mappings.py) in ?(table, table_column, scheme_func, value_name, default_name, default_value, style_name, network, base_url)
   1589             # df_values rows aren't left in a predictable order, so that means the color assignments will vary from
   1590             # run to run. To make this consistent and testable, we sort all values within the same frequency count.
   1591             # To do this, we turn the frequency series into a dataframe then sort first on frequency count and then
   1592             # on value.
-> 1593             df_freq = df_freq.to_frame().rename_axis('index').sort_values(by=[table_column, 'index'],
   1594                                                                           ascending=[True, True])
   1595 
   1596         # Create function to map from DataFrame type to Python type ... this is necessary because if

[~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/pandas/core/frame.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/pandas/core/frame.py) in ?(self, by, axis, ascending, inplace, kind, na_position, ignore_index, key)
   7168                 f"Length of ascending ({len(ascending)})"  # type: ignore[arg-type]
   7169                 f" != length of by ({len(by)})"
   7170             )
   7171         if len(by) > 1:
-> 7172             keys = [self._get_label_or_level_values(x, axis=axis) for x in by]
   7173 
   7174             # need to rewrap columns in Series to apply key function
   7175             if key is not None:

[~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/pandas/core/frame.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/pandas/core/frame.py) in ?(.0)
-> 7172         ...     key=lambda x: np.argsort(index_natsorted(df["time"]))

[~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/pandas/core/generic.py](http://localhost:8888/lab/tree/~/scoop/apps/msys2/2023-01-27/mingw64/lib/python3.11/site-packages/pandas/core/generic.py) in ?(self, key, axis)
   1907             values = self.xs(key, axis=other_axes[0])._values
   1908         elif self._is_level_reference(key, axis=axis):
   1909             values = self.axes[axis].get_level_values(key)._values
   1910         else:
-> 1911             raise KeyError(key)
   1912 
   1913         # Check for duplicates
   1914         if values.ndim > 1:

KeyError: 'group'