On Jul 24, 2009, at 5:49 PM, Kenny Daily wrote:
> So I guess I understand that. However, what I mean is what is your
> method for looking up the correct edge to put in the graph? Defining
> the contents of the edgeDB means that you already know the nodes and
> the relationships between them. So, in the code leading up to the
> assignment of an edge between two nodes, how do you get the right
> edge? It seems that there is some other data structure (a dictionary
> that takes a pair of exons, for example) to look up the right edge in
> the edgeDB that is assigned to G[exon1][exon2]:
>
> some_edge = some_edge_dict[(exon1, exon2)] # where this returns an
> object from edgeDB
> G[exon1][exon2] = some_edge
Hi Kenny,
of course you can load your data in various ways, but for storing a
many-to-many graph in a relational schema, the edge table is generally
the one that really represents the graph (i.e. a row in the edge table
represents an edge between a pair of nodes). For example, to store an
alternative splicing graph, we have a table representing exons
(nodes), and a table representing splices (edges). Each edge object
(row) has a source_exon_id and target_exon_id. So to construct the
Graph we do something like the following:
for splice in spliceDB:
exon1 = exonDB[splice.source_exon_id]
exon2 = exonDB[splice.target_exon_id]
graph += exon1 # add source node
graph[exon1][exon2] = splice # add edge
Once constructed, the Graph object serves the need that you
hypothesized above as "some_edge_dict", but it also lets you do a lot
more. That is, whereas some_edge_dict can only be queried with a pair
of exons (exon1,exon2) to get the edge object, the Graph can also be
queried with exon1, e.g. to ask if exon1 is in graph, or to find its
specific set of target nodes exon2:
for exon2 in graph[exon1]:
do something...
Or we can iterate over all (source) nodes in the graph:
for exon1 in graph:
do something...
More importantly, Graph is designed for transparent persistence...
-- Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pygr-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pygr-dev?hl=en
-~----------~----~----~----~------~----~------~--~---