kegg

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package kegg is the library behind the kegg command line: the HTTP client, request shaping, and the typed data models for the KEGG REST API (rest.kegg.jp).

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load. KEGG returns plain TSV text, not JSON; all parsing converts tab-separated lines into the typed records below.

Index

Constants

View Source
const BaseURL = "https://rest.kegg.jp"

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "kegg-cli/dev (+https://github.com/tamnd/kegg-cli)"

DefaultUserAgent identifies the client to KEGG. A real, honest User-Agent is both polite and the thing most likely to keep you unblocked.

View Source
const Host = "rest.kegg.jp"

Host is the canonical homepage used for URI driver host matching.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	BaseURL   string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the KEGG REST API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with the recommended defaults.

func (*Client) FindEntries

func (c *Client) FindEntries(ctx context.Context, db, query string) ([]*Entry, error)

FindEntries calls /find/<db>/<query> and returns the raw Entry records. db is one of: compound, drug, pathway, genes, disease.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.

func (*Client) GetCompound

func (c *Client) GetCompound(ctx context.Context, id string) (*Compound, error)

GetCompound calls /get/<id> and parses the ENTRY, NAME, and FORMULA sections into a Compound.

func (*Client) GetEntry

func (c *Client) GetEntry(ctx context.Context, id string) ([]byte, error)

GetEntry calls /get/<id> and returns the raw flat-file text. KEGG flat files are structured text (ENTRY / NAME / FORMULA / etc sections), not JSON. The caller can parse the sections it needs; we return the whole body so callers are not limited by what we pre-parse.

func (*Client) ListCompounds

func (c *Client) ListCompounds(ctx context.Context) ([]*Compound, error)

ListCompounds calls /list/compound and returns all compound stubs.

func (*Client) ListPathways

func (c *Client) ListPathways(ctx context.Context) ([]*Pathway, error)

ListPathways calls /list/pathway/hsa and returns human pathway records.

type Compound

type Compound struct {
	ID   string `json:"id" kit:"id"`
	Name string `json:"name"` // first alias
}

Compound is a KEGG compound record (small molecule / metabolite).

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration // minimum gap between requests
	Timeout   time.Duration
	Retries   int
}

Config holds the tunable knobs for the client. Values of zero mean "use the default".

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the recommended defaults for the KEGG free API: 300 ms rate limit (polite), 15 s timeout, 3 retries.

type Domain

type Domain struct{}

Domain is the KEGG driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns a compound id or KEGG URL into (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Entry

type Entry struct {
	ID    string   `json:"id"`
	Names []string `json:"names"`
}

Entry is the generic record returned by the /find endpoint: an id and zero or more semicolon-separated names.

type Gene

type Gene struct {
	ID   string `json:"id"`   // e.g. "hsa:672"
	Name string `json:"name"` // gene symbol(s)
	Desc string `json:"desc"` // description after the semicolon block
}

Gene is a KEGG gene entry from /find/genes.

type Pathway

type Pathway struct {
	ID   string `json:"id" kit:"id"`
	Name string `json:"name"`
}

Pathway is a KEGG pathway record returned by /list/pathway.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL