comparison planemo/lib/python3.7/site-packages/networkx/generators/triads.py @ 1:56ad4e20f292 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:32:28 -0400
parents
children
comparison
equal deleted inserted replaced
0:d30785e31577 1:56ad4e20f292
1 # triads.py - generators for triad graphs
2 #
3 # Copyright 2015 NetworkX developers.
4 # Copyright 2011 Reya Group <http://www.reyagroup.com>
5 # Copyright 2011 Alex Levenson <alex@isnotinvain.com>
6 # Copyright 2011 Diederik van Liere <diederik.vanliere@rotman.utoronto.ca>
7 #
8 # This file is part of NetworkX.
9 #
10 # NetworkX is distributed under a BSD license; see LICENSE.txt for more
11 # information.
12 """Functions that generate the triad graphs, that is, the possible
13 digraphs on three nodes.
14
15 """
16 from networkx.classes import DiGraph
17
18 __all__ = ['triad_graph']
19
20 #: Dictionary mapping triad name to list of directed edges in the
21 #: digraph representation of that triad (with nodes 'a', 'b', and 'c').
22 TRIAD_EDGES = {'003': [],
23 '012': ['ab'],
24 '102': ['ab', 'ba'],
25 '021D': ['ba', 'bc'],
26 '021U': ['ab', 'cb'],
27 '021C': ['ab', 'bc'],
28 '111D': ['ac', 'ca', 'bc'],
29 '111U': ['ac', 'ca', 'cb'],
30 '030T': ['ab', 'cb', 'ac'],
31 '030C': ['ba', 'cb', 'ac'],
32 '201': ['ab', 'ba', 'ac', 'ca'],
33 '120D': ['bc', 'ba', 'ac', 'ca'],
34 '120U': ['ab', 'cb', 'ac', 'ca'],
35 '120C': ['ab', 'bc', 'ac', 'ca'],
36 '210': ['ab', 'bc', 'cb', 'ac', 'ca'],
37 '300': ['ab', 'ba', 'bc', 'cb', 'ac', 'ca']
38 }
39
40
41 def triad_graph(triad_name):
42 """Returns the triad graph with the given name.
43
44 Each string in the following tuple is a valid triad name::
45
46 ('003', '012', '102', '021D', '021U', '021C', '111D', '111U',
47 '030T', '030C', '201', '120D', '120U', '120C', '210', '300')
48
49 Each triad name corresponds to one of the possible valid digraph on
50 three nodes.
51
52 Parameters
53 ----------
54 triad_name : string
55 The name of a triad, as described above.
56
57 Returns
58 -------
59 :class:`~networkx.DiGraph`
60 The digraph on three nodes with the given name. The nodes of the
61 graph are the single-character strings 'a', 'b', and 'c'.
62
63 Raises
64 ------
65 :exc:`ValueError`
66 If `triad_name` is not the name of a triad.
67
68 See also
69 --------
70 triadic_census
71
72 """
73 if triad_name not in TRIAD_EDGES:
74 raise ValueError('unknown triad name "{}"; use one of the triad names'
75 ' in the TRIAD_NAMES constant'.format(triad_name))
76 G = DiGraph()
77 G.add_nodes_from('abc')
78 G.add_edges_from(TRIAD_EDGES[triad_name])
79 return G