ensembl

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package ensembl is the library behind the ensembl command line: the HTTP client, request shaping, and the typed data models for the Ensembl REST API (genomics/genetics).

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.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "ensembl-cli/0.1.0 (github.com/tamnd/ensembl-cli)"

DefaultUserAgent identifies the client to the Ensembl REST API.

View Source
const Host = "rest.ensembl.org"

Host is the Ensembl REST API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	BaseURL   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 the Ensembl REST API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func NewClientFromConfig

func NewClientFromConfig(cfg Config) *Client

NewClientFromConfig returns a Client configured from a Config struct.

func (*Client) Gene

func (c *Client) Gene(ctx context.Context, species, symbol string) (*Gene, error)

Gene looks up a gene by symbol for the given species. species defaults to "human" if empty.

func (*Client) GeneByID

func (c *Client) GeneByID(ctx context.Context, id string) (*Gene, error)

GeneByID looks up a gene by its Ensembl stable ID.

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) Region

func (c *Client) Region(ctx context.Context, species, region, feature string) ([]*Gene, error)

Region returns genes overlapping a chromosomal region for the given species. region format: "chr:start-end" e.g. "17:43044292-43125482" feature defaults to "gene" if empty.

func (*Client) SpeciesList

func (c *Client) SpeciesList(ctx context.Context) ([]*Species, error)

SpeciesList returns all species supported by the Ensembl REST API.

func (*Client) Variant

func (c *Client) Variant(ctx context.Context, species, variantID string) (*VariantRecode, error)

Variant recodes a variant (rs ID) to HGVS/VCF/SPDI for the given species.

type Config

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

Config holds all tunable parameters for the client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the Ensembl REST API.

type Domain

type Domain struct{}

Domain is the ensembl 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). Gene symbols (BRCA1, TP53) map to type "gene". Ensembl IDs (ENSG...) map to type "gene". rs IDs map to type "variant".

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 Gene

type Gene struct {
	ID           string `json:"id" kit:"id"`
	Symbol       string `json:"display_name,omitempty"`
	Description  string `json:"description,omitempty"`
	Chromosome   string `json:"chromosome"`
	Start        int    `json:"start"`
	End          int    `json:"end"`
	Strand       int    `json:"strand"`
	Biotype      string `json:"biotype,omitempty"`
	Species      string `json:"species,omitempty"`
	AssemblyName string `json:"assembly_name,omitempty"`
}

Gene represents a gene record from the Ensembl REST API.

type Species

type Species struct {
	Name        string `json:"name" kit:"id"`
	DisplayName string `json:"display_name"`
	Assembly    string `json:"assembly"`
	TaxonomyID  int    `json:"taxonomy_id"`
	Division    string `json:"division,omitempty"`
}

Species represents a species supported by the Ensembl REST API.

type VariantRecode

type VariantRecode struct {
	Input string   `json:"input" kit:"id"`
	HGVSG []string `json:"hgvsg,omitempty"`
	HGVSC []string `json:"hgvsc,omitempty"`
	HGVSP []string `json:"hgvsp,omitempty"`
	VCF   []string `json:"vcf,omitempty"`
	SPDI  []string `json:"spdi,omitempty"`
}

VariantRecode holds the recoded forms of a variant (rs ID to HGVS/VCF/SPDI).

Jump to

Keyboard shortcuts

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