def test_render_KGML_modify(self): """ Rendering of KGML to PDF, with modification. """ # We test rendering of the original and roundtrip KGML for KO01100, # modifying line width for the lipid pathway p = self.data[0] for filename, ext in [(p.infilename, "_mod_original.pdf"), (p.outfilename, "_mod_roundtrip.pdf")]: with open(filename) as f: pathway = read(f) mod_rs = [e for e in pathway.orthologs if len(set(e.name.split()).intersection(self.ko_ids))] for r in mod_rs: for g in r.graphics: g.width = 10 kgml_map = KGMLCanvas(pathway) kgml_map.draw(os.path.splitext(filename)[0] + ext) # We test rendering of the original and roundtrip KGML for KO3070, # modifying the reaction colours for each ortholog entry p = self.data[1] for filename, ext in [(p.infilename, "_mod_original.pdf"), (p.outfilename, "_mod_roundtrip.pdf")]: with open(filename) as f: pathway = read(f) orthologs = [e for e in pathway.orthologs] # Use Biopython's ColorSpiral to generate colours cs = ColorSpiral(a=2, b=0.2, v_init=0.85, v_final=0.5, jitter=0.03) colors = cs.get_colors(len(orthologs)) for o, c in zip(orthologs, colors): for g in o.graphics: g.bgcolor = c kgml_map = KGMLCanvas(pathway) pathway.image = p.pathway_image kgml_map.import_imagemap = p.show_pathway_image kgml_map.draw(os.path.splitext(filename)[0] + ext)
def test_KEGG_download(self): """ Download a KEGG pathway from the KEGG server and write KGML. """ # Download the KEGG ko01110 pathway, and render it pathway = retrieve_KEGG_pathway('ko01110') kgml_map = KGMLCanvas(pathway) kgml_map.import_imagemap = True kgml_map.draw(os.path.join('KEGG', 'ko01110.pdf')) # Download the KEGG ko01120 pathway and write to file as KGML retrieve_kgml_to_file("ko01120", os.path.join("KEGG", "ko01120.xml"))
def test_KEGG_download(self): """ Download a KEGG pathway from the KEGG server and write KGML. """ # Download the KEGG ko01110 pathway, and render it pathway = retrieve_KEGG_pathway('ko01110') kgml_map = KGMLCanvas(pathway) kgml_map.import_imagemap = True kgml_map.draw(os.path.join('KEGG', 'ko01110.pdf')) # Download the KEGG ko01120 pathway and write to file as KGML retrieve_kgml_to_file("ko01120", os.path.join("KEGG", "ko01120.xml"))
def test_render_KGML_basic(self): """ Basic rendering of KGML: write to PDF without modification. """ # We test rendering of both the original KEGG KGML and the # roundtrip KGML written by this module, using only local files. for p in self.data: for filename, ext in [(p.infilename, "_original.pdf"), (p.outfilename, "_roundtrip.pdf")]: with open(filename, "rU") as f: pathway = read(f) pathway.image = p.pathway_image kgml_map = KGMLCanvas(pathway) kgml_map.import_imagemap = p.show_pathway_image kgml_map.draw(os.path.splitext(filename)[0] + ext)
def test_render_KGML_basic(self): """ Basic rendering of KGML: write to PDF without modification. """ # We test rendering of both the original KEGG KGML and the # roundtrip KGML written by this module, using only local files. for p in self.data: for filename, ext in [(p.infilename, '_original.pdf'), (p.outfilename, '_roundtrip.pdf')]: with open(filename, 'rU') as f: pathway = read(f) pathway.image = p.pathway_image kgml_map = KGMLCanvas(pathway) kgml_map.import_imagemap = p.show_pathway_image kgml_map.draw(os.path.splitext(filename)[0] + ext)
def test_render_KGML_modify(self): """ Rendering of KGML to PDF, with modification. """ # We test rendering of the original and roundtrip KGML for KO01100, # modifying line width for the lipid pathway p = self.data[0] for filename, ext in [(p.infilename, '_mod_original.pdf'), (p.outfilename, '_mod_roundtrip.pdf')]: with open(filename) as f: pathway = read(f) mod_rs = [ e for e in pathway.orthologs if len(set(e.name.split()).intersection(self.ko_ids)) ] for r in mod_rs: for g in r.graphics: g.width = 10 kgml_map = KGMLCanvas(pathway) kgml_map.draw(os.path.splitext(filename)[0] + ext) # We test rendering of the original and roundtrip KGML for KO3070, # modifying the reaction colours for each ortholog entry p = self.data[1] for filename, ext in [(p.infilename, '_mod_original.pdf'), (p.outfilename, '_mod_roundtrip.pdf')]: with open(filename) as f: pathway = read(f) orthologs = [e for e in pathway.orthologs] # Use Biopython's ColorSpiral to generate colours cs = ColorSpiral(a=2, b=0.2, v_init=0.85, v_final=0.5, jitter=0.03) colors = cs.get_colors(len(orthologs)) for o, c in zip(orthologs, colors): for g in o.graphics: g.bgcolor = c kgml_map = KGMLCanvas(pathway) pathway.image = p.pathway_image kgml_map.import_imagemap = p.show_pathway_image kgml_map.draw(os.path.splitext(filename)[0] + ext)
notDE = set([e for e in pathway.orthologs if not len(set(e.name.split()).intersection(enhanceSet))]) kgml_map = KGMLCanvas(pathway, show_maps=True) kgml_map.import_imagemap = True # turn this off to allow all elements to go gray! kgml_map.show_maps = False kgml_map.show_orthologs = False kgml_map.draw_relations = False kgml_map.show_compounds = False kgml_map.show_genes = False os.chdir(args.outDir) colorMapItems(notDE,'#D3D3D3', 1) colorMapItems(knownKOSet,'#666666', 10) if args.upKO != None: colorMapItems(upKOSet,'#FF0000', 10) if args.downKO != None: colorMapItems(downKOSet,'#0000FF', 10) # And rendering elements as an overlay kgml_map.show_compounds = True kgml_map.show_genes = True kgml_map.show_orthologs = True #kgml_map.draw_relations = True kgml_map.draw(args.path + '.pdf')
#notDE = set([e for e in pathway.entries.values() if not len(set(e.name.split()).intersection(enhanceSet)) and e.type != 'map']) notDE = set([e for e in pathway.orthologs if not len(set(e.name.split()).intersection(enhanceSet))]) kgml_map = KGMLCanvas(pathway, show_maps=True) kgml_map.import_imagemap = True #kgml_map.show_maps = False kgml_map.show_orthologs = True kgml_map.draw_relations = False kgml_map.show_compounds = False kgml_map.show_genes = False colorMapItems(notDE,'#D3D3D3', 1) os.chdir(args.outDir) koInMap = open(args.path + '_KO.txt', 'w') colorMapItems(knownKOSet,'#666666', 10) for k in knownKOSet: koInMap.write(k.name + '\t' + 'present' + '\n') koInMap.close() # And rendering elements as an overlay #kgml_map.show_compounds = True #kgml_map.show_genes = True #kgml_map.show_orthologs = True #kgml_map.draw_relations = True kgml_map.draw(args.path + '.pdf')
import sys import os import urllib2 from KGML_scrape import retrieve_kgml_to_file, retrieve_KEGG_pathway from KGML_vis import KGMLCanvas goal_dir = os.path.dirname(os.path.abspath(__file__)) + "\..\Downloads" pathway = retrieve_KEGG_pathway(sys.argv[1]) kgml_map = KGMLCanvas(pathway) kgml_map.import_imagemap = True kgml_map.draw( os.path.join(os.path.normpath(goal_dir) + '\PDF', sys.argv[1] + '.pdf')) retrieve_kgml_to_file( sys.argv[1], os.path.join(os.path.normpath(goal_dir) + '\XML', sys.argv[1] + '.xml')) print sys.argv[1] + '.pdf'