yarn add @weng-lab/genomebrowser
npm install @weng-lab/genomebrowser
The library revolves around creating tracks and adding them to the browser. To do this, first you import the Genome Browser component, creating the browser state and dispatch function, and adding your tracks to the state. Then you pass the state and dispatch function to the GenomeBrowser component as props.
First, import the Genome Browser component:
import { GenomeBrowser } from '@weng-lab/genomebrowser';
Then you create the browser state and dispatch function with the useBrowserState
hook:
import { useBrowserState } from '@weng-lab/genomebrowser';
const [browserState, browserDispatch] = useBrowserState({
domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
preRenderedWidth: 1350,
width: 1500,
tracks: [],
highlights: []
});
There are a few ways to add tracks to the browser.
- You can add a track by dispatching the
ADD_TRACK
action:
import { BigWigTrackProps } from '@weng-lab/genomebrowser';
const myBigWig: BigWigTrackProps = { ... }
browserDispatch({ type: BrowserActionType.ADD_TRACK, track: myBigWig });
- You can add a track by passing a track component as a child to the GenomeBrowser component:
import { BigBedTrack } from '@weng-lab/genomebrowser';
<GenomeBrowser browserState={browserState} browserDispatch={browserDispatch}>
<BigBedTrack ... />
</GenomeBrowser>
- You can also add a track by appending it to the 'tracks' array in the browser state:
import { BigWigTrackProps, BrowserState } from '@weng-lab/genomebrowser';
const myBigWig: BigWigTrackProps = { ... }
const myState: BrowserState = {
domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
... // initialize the rest of the state
tracks: [myBigWig] // add the track to the state
}
// in trackExamples.ts
export const bigWigExample: BigWigTrackProps = {
...DefaultBigWig,
id: "1",
title: "bigwig",
height: 100,
url: "https://downloads.wenglab.org/DNAse_All_ENCODE_MAR20_2024_merged.bw",
color: "blue"
}
export const bigBedExample: BigBedTrackProps = {
...DefaultBigBed,
id: "2",
title: "bigbed",
height: 75,
rowHeight: 12,
color: "red",
url: "https://downloads.wenglab.org/GRCh38-cCREs.DCC.bigBed"
}
export const transcriptExample: TranscriptTrackProps = {
...DefaultTranscript,
id: "3",
title: "transcript",
rowHeight: 12,
assembly: "GRCh38",
queryType: "gene",
version: TranscriptHumanVersion.V47,
height: 100,
color: "green"
}
// in main.tsx
import { useEffect } from 'react'
import {
GenomeBrowser, BrowserState, BrowserActionType, useBrowserState,
BigBedTrack
} from '../lib'
import { bigWigExample, bigBedExample, transcriptExample } from './trackExamples'
const defaultState: BrowserState = {
domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
preRenderedWidth: 1350,
width: 1500,
zoomLevel: 148,
delta: 0,
tracks: [bigWigExample] // adds a BigWig track to the state
}
function Main() {
const [browserState, browserDispatch] = useBrowserState(defaultState)
useEffect(() => {
// add a Transcript track to the state
browserDispatch({ type: BrowserActionType.ADD_TRACK, track: transcriptExample })
}, [])
return (
<GenomeBrowser browserState={browserState} browserDispatch={browserDispatch}>
<BigBedTrack {...bigBedExample} /> // add a BigBed track to the browser
</GenomeBrowser>
)
}