Gene density and transposon density along a chromosome
The tutorials target the JBrowse v5 beta, and the v4.3.0 release
on the download page lacks some of what they show. To install the
beta of JBrowse Web, run npm install -g @jbrowse/cli@next, then
jbrowse create jbrowse2 --branch v5.0.0-beta.22. Desktop beta builds for Linux and
macOS are on the releases page;
the Windows build waits on code signing.
We look at where the genes sit along human chromosome 1 and which transposons sit near them: Alu elements pile up where the genes are, and L1 elements spread more evenly. A whole chromosome holds more genes, and far more repeat copies, than a browser fetches at once. We:
- count each file's features per kilobase into a small bigWig with
jbrowse make-density - load the bigWigs as quantitative tracks of gene and repeat density along chromosome 1
- zoom in to 1q21 and add the genes as a feature track beside the counts
Prerequisites
- a JBrowse to open the figures' sessions in (Web or Desktop)
- Node.js, which the JBrowse CLI runs on
- the JBrowse CLI, for
jbrowse make-density bedGraphToBigWigfrom the UCSC utilities, whichmake-densityruns- htslib (
bgzip,tabix), for the build script
# Debian/Ubuntu
sudo apt install tabix nodejs
# or conda, which has every tool above
conda install -c bioconda -c conda-forge htslib nodejs ucsc-bedgraphtobigwig
# or Linux x86_64 binaries for the tools apt lacks
wget -P ~/.local/bin \
https://hgdownload.soe.ucsc.edu/admin/exe/linux.x86_64/bedGraphToBigWig
chmod +x ~/.local/bin/bedGraphToBigWig
# any platform
npm install -g @jbrowse/cli@nextThe data
The figures read UCSC's hg38 annotation tables, rehosted by genomes.jbrowse.org's hg38 with a per-kilobase bigWig beside each file.
You don't need these files to follow the page: the track configs below read the hosted results. The build script fetches them to rebuild those results. The counting step takes any GFF3, BED or VCF of your own.
| What it is | File |
|---|---|
RefSeq curated genes, UCSC's ncbiRefSeqCurated table as GFF3 |
ncbiRefSeqCurated.gff.gz |
RepeatMasker, UCSC's rmsk table as BED with a column header |
rmsk.bed.gz |
| Reference lengths, for the bigWig header | hg38.chrom.sizes |
Loading hg38
We'll load hg38, the assembly the UCSC tables were cut from. Every track below
names it in assemblyNames.
Goes in the assemblies array of config.json. See Assemblies.
{
"name": "hg38",
"uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz",
"refNameAliases": {
"uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt"
},
"cytobands": "https://jbrowse.org/genomes/GRCh38/cytoBand.txt"
}Edits config.json in the current folder, creating it if there is none. See JBrowse CLI with Desktop.
jbrowse add-assembly https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz \
--name hg38 \
--refNameAliases https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt \
--config '{"cytobands":"https://jbrowse.org/genomes/GRCh38/cytoBand.txt"}'hg38 is one of the genomes JBrowse Desktop hosts, with gene tracks already set up: on the start screen click Browse hosted genomes and pick it. To load the files of this config instead:
In JBrowse Desktop, Open your own genome on the start screen (or File → Open genome... in a session), then Open from a URL and paste, one per line:
https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz
https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.fai
https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.gziJBrowse reads the format off the file name. Then fill in:
- Genome name:
hg38 - refName aliases (under More options):
https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt - cytobands (under More options):
https://jbrowse.org/genomes/GRCh38/cytoBand.txt
Counting features per kilobase into a bigWig
One bigWig per file holds the number of features starting in each 1 kb bin,
counted once. jbrowse make-density reads the GFF3 and writes it beside the
input, named for the file with .density.bw in place of its .gz:
# --chrom-sizes gives the bigWig header its reference lengths;
# --assembly hg38.fa reads them off the FASTA's .fai instead
# a GFF3 counts only lines with no Parent= attribute, so a gene is one
# count however many transcripts and exons hang under it; a BED or VCF
# counts every record, and a GTF its transcript rows
# every bin is written, empty ones included, so the zoomed-out levels of
# the bigWig average over the whole span
jbrowse make-density genes.gff.gz --chrom-sizes hg38.chrom.sizesAdd the bigWig as a track:
Goes in the tracks array of config.json. See Tracks.
{
"trackId": "hg38_genes_density",
"name": "RefSeq genes per kb",
"assemblyNames": ["hg38"],
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.density.bw",
"displayDefaults": { "mark": { "extent": "none" } }
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track https://jbrowse.org/demos/gene_density/genes.gff.density.bw \
--trackId hg38_genes_density \
--name "RefSeq genes per kb" \
--assemblyNames hg38 \
--displayDefaults '{"mark":{"extent":"none"}}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"trackId": "hg38_genes_density",
"name": "RefSeq genes per kb",
"assemblyNames": ["hg38"],
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.density.bw",
"displayDefaults": { "mark": { "extent": "none" } }
}Open this track in JBrowse Web ↗
Needs JBrowse Desktop 5.0 or newer. If nothing opens, copy the link and paste it into Desktop's Open JBrowse Web link..., on the start screen or under File → Session.
https://jbrowse.org/code/jb2/main/?config=https%3A%2F%2Fjbrowse.org%2Fucsc%2Fhg38%2Fconfig.json&session=spec-%7B%22sessionTracks%22%3A%5B%7B%22trackId%22%3A%22hg38_genes_density%22%2C%22name%22%3A%22RefSeq+genes+per+kb%22%2C%22assemblyNames%22%3A%5B%22hg38%22%5D%2C%22uri%22%3A%22https%3A%2F%2Fjbrowse.org%2Fdemos%2Fgene_density%2Fgenes.gff.density.bw%22%2C%22displayDefaults%22%3A%7B%22mark%22%3A%7B%22extent%22%3A%22none%22%7D%7D%7D%5D%2C%22views%22%3A%5B%7B%22type%22%3A%22LinearGenomeView%22%2C%22assembly%22%3A%22hg38%22%2C%22loc%22%3A%22chr1%22%2C%22tracks%22%3A%5B%22hg38_genes_density%22%5D%7D%5D%7D&sessionName=JBrowse+docs%3A+RefSeq+genes+per+kbThis view in a notebook, with jbrowse-anywidget. Swap a track's uri for your file.
from jbrowse_anywidget import JBrowseApp, fetch_hub
config = fetch_hub("https://jbrowse.org/ucsc/hg38/config.json")
app = JBrowseApp(
assemblies=config["assemblies"],
tracks=config.get("tracks", []) + [
{
"trackId": "hg38_genes_density",
"name": "RefSeq genes per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
],
views=[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1",
"tracks": [
"hg38_genes_density"
]
}
],
)
app # display the widgetThis view in your React 19 app, with @jbrowse/react-app2 and @jbrowse/core. Add your own files to tracks.
import { use } from 'react'
import { JBrowse } from '@jbrowse/react-app2'
import '@jbrowse/react-app2/styles.css'
import { addRelativeUris } from '@jbrowse/core/util/addRelativeUris'
const configUrl = "https://jbrowse.org/ucsc/hg38/config.json"
const configPromise = fetch(configUrl)
.then(res => res.json())
.then(config => {
addRelativeUris(config, new URL(configUrl))
return config
})
export default function Figure() {
const config = use(configPromise)
return (
<JBrowse
assemblies={config.assemblies}
tracks={[...(config.tracks ?? []), ...[
{
"trackId": "hg38_genes_density",
"name": "RefSeq genes per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
]]}
aggregateTextSearchAdapters={config.aggregateTextSearchAdapters}
configuration={config.configuration}
views={[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1",
"tracks": [
"hg38_genes_density"
]
}
]}
/>
)
}jbrowse-img draws this view as an SVG, no browser needed. Swap --config or a track for your own.
cat > tracks.json <<'JSON'
[
{
"trackId": "hg38_genes_density",
"name": "RefSeq genes per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
]
JSON
npx @jbrowse/img --config https://jbrowse.org/ucsc/hg38/config.json \
--trackConfigs tracks.json \
--assembly hg38 --loc chr1 \
--track hg38_genes_density \
--out figure.svgFor a PNG, --out figure.png (needs rsvg-convert: apt install librsvg2-bin, brew install librsvg).
mark.extent: "none" draws each bin's mean alone. Most kilobases hold no gene
or one, so the min-max band drawn around the mean would fill every zoomed-out
pixel to the same height.
The Alu, L1 and simple-repeat tracks start from a RepeatMasker BED. For a genome
of your own, RepeatMasker's .out file lists class and family as one
class/family field, and splitting it under a header that names the columns
gives a BED with the same columns:
# the header names the columns, so a track or an awk filter can name repFamily
{
printf '#genoName\tgenoStart\tgenoEnd\tname\tstrand\trepFamily\trepClass\tswScore\tmilliDiv\n'
awk 'BEGIN { OFS = "\t" }
# a data row is the one starting with a bare integer, its SW score
$1 ~ /^[0-9]+$/ {
# "LINE/L1" splits; "Simple_repeat" does not, and UCSC repeats the class
# as the family for exactly those rows. Positions are 1-based inclusive
# and the strand column spells minus "C".
n = split($11, cf, "/")
print $5, $6 - 1, $7, $10, ($9 == "C") ? "-" : "+", (n > 1) ? cf[2] : cf[1], cf[1], $1, int($2 * 10 + 0.5)
}' repeats.out
} > rmsk.bed
# `sort-bed` is `sort -k1,1 -k2,2n` under LC_ALL=C, header kept on top
jbrowse sort-bed rmsk.bed | bgzip > rmsk.bed.gz
tabix -f -C -p bed rmsk.bed.gzWe cut that table into one BED per repFamily, so the Alu bigWig counts only
Alus. An awk filter keeps the header line and the sort order, so tabix
indexes each cut file as it is:
# rmsk.bed.gz is a RepeatMasker BED whose header names repFamily as the sixth
# column; swap Alu for L1 or Simple_repeat for the other two
gzip -dc rmsk.bed.gz | awk -F'\t' -v fam=Alu '/^#/ || $6 == fam' | bgzip > Alu.bed.gz
tabix -f -C -p bed Alu.bed.gzThe make-density line above, run on Alu.bed.gz, writes Alu.bed.density.bw:
Goes in the tracks array of config.json. See Tracks.
{
"trackId": "hg38_Alu_density",
"name": "Alu per kb",
"assemblyNames": ["hg38"],
"uri": "https://jbrowse.org/demos/gene_density/Alu.bed.density.bw",
"displayDefaults": { "mark": { "extent": "none" } }
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track https://jbrowse.org/demos/gene_density/Alu.bed.density.bw \
--trackId hg38_Alu_density \
--name "Alu per kb" \
--assemblyNames hg38 \
--displayDefaults '{"mark":{"extent":"none"}}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"trackId": "hg38_Alu_density",
"name": "Alu per kb",
"assemblyNames": ["hg38"],
"uri": "https://jbrowse.org/demos/gene_density/Alu.bed.density.bw",
"displayDefaults": { "mark": { "extent": "none" } }
}Open this track in JBrowse Web ↗
Needs JBrowse Desktop 5.0 or newer. If nothing opens, copy the link and paste it into Desktop's Open JBrowse Web link..., on the start screen or under File → Session.
https://jbrowse.org/code/jb2/main/?config=https%3A%2F%2Fjbrowse.org%2Fucsc%2Fhg38%2Fconfig.json&session=spec-%7B%22sessionTracks%22%3A%5B%7B%22trackId%22%3A%22hg38_Alu_density%22%2C%22name%22%3A%22Alu+per+kb%22%2C%22assemblyNames%22%3A%5B%22hg38%22%5D%2C%22uri%22%3A%22https%3A%2F%2Fjbrowse.org%2Fdemos%2Fgene_density%2FAlu.bed.density.bw%22%2C%22displayDefaults%22%3A%7B%22mark%22%3A%7B%22extent%22%3A%22none%22%7D%7D%7D%5D%2C%22views%22%3A%5B%7B%22type%22%3A%22LinearGenomeView%22%2C%22assembly%22%3A%22hg38%22%2C%22loc%22%3A%22chr1%22%2C%22tracks%22%3A%5B%22hg38_Alu_density%22%5D%7D%5D%7D&sessionName=JBrowse+docs%3A+Alu+per+kbThis view in a notebook, with jbrowse-anywidget. Swap a track's uri for your file.
from jbrowse_anywidget import JBrowseApp, fetch_hub
config = fetch_hub("https://jbrowse.org/ucsc/hg38/config.json")
app = JBrowseApp(
assemblies=config["assemblies"],
tracks=config.get("tracks", []) + [
{
"trackId": "hg38_Alu_density",
"name": "Alu per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/Alu.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
],
views=[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1",
"tracks": [
"hg38_Alu_density"
]
}
],
)
app # display the widgetThis view in your React 19 app, with @jbrowse/react-app2 and @jbrowse/core. Add your own files to tracks.
import { use } from 'react'
import { JBrowse } from '@jbrowse/react-app2'
import '@jbrowse/react-app2/styles.css'
import { addRelativeUris } from '@jbrowse/core/util/addRelativeUris'
const configUrl = "https://jbrowse.org/ucsc/hg38/config.json"
const configPromise = fetch(configUrl)
.then(res => res.json())
.then(config => {
addRelativeUris(config, new URL(configUrl))
return config
})
export default function Figure() {
const config = use(configPromise)
return (
<JBrowse
assemblies={config.assemblies}
tracks={[...(config.tracks ?? []), ...[
{
"trackId": "hg38_Alu_density",
"name": "Alu per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/Alu.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
]]}
aggregateTextSearchAdapters={config.aggregateTextSearchAdapters}
configuration={config.configuration}
views={[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1",
"tracks": [
"hg38_Alu_density"
]
}
]}
/>
)
}jbrowse-img draws this view as an SVG, no browser needed. Swap --config or a track for your own.
cat > tracks.json <<'JSON'
[
{
"trackId": "hg38_Alu_density",
"name": "Alu per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/Alu.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
]
JSON
npx @jbrowse/img --config https://jbrowse.org/ucsc/hg38/config.json \
--trackConfigs tracks.json \
--assembly hg38 --loc chr1 \
--track hg38_Alu_density \
--out figure.svgFor a PNG, --out figure.png (needs rsvg-convert: apt install librsvg2-bin, brew install librsvg).
The L1 track and the simple-repeat control follow, with the file names swapped:
Goes in the tracks array of config.json. See Tracks.
{
"trackId": "hg38_L1_density",
"name": "L1 per kb",
"assemblyNames": ["hg38"],
"uri": "https://jbrowse.org/demos/gene_density/L1.bed.density.bw",
"displayDefaults": { "mark": { "extent": "none" } }
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track https://jbrowse.org/demos/gene_density/L1.bed.density.bw \
--trackId hg38_L1_density \
--name "L1 per kb" \
--assemblyNames hg38 \
--displayDefaults '{"mark":{"extent":"none"}}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"trackId": "hg38_L1_density",
"name": "L1 per kb",
"assemblyNames": ["hg38"],
"uri": "https://jbrowse.org/demos/gene_density/L1.bed.density.bw",
"displayDefaults": { "mark": { "extent": "none" } }
}Open this track in JBrowse Web ↗
Needs JBrowse Desktop 5.0 or newer. If nothing opens, copy the link and paste it into Desktop's Open JBrowse Web link..., on the start screen or under File → Session.
https://jbrowse.org/code/jb2/main/?config=https%3A%2F%2Fjbrowse.org%2Fucsc%2Fhg38%2Fconfig.json&session=spec-%7B%22sessionTracks%22%3A%5B%7B%22trackId%22%3A%22hg38_L1_density%22%2C%22name%22%3A%22L1+per+kb%22%2C%22assemblyNames%22%3A%5B%22hg38%22%5D%2C%22uri%22%3A%22https%3A%2F%2Fjbrowse.org%2Fdemos%2Fgene_density%2FL1.bed.density.bw%22%2C%22displayDefaults%22%3A%7B%22mark%22%3A%7B%22extent%22%3A%22none%22%7D%7D%7D%5D%2C%22views%22%3A%5B%7B%22type%22%3A%22LinearGenomeView%22%2C%22assembly%22%3A%22hg38%22%2C%22loc%22%3A%22chr1%22%2C%22tracks%22%3A%5B%22hg38_L1_density%22%5D%7D%5D%7D&sessionName=JBrowse+docs%3A+L1+per+kbThis view in a notebook, with jbrowse-anywidget. Swap a track's uri for your file.
from jbrowse_anywidget import JBrowseApp, fetch_hub
config = fetch_hub("https://jbrowse.org/ucsc/hg38/config.json")
app = JBrowseApp(
assemblies=config["assemblies"],
tracks=config.get("tracks", []) + [
{
"trackId": "hg38_L1_density",
"name": "L1 per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/L1.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
],
views=[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1",
"tracks": [
"hg38_L1_density"
]
}
],
)
app # display the widgetThis view in your React 19 app, with @jbrowse/react-app2 and @jbrowse/core. Add your own files to tracks.
import { use } from 'react'
import { JBrowse } from '@jbrowse/react-app2'
import '@jbrowse/react-app2/styles.css'
import { addRelativeUris } from '@jbrowse/core/util/addRelativeUris'
const configUrl = "https://jbrowse.org/ucsc/hg38/config.json"
const configPromise = fetch(configUrl)
.then(res => res.json())
.then(config => {
addRelativeUris(config, new URL(configUrl))
return config
})
export default function Figure() {
const config = use(configPromise)
return (
<JBrowse
assemblies={config.assemblies}
tracks={[...(config.tracks ?? []), ...[
{
"trackId": "hg38_L1_density",
"name": "L1 per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/L1.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
]]}
aggregateTextSearchAdapters={config.aggregateTextSearchAdapters}
configuration={config.configuration}
views={[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1",
"tracks": [
"hg38_L1_density"
]
}
]}
/>
)
}jbrowse-img draws this view as an SVG, no browser needed. Swap --config or a track for your own.
cat > tracks.json <<'JSON'
[
{
"trackId": "hg38_L1_density",
"name": "L1 per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/L1.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
]
JSON
npx @jbrowse/img --config https://jbrowse.org/ucsc/hg38/config.json \
--trackConfigs tracks.json \
--assembly hg38 --loc chr1 \
--track hg38_L1_density \
--out figure.svgFor a PNG, --out figure.png (needs rsvg-convert: apt install librsvg2-bin, brew install librsvg).
Goes in the tracks array of config.json. See Tracks.
{
"trackId": "hg38_Simple_repeat_density",
"name": "Simple repeats per kb",
"assemblyNames": ["hg38"],
"uri": "https://jbrowse.org/demos/gene_density/Simple_repeat.bed.density.bw",
"displayDefaults": { "mark": { "extent": "none" } }
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track https://jbrowse.org/demos/gene_density/Simple_repeat.bed.density.bw \
--trackId hg38_Simple_repeat_density \
--name "Simple repeats per kb" \
--assemblyNames hg38 \
--displayDefaults '{"mark":{"extent":"none"}}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"trackId": "hg38_Simple_repeat_density",
"name": "Simple repeats per kb",
"assemblyNames": ["hg38"],
"uri": "https://jbrowse.org/demos/gene_density/Simple_repeat.bed.density.bw",
"displayDefaults": { "mark": { "extent": "none" } }
}Open this track in JBrowse Web ↗
Needs JBrowse Desktop 5.0 or newer. If nothing opens, copy the link and paste it into Desktop's Open JBrowse Web link..., on the start screen or under File → Session.
https://jbrowse.org/code/jb2/main/?config=https%3A%2F%2Fjbrowse.org%2Fucsc%2Fhg38%2Fconfig.json&session=spec-%7B%22sessionTracks%22%3A%5B%7B%22trackId%22%3A%22hg38_Simple_repeat_density%22%2C%22name%22%3A%22Simple+repeats+per+kb%22%2C%22assemblyNames%22%3A%5B%22hg38%22%5D%2C%22uri%22%3A%22https%3A%2F%2Fjbrowse.org%2Fdemos%2Fgene_density%2FSimple_repeat.bed.density.bw%22%2C%22displayDefaults%22%3A%7B%22mark%22%3A%7B%22extent%22%3A%22none%22%7D%7D%7D%5D%2C%22views%22%3A%5B%7B%22type%22%3A%22LinearGenomeView%22%2C%22assembly%22%3A%22hg38%22%2C%22loc%22%3A%22chr1%22%2C%22tracks%22%3A%5B%22hg38_Simple_repeat_density%22%5D%7D%5D%7D&sessionName=JBrowse+docs%3A+Simple+repeats+per+kbThis view in a notebook, with jbrowse-anywidget. Swap a track's uri for your file.
from jbrowse_anywidget import JBrowseApp, fetch_hub
config = fetch_hub("https://jbrowse.org/ucsc/hg38/config.json")
app = JBrowseApp(
assemblies=config["assemblies"],
tracks=config.get("tracks", []) + [
{
"trackId": "hg38_Simple_repeat_density",
"name": "Simple repeats per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/Simple_repeat.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
],
views=[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1",
"tracks": [
"hg38_Simple_repeat_density"
]
}
],
)
app # display the widgetThis view in your React 19 app, with @jbrowse/react-app2 and @jbrowse/core. Add your own files to tracks.
import { use } from 'react'
import { JBrowse } from '@jbrowse/react-app2'
import '@jbrowse/react-app2/styles.css'
import { addRelativeUris } from '@jbrowse/core/util/addRelativeUris'
const configUrl = "https://jbrowse.org/ucsc/hg38/config.json"
const configPromise = fetch(configUrl)
.then(res => res.json())
.then(config => {
addRelativeUris(config, new URL(configUrl))
return config
})
export default function Figure() {
const config = use(configPromise)
return (
<JBrowse
assemblies={config.assemblies}
tracks={[...(config.tracks ?? []), ...[
{
"trackId": "hg38_Simple_repeat_density",
"name": "Simple repeats per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/Simple_repeat.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
]]}
aggregateTextSearchAdapters={config.aggregateTextSearchAdapters}
configuration={config.configuration}
views={[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1",
"tracks": [
"hg38_Simple_repeat_density"
]
}
]}
/>
)
}jbrowse-img draws this view as an SVG, no browser needed. Swap --config or a track for your own.
cat > tracks.json <<'JSON'
[
{
"trackId": "hg38_Simple_repeat_density",
"name": "Simple repeats per kb",
"assemblyNames": [
"hg38"
],
"uri": "https://jbrowse.org/demos/gene_density/Simple_repeat.bed.density.bw",
"displayDefaults": {
"mark": {
"extent": "none"
}
}
}
]
JSON
npx @jbrowse/img --config https://jbrowse.org/ucsc/hg38/config.json \
--trackConfigs tracks.json \
--assembly hg38 --loc chr1 \
--track hg38_Simple_repeat_density \
--out figure.svgFor a PNG, --out figure.png (needs rsvg-convert: apt install librsvg2-bin, brew install librsvg).
Gene and repeat density along chromosome 1
Add the tracks above, then open chromosome 1 with all of them.
The gap in every track is the centromere and the 1q12 heterochromatin beside it.
Zooming in to 1q21 with the genes as features
Add the gene file as a track, then type chr1:150,000,000-160,000,000, 10 Mb
over 1q21 to 1q23. At this width the gene track's fetch fits, so it draws each
gene:
Goes in the tracks array of config.json. See Tracks.
{
"type": "FeatureTrack",
"trackId": "hg38_genes",
"name": "RefSeq curated genes",
"assemblyNames": ["hg38"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.gz",
"csi": true
}
}Edits config.json in the current folder. See JBrowse CLI with Desktop.
jbrowse add-track-json '{
"type": "FeatureTrack",
"trackId": "hg38_genes",
"name": "RefSeq curated genes",
"assemblyNames": ["hg38"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.gz",
"csi": true
}
}'In JBrowse Desktop, or in any running JBrowse Web session, open a view on this track’s assembly, then File → Open track..., choose Add track from pasted JSON, and paste:
{
"type": "FeatureTrack",
"trackId": "hg38_genes",
"name": "RefSeq curated genes",
"assemblyNames": ["hg38"],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.gz",
"csi": true
}
}Open this track in JBrowse Web ↗
Needs JBrowse Desktop 5.0 or newer. If nothing opens, copy the link and paste it into Desktop's Open JBrowse Web link..., on the start screen or under File → Session.
https://jbrowse.org/code/jb2/main/?config=https%3A%2F%2Fjbrowse.org%2Fucsc%2Fhg38%2Fconfig.json&session=spec-%7B%22sessionTracks%22%3A%5B%7B%22type%22%3A%22FeatureTrack%22%2C%22trackId%22%3A%22hg38_genes%22%2C%22name%22%3A%22RefSeq+curated+genes%22%2C%22assemblyNames%22%3A%5B%22hg38%22%5D%2C%22adapter%22%3A%7B%22type%22%3A%22Gff3TabixAdapter%22%2C%22uri%22%3A%22https%3A%2F%2Fjbrowse.org%2Fdemos%2Fgene_density%2Fgenes.gff.gz%22%2C%22csi%22%3Atrue%7D%7D%5D%2C%22views%22%3A%5B%7B%22type%22%3A%22LinearGenomeView%22%2C%22assembly%22%3A%22hg38%22%2C%22loc%22%3A%22chr1%3A150%2C000%2C000-160%2C000%2C000%22%2C%22tracks%22%3A%5B%22hg38_genes%22%5D%7D%5D%7D&sessionName=JBrowse+docs%3A+RefSeq+curated+genesThis view in a notebook, with jbrowse-anywidget. Swap a track's uri for your file.
from jbrowse_anywidget import JBrowseApp, fetch_hub
config = fetch_hub("https://jbrowse.org/ucsc/hg38/config.json")
app = JBrowseApp(
assemblies=config["assemblies"],
tracks=config.get("tracks", []) + [
{
"type": "FeatureTrack",
"trackId": "hg38_genes",
"name": "RefSeq curated genes",
"assemblyNames": [
"hg38"
],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.gz",
"csi": True
}
}
],
views=[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1:150,000,000-160,000,000",
"tracks": [
"hg38_genes"
]
}
],
)
app # display the widgetThis view in your React 19 app, with @jbrowse/react-app2 and @jbrowse/core. Add your own files to tracks.
import { use } from 'react'
import { JBrowse } from '@jbrowse/react-app2'
import '@jbrowse/react-app2/styles.css'
import { addRelativeUris } from '@jbrowse/core/util/addRelativeUris'
const configUrl = "https://jbrowse.org/ucsc/hg38/config.json"
const configPromise = fetch(configUrl)
.then(res => res.json())
.then(config => {
addRelativeUris(config, new URL(configUrl))
return config
})
export default function Figure() {
const config = use(configPromise)
return (
<JBrowse
assemblies={config.assemblies}
tracks={[...(config.tracks ?? []), ...[
{
"type": "FeatureTrack",
"trackId": "hg38_genes",
"name": "RefSeq curated genes",
"assemblyNames": [
"hg38"
],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.gz",
"csi": true
}
}
]]}
aggregateTextSearchAdapters={config.aggregateTextSearchAdapters}
configuration={config.configuration}
views={[
{
"type": "LinearGenomeView",
"assembly": "hg38",
"loc": "chr1:150,000,000-160,000,000",
"tracks": [
"hg38_genes"
]
}
]}
/>
)
}jbrowse-img draws this view as an SVG, no browser needed. Swap --config or a track for your own.
cat > tracks.json <<'JSON'
[
{
"type": "FeatureTrack",
"trackId": "hg38_genes",
"name": "RefSeq curated genes",
"assemblyNames": [
"hg38"
],
"adapter": {
"type": "Gff3TabixAdapter",
"uri": "https://jbrowse.org/demos/gene_density/genes.gff.gz",
"csi": true
}
}
]
JSON
npx @jbrowse/img --config https://jbrowse.org/ucsc/hg38/config.json \
--trackConfigs tracks.json \
--assembly hg38 --loc chr1:150,000,000-160,000,000 \
--track hg38_genes \
--out figure.svgFor a PNG, --out figure.png (needs rsvg-convert: apt install librsvg2-bin, brew install librsvg).
Reproduce it end to end
build_gene_density.sh
wraps every step above. It:
- fetches the two UCSC tables and the reference lengths
- cuts the RepeatMasker table into the three family BEDs
- counts each file per kilobase into a bigWig
- writes a JBrowse with the files and their bigWigs as tracks
curl -fO https://raw.githubusercontent.com/GMOD/jbrowse-components/main/scripts/build_gene_density.sh
bash build_gene_density.sh # builds ./gene_density_build/jbrowse2
npx --yes serve gene_density_build/jbrowse2 # then open the printed URLSee also
- Tutorial: RepeatMasker as one row per class
- Tutorial: Synteny on a circle (human and mouse)
- Tutorial: A map of the human mitochondrial genome
- Tutorial: Reviewing a gene prediction (Tiberius)
- Docs: Command line tools (JBrowse CLI)
- Docs: JBrowse web quick start
Citations
- Lander et al. (2001). Initial sequencing and analysis of the human genome
- Smit, Hubley and Green (2013-2015). RepeatMasker Open-4.0
Feedback on this tutorial is welcome: contact us.