GOXGraph.py

Go to the documentation of this file.
00001 ## \package GOXGraph A weighted undirected graph representation of the Gene Ontology.
00002 # \author Brian Muller <mullerb@musc.edu>      
00003 
00004 from networkx.xgraph import XGraph
00005 from GOGraphBase import GOGraphBase
00006 import Aspects
00007 import DOMLight
00008 
00009 class GOXGraph(XGraph, GOGraphBase):
00010     def __init__(self, storage, species, aspect=Aspects.BP):
00011         GOGraphBase.__init__(self, storage, species, aspect)
00012         XGraph.__init__(self)
00013                         
00014     def toXGMML(self, fhandle):
00015         xml = DOMLight.XMLMaker()
00016         fhandle.write("""<?xml version="1.0" encoding="UTF-8"?>
00017         <graph xmlns="http://www.cs.rpi.edu/XGMML" label="GOGrapher Network">
00018         """)
00019         cid = 0
00020         goids = {}
00021         for node in self.nodes_iter():
00022             goids[node.goid] = cid
00023             fhandle.write(str(xml.node({'id': cid, 'label': node.goid})) + "\n")
00024             cid += 1
00025         count = 0
00026         for edge in self.edges_iter():
00027             fhandle.write(str(xml.edge({'source': goids[edge[0].goid], 'target': goids[edge[1].goid], 'weight': edge[2], 'label': ""})) + "\n")
00028             if count == 1000:
00029                 break
00030             count += 1
00031         fhandle.write("</graph>")
00032                                                                                                                     

Generated on Tue Apr 7 11:34:50 2009 for GOGrapher by  doxygen 1.5.6