allpy
view allpy/graph.py @ 1091:afed1fd8920c
Added backreferences to `Seqeunce`s from `Monomer`s (closes #49)
WARNING! Please note that `Sequence` API almost changed entirely!
WARNING! This commit immediately obsoletes classmethods `Monomer.from_code*`,
`Monomer.from_name` and `Sequence.from_monomers`.
Turns out, python can not pickle sets/dicts which have keys, which inderecly
reference the set/dict itself: http://bugs.python.org/issue9269 -- which is
excatly what we have in abundance after this change.
To allow pickling added `__getstate__` to `Monomer` to return all attributes,
except `sequence` and `__setstate__` to `Sequence`, which runs through all
monomers and returns the `sequence` attribute back to where it belongs.
WARNING! This MAY result in unexpected behaviour in some cases. (Which should
be rare enough).
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Sat, 02 Jun 2012 19:33:42 +0400 |
parents | 53690e470eff |
children |
line source
7 pass
10 """ Undirected weighted graph
12 graph[vertex1][vertex2] = weight
13 * vertex1 != vertex2 (no such edges)
14 * weight is float in (0, 1] or 1 (if all edges are equal)
15 * symmetrical
17 Features:
18 * this graph cannot contain vertices without any edges
20 >>> config.debug = True
21 >>> g = Graph()
22 >>> g.set_edge(1, 2)
23 >>> g.fast_cliques()
24 Fast algorithm started
25 [frozenset([1, 2])]
26 >>> g.set_edge(2, 3)
27 >>> g.set_edge(1, 3)
28 >>> g.fast_cliques()
29 Fast algorithm started
30 [frozenset([1, 2, 3])]
31 >>> g.bron_kerbosch()
32 Bron and Kerbosch algorithm started
33 [frozenset([1, 2, 3])]
34 >>> g.cliques()
35 Bron and Kerbosch algorithm started
36 [frozenset([1, 2, 3])]
38 """
56 """ Remove vertex and all involved edges """
64 """ Returns sum of weights of all connections of this vertex """
71 """ Add vertex and corresponding edges from parent_graph
73 Added edges should be contained in self graph
74 (takes care of hanging edges)
75 """
81 """ Deprecated. Use bron_kerbosch() instead """
85 """ Bron and Kerbosch algorithm implementation
87 returns list of cliques
88 clique is frozenset
89 if timeout=-1, it means infinity
90 if timeout has happened, raises TimeoutError
91 """
105 """ return some v from candidates """
109 """ if v from used connected with all from candidates """
113 break
119 """ process call and return list of recursive calls """
151 """ drop vertices untill self becomes a clique """
165 """ add vertices untill self becomes a nonextendible clique """
177 break
187 """ returns list of cliques
189 clique is frozenset
190 """
201 break
208 break
212 """ return list of connected components, remove single vertices """
232 """ returns length-sorted list of cliques
234 clique is frozenset
236 try to execute bron_kerbosch
237 if it raises TimeoutError, executes fast_cliques
238 """