Indexed FASTA Six-Frame Translation¶
This example translates the visible reference sequence in all three reading frames on both strands. A reference sequence track sits above the six translation lanes.
{
"description": [
"Indexed FASTA Six-Frame Translation",
"Translates a visible hg38 FASTA interval in three forward and three reverse reading frames using generic flattenSequence, lookup, window, and formula transforms.",
"Data source: UCSC hg38 / GRCh38 reference FASTA (`goldenPath/hg38/bigZips/latest/hg38.fa.gz`). Terms: UCSC downloadable data files are freely reusable."
],
"assembly": "hg38",
"name": "indexed-fasta-six-frame-translation",
"scales": {
"x": {
"domain": [
{ "chrom": "chr7", "pos": 20395929 },
{ "chrom": "chr7", "pos": 20395976 }
]
}
},
"datasets": {
"nucleotideComplements": [
{ "base": "A", "complement": "T" },
{ "base": "C", "complement": "G" },
{ "base": "G", "complement": "C" },
{ "base": "T", "complement": "A" },
{ "base": "N", "complement": "N" }
],
"geneticCode": [
{ "codon": "TTT", "aminoAcid": "F", "kind": "other" },
{ "codon": "TTC", "aminoAcid": "F", "kind": "other" },
{ "codon": "TTA", "aminoAcid": "L", "kind": "other" },
{ "codon": "TTG", "aminoAcid": "L", "kind": "other" },
{ "codon": "TCT", "aminoAcid": "S", "kind": "other" },
{ "codon": "TCC", "aminoAcid": "S", "kind": "other" },
{ "codon": "TCA", "aminoAcid": "S", "kind": "other" },
{ "codon": "TCG", "aminoAcid": "S", "kind": "other" },
{ "codon": "TAT", "aminoAcid": "Y", "kind": "other" },
{ "codon": "TAC", "aminoAcid": "Y", "kind": "other" },
{ "codon": "TAA", "aminoAcid": "STOP", "kind": "stop" },
{ "codon": "TAG", "aminoAcid": "STOP", "kind": "stop" },
{ "codon": "TGT", "aminoAcid": "C", "kind": "other" },
{ "codon": "TGC", "aminoAcid": "C", "kind": "other" },
{ "codon": "TGA", "aminoAcid": "STOP", "kind": "stop" },
{ "codon": "TGG", "aminoAcid": "W", "kind": "other" },
{ "codon": "CTT", "aminoAcid": "L", "kind": "other" },
{ "codon": "CTC", "aminoAcid": "L", "kind": "other" },
{ "codon": "CTA", "aminoAcid": "L", "kind": "other" },
{ "codon": "CTG", "aminoAcid": "L", "kind": "other" },
{ "codon": "CCT", "aminoAcid": "P", "kind": "other" },
{ "codon": "CCC", "aminoAcid": "P", "kind": "other" },
{ "codon": "CCA", "aminoAcid": "P", "kind": "other" },
{ "codon": "CCG", "aminoAcid": "P", "kind": "other" },
{ "codon": "CAT", "aminoAcid": "H", "kind": "other" },
{ "codon": "CAC", "aminoAcid": "H", "kind": "other" },
{ "codon": "CAA", "aminoAcid": "Q", "kind": "other" },
{ "codon": "CAG", "aminoAcid": "Q", "kind": "other" },
{ "codon": "CGT", "aminoAcid": "R", "kind": "other" },
{ "codon": "CGC", "aminoAcid": "R", "kind": "other" },
{ "codon": "CGA", "aminoAcid": "R", "kind": "other" },
{ "codon": "CGG", "aminoAcid": "R", "kind": "other" },
{ "codon": "ATT", "aminoAcid": "I", "kind": "other" },
{ "codon": "ATC", "aminoAcid": "I", "kind": "other" },
{ "codon": "ATA", "aminoAcid": "I", "kind": "other" },
{ "codon": "ATG", "aminoAcid": "M", "kind": "start" },
{ "codon": "ACT", "aminoAcid": "T", "kind": "other" },
{ "codon": "ACC", "aminoAcid": "T", "kind": "other" },
{ "codon": "ACA", "aminoAcid": "T", "kind": "other" },
{ "codon": "ACG", "aminoAcid": "T", "kind": "other" },
{ "codon": "AAT", "aminoAcid": "N", "kind": "other" },
{ "codon": "AAC", "aminoAcid": "N", "kind": "other" },
{ "codon": "AAA", "aminoAcid": "K", "kind": "other" },
{ "codon": "AAG", "aminoAcid": "K", "kind": "other" },
{ "codon": "AGT", "aminoAcid": "S", "kind": "other" },
{ "codon": "AGC", "aminoAcid": "S", "kind": "other" },
{ "codon": "AGA", "aminoAcid": "R", "kind": "other" },
{ "codon": "AGG", "aminoAcid": "R", "kind": "other" },
{ "codon": "GTT", "aminoAcid": "V", "kind": "other" },
{ "codon": "GTC", "aminoAcid": "V", "kind": "other" },
{ "codon": "GTA", "aminoAcid": "V", "kind": "other" },
{ "codon": "GTG", "aminoAcid": "V", "kind": "other" },
{ "codon": "GCT", "aminoAcid": "A", "kind": "other" },
{ "codon": "GCC", "aminoAcid": "A", "kind": "other" },
{ "codon": "GCA", "aminoAcid": "A", "kind": "other" },
{ "codon": "GCG", "aminoAcid": "A", "kind": "other" },
{ "codon": "GAT", "aminoAcid": "D", "kind": "other" },
{ "codon": "GAC", "aminoAcid": "D", "kind": "other" },
{ "codon": "GAA", "aminoAcid": "E", "kind": "other" },
{ "codon": "GAG", "aminoAcid": "E", "kind": "other" },
{ "codon": "GGT", "aminoAcid": "G", "kind": "other" },
{ "codon": "GGC", "aminoAcid": "G", "kind": "other" },
{ "codon": "GGA", "aminoAcid": "G", "kind": "other" },
{ "codon": "GGG", "aminoAcid": "G", "kind": "other" }
]
},
"resolve": { "axis": { "x": "shared" } },
"spacing": 5,
"data": {
"lazy": {
"type": "indexedFasta",
"url": "https://data.genomespy.app/genomes/hg38/hg38.fa"
}
},
"transform": [
{
"type": "flattenSequence",
"field": "sequence",
"as": ["rawPos", "base"]
},
{
"type": "formula",
"expr": "datum.start + datum.rawPos",
"as": "pos"
}
],
"vconcat": [
{
"name": "reference-bases",
"height": 20,
"encoding": {
"x": { "chrom": "chrom", "pos": "pos", "type": "locus" },
"color": {
"field": "base",
"type": "nominal",
"scale": {
"domain": ["A", "C", "T", "G", "a", "c", "t", "g", "N"],
"range": [
"#7BD56C",
"#FF9B9B",
"#86BBF1",
"#FFC56C",
"#7BD56C",
"#FF9B9B",
"#86BBF1",
"#FFC56C",
"#E0E0E0"
]
},
"legend": null
}
},
"layer": [
{
"name": "reference-base-background",
"mark": { "type": "rect", "tooltip": null }
},
{
"name": "reference-base-labels",
"mark": {
"type": "text",
"size": 13,
"fitToBand": true,
"paddingX": 1.5,
"paddingY": 1,
"opacity": 0.7,
"flushX": false,
"tooltip": null
},
"encoding": {
"color": { "value": "black" },
"text": { "field": "base" }
}
}
]
},
{
"name": "translation",
"height": { "step": 17 },
"view": { "stroke": "#c0c0c0" },
"encoding": {
"y": {
"field": "lane",
"type": "ordinal",
"scale": {
"domain": [
"forward 2",
"forward 1",
"forward 0",
"reverse 0",
"reverse 1",
"reverse 2"
]
},
"axis": { "title": null }
},
"x": {
"chrom": "chrom",
"pos": "pos",
"type": "locus",
"band": 0
},
"x2": { "chrom": "chrom", "pos": "end", "band": 0 }
},
"transform": [
{ "type": "formula", "expr": "upper(datum.base)", "as": "base" },
{
"type": "lookup",
"from": { "name": "nucleotideComplements" },
"key": "base",
"values": ["complement"],
"default": "N"
},
{
"type": "window",
"sort": { "field": "pos" },
"ops": ["lead", "lead", "lead", "lead"],
"fields": ["base", "base", "complement", "complement"],
"params": [1, 2, 1, 2],
"as": ["base1", "base2", "complement1", "complement2"]
},
{
"type": "filter",
"expr": "isValid(datum.base2) && isValid(datum.complement2)"
},
{ "type": "formula", "expr": "datum.pos + 3", "as": "end" }
],
"templates": {
"amino-acid-translation": {
"params": [{ "name": "strand", "value": "forward" }],
"transform": [
{
"type": "formula",
"expr": "strand === 'reverse' ? datum.complement2 + datum.complement1 + datum.complement : datum.base + datum.base1 + datum.base2",
"as": "codon"
},
{
"type": "lookup",
"from": { "name": "geneticCode" },
"key": "codon",
"default": "?"
},
{
"type": "formula",
"expr": "strand + ' ' + (datum.pos % 3)",
"as": "lane"
}
],
"layer": [
{
"name": "amino-acids",
"mark": {
"type": "arrow",
"style": "arrow-block-notch",
"stroke": "#C0C0C0",
"headAngle": 65,
"strokeWidth": {
"expr": "1.0 - smoothstep(0.2, 1, span(domain('x')) / width)"
},
"tooltip": null
},
"encoding": {
"direction": { "value": { "expr": "strand" } },
"color": {
"field": "kind",
"type": "nominal",
"scale": {
"domain": ["start", "stop", "other", "?"],
"range": ["#40B050", "#F06060", "#F8F8F8", "#E0E0E0"]
},
"legend": null
}
}
},
{
"name": "amino-acid-labels",
"mark": {
"type": "text",
"size": 12,
"paddingX": 1.5,
"tooltip": null
},
"encoding": {
"color": { "value": "black" },
"text": { "field": "aminoAcid" }
}
}
]
}
},
"layer": [
{
"import": { "template": "amino-acid-translation" },
"name": "forward-translation",
"params": { "strand": "forward" }
},
{
"import": { "template": "amino-acid-translation" },
"name": "reverse-translation",
"params": { "strand": "reverse" }
}
]
}
]
}
The visualization uses a mirrored, indexed copy of UCSC's hg38 / GRCh38 reference FASTA from goldenPath/hg38/bigZips/latest/hg38.fa.gz. UCSC states that its downloadable data files and database tables are freely available for public and commercial use, subject to any upstream restrictions noted for the original assembly data.
What to notice¶
The indexedFasta source returns lazily loaded sequence chunks for the visible
region. These chunks are expanded into base-level rows with absolute genomic
coordinates. The concatenated reference and translation views inherit those
rows, so the two tracks remain aligned while panning.
The translation view uppercases bases, looks up nucleotide complements, and
uses four window lead operations to gather the following two bases and
complements. Rows without two following bases are removed before translation,
so a chunk's final two bases never form partial codons.
The forward and reverse views each assemble a codon and look up its amino acid in the standard genetic code. Reverse codons concatenate the three complements in reverse order. Their lanes use the absolute genomic position modulo three, which keeps reading-frame assignments stable even when a lazy reload begins at a different position.
Start codons are green and stop codons are red. The amino-acid blocks use notched arrows with white outlines and 65-degree heads; their labels are placed over the three-base spans.
GenomeSpy Features¶
This example combines several GenomeSpy capabilities in one track:
- Lazy data sources load reference sequence only for the visible region.
flattenSequenceandformulaturn sequence chunks into base-level genomic rows.lookupmaps nucleotide complements and codons through root-level lookup tables.windowuses sortedleadvalues to create overlapping three-base windows without sequence-specific logic.- Named templates define the shared translation track, with each import supplying its strand.
vconcatkeeps the reference sequence and translation tracks separate while sharing their x scale.arrowmarks show the forward and reverse reading directions for each amino-acid block.