Ejemplo n.º 1
0
 def test_read_and_write_KGML_files(self):
     """ Read KGML from, and write KGML to, local files.
         Check we read/write the correct number of elements.
     """
     for p in self.data:
         # Test opening file
         with open(p.infilename, 'rU') as f:
             pathway = read(f)
             # Do we have the correct number of elements of each type
             self.assertEqual((len(pathway.entries), 
                               len(pathway.orthologs),
                               len(pathway.compounds),
                               len(pathway.maps)),
                              p.element_counts)
         # Test writing file
         with open(p.outfilename, 'w') as f:
             f.write(pathway.get_KGML())
         # Can we read the file we wrote?
         with open(p.outfilename, 'rU') as f:
             pathway = read(f)
             # Do we have the correct number of elements of each type
             self.assertEqual((len(pathway.entries), 
                               len(pathway.orthologs),
                               len(pathway.compounds),
                               len(pathway.maps)),
                              p.element_counts)
Ejemplo n.º 2
0
 def test_read_and_write_KGML_files(self):
     """ Read KGML from, and write KGML to, local files.
         Check we read/write the correct number of elements.
     """
     for p in self.data:
         # Test opening file
         with open(p.infilename, 'rU') as f:
             pathway = read(f)
             # Do we have the correct number of elements of each type
             self.assertEqual((len(pathway.entries),
                               len(pathway.orthologs),
                               len(pathway.compounds),
                               len(pathway.maps)),
                              p.element_counts)
         # Test writing file
         with open(p.outfilename, 'w') as f:
             f.write(pathway.get_KGML())
         # Can we read the file we wrote?
         with open(p.outfilename, 'rU') as f:
             pathway = read(f)
             # Do we have the correct number of elements of each type
             self.assertEqual((len(pathway.entries),
                               len(pathway.orthologs),
                               len(pathway.compounds),
                               len(pathway.maps)),
                              p.element_counts)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def retrieve_KEGG_pathway(map_id):
    """ Returns a KEGGPathway object, downloaded from KEGG, for the passed
        KEGG map ID
    """
    return read(retrieve_kgml_stream(map_id))
Ejemplo n.º 8
0
def retrieve_KEGG_pathway(map_id):
    """ Returns a KEGGPathway object, downloaded from KEGG, for the passed
        KEGG map ID
    """
    return read(retrieve_kgml_stream(map_id))