Constants
Contains constants used by the NDEx2 Python Client
- ndex2.constants.ASPECT_ID = 'id'
Key for aspect ID
- ndex2.constants.ASPECT_VALUES = 'v'
Key for aspect values
- ndex2.constants.ATTR_DATATYPE = 'd'
Key for attribute data type
- ndex2.constants.ATTR_NAME = 'n'
Key for attribute name
- ndex2.constants.BOOLEAN_DATATYPE = 'boolean'
Boolean data type for CX
- ndex2.constants.CARTESIAN_LAYOUT_ASPECT = 'cartesianLayout'
Name of opaque aspect containing coordinates of nodes
"cartesianLayout": [ { "node": 0, "x": 25.0, "y": 50.0 }, { "node": 1, "x": -10.0, "y": -200.0 } ]
Note
Although the name implies a cartesian coordinate system, that is actually wrong. The Y access is inverted so lower values of Y are rendered higher on a graph. 0,0 is considered upper left corner, but negative values are allowed
- ndex2.constants.DOUBLE_DATATYPE = 'double'
Double data type for CX
- ndex2.constants.EDGES_ASPECT = 'edges'
Key for nodes attribute
- ndex2.constants.EDGE_ID = '@id'
Key for id of edge
- ndex2.constants.EDGE_INTERACTION = 'i'
Key for edge interaction
- ndex2.constants.EDGE_INTERACTION_EXPANDED = 'interaction'
Expanded key for edge interaction
- ndex2.constants.EDGE_SOURCE = 's'
Key for edge source
- ndex2.constants.EDGE_TARGET = 't'
Key for edge target
- ndex2.constants.INTEGER_DATATYPE = 'integer'
Integer data type for CX
- ndex2.constants.LAYOUT_NODE = 'node'
Key for node id in
CARTESIAN_LAYOUT_ASPECT
opaque aspect
- ndex2.constants.LAYOUT_X = 'x'
Key for X coordinate in
CARTESIAN_LAYOUT_ASPECT
opaque aspect
- ndex2.constants.LAYOUT_Y = 'y'
Key for Y coordinate in
CARTESIAN_LAYOUT_ASPECT
opaque aspect
- ndex2.constants.LAYOUT_Z = 'z'
Key for Z coordinate in
CARTESIAN_LAYOUT_ASPECT
opaque aspect
- ndex2.constants.LIST_OF_BOOLEAN = 'list_of_boolean'
List of Boolean data type for CX
- ndex2.constants.LIST_OF_DOUBLE = 'list_of_double'
List of Double data type for CX
- ndex2.constants.LIST_OF_INTEGER = 'list_of_integer'
List of Integer data type for CX
- ndex2.constants.LIST_OF_LONG = 'list_of_long'
List of Long data type for CX
- ndex2.constants.LIST_OF_STRING = 'list_of_string'
List of String data type for CX
- ndex2.constants.LONG_DATATYPE = 'long'
Long data type for CX
- ndex2.constants.NET_ATTR_NAME = 'n'
Key for network attribute name
- ndex2.constants.NET_ATTR_VALUE = 'v'
Key for network attribute value
- ndex2.constants.NODES_ASPECT = 'nodes'
Key for nodes attribute
- ndex2.constants.NODE_ATTR_DATATYPE = 'd'
Key for node attribute data type
- ndex2.constants.NODE_ATTR_NAME = 'n'
Key for node attribute name
- ndex2.constants.NODE_ATTR_PROPERTYOF = 'po'
Key for node property of
- ndex2.constants.NODE_ATTR_VALUE = 'v'
Key for node attribute value
- ndex2.constants.NODE_ID = '@id'
Key for id of node
- ndex2.constants.NODE_NAME = 'n'
Key for node name
- ndex2.constants.NODE_NAME_EXPANDED = 'name'
Expanded key for node name
- ndex2.constants.NODE_REPRESENTS = 'r'
Key for node represents
- ndex2.constants.STRING_DATATYPE = 'string'
String data type for CX
- ndex2.constants.VALID_ATTRIBUTE_DATATYPES = ['boolean', 'double', 'integer', 'long', 'string', 'list_of_boolean', 'list_of_double', 'list_of_integer', 'list_of_long', 'list_of_string']
List of valid attribute data types
Miscellaneous
- class ndex2.util.DataConverter[source]
Base class for subclasses that convert CX data types to/from native data types
- convert_value(value=None, datatype=None)[source]
Defines method to converts value from CX to native data type using datatype as a guide
- Parameters:
value (object) – Value to convert
datatype (str) – CX data type which is one of the following:
ndex2.constants.VALID_ATTRIBUTE_DATATYPES
- Raises:
NotImplementedError – Always raises this error cause subclasses should implement
- Returns:
Always raises
NotImplementedError
- class ndex2.util.PandasDataConverter[source]
Converts CX values to native Python data types via
PandasDataConverter.convert_value()
methodAdded in version 3.5.0.
- convert_value(value=None, datatype=None)[source]
Converts value parameter passed in to type based on value of datatype parameter passed in. This is used in data conversion by
to_pandas_dataframe()
Added in version 3.5.0.
Conversion rules for different values of datatype parameter:
STRING_DATATYPE
orNone
value is converted by
str
and returned
-
-
INTEGER_DATATYPE
orLONG_DATATYPE
LIST_OF_STRING
,LIST_OF_BOOLEAN
LIST_OF_DOUBLE
,LIST_OF_INTEGER
,LIST_OF_LONG
If value is NOT of type
list
then the value converted as if it’s datatype isSTRING_DATATYPE
. If value is a list, each element is converted as if it’s datatype isSTRING_DATATYPE
and values oflist
are converted to a comma delimitedstr
Example usage:
from ndex2.util import PandasDataConverter converter = PandasDataConverter() # converts number to type str res = converter.convert_value(123, 'string') # would output <class 'str'> print(type(res))
- class ndex2.client.DecimalEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Custom
json.JSONEncoder
that handlesnumpy.integer
,decimal.Decimal
, andbytes
that can appear in CX dataConstructor for JSONEncoder, with sensible defaults.
If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.
If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.
If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an RecursionError). Otherwise, no such check takes place.
If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.
If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.
If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.
If specified, separators should be an (item_separator, key_separator) tuple. The default is (’, ‘, ‘: ‘) if indent is
None
and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a
TypeError
.- default(o)[source]
Overrides default behavior by converting
numpy.integer
toint
,decimal.Decimal
tofloat
, andbytes
to ascii decodedstr
and defaults tojson.JSONEncoder()
for all other object types for o- Parameters:
o – object to convert
- Returns:
converted object o
Exceptions
- class ndex2.exceptions.NDExError[source]
Base Exception for all NDEx2 Python Client Exceptions
Warning
Many methods in this code base still incorrectly raise errors not derived from this base class
- class ndex2.exceptions.NDExUnauthorizedError[source]
Raised if unable to authenticate, either due to lack of or invalid credentials.
- class ndex2.exceptions.NDExUnsupportedCallError[source]
Raised if call is unsupported, for example a method that is only supported in 2.0+ of NDEx server is attempted against a server running 1.0