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:

FieldTypeDescription
statusintHTTP status code
bodystringResponse body
headersmapResponse headers
OptionTypeDescription
headersmapRequest headers
# Fetch gene info from NCBI
let resp = http_get("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi", {
  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-CHM13")
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
DatabaseExample IDReturns
"ncbi_gene"672Gene summary, aliases, location
"uniprot""P38398"Protein info, sequence, function
"ensembl""ENSG00000012048"Gene model, transcripts
"clinvar""VCV000017661"Variant clinical significance
let gene = bio_fetch("ncbi_gene", 672)
println("Name:", gene.name)              # "BRCA1"
println("Location:", gene.location)      # "17q21.31"
println("Summary:", gene.summary)

let protein = bio_fetch("uniprot", "P38398")
println("Length:", protein.length, "aa")
println("Function:", protein.function)