当前位置: 首页>>代码示例>>Python>>正文


Python MultiGraph.add_node方法代码示例

本文整理汇总了Python中Bio.Pathway.Rep.MultiGraph.add_node方法的典型用法代码示例。如果您正苦于以下问题:Python MultiGraph.add_node方法的具体用法?Python MultiGraph.add_node怎么用?Python MultiGraph.add_node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bio.Pathway.Rep.MultiGraph的用法示例。


在下文中一共展示了MultiGraph.add_node方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Network

# 需要导入模块: from Bio.Pathway.Rep import MultiGraph [as 别名]
# 或者: from Bio.Pathway.Rep.MultiGraph import add_node [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()
开发者ID:BingW,项目名称:biopython,代码行数:60,代码来源:__init__.py

示例2: testNodes

# 需要导入模块: from Bio.Pathway.Rep import MultiGraph [as 别名]
# 或者: from Bio.Pathway.Rep.MultiGraph import add_node [as 别名]
 def testNodes(self):
     a = MultiGraph()
     self.assertEqual(a.nodes(), [], "default graph not empty")
     a.add_node('a')
     self.assertEqual(a.nodes(), ['a'], "one node not added")
     a.add_node('a')
     self.assertEqual(a.nodes(), ['a'], "duplicate node added")
     a.add_node('b')
     l = a.nodes()
     l.sort()
     self.assertEqual(l, ['a', 'b'], "second node not added")
开发者ID:,项目名称:,代码行数:13,代码来源:


注:本文中的Bio.Pathway.Rep.MultiGraph.add_node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。