[Biopython-dev] interaction networks in biopython

Jake Feala jfeala at gmail.com
Mon Jun 4 17:55:11 UTC 2007

Michiel -

Thanks for the advice.  For consistency with Biopython parsers, I did
write an __init__.py for the module that contains a parse(f,format)
function to behave like you suggest.  I'll put the script up on the
website (http://cmrg.ucsd.edu/JakeFeala#software) with the others.

As for the create_network function, I think it is necessary to pass a
"directed" argument in order to create a Network object with the right
superclass.  (sorry this was not obvious from the usage example I
gave).  My Network objects inherit either a directed or undirected
graph class from the existing NetworkX package.  The code looks like

from networkx import XGraph,XDiGraph

def create_network(directed=False):
    """Generates Network object derived from a directed or undirected
NetworkX Graph class """
    if not directed:
        GraphClass = XGraph
        GraphClass = XDiGraph

    class Network(GraphClass):
        """Biological network based on NetworkX XGraph class.  This wrapper
        bundles biological annotations (from InteractionRecord) with the
        graph representation and offers compatibility with Biopython, SBML,
        and Cytoscape
        def __init__(self):
            """Initializes a new Network object."""
            self.__interaction_recs = {}

        def <rest of class definition>...

I tried to think of a better way to do this but this was the easiest I
could think of.  What I could do is add to parse(f,format) the
capability of choosing the type of GraphClass based on the input file
format, but I am afraid of taking away the flexibility of choosing to
treat directed links as undirected.  Any ideas?


On 6/2/07, Michiel de Hoon <mdehoon at c2b2.columbia.edu> wrote:
> Jake Feala wrote:
> > Here is an example that worked fine for me:
> >    from Network import *
> >    f = open(<GRID flat file from http://theBioGRID.org>)
> >    parser = GRIDIterator(f):
> >    net = create_network()
> >    net.load(parser)
> >
> To be more consistent with recent parsers in Biopython, this would be
> more appropriate:
>  >>> import Network
>  >>> f = open(<GRID flat file from http://theBioGRID.org>)
>  >>> net = Network.parse(f, format="GRID")
> Also, assuming that
>  >>> net = create_network()
> creates a NetworkObject representing an empty network, you could instead
> use the initialization function of Network objects. As in
>  >>> import Network
>  >>> net = Network.NetworkObject()
> For the example above, you might then also consider
>  >>> import Network
>  >>> f = open(<GRID flat file from http://theBioGRID.org>)
>  >>> net = Network.NetworkObject(f, format="GRID")
> instead of using "parse".
> I'm using "NetworkObject" here only as a placeholder to distinguish it
> from the Network module; there are probably better names.
> --Michiel.

More information about the Biopython-dev mailing list