本文整理汇总了Python中Bio.Pathway.Rep.MultiGraph.add_edge方法的典型用法代码示例。如果您正苦于以下问题:Python MultiGraph.add_edge方法的具体用法?Python MultiGraph.add_edge怎么用?Python MultiGraph.add_edge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bio.Pathway.Rep.MultiGraph
的用法示例。
在下文中一共展示了MultiGraph.add_edge方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Network
# 需要导入模块: from Bio.Pathway.Rep import MultiGraph [as 别名]
# 或者: from Bio.Pathway.Rep.MultiGraph import add_edge [as 别名]
class Network(object):
"""A set of species that are explicitly linked by interactions.
The network is a directed multigraph with labeled edges. The nodes in the graph
are the biochemical species involved. The edges represent an interaction between
two species, and the edge label is a reference to the associated Interaction
object.
Attributes:
None
"""
def __init__(self, species = []):
"""Initializes a new Network object."""
self.__graph = MultiGraph(species)
def __repr__(self):
"""Returns a debugging string representation of this network."""
return "<Network: __graph: " + repr(self.__graph) + ">"
def __str__(self):
"""Returns a string representation of this network."""
return "Network of " + str(len(self.species())) + " species and " + \
str(len(self.interactions())) + " interactions."
def add_species(self, species):
"""Adds species to this network."""
self.__graph.add_node(species)
def add_interaction(self, source, sink, interaction):
"""Adds interaction to this network."""
self.__graph.add_edge(source, sink, interaction)
def source(self, species):
"""Returns list of unique sources for species."""
return self.__graph.parents(species)
def source_interactions(self, species):
"""Returns list of (source, interaction) pairs for species."""
return self.__graph.parent_edges(species)
def sink(self, species):
"""Returns list of unique sinks for species."""
return self.__graph.children(species)
def sink_interactions(self, species):
"""Returns list of (sink, interaction) pairs for species."""
return self.__graph.child_edges(species)
def species(self):
"""Returns list of the species in this network."""
return self.__graph.nodes()
def interactions(self):
"""Returns list of the unique interactions in this network."""
return self.__graph.labels()
示例2: testRemoveNode
# 需要导入模块: from Bio.Pathway.Rep import MultiGraph [as 别名]
# 或者: from Bio.Pathway.Rep.MultiGraph import add_edge [as 别名]
def testRemoveNode(self):
a = MultiGraph(['a','b','c','d','e'])
a.add_edge('a','e','label1')
a.add_edge('b','e','label1')
a.add_edge('c','e','label2')
a.add_edge('d','e','label3')
a.add_edge('e','d','label4')
a.add_edge('a','b','label5')
a.remove_node('e')
b = MultiGraph(['a','b','c','d'])
b.add_edge('a','b','label5')
self.assertEqual(a, b)#, "incorrect node removal")
示例3: testEdges
# 需要导入模块: from Bio.Pathway.Rep import MultiGraph [as 别名]
# 或者: from Bio.Pathway.Rep.MultiGraph import add_edge [as 别名]
def testEdges(self):
a = MultiGraph(['a','b','c','d'])
a.add_edge('a','b','label1')
self.assertEqual(a.child_edges('a'), [('b','label1')], "incorrect child edges")
a.add_edge('a','b','label2')
l = a.child_edges('a')
l.sort()
self.assertEqual(l, [('b','label1'),('b','label2')], "incorrect child edges")
a.add_edge('b','a','label2')
self.assertEqual(a.parent_edges('a'), [('b','label2')], "incorrect parent edges")
a.add_edge('b','c','label3')
self.assertEqual(a.parent_edges('c'), [('b','label3')], "incorrect parent edges")
l = a.children('b')
l.sort()
self.assertEqual(l, ['a', 'c'], "incorrect children")
self.assertEqual(a.children('d'), [], "incorrect children for singleton")
self.assertEqual(a.parents('a'), ['b'], "incorrect parents")
示例4: testEquals
# 需要导入模块: from Bio.Pathway.Rep import MultiGraph [as 别名]
# 或者: from Bio.Pathway.Rep.MultiGraph import add_edge [as 别名]
def testEquals(self):
a = MultiGraph(['a','b','c'])
a.add_edge('a','b','label1')
a.add_edge('b','c','label1')
a.add_edge('b','a','label2')
b = MultiGraph(['a','b','c'])
self.assertNotEqual(a, b, "equal to similar nodes, no edges")
b.add_edge('a','b','label1')
self.assertNotEqual(a, b, "equal to similar nodes, edge subset")
b.add_edge('b','c','label1')
b.add_edge('b','a','label2')
self.assertEqual(a, b, "not equal to similar")
c = MultiGraph(['a','b','c'])
c.add_edge('a','b','label2')
c.add_edge('b','c','label2')
c.add_edge('b','a','label1')
self.assertNotEqual(a, c, "equal to similar with different labels")
self.assertNotEqual(c, MultiGraph(), "equal to empty graph")
self.assertEqual(MultiGraph(), MultiGraph(), "empty graph not equal to self")