Custom browser tutorial

When your genome is one of the hosted hubs, JBrowseR("hg38") is all you need. This tutorial covers the other case: building a browser for a genome you host yourself, with your own tracks, gene-name search, and theme.

library(JBrowseR)

Describe the assembly

assembly() builds the reference from a FASTA URL. JBrowse derives the index locations (.fai, plus .gzi for bgzipped FASTA) from the URL, so you only point at the FASTA itself. Add reference-name aliases so chr1/1 both resolve.

hg19 <- assembly(
  "https://jbrowse.org/genomes/hg19/fasta/hg19.fa.gz",
  aliases = "GRCh37",
  refname_aliases = "https://jbrowse.org/genomes/hg19/hg19_aliases.txt"
)

Add tracks

track() infers the track type and adapter from the file extension. Group your tracks with tracks(). You do not need to set assemblyNames on each track — JBrowseR() fills it in from the assembly you load.

my_tracks <- tracks(
  track(
    "https://jbrowse.org/genomes/hg19/GRCh37_latest_genomic.sort.gff.gz",
    name = "NCBI RefSeq Genes"
  )
)

Put it together

JBrowseR(
  assembly = hg19,
  tracks = my_tracks,
  text_search = hg19_search,
  theme = theme("#311b92", "#0097a7"),
  location = "MYC"
)

Show results computed in R

track_data_frame() turns a data frame into an in-browser track with no files and no server — the natural way to put an analysis you ran in R onto the genome. The frame needs chrom, start, end, and name columns; an optional score column makes it a quantitative track.

regions <- data.frame(
  chrom = c("10", "10"),
  start = c(29838737, 29850000),
  end   = c(29840000, 29855000),
  name  = c("regionA", "regionB"),
  score = c(42, 88)
)

JBrowseR(
  assembly = hg19,
  tracks = list(track_data_frame(regions, "my_regions")),
  location = "10:29,838,737..29,855,000"
)

Reacting to clicks in Shiny

When rendered inside Shiny, clicking a feature sets input$selectedFeature to the feature’s data, so you can build tables, plots, or links from the current selection.

# server side
output$browser <- renderJBrowseR(
  JBrowseR(assembly = hg19, tracks = my_tracks, location = "MYC")
)
observeEvent(input$selectedFeature, {
  print(input$selectedFeature$name)
})