Reverse Symmetric Graph#

Graph#

class RevSymGraph#

Reverse symmetric graph class.

This graph is considering each orientation for all vertices and for all edges. It can contain several weakly connected components, which can contain only one strand or both merged.

Methods:

attr(attrname)

Return the value associated to attribute attrname.

attrs()

Return the dictionnary of all attributes.

edges()

Return the edge container.

is_attr(attrname)

Return True if there is an attribute called attrname.

set_attr(attrname, attrvalue)

Change the value of the attributes else create them.

vertices()

Return the vertices container.

attr(attrname)#

Return the value associated to attribute attrname.

Parameters:

attrname (str) – Attribute’s name

Returns:

Attribute value corresponding to the attribute name

Return type:

Any

Raises:

NoGraphAttribute – When there is no attribute key

attrs()#

Return the dictionnary of all attributes.

Returns:

Dictionnary of attribute name as key and their value

Return type:

dict

edges()#

Return the edge container.

Returns:

Edges container

Return type:

Edges

is_attr(attrname)#

Return True if there is an attribute called attrname.

Parameters:

attrname (str) – Attribute’s name answered

Returns:

If there is an attribute called attrname

Return type:

bool

set_attr(attrname, attrvalue)#

Change the value of the attributes else create them.

Parameters:
  • attrname (str) – Attribute’s name

  • attrvalue (Any) – Attribute’s value

vertices()#

Return the vertices container.

Returns:

Vertices container

Return type:

Vertices

Vertices Container#

class Vertices#

Vertices container class for both vertices’ orientations.

For each raw read \(r \in \mathcal{R_{aw}}\) there is one vertex for each orientation \(v \in V\) and \(\bar{v} \in V\).

Warning

You must not instantiate a Vertices object. Use it only for typing or get an already instanciated object.

Methods:

__contains__(vertex_index)

Return True if vertex index is in container, else False.

__iter__()

Iterate on oriented vertices.

__len__()

Return the number of oriented vertices.

add([number])

Add vertices to vertices container.

attr(vertex_index, attrname)

Return the value associated to vertex attribute attrname.

attrs(vertex_index)

Iterate over all vertex's attributes.

card_index()

Returns the number of distinct indices.

delete(vertex_index)

Remove vertex from vertices container.

delete_several(vertex_indices)

Remove vertices from vertices container.

new_attr(attrname, default)

Add an attribute entry.

set_attr(vertex_index, attrname, attrvalue)

Change the value of the attributes else create them.

__contains__(vertex_index)#

Return True if vertex index is in container, else False.

Parameters:

vertex_index (IndexT) – Vertex index

Returns:

True if oriented vertex is in container, else False

Return type:

bool

__iter__()#

Iterate on oriented vertices.

Yields:

IndOrT – Oriented vertices

__len__()#

Return the number of oriented vertices.

Returns:

Number of oriented vertices

Return type:

int

add(number=1)#

Add vertices to vertices container.

Parameters:

number (int, default 1) – Number of vertices to add

Returns:

Last vertex’s index (non-oriented)

Return type:

IndexT

attr(vertex_index, attrname)#

Return the value associated to vertex attribute attrname.

Parameters:
  • vertex_index (IndexT) – Vertex’s index

  • attrname (str) – Attribute name

Returns:

Attribute value corresponding to the attribute name

Return type:

Any

Raises:
attrs(vertex_index)#

Iterate over all vertex’s attributes.

Parameters:

vertex_index (IndexT) – Vertex’s index

Yields:
  • str – Attribute’s name

  • Any – Attribute’s value

Raises:

NoVertexIndex – If there is no vertex index

card_index()#

Returns the number of distinct indices.

Note

The cardinality of indices set \(V_{ind}\) is equal to \(|V_{ind}|\)

Returns:

Number of distinct indices

Return type:

int

delete(vertex_index)#

Remove vertex from vertices container.

Parameters:

vertex_index (IndexT) – Vertex to delete

Raises:

NoVertexIndex – If vertex does not exist

Warning

This operation may invalidate vertex indices. In fact, deleting one vertex implies shifting all next indices. Because of this, keys should always be removed in decreasing index order:

>>> for vertex in sorted(vertices_to_del, reverse=True):
>>>     graph.vertices().delete(vertex)

Note

All next vertex indices are decreased in edges they belong. But concerned edges’ indices are not.

delete_several(vertex_indices)#

Remove vertices from vertices container.

Parameters:

vertex_indices (iterable of IndexT) – Vertices to delete

Raises:

NoVertexIndex – If one vertex does not exist

Warning

This operation may invalidate vertex indices. In fact, deleting one vertex implies shifting all next indices.

Notes

At the oposite of delete() method, it is not necessary to sort vertex_indices. This is done internally.

All next vertex indices are decreased in edges they belong. But concerned edges’ indices are not.

new_attr(attrname, default)#

Add an attribute entry.

Parameters:
  • attrname (str) – Attribute’s name

  • default (Any) – Default attribute value

Note

Before setting attribute to one vertex, it is necessary to add an attribute entry using this method.

set_attr(vertex_index, attrname, attrvalue)#

Change the value of the attributes else create them.

Parameters:
  • vertex_index (IndexT) – Vertex’s index

  • attrname (str) – Attribute’s name

  • attrvalue (Any) – Attribute’s value

Raises:

Note

Be sure having added an attribute entry using the method new_attr()

Edges Container#

class Edges#

Edges container class for both edges’ orientations.

For each overlap \(o \in \mathcal{O}\), there are two edges \(e \in E\) and \(\bar{e} \in E\) i.e. one for both orientations.

Warning

You must not call this class. Use it only for typing or get an already existing object.

Methods:

__contains__(edge)

Return True if the oriented edge is in edges container.

__iter__()

Iterate on oriented edges with edge index.

__len__()

Return the number of oriented edges.

add(first_vertex, second_vertex)

Add an edge to edges container.

attr(edge_index, attrname)

Return the edge attribute attrname.

attrs(edge_index)

Iterate over all edge's attributes.

biggest_edge_index()

Return the biggest edge index.

delete(first_vertex, second_vertex, edge_index)

Remove the edge.

eindor_to_eind(first_vertex, second_vertex)

Iterate over edge indices from oriented edge.

neighbours(vertex)

Return the generator of vertex's adjacencies vertices.

new_attr(attrname, default)

Add an attribute entry.

preds(vertex)

Iterate over vertex's predecessors.

set_attr(edge_index, attrname, attrvalue)

Change the value of one attribute.

succs(vertex)

Iterate over vertex's successors.

__contains__(edge)#

Return True if the oriented edge is in edges container.

Parameters:

edge (EIndOrT) – Oriented edge

Returns:

Oriented edges in edges container

Return type:

bool

__iter__()#

Iterate on oriented edges with edge index.

Yields:

EIndOrIndT – Oriented edges with their edge index

__len__()#

Return the number of oriented edges.

Returns:

Number of oriented edges

Return type:

int

Notes

\(\forall e \in E, \bar{e} \in E\)

add(first_vertex, second_vertex)#

Add an edge to edges container.

Parameters:
  • first_vertex (IndOrT) – First oriented vertex

  • second_vertex (IndOrT) – Second oriented vertex

Returns:

Edge index

Return type:

IndexT

Raises:

NoVertexIndex – If one vertex does not exist

Notes

Edges container contains the two orientations of each edge i.e. \(\forall e \in E, \bar{e} \in E\)

attr(edge_index, attrname)#

Return the edge attribute attrname.

Parameters:
  • edge_index (IndexT) – Edge’s index

  • attrname (str) – Attribute name

Returns:

Attribute value

Return type:

Any

Raises:

Note

A removed edge still have a recorded attribute.

attrs(edge_index)#

Iterate over all edge’s attributes.

Parameters:

edge_index (IndexT) – Edge’s index

Yields:
  • str – Attribute’s name

  • Any – Attribute’s value

Raises:

NoEdgeIndex – If there is no edge index

Note

A removed edge still have a recorded attribute.

biggest_edge_index()#

Return the biggest edge index.

Returns:

The biggest edge index

Return type:

int

Notes

The number of distinct edges indices is equal to the biggest edge index plus one.

delete(first_vertex, second_vertex, edge_index)#

Remove the edge.

Parameters:
  • first_vertex (IndOrT) – First oriented vertex

  • second_vertex (IndOrT) – Second oriented vertex

  • edge_index (IndexT) – Edge’s index

Raises:
  • NoVertexIndex – If vertex does not exist

  • NoEdge – If there is no recorded edge with these vertices and this index

Note

When deleting, the edge is replacing by the last one in adjancy list, and the last element of the adjancy list is removed.

Warning

As :class::revsymg.graphs.Edges has the reverse symmetry property, removing one orientation of an edge has the consequence of removing the other orientation i.e. \(\forall e \in E, \bar{e} \notin E \setminus \{e\}\)

eindor_to_eind(first_vertex, second_vertex)#

Iterate over edge indices from oriented edge.

Parameters:
  • first_vertex (IndOrT) – First oriented vertex

  • second_vertex (IndOrT) – Second oriented vertex

Yields:

IndexT – Edge index

Raises:

NoVertexIndex – One of the vertex in edge does not exist

neighbours(vertex)#

Return the generator of vertex’s adjacencies vertices.

Parameters:

vertex (IndOrT) – Oriented vertex

Yields:

IndOrIndT – Oriented neighbouring vertices with edge index

Raises:

NoVertexIndex – If vertex does not exist

new_attr(attrname, default)#

Add an attribute entry.

Parameters:
  • attrname (str) – Attribute’s name

  • default (Any) – Default attribute value

Note

Before setting attribute to one edge, it is necessary to add an attribute entry using this method.

preds(vertex)#

Iterate over vertex’s predecessors.

Parameters:

vertex (IndOrT) – Oriented vertex

Yields:

IndOrIndT – Predecessor oriented vertex with edge index

Raises:

NoVertexIndex – If vertex does not exist

set_attr(edge_index, attrname, attrvalue)#

Change the value of one attribute.

Parameters:
  • edge_index (IndexT) – Edge’s index

  • attrname (str) – Attribute’s name

  • attrvalue (Any) – Attribute’s value

Raises:

Note

Be sure having added an attribute entry using the method new_attr()

succs(vertex)#

Iterate over vertex’s successors.

Parameters:

vertex (IndOrT) – Oriented vertex

Yields:

IndOrIndT – Successor oriented vertex with edge index

Raises:

NoVertexIndex – If vertex does not exist