Show a track programmatically
Open a track from code rather than the init prop.
launchTrack and the view’s other actions are in the
CircularView state model.
View source — 51 lines
import { useEffect } from 'react'
import {
JBrowseCircularGenomeView,
useCreateViewState,
} from '@jbrowse/react-circular-genome-view2'
const assembly = {
name: 'volvox',
aliases: ['vvx'],
sequence: {
adapter: {
type: 'TwoBitAdapter',
uri: 'https://jbrowse.org/genomes/volvox/volvox.2bit',
},
},
refNameAliases: {
adapter: {
type: 'FromConfigAdapter',
adapterId: 'W6DyPGJ0UU',
features: [
{ refName: 'ctgA', uniqueId: 'alias1', aliases: ['A', 'contigA'] },
{ refName: 'ctgB', uniqueId: 'alias2', aliases: ['B', 'contigB'] },
],
},
},
}
const tracks = [
{
type: 'VariantTrack',
trackId: 'volvox_sv_test',
name: 'volvox structural variant test',
category: ['VCF'],
assemblyNames: ['volvox'],
adapter: {
type: 'VcfTabixAdapter',
uri: 'https://jbrowse.org/code/jb2/main/test_data/volvox/volvox.dup.vcf.gz',
},
},
]
export default function ShowTrack() {
const state = useCreateViewState({ assembly, tracks })
useEffect(() => {
void state?.session.view.launchTrack('volvox_sv_test')
}, [state])
return state ? <JBrowseCircularGenomeView viewState={state} /> : null
}