biosample

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

Documentation

Overview

Package biosample is the library behind the biosample command line: the HTTP client, request shaping, and the typed data models for NCBI BioSample.

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 = "biosample-cli/dev (+https://github.com/tamnd/biosample-cli)"

DefaultUserAgent identifies the client to NCBI.

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

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

Variables

This section is empty.

Functions

This section is empty.

Types

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 BioSample 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) FetchSamples

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

FetchSamples fetches esummary for a batch of BioSample UIDs and returns Sample 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) GetSample

func (c *Client) GetSample(ctx context.Context, uid string) (*Sample, error)

GetSample fetches a single BioSample 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 BioSample 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) ([]*Sample, int, error)

SearchAndFetch runs Search then FetchSamples in one call.

type Config

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

Config carries the tunable parameters for the BioSample 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 BioSample 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). All-digit strings are BioSample UIDs. Anything else is an error.

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 Sample

type Sample struct {
	ID              string `json:"id"               kit:"id"` // BioSample UID (numeric)
	Accession       string `json:"accession"`
	Title           string `json:"title"`
	Organism        string `json:"organism,omitempty"`
	TaxID           string `json:"tax_id,omitempty"`
	Organization    string `json:"organization,omitempty"`
	Status          string `json:"status,omitempty"`
	PublicationDate string `json:"publication_date,omitempty"`
	SubmissionDate  string `json:"submission_date,omitempty"`
}

Sample is a single NCBI BioSample record.

Jump to

Keyboard shortcuts

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