Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix D: Quick Reference Card

A concise reference for BioLang syntax, builtins, REPL commands, and CLI usage.

Language Syntax

Variables

let x = 42
let name = "BRCA1"
let seq = dna"ATGCGATCG"
let rna_seq = rna"AUGCGAUCG"
let protein = protein"MARS"

Reassignment (updates an existing binding):

x = 100

Types

TypeExampleNotes
Int42Integer
Float3.14Floating-point
Str"hello"String
Booltrue, falseBoolean
NilnilNull value
DNAdna"ATGC"DNA sequence
RNArna"AUGC"RNA sequence
Proteinprotein"MARS"Amino acid sequence
List[1, 2, 3]Ordered collection
Record{name: "A", val: 1}Named fields
Tableto_table(rows, cols)2D data structure
Intervalinterval("chr1", 100, 200)Genomic region
Functionfn(x) { x + 1 }Named function
Closure|x| x + 1Anonymous function
Streamstream_fastq(path)Lazy iterator

Operators

OperatorMeaningExample
+ - * /Arithmetic3 + 4
%Modulo17 % 5
**Power2 ** 10
== !=Equalityx == 5
< > <= >=Comparisonx > 0
and or notLogicalx > 0 and x < 10
|>Pipex |> f()
~ApproximatePattern matching
..Range1..10

Pipe Syntax

The pipe operator passes the left-hand value as the first argument to the right-hand function:

# These are equivalent:
x |> f(y)
f(x, y)

# Chaining multiple operations:
data
  |> filter(|r| r.quality > 30)
  |> map(|r| gc_content(r.sequence))
  |> mean()

Functions

Named functions:

let square = fn(x) {
  x * x
}

Closures (anonymous functions / lambdas):

|x| x * 2
|a, b| a + b
|r| r.quality >= 30

Records

let gene = {name: "TP53", chrom: "chr17", start: 7571720}
gene.name        # Access field: "TP53"
keys(gene)       # ["name", "chrom", "start"]
values(gene)     # ["TP53", "chr17", 7571720]

Lists

let nums = [1, 2, 3, 4, 5]
nums[0]          # First element: 1
len(nums)        # Length: 5
nums |> map(|x| x * 2)    # [2, 4, 6, 8, 10]
nums |> filter(|x| x > 3) # [4, 5]

Tables

let t = to_table(rows, ["name", "value", "score"])
t |> select("name", "score")
t |> where(|row| row.score > 0.5)
t |> mutate("log_score", |row| log2(row.score))
t |> summarize(|key, rows| {category: key, mean_score: mean(rows |> col("score"))})
t |> group_by("category")
t |> sort_by("score", "desc")

Control Flow

# If/else
if x > 0 then
  println("positive")
else
  println("non-positive")
end

# For loop
for item in items do
  println(item)
end

# While loop
while x > 0 do
  x = x - 1
end

Error Handling

try
  let data = read_fasta("missing.fa")
catch e
  println(f"Error: {e}")
end

Requires CLI: This example uses file I/O not available in the browser. Run with bl run.

Imports

import "utils.bl"
import "helpers.bl" as h
h.my_function()

Builtins by Category

Sequence Operations

FunctionDescription
gc_content(seq)GC fraction (0.0-1.0)
complement(seq)Complementary strand
reverse_complement(seq)Reverse complement
translate(seq)DNA/RNA to protein
kmers(seq, k)List of k-mers
find_motif(seq, pattern)Find motif positions

File I/O

FunctionDescription
read_fasta(path)Read FASTA file, returns list of records
read_fastq(path)Read FASTQ file, returns list of records
read_csv(path)Read CSV file, returns table
read_vcf(path)Read VCF file, returns list of variant records
read_bed(path)Read BED file, returns list of interval records
read_gff(path)Read GFF/GTF file, returns list of feature records
write_csv(table, path)Write table to CSV
write_fasta(records, path)Write records to FASTA

Streaming

FunctionDescription
stream_fastq(path)Lazy FASTQ iterator (memory-efficient)
stream_fasta(path)Lazy FASTA iterator (memory-efficient)

Table Operations

FunctionDescription
to_table(rows, columns)Create table from row data and column names
select(table, "col1", "col2", ...)Select columns by name
where(table, predicate)Filter rows by condition
mutate(table, name, func)Add or transform a column
summarize(grouped, |key, rows| {...})Aggregate grouped data
join_tables(t1, t2, key)Join two tables on a key column
group_by(table, column)Group rows by column value
sort_by(table, column, order)Sort rows ("asc" or "desc")

Statistics

FunctionDescription
mean(list)Arithmetic mean
median(list)Median value
stdev(list)Standard deviation
var(list)Variance
t_test(list1, list2)Two-sample t-test
cor(list1, list2)Pearson correlation

Math

FunctionDescription
log(x)Natural logarithm
log2(x)Base-2 logarithm
log10(x)Base-10 logarithm
abs(x)Absolute value
sqrt(x)Square root
pow(base, exp)Exponentiation
round(x)Round to nearest integer
ceil(x)Round up
floor(x)Round down

Visualization

FunctionDescription
scatter(x, y, opts)Scatter plot
bar(labels, values, opts)Bar chart
hist(values, opts)Histogram
heatmap(matrix, opts)Heatmap
box(groups, opts)Box plot
line(x, y, opts)Line chart
volcano(log2fc, pvals, opts)Volcano plot
dotplot(data, opts)Dot plot
phylo_tree(tree, opts)Phylogenetic tree

String Operations

FunctionDescription
split(str, delimiter)Split string into list
join(list, delimiter)Join list into string
trim(str)Remove leading/trailing whitespace
upper(str)Convert to uppercase
lower(str)Convert to lowercase
contains(str, substring)Check if substring exists
starts_with(str, prefix)Check prefix
ends_with(str, suffix)Check suffix
replace(str, old, new)Replace occurrences

Higher-Order Functions

FunctionDescription
map(collection, func)Transform each element
filter(collection, func)Keep elements matching predicate
reduce(collection, func, init)Fold into single value
sort(collection, func)Sort by comparison function
each(collection, func)Execute function for each element (no return)
flatten(nested_list)Flatten one level of nesting
group_by(list, func)Group elements by key function
par_map(collection, func)Parallel map (multi-threaded)
par_filter(collection, func)Parallel filter (multi-threaded)

API Access

FunctionDescription
ncbi_search(db, query)Search NCBI database
ncbi_gene(symbol, species)Get gene info from NCBI
ncbi_sequence(id)Fetch sequence by accession
ensembl_gene(id_or_symbol)Get gene info from Ensembl
ensembl_vep(hgvs)Variant Effect Predictor
uniprot_search(query)Search UniProt
uniprot_entry(accession)Get UniProt entry
ucsc_sequence(genome, chrom, start, end)Get UCSC sequence
kegg_get(id)Get KEGG entry
kegg_find(db, query)Search KEGG
go_term(id)Get Gene Ontology term
go_annotations(gene)Get GO annotations
string_network(genes, species)STRING protein network
pdb_entry(id)Get PDB structure entry
reactome_pathways(gene)Get Reactome pathways
cosmic_gene(symbol)COSMIC cancer mutations
datasets_gene(symbol)NCBI Datasets gene info

Utility Functions

FunctionDescription
println(value)Print to stdout with newline
len(collection)Length of list, string, or table
typeof(value)Type name as string
keys(record)Record field names
values(record)Record field values
range(start, end)Integer range
zip(list1, list2)Pair elements from two lists
json_encode(value)Convert to JSON string
json_decode(str)Parse JSON string to value

File System

FunctionDescription
file_exists(path)Check if file exists
read_lines(path)Read file as list of lines
write_lines(lines, path)Write list of lines to file
mkdir(path)Create directory
list_dir(path)List directory contents

LLM Integration

FunctionDescription
chat(prompt)Send prompt to configured LLM, returns response

REPL Commands

Type these at the bl> prompt (they start with :):

CommandDescription
:helpShow all available REPL commands
:envDisplay all variables in the current environment
:resetClear the environment and start fresh
:load file.blLoad and execute a BioLang script
:save file.blSave the current session history to a file
:time expressionExecute an expression and print elapsed time
:type expressionShow the type of an expression without executing it
:profile expressionProfile execution with detailed timing
:pluginsList available plugins
:historyShow command history for the session
:plotDisplay the most recently generated plot

CLI Commands

The bl command-line tool:

CommandDescription
bl run script.blExecute a BioLang script
bl replStart interactive REPL (also: bl with no args)
bl lspStart the Language Server Protocol server
bl init project-nameScaffold a new project directory
bl pluginsList installed plugins

Common Usage Patterns

Run a script:

bl run analysis.bl

Run a one-liner:

bl -e 'gc_content(dna"ATGCGATCG") |> println()'

Start the REPL and load a file:

bl repl
bl> :load helpers.bl
bl> my_function("input.fasta")

Run with environment variables:

NCBI_API_KEY=your-key bl run fetch_genes.bl

Common Patterns

Read, Filter, Analyze

read_fastq("data/reads.fastq")
  |> filter(|r| r.quality >= 30)
  |> map(|r| gc_content(r.sequence))
  |> mean()

Requires CLI: This example uses file I/O not available in the browser. Run with bl run.

Stream Large Files

stream_fastq("huge.fastq")
  |> filter(|r| len(r.sequence) >= 100)
  |> each(|r| println(r.name))

Requires CLI: This example uses file I/O not available in the browser. Run with bl run.

Build a Summary Table

let reads = read_fastq("data/reads.fastq")
let rows = reads |> map(|r| {
  name: r.name,
  length: len(r.sequence),
  gc: gc_content(r.sequence),
  quality: r.quality
})
let t = to_table(rows, ["name", "length", "gc", "quality"])
t |> sort_by("gc", "desc") |> write_csv("summary.csv")

Requires CLI: This example uses file I/O not available in the browser. Run with bl run.

Fetch and Analyze from Database

let gene = ncbi_gene("TP53", "human")
let seq = ncbi_sequence(gene.id)
let motifs = find_motif(seq, "TATA")
println(f"Found {len(motifs)} TATA boxes in TP53")

Requires CLI: This example uses network APIs not available in the browser. Run with bl run.

Multi-Step Pipeline with Error Handling

try
  let variants = read_vcf("data/variants.vcf")
  let filtered = variants
    |> filter(|v| v.quality >= 30)
    |> filter(|v| v.alt != ".")
  println(f"Kept {len(filtered)} of {len(variants)} variants")
  write_csv(to_table(filtered, keys(filtered[0])), "filtered.csv")
catch e
  println(f"Pipeline failed: {e}")
end

Requires CLI: This example uses file I/O not available in the browser. Run with bl run.

Parallel Processing

let files = list_dir("fastq/") |> filter(|f| ends_with(f, ".fastq"))
let results = files |> par_map(|f| {
  let reads = read_fastq(f)
  {
    file: f,
    count: len(reads),
    mean_gc: reads |> map(|r| gc_content(r.sequence)) |> mean()
  }
})
to_table(results, ["file", "count", "mean_gc"]) |> write_csv("batch_results.csv")

Requires CLI: This example uses file I/O not available in the browser. Run with bl run.