uniref

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: 12 Imported by: 0

Documentation

Overview

Package uniref is the library behind the uniref command line: the HTTP client, request shaping, and the typed data models for the UniRef REST API (UniProt Reference Clusters, 381M protein cluster records).

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 + "/uniref"

BaseURL is the root every UniRef request is built from.

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

DefaultUserAgent identifies the client to UniRef 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 UniRef 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) GetCluster

func (c *Client) GetCluster(ctx context.Context, id string) (*Cluster, error)

GetCluster fetches a single cluster by ID (e.g. "UniRef50_P04637").

func (*Client) GetMembers

func (c *Client) GetMembers(ctx context.Context, id string, limit int) ([]*Member, error)

GetMembers fetches members of a cluster by ID.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, limit int) ([]*Cluster, error)

Search searches UniRef clusters by query string.

type Cluster

type Cluster struct {
	ID           string `json:"id"            kit:"id"`
	Name         string `json:"name"`
	EntryType    string `json:"entry_type"`
	MemberCount  int    `json:"member_count"`
	TaxonName    string `json:"taxon_name,omitempty"`
	TaxonID      int    `json:"taxon_id,omitempty"`
	Updated      string `json:"updated,omitempty"`
	RepName      string `json:"representative_name,omitempty"`
	RepProtein   string `json:"representative_protein,omitempty"`
	RepAccession string `json:"representative_accession,omitempty"`
	SeqLength    int    `json:"seq_length,omitempty"`
	MolWeight    int    `json:"mol_weight,omitempty"`
}

Cluster is a flattened, output-friendly UniRef cluster record.

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 uniref 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). Inputs matching UniRef(50|90|100)_... pattern map to type "cluster".

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 Member

type Member struct {
	ID        string `json:"id"         kit:"id"` // memberId
	Type      string `json:"type"`
	Organism  string `json:"organism,omitempty"`
	Protein   string `json:"protein,omitempty"`
	Accession string `json:"accession,omitempty"`
	UniRef50  string `json:"uniref50,omitempty"`
	UniRef90  string `json:"uniref90,omitempty"`
	UniRef100 string `json:"uniref100,omitempty"`
}

Member is a single member entry within a UniRef cluster.

Jump to

Keyboard shortcuts

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