@weng-lab/genomebrowser 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +115 -40
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,50 +1,125 @@
1
- # React + TypeScript + Vite
1
+ # Genome Browser Component Library
2
2
 
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3
+ ## Installation
4
+ `yarn add @weng-lab/genomebrowser`
4
5
 
5
- Currently, two official plugins are available:
6
+ `npm install @weng-lab/genomebrowser`
6
7
 
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
8
+ ## Usage
9
9
 
10
- ## Expanding the ESLint configuration
10
+ 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.
11
11
 
12
- If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
12
+ ### Walkthrough
13
+ First, import the Genome Browser component:
14
+ ```tsx
15
+ import { GenomeBrowser } from '@weng-lab/genomebrowser';
16
+ ```
17
+ Then you create the browser state and dispatch function with the `useBrowserState` hook:
18
+
19
+ ```tsx
20
+ import { useBrowserState } from '@weng-lab/genomebrowser';
21
+ const [browserState, browserDispatch] = useBrowserState({
22
+ domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
23
+ preRenderedWidth: 1350,
24
+ width: 1500,
25
+ zoomLevel: 148,
26
+ delta: 0,
27
+ tracks: []
28
+ });
29
+ ```
30
+
31
+ There are a few ways to add tracks to the browser.
32
+ 1. You can add a track by dispatching the `ADD_TRACK` action:
33
+ ```tsx
34
+ import { BigWigTrackProps } from '@weng-lab/genomebrowser';
35
+ const myBigWig: BigWigTrackProps = { ... }
36
+ browserDispatch({ type: BrowserActionType.ADD_TRACK, track: myBigWig });
37
+ ```
38
+ 2. You can add a track by passing a track component as a child to the GenomeBrowser component:
39
+ ```tsx
40
+ import { BigBedTrack } from '@weng-lab/genomebrowser';
41
+ <GenomeBrowser browserState={browserState} browserDispatch={browserDispatch}>
42
+ <BigBedTrack ... />
43
+ </GenomeBrowser>
44
+ ```
45
+ 3. You can also add a track by appending it to the 'tracks' array in the browser state:
46
+ ```tsx
47
+ import { BigWigTrackProps, BrowserState } from '@weng-lab/genomebrowser';
48
+ const myBigWig: BigWigTrackProps = { ... }
49
+ const myState: BrowserState = {
50
+ domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
51
+ ... // initialize the rest of the state
52
+ tracks: [myBigWig] // add the track to the state
53
+ }
54
+ ```
13
55
 
14
- - Configure the top-level `parserOptions` property like this:
56
+ ## Full Example
15
57
 
16
- ```js
17
- export default tseslint.config({
18
- languageOptions: {
19
- // other options...
20
- parserOptions: {
21
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
22
- tsconfigRootDir: import.meta.dirname,
23
- },
24
- },
25
- })
58
+ ```tsx
59
+ // in trackExamples.ts
60
+ export const bigWigExample: BigWigTrackProps = {
61
+ ...DefaultBigWig,
62
+ id: "1",
63
+ title: "bigwig",
64
+ height: 100,
65
+ url: "https://downloads.wenglab.org/DNAse_All_ENCODE_MAR20_2024_merged.bw",
66
+ color: "blue"
67
+ }
68
+ export const bigBedExample: BigBedTrackProps = {
69
+ ...DefaultBigBed,
70
+ id: "2",
71
+ title: "bigbed",
72
+ height: 75,
73
+ rowHeight: 12,
74
+ color: "red",
75
+ url: "https://downloads.wenglab.org/GRCh38-cCREs.DCC.bigBed"
76
+ }
77
+ export const transcriptExample: TranscriptTrackProps = {
78
+ ...DefaultTranscript,
79
+ id: "3",
80
+ title: "transcript",
81
+ rowHeight: 12,
82
+ assembly: "GRCh38",
83
+ queryType: "gene",
84
+ version: TranscriptHumanVersion.V47,
85
+ height: 100,
86
+ color: "green"
87
+ }
26
88
  ```
27
89
 
28
- - Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
29
- - Optionally add `...tseslint.configs.stylisticTypeChecked`
30
- - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
31
-
32
- ```js
33
- // eslint.config.js
34
- import react from 'eslint-plugin-react'
35
-
36
- export default tseslint.config({
37
- // Set the react version
38
- settings: { react: { version: '18.3' } },
39
- plugins: {
40
- // Add the react plugin
41
- react,
42
- },
43
- rules: {
44
- // other rules...
45
- // Enable its recommended rules
46
- ...react.configs.recommended.rules,
47
- ...react.configs['jsx-runtime'].rules,
48
- },
49
- })
90
+ ```tsx
91
+ // in main.tsx
92
+ import { useEffect } from 'react'
93
+ import {
94
+ GenomeBrowser, BrowserState, BrowserActionType, useBrowserState,
95
+ BigBedTrack
96
+ } from '../lib'
97
+ import { bigWigExample, bigBedExample, transcriptExample } from './trackExamples'
98
+
99
+ const defaultState: BrowserState = {
100
+ domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
101
+ preRenderedWidth: 1350,
102
+ width: 1500,
103
+ zoomLevel: 148,
104
+ delta: 0,
105
+ tracks: [bigWigExample] // addS a BigWig track to the state
106
+ }
107
+
108
+ function Main() {
109
+ const [browserState, browserDispatch] = useBrowserState(defaultState)
110
+
111
+ useEffect(() => {
112
+ // add a Transcript track to the state
113
+ browserDispatch({ type: BrowserActionType.ADD_TRACK, track: transcriptExample })
114
+ }, [])
115
+
116
+ return (
117
+ <GenomeBrowser browserState={browserState} browserDispatch={browserDispatch}>
118
+ <BigBedTrack {...bigBedExample} /> // add a BigBed track to the browser
119
+ </GenomeBrowser>
120
+ )
121
+ }
50
122
  ```
123
+
124
+ The browser will look something like this:
125
+ ![Browser Example](image.png)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weng-lab/genomebrowser",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/weng-lab/genomebrowser.git"