sra

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

Documentation

Overview

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

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

DefaultUserAgent identifies the client to NCBI.

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

Host is the SRA site, 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 SRA 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) FetchRuns

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

FetchRuns fetches esummary for a batch of SRA UIDs and returns Run 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) GetRun

func (c *Client) GetRun(ctx context.Context, uid string) (*Run, error)

GetRun fetches a single SRA run 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 SRA 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) ([]*Run, int, error)

SearchAndFetch runs Search then FetchRuns 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 SRA 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 SRA 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 SRA UIDs. SRR/ERR/DRR accessions resolve via search. Any other non-empty string is treated as a run reference.

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 Run

type Run struct {
	ID         string `json:"id"                    kit:"id"` // SRA UID (numeric)
	Title      string `json:"title"`
	Accession  string `json:"accession,omitempty"` // first run acc (SRR...)
	Platform   string `json:"platform,omitempty"`
	Instrument string `json:"instrument,omitempty"`
	TaxID      string `json:"tax_id,omitempty"`
	TotalSpots string `json:"total_spots,omitempty"`
	TotalBases string `json:"total_bases,omitempty"`
	Status     string `json:"status,omitempty"`
	CreateDate string `json:"create_date,omitempty"`
	UpdateDate string `json:"update_date,omitempty"`
}

Run is a single SRA experiment/run record.

Jump to

Keyboard shortcuts

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