Documentation
¶
Overview ¶
Package ncbinucleotide is the library behind the ncbinucleotide command line: the HTTP client, request shaping, and the typed data models for NCBI Nucleotide.
The Client talks to the NCBI eUtils API (db=nucleotide). It sets a real User-Agent, paces requests to stay within NCBI's rate limits, and retries transient failures (429 and 5xx) automatically.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) FetchSequences(ctx context.Context, ids []string) ([]*Sequence, error)
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetSequence(ctx context.Context, uid string) (*Sequence, error)
- func (c *Client) Search(ctx context.Context, query string, limit, start int) ([]string, int, error)
- func (c *Client) SearchAndFetch(ctx context.Context, query string, limit, start int) ([]*Sequence, int, error)
- type Domain
- type Sequence
Constants ¶
const ( Rate = 400 * time.Millisecond Retries = 3 Timeout = 30 * time.Second )
Default client settings.
const DefaultUserAgent = "ncbinucleotide/dev (+https://github.com/tamnd/ncbinucleotide-cli)"
DefaultUserAgent identifies the client to NCBI. A real, honest User-Agent is both polite and the thing most likely to keep you unblocked.
const Host = "eutils.ncbi.nlm.nih.gov"
Host is the NCBI eUtils hostname this client talks to.
const NucleotideURL = "https://www.ncbi.nlm.nih.gov/nuccore"
NucleotideURL is the base URL for NCBI Nucleotide human-readable pages.
Variables ¶
var BaseURL = "https://" + Host + "/entrez/eutils"
BaseURL is the root every eUtils request is built from. It is a var so tests can swap it to point at an httptest.Server.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent 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 NCBI eUtils over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults aligned with NCBI's recommended usage: a 30s timeout, 400ms minimum gap between requests (3 requests/s without an API key), and 3 retries on transient errors.
func (*Client) FetchSequences ¶
FetchSequences retrieves summaries for a list of UIDs in a single batch request and returns them as Sequence records.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings.
func (*Client) GetSequence ¶
GetSequence fetches a single sequence by its numeric UID (GI number).
type Domain ¶
type Domain struct{}
Domain is the ncbinucleotide driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns any accepted input — a bare UID or a full NCBI nuccore URL — into the canonical (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.
type Sequence ¶
type Sequence struct {
ID string `json:"id" kit:"id"`
Accession string `json:"accession"`
Title string `json:"title"`
TaxID int `json:"tax_id,omitempty"`
Length int `json:"length,omitempty"`
BioMol string `json:"biomol,omitempty"`
MolType string `json:"mol_type,omitempty"`
Topology string `json:"topology,omitempty"`
SourceDB string `json:"source_db,omitempty"`
CreateDate string `json:"create_date,omitempty"`
UpdateDate string `json:"update_date,omitempty"`
}
Sequence is a single NCBI Nucleotide record.