Generate Kegg Imagemaps Programmatically
4
3
Entering edit mode
13.5 years ago
pufferfish ▴ 290

I'm using the color.pathway.by.objects() 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:

ftp://ftp.genome.jp/pub/kegg/pathway/map/map00010.conf contains coords for ftp://ftp.genome.jp/pub/kegg/pathway/map/map00010.png

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

kegg r • 4.9k views
ADD COMMENT
2
Entering edit mode
13.5 years ago

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

BEGIN   {
    FS="[\t]";
    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);
    next;
    }
/^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);
    next;
    }

    {
    }

END {
    printf("</map>");
    }

test:

curl -s ftp://ftp.genome.jp/pub/kegg/pathway/map/map00010.conf |\
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 COMMENT
2
Entering edit mode
13.5 years ago
pufferfish ▴ 290

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

    get.html.of.colored.pathway.by.objects <- functionpathway.id, object.id.list, fg.color.list, bg.color.list) { SSOAP::.SOAP(KEGGserver, "gethtmlofcoloredpathwaybyobjects", .soapArgs=list('pathwayid' = pathway.id, 'objectidlist' = object.id.list, 'fgcolorlist' = fg.color.list, 'bgcolor_list' = bg.color.list), action = KEGGaction, xmlns = KEGGxmlns, nameSpaces = SOAPNameSpaces(version=KEGGsoapns)) }

  3. Add "get.html.of.colored.pathway.by.objects" 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 COMMENT
1
Entering edit mode
13.5 years ago

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=\"http://www.genome.jp", s)

        print >> fh_out, s
        fh_out.close()

if __name__ == '__main__':
    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 COMMENT
1
Entering edit mode
13.5 years ago

This might be a useful alternative:

Converted KEGG files are available in .GPML format at http://www.pathvisio.org/wiki/PathVisioDownload (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 COMMENT

Login before adding your answer.

Traffic: 4441 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6