@weng-lab/genomebrowser
TypeScript icon, indicating that this package has built-in type declarations

0.0.24 • Public • Published

Genome Browser Component Library

Installation

yarn add @weng-lab/genomebrowser

npm install @weng-lab/genomebrowser

Usage

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.

Walkthrough

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.

  1. 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 });
  1. 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>
  1. 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
}

Full Example

// 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>
    )
}

The browser will look something like this: Browser Example

Package Sidebar

Install

npm i @weng-lab/genomebrowser

Weekly Downloads

10

Version

0.0.24

License

ISC

Unpacked Size

6.94 MB

Total Files

185

Last publish

Collaborators

  • jairmeza
  • wenglab-umms
  • jfisher72
  • nishiphalke