Skip to content

Issue with KEGG API #349

Description

@ArnaudBelcour

Hi,

Thank you for the package. I am using it to query KEGG to make metabolic graphs. There is an issue with the request to get the list of organisms (ArnaudBelcour/kegg2bipartitegraph#1).

Here is an example of code that leads to the issue on Python 3.12.2 using bioservices version 1.16.0:

from bioservices import KEGG

s = KEGG()
s.organismIds()

Leading to the error:

WARNING [bioservices.KEGG:535]:  HTTP 400 Bad Request (https://rest.kegg.jp/list/organism)
HTTP 400 Bad Request (https://rest.kegg.jp/list/organism)

WARNING [bioservices.KEGG:535]:  HTTP 400 Bad Request (https://rest.kegg.jp/list/organism)
HTTP 400 Bad Request (https://rest.kegg.jp/list/organism)
Traceback (most recent call last):
  File "/shared/Python_env/work_env/bin/k2bg", line 33, in <module>
    sys.exit(load_entry_point('kegg2bipartitegraph', 'console_scripts', 'k2bg')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/shared/Softwares/git/kegg2bipartitegraph/kegg2bipartitegraph/__main__.py", line 269, in main
    create_organism_network(args.input, args.output, args.reference_folder)
  File "/shared/Softwares/git/kegg2bipartitegraph/kegg2bipartitegraph/organism.py", line 173, in create_organism_network
    if KEGG_BIOSERVICES.isOrganism(organism) is not True:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/shared/Softwares/git/bioservices/src/bioservices/kegg.py", line 325, in isOrganism
    if org in self.organismIds:
              ^^^^^^^^^^^^^^^^
  File "/shared/Softwares/git/bioservices/src/bioservices/kegg.py", line 279, in __getattr__
    Ids = [x.split()[0] for x in res.split("\n") if len(x)]
                                 ^^^^^^^^^
AttributeError: 'HTTPResponseError' object has no attribute 'split'

I am not sure if this a temporary unavailability of the service or it is a change of the API. But currently https://rest.kegg.jp/list/organism leads to an error 400.

It is possible to get organism IDs with the list/genome request (https://rest.kegg.jp/list/genome), that also returns three/four letters code of organism names:

from bioservices import KEGG

s = KEGG()
s.list("genome")

I have made a fork with a small fix for self.organismIds to avoid encountering these errors when using the KEGG service (ArnaudBelcour@b388962), do you want me to do a PR?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions