uniprot

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package uniprot is the library behind the uniprot command line: the HTTP client, request shaping, and the typed data models for the UniProt REST API.

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 API throws under load.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "uniprot-cli/0.1.0 (github.com/tamnd/uniprot-cli)"

DefaultUserAgent identifies the client to UniProt servers.

View Source
const Host = "rest.uniprot.org"

Host is the site this client talks to.

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 UniProt REST API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func NewClientFromConfig

func NewClientFromConfig(cfg Config) *Client

NewClientFromConfig returns a Client configured from cfg.

func (*Client) Get

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

Get fetches the URL and returns the response body. It paces and retries according to the client's settings.

func (*Client) Protein

func (c *Client) Protein(ctx context.Context, accession string) (*Protein, error)

Protein fetches a single protein by accession (e.g. "P04637").

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, opts SearchOptions) ([]*Protein, error)

Search searches UniProt proteins by query string.

func (*Client) Taxonomy

func (c *Client) Taxonomy(ctx context.Context, taxonID int) (*Taxonomy, error)

Taxonomy fetches organism taxonomy info by taxon ID (e.g. 9606 for human).

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable client parameters.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

type Domain

type Domain struct{}

Domain is the uniprot 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 any accepted input into (type, id). UniProt accessions (e.g. P04637, Q9Y2T1) → type "protein". Taxon IDs (numeric, e.g. 9606) → type "taxonomy".

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 Protein

type Protein struct {
	Accession   string `json:"accession" kit:"id"`
	EntryName   string `json:"entry_name"`
	ProteinName string `json:"protein_name"`
	GeneName    string `json:"gene_name,omitempty"`
	Organism    string `json:"organism"`
	TaxonomyID  int    `json:"taxonomy_id,omitempty"`
	Reviewed    bool   `json:"reviewed"` // Swiss-Prot vs TrEMBL
	Length      int    `json:"length,omitempty"`
	Function    string `json:"function,omitempty"`
}

Protein is a flattened, output-friendly UniProt protein record.

type SearchOptions

type SearchOptions struct {
	Limit    int
	Reviewed bool
}

SearchOptions controls the search query.

type Taxonomy

type Taxonomy struct {
	TaxonID    int    `json:"taxon_id"`
	Scientific string `json:"scientific_name"`
	Common     string `json:"common_name,omitempty"`
	Lineage    string `json:"lineage,omitempty"`
}

Taxonomy holds organism taxonomy info from UniProt.

Jump to

Keyboard shortcuts

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