Quantcast

Bioinformatics Toolbox

Connecting to the KEGG API Web Service

This example shows how to access the KEGG system using the SOAP/WSDL based web service from within MATLAB®. We show some examples using the KEGG Pathway API. Refer to the KEGG API Manual for more examples and information.

Note: The pathway information and maps shown in this example may differ from the results you get due to the frequent update to the KEGG pathway database.

Contents

Setting up Web Connection

Create a variable containing the definition URL of the Web Service Description Language (WSDL) web service for the KEGG database

wsdlURL = 'http://soap.genome.jp/KEGG.wsdl';

In MATLAB, use the createClassFromWSDL function to call web service methods. Create the classes from KEGG WSDL. This will create a directory called @KEGG in the current directory.

className = createClassFromWsdl(wsdlURL);
Retrieving document at 'http://soap.genome.jp/KEGG.wsdl'

The @KEGG directory contains automatically generated files that implement the KEGG web service methods

dir @KEGG
.                                          get_kos_by_pathway.m
..                                         get_linkdb_between_databases.m
KEGG.m                                     get_linkdb_by_entry.m
bconv.m                                    get_linked_pathways.m
bfind.m                                    get_motifs_by_gene.m
bget.m                                     get_number_of_genes_by_organism.m
binfo.m                                    get_paralogs_by_gene.m
btit.m                                     get_pathways_by_compounds.m
color_pathway_by_elements.m                get_pathways_by_drugs.m
color_pathway_by_objects.m                 get_pathways_by_enzymes.m
convert_mol_to_kcf.m                       get_pathways_by_genes.m
display.m                                  get_pathways_by_glycans.m
get_best_best_neighbors_by_gene.m          get_pathways_by_kos.m
get_best_neighbors_by_gene.m               get_pathways_by_reactions.m
get_compounds_by_enzyme.m                  get_reactions_by_compound.m
get_compounds_by_pathway.m                 get_reactions_by_enzyme.m
get_compounds_by_reaction.m                get_reactions_by_glycan.m
get_drugs_by_pathway.m                     get_reactions_by_pathway.m
get_element_relations_by_pathway.m         get_references_by_pathway.m
get_elements_by_pathway.m                  get_reverse_best_neighbors_by_gene.m
get_enzymes_by_compound.m                  list_databases.m
get_enzymes_by_gene.m                      list_ko_classes.m
get_enzymes_by_glycan.m                    list_organisms.m
get_enzymes_by_pathway.m                   list_pathways.m
get_enzymes_by_reaction.m                  mark_pathway_by_objects.m
get_genes_by_enzyme.m                      search_compounds_by_composition.m
get_genes_by_ko.m                          search_compounds_by_mass.m
get_genes_by_ko_class.m                    search_compounds_by_name.m
get_genes_by_motifs.m                      search_compounds_by_subcomp.m
get_genes_by_organism.m                    search_drugs_by_composition.m
get_genes_by_pathway.m                     search_drugs_by_mass.m
get_glycans_by_enzyme.m                    search_drugs_by_name.m
get_glycans_by_pathway.m                   search_drugs_by_subcomp.m
get_glycans_by_reaction.m                  search_glycans_by_composition.m
get_html_of_colored_pathway_by_elements.m  search_glycans_by_kcam.m
get_html_of_colored_pathway_by_objects.m   search_glycans_by_mass.m
get_html_of_marked_pathway_by_objects.m    search_glycans_by_name.m
get_ko_by_gene.m
get_ko_by_ko_class.m

You can also use the methods command to view the list of methods available for the KEGG class. You will notice that there are more methods available than files in the @KEGG directory. These are inherited methods that are available for all objects in MATLAB.

methods(KEGG)
Methods for class KEGG:

KEGG                                     get_linkdb_between_databases
bconv                                    get_linkdb_by_entry
bfind                                    get_linked_pathways
bget                                     get_motifs_by_gene
binfo                                    get_number_of_genes_by_organism
btit                                     get_paralogs_by_gene
color_pathway_by_elements                get_pathways_by_compounds
color_pathway_by_objects                 get_pathways_by_drugs
convert_mol_to_kcf                       get_pathways_by_enzymes
display                                  get_pathways_by_genes
get_best_best_neighbors_by_gene          get_pathways_by_glycans
get_best_neighbors_by_gene               get_pathways_by_kos
get_compounds_by_enzyme                  get_pathways_by_reactions
get_compounds_by_pathway                 get_reactions_by_compound
get_compounds_by_reaction                get_reactions_by_enzyme
get_drugs_by_pathway                     get_reactions_by_glycan
get_element_relations_by_pathway         get_reactions_by_pathway
get_elements_by_pathway                  get_references_by_pathway
get_enzymes_by_compound                  get_reverse_best_neighbors_by_gene
get_enzymes_by_gene                      list_databases
get_enzymes_by_glycan                    list_ko_classes
get_enzymes_by_pathway                   list_organisms
get_enzymes_by_reaction                  list_pathways
get_genes_by_enzyme                      mark_pathway_by_objects
get_genes_by_ko                          search_compounds_by_composition
get_genes_by_ko_class                    search_compounds_by_mass
get_genes_by_motifs                      search_compounds_by_name
get_genes_by_organism                    search_compounds_by_subcomp
get_genes_by_pathway                     search_drugs_by_composition
get_glycans_by_enzyme                    search_drugs_by_mass
get_glycans_by_pathway                   search_drugs_by_name
get_glycans_by_reaction                  search_drugs_by_subcomp
get_html_of_colored_pathway_by_elements  search_glycans_by_composition
get_html_of_colored_pathway_by_objects   search_glycans_by_kcam
get_html_of_marked_pathway_by_objects    search_glycans_by_mass
get_ko_by_gene                           search_glycans_by_name
get_ko_by_ko_class
get_kos_by_pathway

Using the Web Service

In order to use the web service, you must first create an instance of the KEGG object.

kegg = KEGG;

You can confirm that kegg is an instance of the KEGG using the class command

classType = class(kegg)
classType =

KEGG

Using KEGG Pathway API

The KEGG API functions work with KEGG IDs only. The bconv method converts NCBI GIs, NCBI GeneIDs, GenBank® IDs, and UniProt IDs to KEGG IDs

kegg_ids_conv = bconv(kegg, 'ncbi-gi:10047086 ncbi-geneid:14751')
kegg_ids_conv =

ncbi-gi:10047086    hsa:54206    equivalent
ncbi-geneid:14751    mmu:14751    equivalent


Use the list_organisms method to get a structure array containing the organisms in the KEGG/GENES database. The organism full names are in the definition field.

organisms = list_organisms(kegg)
organisms =

1485x1 struct array with fields:
    entry_id
    definition

Find the entry where definition has the string Homo sapiens .

homo_idx = find(~cellfun(@isempty,regexpi({organisms.definition},'Homo sapi
ens')))
homo = organisms(homo_idx)
homo_idx =

     1


homo =

      entry_id: 'hsa'
    definition: 'Homo sapiens (human)'

You can get a list of pathway ids for Homo sapiens in KEGG PATHWAY database.

pathway_list = list_pathways(kegg, homo.entry_id);
num_pathways = length(pathway_list)
num_pathways =

   233

This example uses the Fatty acid metabolism pathway. Find the entry where definition has the string Fatty acid metabolism.

famp_idx =  find(~cellfun(@isempty,regexpi({pathway_list.definition},'Fatty
 acid metabolism')))
famp_pathway = pathway_list(famp_idx)
famp_idx =

    10


famp_pathway =

      entry_id: 'path:hsa00071'
    definition: 'Fatty acid metabolism - Homo sapiens (human)'

Get lists of genes, compounds, enzymes and reactions involved in the Fatty acid metabolism pathway.

famp_genes = get_genes_by_pathway(kegg, famp_pathway.entry_id);
num_genes = length(famp_genes)
num_genes =

    43

famp_compounds= get_compounds_by_pathway(kegg, famp_pathway.entry_id);
num_compounds = length(famp_compounds)
num_compounds =

    50

famp_enzymes = get_enzymes_by_pathway(kegg, famp_pathway.entry_id);
num_enzymes = length(famp_enzymes)
num_enzymes =

    17

famp_reactions = get_reactions_by_pathway(kegg, famp_pathway.entry_id);
num_reactions = length(famp_reactions)
num_reactions =

    36

You can get KEGG pathway IDs from a list of KEGG gene IDs, enzymes or reactions. For example, you can get the pathways IDs for the first 10 genes and reactions.

pathway_by_genes = get_pathways_by_genes(kegg, famp_genes(1:10))
pathway_by_genes =

path:hsa00071

pathway_by_react = get_pathways_by_reactions(kegg, famp_reactions(1:10))
pathway_by_react =

path:rn00071

Coloring Pathways

In KEGG pathway maps, a gene or enzyme is represented by a rectangle, and a compound is shown as a small circle. In this example, the Fatty acid metabolism pathway map returned by KEGG has already colored the gene products related to Homo sapiens in green. In addition, you can specify colors for specific genes or compounds, for example, the highly expressed genes from a gene expression experiment. KEGG returns an URL of the given pathway map with the elements corresponding to the specified colored genes.

List the objects to be colored, and specify the colors for each object

obj_list = [famp_genes(30:31); {'hsa:8310'}; {'cpd:C00823'}; famp_comp
ounds(5:6)];
fg_list  = {'#ff6600', '#0000ff', '#0000ff', '#0000ff', '#ff0000', '#ff0000
'};
bg_list  = {'#99ccff', 'yellow',  '#ff6633', '#ff0000', '#ccffff', '#ccffff
'};

KEGG colors the given objects on the pathway map with the specified colors and return the URL of a static colored pathway map in gif format.

pathway_map_colored = color_pathway_by_objects(kegg, famp_pathway.entry_id,...
                        obj_list, fg_list, bg_list)
pathway_map_colored =

http://soap.genome.jp/tmp/mark_pathway_www_api.130564599322942/hsa00071.png

The get_html_of_colored_pathway_by_objects method returns an URL of an interactive pathway map.

pathway_map_html = get_html_of_colored_pathway_by_objects(kegg,...
                    famp_pathway.entry_id, obj_list, fg_list, bg_list)
pathway_map_html =

http://www.genome.jp/kegg-bin/mark_pathway_www?130564599923048/hsa00071.args

Displaying Pathway Maps

You can simply display the pathway map in a browser.

web(pathway_map_html)

You can display the static pathway map in a figure. Use imread function to read the image data and the associate color map from the pathway map in gif format.

[x,cmap] = imread(pathway_map_colored);

Display the image in a figure. You need to set the color map of the figure to cmap. Note: If you have Image Processing Toolbox™, just use imshow(x,map) to display the pathway map.

hfig = figure('Colormap', cmap);
hax = axes('Parent', hfig);
himg = image(x, 'Parent', hax);
set(hax, 'Visible', 'off')
scaleimagefigure(hfig, hax, himg);

Suggest an enhancement for this example.