corneto package#

Subpackages#

Module contents#

class corneto.Attr(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: str, Enum

Enum class representing predefined attribute names used in the Attributes class.

VALUE#

Represents the key for a value attribute.

EDGE_TYPE#

Represents the key for an edge type attribute.

SOURCE_ATTR#

Represents the key for a source attribute.

TARGET_ATTR#

Represents the key for a target attribute.

CUSTOM_ATTR#

Represents the key for a custom attribute.

VALUE = '__value'#
EDGE_TYPE = '__edge_type'#
SOURCE_ATTR = '__source_attr'#
TARGET_ATTR = '__target_attr'#
CUSTOM_ATTR = '__custom_attr'#
class corneto.EdgeType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: str, Enum

DIRECTED = 'directed'#
UNDIRECTED = 'undirected'#
class corneto.Attributes#

Bases: dict

A dictionary-based class to manage attributes.

Uses reserved attributes used by CORNETO Graphs.

set_attr(key, value)#

Set an attribute in the dictionary using an Attr key.

Parameters:
  • key (Attr) – The key for the attribute, represented as an Attr enum.

  • value (Any) – The value to assign to the key. If the value is an enum, its value is used.

Return type:

None

has_attr(key, value=None)#

Check if a given attribute exists in the dictionary, optionally with a specific value.

Parameters:
  • key (Attr) – The key for the attribute, represented as an Attr enum.

  • value (Optional[Any]) – The optional value to check for.

Returns:

True if the attribute exists and matches the value (if provided),

otherwise False.

Return type:

bool

get_attr(key, default=None)#

Retrieve the value of an attribute, or return a default value if not found.

Parameters:
  • key (Attr) – The key for the attribute, represented as an Attr enum.

  • default (Any) – The default value to return if the attribute does not exist.

Returns:

The value of the attribute, or the default value if not found.

Return type:

Any

class corneto.Graph(default_edge_type=EdgeType.DIRECTED, **kwargs)#

Bases: BaseGraph

Default Graph class with support for undirected, directed, parallel and hypergedes.

Parameters:
  • default_edge_type (EdgeType (default: <EdgeType.DIRECTED: 'directed'>)) – Default edge type EdgeType.

  • Examples

  • --------

  • corneto.Graph() (>>> graph =)

  • graph.add_edge(1 (>>>)

  • 2)

  • graph.plot() (>>>)

get_edge(index)#
Return type:

Tuple[FrozenSet[Any], FrozenSet[Any]]

Parameters:

index (int)

get_graph_attributes()#
Return type:

Attributes

extract_subgraph(vertices=None, edges=None)#
Parameters:
reverse()#

Create a new graph and reverse the direction of all edges in the graph.

Return type:

Graph

filter_graph(filter_vertex=None, filter_edge=None)#
Parameters:
copy()#
Return type:

Graph

static from_sif(sif_file, delimiter='\\t', has_header=False, discard_self_loops=True, column_order=[0, 1, 2])#
Parameters:
  • sif_file (str)

  • delimiter (str)

  • has_header (bool)

  • discard_self_loops (bool | None)

  • column_order (List[int])

static from_sif_tuples(tuples)#
Parameters:

tuples (Iterable[Tuple])

static from_cobra_model(model)#
Parameters:

model (CobraModel)

static from_miom_model(model)#
corneto.info()#
corneto.available_backends()#