Question: Generate Kegg Imagemaps Programmatically
gravatar for pufferfish
8.8 years ago by
South Africa
pufferfish260 wrote:

I'm using the method of the R KEGG API to retrieve images of pathways with custom coloring of enzymes. This method however only returns an image, so the imagemap (mouseover -> get gene details) is not available.

It looks like I can get the coords from the corresponding .conf file eg: contains coords for

and build up my own imagemap, but is there an easier way via the API that I'm missing?

R kegg • 3.5k views
ADD COMMENTlink written 8.8 years ago by pufferfish260
gravatar for Pierre Lindenbaum
8.8 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum127k wrote:

The following AWK script seems to work with the URL you gave:

    printf("<map name=\"keggmap\">");
/^circ/ {
    n=split($1,a,/[\(, \)]+/);
    printf("<area shape=\"circle\" coords=\"%s,%s,%s\" href=\"%s\" alt=\"%s\"/>\n",a[2],a[3],a[4],$2,$3);
/^rect/ {
    n=split($1,a,/[\(, \)]+/);
    printf("<area shape=\"rect\" coords=\"%s,%s,%s,%s\" href=\"%s\" alt=\"%s\"/>\n",a[2],a[3],a[4],a[5],$2,$3);




curl -s |\
awk -f map.awk

C00033 (Acetate)
C00031 (D-Glucose)
C00103 (D-Glucose 1-phosphate)
C00631 (2-Phospho-D-glycerate)
C00267 (alpha-D-Glucose)
C00221 (beta-D-Glucose)
C00111 (Glycerone phosphate)
C01172 (beta-D-Glucose 6-phosphate)
C00668 (alpha-D-Glucose 6-phosphate)
C05345 (beta-D-Fructose 6-phosphate)
ADD COMMENTlink written 8.8 years ago by Pierre Lindenbaum127k
gravatar for pufferfish
8.8 years ago by
South Africa
pufferfish260 wrote:

Yet another way:

The KEGG SOAP API does in fact have other methods, like gethtmlofcoloredpathwaybyobjects, which just haven't been included in the R KEGGSOAP library.

To fix this:

  1. Download the KEGGSOAP source package from here, and unpack it
  2. Edit the file KEGGSOAP/R/KEGGSOAP.R, and add the following snippet <-,, fg.color.list, bg.color.list) { SSOAP::.SOAP(KEGGserver, "gethtmlofcoloredpathwaybyobjects", .soapArgs=list('pathwayid' =, 'objectidlist' =, 'fgcolorlist' = fg.color.list, 'bgcolor_list' = bg.color.list), action = KEGGaction, xmlns = KEGGxmlns, nameSpaces = SOAPNameSpaces(version=KEGGsoapns)) }

  3. Add "" to the export list in the NAMESPACE file

  4. Repack the source tree into a tar.gz file
  5. Install with R CMD INSTALL KEGGSOAP.tar.gz

I prefer this because it uses the public KEGG SOAP API, which is hopefully less likely to change.

On the other hand, I still now have to parse the HTML to get out the images and JS if I want to customize the mouseover.

ADD COMMENTlink modified 8.8 years ago • written 8.8 years ago by pufferfish260
gravatar for Michael Kuhn
8.8 years ago by
Michael Kuhn5.0k
EMBL Heidelberg
Michael Kuhn5.0k wrote:

When I faced this problem five years ago, I resorted to scraping the image map from downloaded HTML files:

#!/usr/bin/env python
# encoding: utf-8

import sys
import os
import glob
from BeautifulSoup import BeautifulSoup

def main():

    re_link = re.compile("href=\"")
    re_js = re.compile("onmouseover=[^>]*")

    path = "kegg_tar_files_expanded/pathway/hsa/*.html"

    for filename in glob.glob(path):
        print >> sys.stderr, filename
        soup = BeautifulSoup(open(filename))
        fh_out = open("kegg_map/%s" % filename.rsplit("/",1)[1], "w")

        s = str(soup.find("map"))
        s = re_js.sub("", s) 
        s = re_link.sub("href=\"", s)

        print >> fh_out, s

if __name__ == '__main__':

This is my old Python code: I haven't tested it yet if it still works, and perhaps there's a better way to do this now.

ADD COMMENTlink written 8.8 years ago by Michael Kuhn5.0k
gravatar for Chris Evelo
8.8 years ago by
Chris Evelo10.0k
Maastricht, The Netherlands
Chris Evelo10.0k wrote:

This might be a useful alternative:

Converted KEGG files are available in .GPML format at (not sure they will stay there). The conversion is not perfect, but it will allow you to open the pathways in PathVisio where you could do the things you want to do.

If this helpful you might be interested in the PathVisio html plugin, which allows you to produce html pages that you ca publish and where mouseover can be used to show information about the genes and also about experimental data that you loaded on top.

In case you might want to improve the importer, I think the converter itself is in the source repository. But if not you could just ask for it.

ADD COMMENTlink modified 8.8 years ago • written 8.8 years ago by Chris Evelo10.0k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1130 users visited in the last hour