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:
- 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:
- 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 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.
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.
- __len__()#
Return the number of oriented vertices.
- Returns:
Number of oriented vertices
- Return type:
- add(number=1)#
Add vertices to vertices container.
- attr(vertex_index, attrname)#
Return the value associated to vertex attribute attrname.
- Parameters:
- Returns:
Attribute value corresponding to the attribute name
- Return type:
- Raises:
NoVertexIndex – If vertex does not exist
NoVerticesAttribute – If there is no attribute nammed like this for vertices
- attrs(vertex_index)#
Iterate over all vertex’s attributes.
- Parameters:
vertex_index (
IndexT
) – Vertex’s index- Yields:
- 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:
- 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
ofIndexT
) – 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.
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:
- Raises:
NoVerticesAttribute – If there is no attribute nammed like this for vertices
WrongAttributeType – Given value does not correspond to attribute’s type
NoVertexIndex – If there is no vertex index
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.
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.
- __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:
Notes
\(\forall e \in E, \bar{e} \in E\)
- add(first_vertex, second_vertex)#
Add an edge to edges container.
- Parameters:
- Returns:
Edge index
- Return type:
- 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:
- Returns:
Attribute value
- Return type:
- Raises:
NoEdgeIndex – If edge does not exist
NoEdgesAttribute – If there is no attribute name like this for edges
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:
- 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:
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:
- 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:
- 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.
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:
- Raises:
NoEdgesAttribute – If there is no attribute nammed like this for edges
WrongAttributeType – Given value does not correspond to attribute’s type
NoEdgeIndex – If there is no vertex index
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