ncbiassembly

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 ncbiassembly is the library behind the ncbiassembly command line: the HTTP client, request shaping, and the typed data models for the NCBI Assembly database (3.6M+ genome assemblies).

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. Search and summary calls follow the standard eUtils two-step: esearch returns a list of numeric UIDs, esummary turns them into records.

Index

Constants

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

DefaultUserAgent identifies the client to NCBI.

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

Host is the NCBI Assembly web host, used for Locate / URI resolution.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assembly

type Assembly struct {
	ID          string `json:"id"             kit:"id"` // numeric UID
	Accession   string `json:"accession,omitempty"`
	Name        string `json:"name,omitempty"`
	Organism    string `json:"organism,omitempty"`
	SpeciesName string `json:"species,omitempty"`
	TaxID       string `json:"tax_id,omitempty"`
	Type        string `json:"type,omitempty"`
	Status      string `json:"status,omitempty"`
	WGS         string `json:"wgs,omitempty"`
	BioSample   string `json:"biosample,omitempty"`
}

Assembly is a single NCBI Assembly record.

type Client

type Client struct {
	HTTP *http.Client

	// exported shims so domain.go newClient can set them like the scaffold does
	UserAgent string
	Rate      time.Duration
	Retries   int
	// contains filtered or unexported fields
}

Client talks to the NCBI eUtils Assembly API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with the default config.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

NewClientWithConfig returns a Client using the given config.

func (*Client) FetchAssemblies

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

FetchAssemblies fetches esummary for a batch of Assembly UIDs and returns Assembly records.

func (*Client) Get

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

Get fetches rawURL and returns the response body, pacing and retrying.

func (*Client) GetAssembly

func (c *Client) GetAssembly(ctx context.Context, uid string) (*Assembly, error)

GetAssembly fetches a single Assembly record by numeric UID.

func (*Client) Search

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

Search runs an esearch query against the Assembly database and returns a list of numeric UIDs plus the total count.

func (*Client) SearchAndFetch

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

SearchAndFetch runs Search then FetchAssemblies in one call.

type Config

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

Config carries the tunable parameters for the Assembly client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for the free-tier NCBI eUtils API (3 req/s without a key).

type Domain

type Domain struct{}

Domain is the NCBI Assembly 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 the canonical (type, id). Non-empty strings are accepted and returned as assembly IDs.

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.

Jump to

Keyboard shortcuts

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