HTTP & Network
6 functions for HTTP requests, file downloads, and biological database queries.
HTTP Methods
http_get(url, opts?) -> response
http_post(url, body, opts?) -> response
All return a response map:
| Field | Type | Description |
|---|---|---|
| status | int | HTTP status code |
| body | string | Response body |
| headers | map | Response headers |
| Option | Type | Description |
|---|---|---|
| headers | map | Request headers |
# Fetch gene info from NCBI
# esummary.fcgi needs db, id and retmode; without them it answers with an
# error page, and json_parse then fails on the first character.
let resp = http_get("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=gene&id=672&retmode=json", {
headers: {"Accept": "application/json"}
})
let data = json_parse(resp.body)
# POST to REST API
resp = http_post("https://api.example.com/submit", "{\"sample\": \"S001\", \"pipeline\": \"rnaseq\"}")
download / upload
Download a file from a URL or upload to an endpoint. Downloads support resume and progress.
download(url, path?) -> string # returns local path
upload(path, url, opts?) -> response
# Download reference genome
download(
"https://ftp.ensembl.org/pub/release-111/fasta/homo_sapiens/dna/Homo_sapiens.GRCh38.dna.primary_assembly.fa.gz",
"reference/GRCh38.fa.gz"
)
# Download (auto-infer filename from URL)
download("https://example.com/data.bam")
ref_genome
Download a reference genome by name from built-in sources registry. Handles URL resolution, checksum verification, and caching.
ref_genome(name, opts?) -> string
let ref = ref_genome("GRCh38") # downloads if not cached
let ref37 = ref_genome("GRCh37")
let t2t = ref_genome("t2t")
let dbsnp = ref_genome("dbSNP") # also works for databases
# With specific output location
ref_genome("GRCh38", {outdir: "references/"})
bio_fetch
Fetch a record from a biological database by ID. Supports NCBI, UniProt, Ensembl, and more.
bio_fetch(database, id) -> map
| Database | Example ID | Returns |
|---|---|---|
| "ncbi_gene" | 672 | Gene summary, aliases, location |
| "uniprot" | "P38398" | Protein info, sequence, function |
| "ensembl" | "ENSG00000012048" | Gene model, transcripts |
| "clinvar" | "VCV000017661" | Variant clinical significance |
# bio_fetch downloads reference datasets — genomes, annotations, variant
# sets — and its sources are named accordingly. It is not a record lookup:
# there is no "ncbi_gene" or "uniprot" source.
bio_sources() |> take(3) |> println()
# For a single database record, call the API client directly.
let protein = uniprot_entry("P38398")
println("Name:", protein.name) # "Breast cancer type 1 susceptibility protein"
println("Organism:", protein.organism) # "Homo sapiens"
println("Function:", protein.function)