JBrowse 2 · Linear Genome View examples

Text search

Search by gene name or ID, across all tracks with an aggregate adapter, or per-track.

Aggregate text searching

Typing a gene symbol into the location box jumps the view to matching features, given a prebuilt trix index. An aggregate index covers several tracks at once — the right shape when you want one global search — and goes on aggregateTextSearchAdapters.

Build it with the --file form of jbrowse text-index, one --file/--fileId pair per track:

jbrowse text-index --file genes.gff3.gz --fileId volvox_genes \
                   --file vars.vcf.gz   --fileId volvox_vars

Two ways to get this wrong, both quiet: --fileId must match the runtime trackId, or a hit has no way to know which track to open; and the two flags are paired by position, so a --fileId list that doesn’t run in the same order as the --file list indexes each track under its neighbour’s id.

For one index per track instead, see per-track text searching.

View source — 37 lines
import {
  JBrowseLinearGenomeView,
  useCreateViewState,
} from '@jbrowse/react-linear-genome-view2'

export default function WithAggregateTextSearching() {
  const state = useCreateViewState({
    assembly: {
      name: 'volvox',
      uri: 'https://jbrowse.org/genomes/volvox/volvox.2bit',
    },
    aggregateTextSearchAdapters: [
      {
        type: 'TrixTextSearchAdapter',
        // point `uri` at the `.ix`; the `.ixx` and `_meta.json` are derived
        uri: 'https://jbrowse.org/code/jb2/main/test_data/volvox/storybook_data/volvox.ix',
        assemblyNames: ['volvox'],
      },
    ],
    tracks: [
      {
        type: 'FeatureTrack',
        // trackId matches the id baked into the index, so a search hit (type
        // "EDEN" in the location box) both navigates and opens this track
        trackId: 'gff3tabix_genes',
        name: 'Volvox genes',
        assemblyNames: ['volvox'],
        adapter: {
          type: 'Gff3TabixAdapter',
          uri: 'https://jbrowse.org/code/jb2/main/test_data/volvox/volvox.sort.gff3.gz',
        },
      },
    ],
    location: 'ctgA:1..800',
  })
  return <JBrowseLinearGenomeView viewState={state} />
}

Per-track text searching

A per-track index lives in a textSearching block on the track config rather than at the top level, and is opened only when that track loads — the right shape when tracks come and go dynamically.

Build it with jbrowse text-index --file myfile.gff3.gz --fileId my_track, where --fileId matches the runtime trackId. Slots are documented in TrixTextSearchAdapter. For one index spanning many tracks, see aggregate text searching.

View source — 35 lines
import {
  JBrowseLinearGenomeView,
  useCreateViewState,
} from '@jbrowse/react-linear-genome-view2'

export default function WithPerTrackTextSearching() {
  const state = useCreateViewState({
    assembly: {
      name: 'volvox',
      uri: 'https://jbrowse.org/genomes/volvox/volvox.2bit',
    },
    tracks: [
      {
        type: 'FeatureTrack',
        trackId: 'gff3tabix_genes',
        assemblyNames: ['volvox'],
        name: 'GFF3Tabix genes',
        adapter: {
          type: 'Gff3TabixAdapter',
          uri: 'https://jbrowse.org/code/jb2/main/test_data/volvox/volvox.sort.gff3.gz',
        },
        textSearching: {
          textSearchAdapter: {
            type: 'TrixTextSearchAdapter',
            // point `uri` at the `.ix`; the `.ixx` and `_meta.json` are derived
            uri: 'https://jbrowse.org/code/jb2/main/test_data/volvox/storybook_data/gff3tabix_genes.ix',
            assemblyNames: ['volvox'],
          },
        },
      },
    ],
    location: 'ctgA:1..800',
  })
  return <JBrowseLinearGenomeView viewState={state} />
}