Beispiel #1
0
 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"))
Beispiel #2
0
 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"))
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
#get KO numbers from previously created file
#ko = ['ko:'+ ko for (trans,sp,ko) in (line.strip().split("\t") for line in (open(args.KO, 'r')))]

knownKOSet = readKOFile(args.transKO, pathway)
enhanceSet = knownKOSet
if args.upKO != None:
    upKOSet = readKOFile(args.upKO, pathway)
    enhanceSet.update(upKOSet)
if args.downKO != None:
    downKOSet = readKOFile(args.downKO, pathway)
    enhanceSet.update(downKOSet)

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:
knownKOSet = set([e for e in pathway.orthologs if len(set(e.name.split()).intersection(ko))])

def colorMapItems(geneSet, color, width):
    for e in geneSet:
	for g in e.graphics:
	    if g.type == 'line':
		g.fgcolor = color
		g.width = width
	    g.bgcolor = color

#main
enhanceSet = knownKOSet 
#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()
Beispiel #9
0
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'
Beispiel #10
0
knownKOSet = readKOFile(args.transKO, pathway)
enhanceSet = knownKOSet
if args.upKO != None:
    upKOSet = readKOFile(args.upKO, pathway)
    enhanceSet.update(upKOSet)
if args.downKO != None:
    downKOSet = readKOFile(args.downKO, pathway)
    enhanceSet.update(downKOSet)

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: