ncbinucleotide

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

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

View Source
const (
	Rate    = 400 * time.Millisecond
	Retries = 3
	Timeout = 30 * time.Second
)

Default client settings.

View Source
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.

View Source
const Host = "eutils.ncbi.nlm.nih.gov"

Host is the NCBI eUtils hostname this client talks to.

View Source
const NucleotideURL = "https://www.ncbi.nlm.nih.gov/nuccore"

NucleotideURL is the base URL for NCBI Nucleotide human-readable pages.

Variables

View Source
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

func (c *Client) FetchSequences(ctx context.Context, ids []string) ([]*Sequence, error)

FetchSequences retrieves summaries for a list of UIDs in a single batch request and returns them as Sequence records.

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.

func (*Client) GetSequence

func (c *Client) GetSequence(ctx context.Context, uid string) (*Sequence, error)

GetSequence fetches a single sequence by its numeric UID (GI number).

func (*Client) Search

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

Search queries NCBI Nucleotide for sequences matching query and returns the list of UIDs plus the total count of matching records.

func (*Client) SearchAndFetch

func (c *Client) SearchAndFetch(ctx context.Context, query string, limit, start int) ([]*Sequence, int, error)

SearchAndFetch searches for sequences and returns them with the total count in a single call.

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

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

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.

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 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.

Jump to

Keyboard shortcuts

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