py4cytoscape.style_mappings.map_visual_property

map_visual_property(visual_prop, table_column, mapping_type, table_column_values=[], visual_prop_values=[], network=None, base_url='http://127.0.0.1:1234/v1')[source]

Create a mapping between an attribute and a visual property.

Generates the appropriate data structure for the “mapping” parameter in update_style_mapping().

The paired list of values must be of the same length or mapping will fail. For gradient mapping, you may include two additional visual_prop_values in the first and last positions to map respectively to values less than and greater than those specified in table_column_values. Mapping will also fail if the data type of table_column_values does not match that of the existing table_column. Note that all imported numeric data are stored as Integers or Doubles in Cytosacpe tables; and character or mixed data are stored as Strings.

Parameters
  • visual_prop (str) – name of visual property to map

  • table_column (str) – name of table column to map

  • mapping_type (str) – continuous, discrete or passthrough (c,d,p)

  • table_column_values (list) – list of values paired with visual_prop_values; skip for passthrough mapping

  • visual_prop_values (list) – list of values paired with table_column_values; skip for passthrough mapping

  • network (SUID or str or None) – Name or SUID of a network. Default is the “current” network active in Cytoscape.

  • base_url (str) – Ignore unless you need to specify a custom domain, port or version to connect to the CyREST API. Default is http://127.0.0.1:1234 and the latest version of the CyREST API supported by this version of py4cytoscape.

Returns

{‘mappingType’: type of mapping, ‘mappingColumn’: column to map, ‘mappingColumnType’: column data type, ‘visualProperty’: name of property, cargo}

Return type

dict

Raises
  • CyError – if network name or SUID doesn’t exist

  • requests.exceptions.RequestException – if can’t connect to Cytoscape or Cytoscape returns an error

Examples

>>> map_visual_property('node fill color', 'gal1RGexp', 'c', [-2.426, 0.0, 2.058], ['#0066CC', '#FFFFFF','#FFFF00'])
{'mappingType': 'continuous', 'mappingColumn': 'gal1RGexp', 'mappingColumnType': 'Double', 'visualProperty': 'NODE_FILL_COLOR', 'points': [{'value': -2.426, 'lesser': '#0066CC', 'equal': '#0066CC', 'greater': '#0066CC'}, {'value': 0.0, 'lesser': '#FFFFFF', 'equal': '#FFFFFF', 'greater': '#FFFFFF'}, {'value': 2.058, 'lesser': '#FFFF00', 'equal': '#FFFF00', 'greater': '#FFFF00'}]}
>>> map_visual_property('node fill color', 'gal1RGexp', 'c', [-2.426, 0.0, 2.058], ['#0066CC', 'white','yellow'])
{'mappingType': 'continuous', 'mappingColumn': 'gal1RGexp', 'mappingColumnType': 'Double', 'visualProperty': 'NODE_FILL_COLOR', 'points': [{'value': -2.426, 'lesser': '#0066CC', 'equal': '#0066CC', 'greater': '#0066CC'}, {'value': 0.0, 'lesser': '#FFFFFF', 'equal': '#FFFFFF', 'greater': '#FFFFFF'}, {'value': 2.058, 'lesser': '#FFFF00', 'equal': '#FFFF00', 'greater': '#FFFF00'}]}
>>> map_visual_property('node shape', 'degree.layout', 'd', [1, 2], ['ellipse', 'rectangle'])
{'mappingType': 'discrete', 'mappingColumn': 'degree.layout', 'mappingColumnType': 'Integer', 'visualProperty': 'NODE_SHAPE', 'map': [{'key': 1, 'value': 'ellipse'}, {'key': 2, 'value': 'rectangle'}]}
>>> map_visual_property('node label', 'COMMON', 'p')
{'mappingType': 'passthrough', 'mappingColumn': 'COMMON', 'mappingColumnType': 'String', 'visualProperty': 'NODE_LABEL'}

Note

For the return value, mapping type can be ‘continuous’, ‘discrete’ or ‘passthrough’. For the mappingColumn, the name of the column. For the mappingColumnType, the Cytoscape data type (Double, Integer, String, Boolean). For the visualProperty, the canonical name of the visual property. The cargo depends on the mapping type. For ‘continuous’, it’s a list of way points as ‘points’: [waypoint, waypoint, …] where a waypoint is {‘value’: a Double, ‘lesser’: a color, ‘equal’: a color, ‘greater’: a color}. For ‘discrete’, it’s a list of mappings as ‘map’: [key-value, key-value, …] where a key-value is {‘key’: column data value, ‘value’: value appropriate for visualProperty}.

See also

update_style_mapping(), get_visual_property_names()