Skip to main content

A Python wrapper for the COCONUT natural product database REST API.

Project description

GitHub repo size

coconutPy

A Python wrapper for the COCONUT natural product database REST API. All responses are retrieved as JSON.

Install

# from github using pip
pip install git+https://github.com/kenscripts/coconutPy.git

Quick Start

Load Packages

import os
from cocoAPI import cocoPy

Login to COCONUT Database

To get login credentials, sign up on COCONUT.

Enter email and password to login. This can be done manually or by saving credentials to ENVIRONMENT variable

# save login credenitals as env variables
# get email and password from env 
# account email may need to be verified periodically through website
EMAIL = os.getenv(
                  "COCONUT_EMAIL"
                  )
PSSWD = os.getenv(
                  "COCONUT_PASSWORD"
                  )

# login
coco = cocoPy(
              email = EMAIL,
              password = PSSWD
              )

Get COCONUT Resource Details

COCONUT resources include: citations, collections, molecules, organisms, properties, and reports.

To retrive resource details:

coco.get.resource_json(
                       resource_endpoint = "properties"
                       )

To retrieve resource fields

coco.get.resource_fields(
                         resource_endpoint = "properties"
                         )

Search COCONUT Resources

Input

search_query is a list of entries. Each entry is a list of the format [key,field,value].

Find Keys & Fields

To find keys for resource:

# molecules resource
coco.search.default_molecules_search_req["search"].keys()

To find fields for resource:

# molecules resource
coco.get.resource_fields(
                         resource_endpoint = "molecules"
                         )

Search Example (Molecules)

Here is a search example for molecules:

# save search query as variable for readability
mol_search_query = [
                    ["filters","name","Ferutidin"],
                    ["selects","standard_inchi_key",None] # selects key doesn't have values
                    ]

# molecules search
coco.search.query(
                  resource_endpoint = "molecules",
                  search_query = mol_search_query
                  )

Properties can be included with molecule search:

# value to include properties
include_properties = [
                      {'relation':'properties'}
                      ]

# search query
mol_search_query = [
                    ["filters","name","Ferutidin"],
                    ["includes",None,include_properties]
                    ]

# molecules search with properties included
coco.search.query(
                  resource_endpoint = "molecules",
                  search_query = mol_search_query
                  )

Search Example (Properties)

Here is a search example for properties:

# save search query as variable for readability
prop_search_query = [
                     ["filters","lipinski_rule_of_five_violations","0"],
                     ["filters","np_classifier_pathway","Terpenoids"],
                     ["selects","np_classifier_superclass",None],
                     ["limit",None,50] # a limit of >50 not allowed by COCONUT API
                     ]

# properties search
# increase sleep_time for 502 Bad Gateway error
coco.search.query(
                  resource_endpoint = "properties",
                  search_query = prop_search_query,
                  sleep_time = 0.5
                  )

Search Example (Collections)

Here is a search example for collections to identify plant collections:

# get fields for collections resource
coco.get.resource_fields(
                         resource_endpoint = "collections"
                         )

# get all records for collections resource
coll_recs = coco.search.get_all_records(
                                        resource_endpoint = "collections"
                                        )

# find plant collections
for coll in coll_recs:
   # find collections that mention plants
   if "plant" in coll["description"]:
      print(
            coll["title"]
            )

Advanced Search For COCONUT Molecules Resource

Input

adv_search_query is a list of entries. Each entry is a list of the following format: [type, tag|filter,value].

Find Types, Tags, & Filters

To find accepted types:

coco.advSearch.adv_mol_search_types

To find accepted tags:

coco.advSearch.adv_mol_search_info["tags"]

To find accepted filters:

coco.advSearch.adv_mol_search_info["filters"]

Tag-Based Advanced Search

# advanced search query
adv_mol_search_query = [
                        ["tags","organisms","Ferula"]
                        ]

# tag-based advanced search
# API may fail with page limits > 50
# increase sleep_time for 502 Bad Gateway error
coco.advSearch.advanced_query(
                              adv_search_query = adv_mol_search_query,
                              sleep_time = 0.5,
                              pg_limit = 50
                              )

Filter-Based Advanced Search (Single Filter)

# advanced search query
adv_mol_search_query = [
                        ["filters","np_pathway","Alkaloids"]
                        ]

# filter-based advanced search
# API may fail with page limits > 50
# increase sleep_time for 502 Bad Gateway error
coco.advSearch.advanced_query(
                              adv_search_query = adv_mol_search_query,
                              sleep_time = 0.5,
                              pg_limit = 50
                              )

Filter-Based Advanced Search (Multiple Filters)

First build the advanced search request:

# advanced searcy query
adv_mol_search_query = [
                        ["filters","np_pathway","Alkaloids"],
                        ["filters","mw","500..1000"]
                        ]

# filter-based advanced search
# API may fail with page limits > 50
# increase sleep_time for 502 Bad Gateway error
coco.advSearch.advanced_query(
                              adv_search_query = adv_mol_search_query,
                              sleep_time = 0.5,
                              pg_limit = 50
                              )

Filter-Based Advanced Search (Complex Filters)

# build the advanced search request with OR logical operator:
adv_mol_search_query = [
                        ["filters","np_pathway","Alkaloids"],
                        ["filters","cs","true OR"],
                        ["filters","mw","500..1000"]
                        ]

# filter-based advanced search
# API may fail with page limits > 50
# increase sleep_time for 502 Bad Gateway error
coco.advSearch.advanced_query(
                              adv_search_query = adv_mol_search_query,
                              sleep_time = 0.5,
                              pg_limit = 50
                              )

Basic Advanced Search

# value for basic advanced search must be a string of name, SMILES, InChI, or InChI key.
adv_mol_search_query = [
                        ["basic",None,"REFJWTPEDVJJIY-UHFFFAOYSA-N"]
                        ]

# basic advanced search
coco.advSearch.advanced_query(
                              adv_search_query = adv_mol_search_query
                              )

Documentation

API documentation is available at: https://coconutpy.readthedocs.io/en/latest/api.html

Database Citations

COCONUT Paper:
Venkata Chandrasekhar, Kohulan Rajan, Sri Ram Sagar Kanakam, Nisha Sharma, Viktor Weißenborn, Jonas Schaub, Christoph Steinbeck, COCONUT 2.0: a comprehensive overhaul and curation of the collection of open natural products database, Nucleic Acids Research, 2024;, gkae1063, https://doi.org/10.1093/nar/gkae1063

COCONUT Software:
Venkata, C., Kanakam, S. R. S., Sharma, N., Schaub, J., Steinbeck, C., & Rajan, K. (2024). COCONUT (Version v0.0.1 - prerelease) [Computer software]. https://doi.org/10.5281/zenodo.13283949

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coconutpy_api-0.1.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coconutpy_api-0.1.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file coconutpy_api-0.1.0.tar.gz.

File metadata

  • Download URL: coconutpy_api-0.1.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for coconutpy_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b25df4ce7eec88da0ec2f16e532ad84b03e7092fe1f21d2538986ca860a7d166
MD5 8d72a2a53639adffc73bf117ee9ca0c9
BLAKE2b-256 f7a9f1cda01c6212e26122aefec256c1c13d074fba6aee361629b909f9109fe1

See more details on using hashes here.

File details

Details for the file coconutpy_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: coconutpy_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for coconutpy_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b33be9ccfa356a5e967d082617d0d54a80740f9af26aa9fec236e53896af52c
MD5 7337d7f95a8d7bd4c9beaa5f4e9bc653
BLAKE2b-256 227ed3589a55e1fd0a1ef8a49e478db8ef4d12032700942cb7ae7dc160bc7585

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page