예제 #1
0
class Network:
    """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=()):
        """Initialize a new Network object."""
        self.__graph = MultiGraph(species)

    def __repr__(self):
        """Return a debugging string representation of this network."""
        return "<Network: __graph: " + repr(self.__graph) + ">"

    def __str__(self):
        """Return a string representation of this network."""
        return "Network of %i species and %i interactions." % (
            len(self.species()),
            len(self.interactions()),
        )

    def add_species(self, species):
        """Add species to this network."""
        self.__graph.add_node(species)

    def add_interaction(self, source, sink, interaction):
        """Add interaction to this network."""
        self.__graph.add_edge(source, sink, interaction)

    def source(self, species):
        """Return list of unique sources for species."""
        return self.__graph.parents(species)

    def source_interactions(self, species):
        """Return list of (source, interaction) pairs for species."""
        return self.__graph.parent_edges(species)

    def sink(self, species):
        """Return list of unique sinks for species."""
        return self.__graph.children(species)

    def sink_interactions(self, species):
        """Return list of (sink, interaction) pairs for species."""
        return self.__graph.child_edges(species)

    def species(self):
        """Return list of the species in this network."""
        return self.__graph.nodes()

    def interactions(self):
        """Return list of the unique interactions in this network."""
        return self.__graph.labels()
예제 #2
0
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=()):
        """Initialize a new Network object."""
        self.__graph = MultiGraph(species)

    def __repr__(self):
        """Return a debugging string representation of this network."""
        return "<Network: __graph: " + repr(self.__graph) + ">"

    def __str__(self):
        """Return 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):
        """Add species to this network."""
        self.__graph.add_node(species)

    def add_interaction(self, source, sink, interaction):
        """Add interaction to this network."""
        self.__graph.add_edge(source, sink, interaction)

    def source(self, species):
        """Return list of unique sources for species."""
        return self.__graph.parents(species)

    def source_interactions(self, species):
        """Return list of (source, interaction) pairs for species."""
        return self.__graph.parent_edges(species)

    def sink(self, species):
        """Return list of unique sinks for species."""
        return self.__graph.children(species)

    def sink_interactions(self, species):
        """Return list of (sink, interaction) pairs for species."""
        return self.__graph.child_edges(species)

    def species(self):
        """Return list of the species in this network."""
        return self.__graph.nodes()

    def interactions(self):
        """Return list of the unique interactions in this network."""
        return self.__graph.labels()
예제 #3
0
 def test_Nodes(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')
     self.assertEqual(sorted(a.nodes()), ['a', 'b'], "second node not added")
예제 #4
0
 def test_Nodes(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")
     self.assertEqual(sorted(a.nodes()), ["a", "b"], "second node not added")
예제 #5
0
 def test_Nodes(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')
     self.assertEqual(sorted(a.nodes()), ['a', 'b'],
                      "second node not added")