@weng-lab/genomebrowser 0.0.2 → 0.0.4

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.
package/README.md CHANGED
@@ -1,50 +1,125 @@
1
- # React + TypeScript + Vite
2
-
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
-
5
- Currently, two official plugins are available:
6
-
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
9
-
10
- ## Expanding the ESLint configuration
11
-
12
- If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13
-
14
- - Configure the top-level `parserOptions` property like this:
15
-
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
- })
26
- ```
27
-
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
- })
50
- ```
1
+ # Genome Browser Component Library
2
+
3
+ ## Installation
4
+ `yarn add @weng-lab/genomebrowser`
5
+
6
+ `npm install @weng-lab/genomebrowser`
7
+
8
+ ## Usage
9
+
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
+
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
+ ```
55
+
56
+ ## Full Example
57
+
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
+ }
88
+ ```
89
+
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
+ }
122
+ ```
123
+
124
+ The browser will look something like this:
125
+ ![Browser Example](image.png)
@@ -1,9 +1,8 @@
1
1
  import { Domain } from '../../utils/types';
2
- type stateContext<T> = [
3
- T,
4
- React.Dispatch<React.SetStateAction<T>>
5
- ];
2
+ export type DeltaContextType = {
3
+ delta: number;
4
+ setDelta: (delta: number) => void;
5
+ };
6
6
  export declare const DomainContext: import('react').Context<Domain>;
7
7
  export declare const DomainDispatchContext: import('react').Context<any>;
8
- export declare const DeltaContext: import('react').Context<stateContext<number>>;
9
- export {};
8
+ export declare const DeltaContext: import('react').Context<DeltaContextType>;
@@ -1,6 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { BrowserState, BrowserAction } from './browserContext';
3
3
  import { TrackModalInfo } from '../../hooks/useModal';
4
+ import { DeltaContextType } from './domainContext';
4
5
  export declare const ModalContext: import('react').Context<{
5
6
  openModal: TrackModalInfo | null;
6
7
  showModal: (trackId: string, mouseX: number, mouseY: number) => void;
@@ -10,7 +11,7 @@ interface ContextObjects {
10
11
  children: ReactNode;
11
12
  browserState: BrowserState;
12
13
  browserDispatch: React.Dispatch<BrowserAction>;
13
- deltaContext: [number, React.Dispatch<React.SetStateAction<number>>];
14
+ deltaContext: DeltaContextType;
14
15
  modalState: {
15
16
  openModal: TrackModalInfo | null;
16
17
  showModal: (trackId: string, mouseX: number, mouseY: number) => void;
@@ -1,7 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  import { Domain } from '../../../utils/types';
3
- export declare const humanVersions: number[];
4
- export declare const mouseVersions: number[];
5
3
  export interface GenomicElement {
6
4
  coordinates: Domain;
7
5
  }
@@ -51,14 +51,14 @@ export type BigBedTrackProps = {
51
51
  props?: BigBedOptions;
52
52
  } & BaseTrack;
53
53
  export declare enum TranscriptHumanVersion {
54
- V47 = 47,
55
- V48 = 48,
56
- V29 = 29
54
+ V29 = 29,
55
+ V40 = 40,
56
+ V47 = 47
57
57
  }
58
58
  export declare enum TranscriptMouseVersion {
59
- V36 = 36,
59
+ V21 = 21,
60
60
  V25 = 25,
61
- V21 = 21
61
+ V36 = 36
62
62
  }
63
63
  export declare function TranscriptTrack(_: TranscriptTrackProps): null;
64
64
  export type TranscriptTrackProps = {