Created
February 1, 2013 18:07
-
-
Save widdowquinn/4692994 to your computer and use it in GitHub Desktop.
Example code to generate three renderings of a non-metabolic KEGG pathway, with important information in the .png.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import KGML_parser | |
from KGML_scrape import retrieve_KEGG_pathway | |
from KGML_vis import KGMLCanvas | |
from Bio.Graphics.ColorSpiral import ColorSpiral | |
# Get the ko03070 map from KEGG, and write it out to file, visualised as | |
# the .png, and as the elements from the KGML file | |
pathway = retrieve_KEGG_pathway('ko03070') | |
kgml_map = KGMLCanvas(pathway, show_maps=True) | |
# Let's use some arbitrary colours for the orthologs | |
cs = ColorSpiral(a=2, b=0.2, v_init=0.85, v_final=0.5, | |
jitter=0.03) | |
# Loop over the orthologs in the pathway, and change the | |
# background colour | |
orthologs = [e for e in pathway.orthologs] | |
for o, c in zip(orthologs, | |
cs.get_colors(len(orthologs))): | |
for g in o.graphics: | |
g.bgcolor = c | |
# Default settings are for the KGML elements only | |
kgml_map.draw('ex2_kgml_render.pdf') | |
# We need to use the image map, and turn off the KGML elements, to see | |
# only the .png base map. We could have set these values on canvas | |
# instantiation | |
kgml_map.import_imagemap = True | |
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 | |
kgml_map.draw('ex2_png_render.pdf') | |
# And rendering elements as an overlay | |
kgml_map.show_compounds = True | |
kgml_map.show_genes = True | |
kgml_map.show_orthologs = True | |
kgml_map.draw('ex2_overlay_render.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment