@weng-lab/genomebrowser 0.0.17 → 0.0.18

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,124 +1,124 @@
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
- tracks: [],
26
- highlights: []
27
- });
28
- ```
29
-
30
- There are a few ways to add tracks to the browser.
31
- 1. You can add a track by dispatching the `ADD_TRACK` action:
32
- ```tsx
33
- import { BigWigTrackProps } from '@weng-lab/genomebrowser';
34
- const myBigWig: BigWigTrackProps = { ... }
35
- browserDispatch({ type: BrowserActionType.ADD_TRACK, track: myBigWig });
36
- ```
37
- 2. You can add a track by passing a track component as a child to the GenomeBrowser component:
38
- ```tsx
39
- import { BigBedTrack } from '@weng-lab/genomebrowser';
40
- <GenomeBrowser browserState={browserState} browserDispatch={browserDispatch}>
41
- <BigBedTrack ... />
42
- </GenomeBrowser>
43
- ```
44
- 3. You can also add a track by appending it to the 'tracks' array in the browser state:
45
- ```tsx
46
- import { BigWigTrackProps, BrowserState } from '@weng-lab/genomebrowser';
47
- const myBigWig: BigWigTrackProps = { ... }
48
- const myState: BrowserState = {
49
- domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
50
- ... // initialize the rest of the state
51
- tracks: [myBigWig] // add the track to the state
52
- }
53
- ```
54
-
55
- ## Full Example
56
-
57
- ```tsx
58
- // in trackExamples.ts
59
- export const bigWigExample: BigWigTrackProps = {
60
- ...DefaultBigWig,
61
- id: "1",
62
- title: "bigwig",
63
- height: 100,
64
- url: "https://downloads.wenglab.org/DNAse_All_ENCODE_MAR20_2024_merged.bw",
65
- color: "blue"
66
- }
67
- export const bigBedExample: BigBedTrackProps = {
68
- ...DefaultBigBed,
69
- id: "2",
70
- title: "bigbed",
71
- height: 75,
72
- rowHeight: 12,
73
- color: "red",
74
- url: "https://downloads.wenglab.org/GRCh38-cCREs.DCC.bigBed"
75
- }
76
- export const transcriptExample: TranscriptTrackProps = {
77
- ...DefaultTranscript,
78
- id: "3",
79
- title: "transcript",
80
- rowHeight: 12,
81
- assembly: "GRCh38",
82
- queryType: "gene",
83
- version: TranscriptHumanVersion.V47,
84
- height: 100,
85
- color: "green"
86
- }
87
- ```
88
-
89
- ```tsx
90
- // in main.tsx
91
- import { useEffect } from 'react'
92
- import {
93
- GenomeBrowser, BrowserState, BrowserActionType, useBrowserState,
94
- BigBedTrack
95
- } from '../lib'
96
- import { bigWigExample, bigBedExample, transcriptExample } from './trackExamples'
97
-
98
- const defaultState: BrowserState = {
99
- domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
100
- preRenderedWidth: 1350,
101
- width: 1500,
102
- zoomLevel: 148,
103
- delta: 0,
104
- tracks: [bigWigExample] // adds a BigWig track to the state
105
- }
106
-
107
- function Main() {
108
- const [browserState, browserDispatch] = useBrowserState(defaultState)
109
-
110
- useEffect(() => {
111
- // add a Transcript track to the state
112
- browserDispatch({ type: BrowserActionType.ADD_TRACK, track: transcriptExample })
113
- }, [])
114
-
115
- return (
116
- <GenomeBrowser browserState={browserState} browserDispatch={browserDispatch}>
117
- <BigBedTrack {...bigBedExample} /> // add a BigBed track to the browser
118
- </GenomeBrowser>
119
- )
120
- }
121
- ```
122
-
123
- The browser will look something like this:
124
- ![Browser Example](https://github.com/weng-lab/genomebrowser-components/blob/master/image.png)
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
+ tracks: [],
26
+ highlights: []
27
+ });
28
+ ```
29
+
30
+ There are a few ways to add tracks to the browser.
31
+ 1. You can add a track by dispatching the `ADD_TRACK` action:
32
+ ```tsx
33
+ import { BigWigTrackProps } from '@weng-lab/genomebrowser';
34
+ const myBigWig: BigWigTrackProps = { ... }
35
+ browserDispatch({ type: BrowserActionType.ADD_TRACK, track: myBigWig });
36
+ ```
37
+ 2. You can add a track by passing a track component as a child to the GenomeBrowser component:
38
+ ```tsx
39
+ import { BigBedTrack } from '@weng-lab/genomebrowser';
40
+ <GenomeBrowser browserState={browserState} browserDispatch={browserDispatch}>
41
+ <BigBedTrack ... />
42
+ </GenomeBrowser>
43
+ ```
44
+ 3. You can also add a track by appending it to the 'tracks' array in the browser state:
45
+ ```tsx
46
+ import { BigWigTrackProps, BrowserState } from '@weng-lab/genomebrowser';
47
+ const myBigWig: BigWigTrackProps = { ... }
48
+ const myState: BrowserState = {
49
+ domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
50
+ ... // initialize the rest of the state
51
+ tracks: [myBigWig] // add the track to the state
52
+ }
53
+ ```
54
+
55
+ ## Full Example
56
+
57
+ ```tsx
58
+ // in trackExamples.ts
59
+ export const bigWigExample: BigWigTrackProps = {
60
+ ...DefaultBigWig,
61
+ id: "1",
62
+ title: "bigwig",
63
+ height: 100,
64
+ url: "https://downloads.wenglab.org/DNAse_All_ENCODE_MAR20_2024_merged.bw",
65
+ color: "blue"
66
+ }
67
+ export const bigBedExample: BigBedTrackProps = {
68
+ ...DefaultBigBed,
69
+ id: "2",
70
+ title: "bigbed",
71
+ height: 75,
72
+ rowHeight: 12,
73
+ color: "red",
74
+ url: "https://downloads.wenglab.org/GRCh38-cCREs.DCC.bigBed"
75
+ }
76
+ export const transcriptExample: TranscriptTrackProps = {
77
+ ...DefaultTranscript,
78
+ id: "3",
79
+ title: "transcript",
80
+ rowHeight: 12,
81
+ assembly: "GRCh38",
82
+ queryType: "gene",
83
+ version: TranscriptHumanVersion.V47,
84
+ height: 100,
85
+ color: "green"
86
+ }
87
+ ```
88
+
89
+ ```tsx
90
+ // in main.tsx
91
+ import { useEffect } from 'react'
92
+ import {
93
+ GenomeBrowser, BrowserState, BrowserActionType, useBrowserState,
94
+ BigBedTrack
95
+ } from '../lib'
96
+ import { bigWigExample, bigBedExample, transcriptExample } from './trackExamples'
97
+
98
+ const defaultState: BrowserState = {
99
+ domain: { chromosome: "chr11", start: 5220000, end: 5420000 },
100
+ preRenderedWidth: 1350,
101
+ width: 1500,
102
+ zoomLevel: 148,
103
+ delta: 0,
104
+ tracks: [bigWigExample] // adds a BigWig track to the state
105
+ }
106
+
107
+ function Main() {
108
+ const [browserState, browserDispatch] = useBrowserState(defaultState)
109
+
110
+ useEffect(() => {
111
+ // add a Transcript track to the state
112
+ browserDispatch({ type: BrowserActionType.ADD_TRACK, track: transcriptExample })
113
+ }, [])
114
+
115
+ return (
116
+ <GenomeBrowser browserState={browserState} browserDispatch={browserDispatch}>
117
+ <BigBedTrack {...bigBedExample} /> // add a BigBed track to the browser
118
+ </GenomeBrowser>
119
+ )
120
+ }
121
+ ```
122
+
123
+ The browser will look something like this:
124
+ ![Browser Example](https://github.com/weng-lab/genomebrowser-components/blob/master/image.png)
@@ -0,0 +1,32 @@
1
+ import { Domain } from '../../../utils/types';
2
+ import { DisplayMode } from '../types';
3
+ import { ImportanceTrackAnnotation, ImportanceTrackData, ImportanceTrackDataPoint } from './importanceTrack';
4
+ export type ImportanceProps = {
5
+ data: ImportanceTrackData;
6
+ width: number;
7
+ height: number;
8
+ domain: Domain;
9
+ id: string;
10
+ title: string;
11
+ titleSize: number;
12
+ trackMargin: number;
13
+ displayMode: DisplayMode;
14
+ };
15
+ export type ImportanceOptions = {
16
+ onSequenceLoaded?: (sequence: string) => void;
17
+ allowSelection?: boolean;
18
+ onSelectionEnd?: (coordinates: [number, number], values: ImportanceTrackDataPoint[]) => void;
19
+ onBaseMousedOver?: (x: ImportanceTrackDataPoint, i: number) => void;
20
+ onBaseClicked?: (x: ImportanceTrackDataPoint, i: number) => void;
21
+ onBaseMousedOut?: () => void;
22
+ svgRef?: React.RefObject<SVGSVGElement>;
23
+ zeroLineProps?: React.SVGProps<SVGLineElement>;
24
+ annotations?: ImportanceTrackAnnotation[];
25
+ transform?: string;
26
+ };
27
+ export declare const DefaultImportance: {
28
+ titleSize: number;
29
+ trackMargin: number;
30
+ canDrag: boolean;
31
+ };
32
+ export default function Importance(props: ImportanceProps & ImportanceOptions): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,62 @@
1
+ import { default as React } from 'react';
2
+ export type ImportanceTrackAnnotation = {
3
+ coordinates: [number, number];
4
+ color: string;
5
+ onMouseOver?: () => void;
6
+ children?: React.ReactElement[];
7
+ };
8
+ export type ImportanceTrackDataPoint = {
9
+ base: string;
10
+ importance: number;
11
+ };
12
+ export type ImportanceTrackSequence = {
13
+ sequence: string;
14
+ importance: number[];
15
+ };
16
+ export type ImportanceTrackData = ImportanceTrackDataPoint[] | ImportanceTrackSequence;
17
+ export declare function isImportanceTrackSequence(data: ImportanceTrackData): data is ImportanceTrackSequence;
18
+ /**
19
+ * Properties of an ImportanceTrack component.
20
+ * @member width the width of the component in SVG coordinates.
21
+ * @member height the height of the component in SVG coordinates.
22
+ * @member transform optional SVG transform to apply to the component.
23
+ * @member allowSelection if set, allows the user to click and drag to select sequences from the track.
24
+ * @member onSelectionEnd callback receiving information about a selection when the user releases the mouse.
25
+ * @member onBaseMousedOver callback receiving information about a moused over base in the sequence.
26
+ * @member onBaseMousedOut callback triggered when the user mouses out of a previously moused over base.
27
+ * @member onBaseClicked callback receiving information about a clicked base in the sequence.
28
+ * @member svgRef optional React reference to the containing SVG component.
29
+ * @member zeroLineProps optional SVG properties of the horizontal line at importance=0.
30
+ */
31
+ export type TrackProps = {
32
+ width: number;
33
+ height: number;
34
+ transform?: string;
35
+ allowSelection?: boolean;
36
+ onSelectionEnd?: (coordinates: [number, number], values: ImportanceTrackDataPoint[]) => void;
37
+ onBaseMousedOver?: (x: ImportanceTrackDataPoint, i: number) => void;
38
+ onBaseClicked?: (x: ImportanceTrackDataPoint, i: number) => void;
39
+ onBaseMousedOut?: () => void;
40
+ svgRef?: React.RefObject<SVGSVGElement>;
41
+ zeroLineProps?: React.SVGProps<SVGLineElement>;
42
+ annotations?: ImportanceTrackAnnotation[];
43
+ };
44
+ /**
45
+ * Properties of an ImportanceTrack component.
46
+ * @member data the sequence/importance data to render.
47
+ */
48
+ export type ImportanceTrackProps = TrackProps & {
49
+ data: ImportanceTrackData;
50
+ onSequenceLoaded?: (sequence: string) => void;
51
+ };
52
+ /**
53
+ *
54
+ * A sequence/importance track. Must be rendered within an SVG element. Data may be provided as a sequence string
55
+ * plus an array of importance values or an array of sequence/importance value pairs.
56
+ *
57
+ * @param props component properties; see TrackProps and ImportanceTrackProps.
58
+ * @returns a rendered ImportanceTrack component instance.
59
+ *
60
+ */
61
+ declare const ImportanceTrack: React.FC<ImportanceTrackProps>;
62
+ export default ImportanceTrack;
@@ -0,0 +1,4 @@
1
+ import { default as Importance, ImportanceProps, ImportanceOptions, DefaultImportance } from './importance';
2
+ export { Importance };
3
+ export type { ImportanceProps, ImportanceOptions };
4
+ export { DefaultImportance };
@@ -0,0 +1,16 @@
1
+ import { default as React } from 'react';
2
+ import { ImportanceTrackDataPoint } from './importanceTrack';
3
+ export type LetterProps = ImportanceTrackDataPoint & {
4
+ fill?: string;
5
+ x: number;
6
+ totalHeight: number;
7
+ totalWidth: number;
8
+ transform: (x: number) => [number, number, string];
9
+ xScale: number;
10
+ onMouseOver?: () => void;
11
+ onMouseOut?: () => void;
12
+ onMouseUp?: () => void;
13
+ onClick?: () => void;
14
+ };
15
+ declare const Letter: React.FC<LetterProps>;
16
+ export default Letter;
@@ -0,0 +1,27 @@
1
+ import { ImportanceTrackAnnotation, ImportanceTrackData, ImportanceTrackDataPoint } from './importanceTrack';
2
+ export type Range = {
3
+ start: number;
4
+ end: number;
5
+ };
6
+ export declare function linearTransform(initial: Range, final: Range): (value: number) => number;
7
+ type YRange = {
8
+ start: number;
9
+ end: number;
10
+ };
11
+ export type GenomicRange = {
12
+ chromosome: string;
13
+ start: number;
14
+ end: number;
15
+ };
16
+ export declare function yRange<T>(values: T[], transform: (v: T) => number): YRange;
17
+ export declare function svgElementTransform(transform: (x: number) => number): (x: number) => [number, number, string];
18
+ export declare function useRenderedImportanceTrackData(data: ImportanceTrackData, height: number): [ImportanceTrackDataPoint[], (x: number) => [number, number, string], (x: number) => number];
19
+ export declare function useRenderedImportanceTrackAnnotations(annotations: ImportanceTrackAnnotation[], data: ImportanceTrackDataPoint[], transform: (x: number) => number): {
20
+ y: number;
21
+ height: number;
22
+ coordinates: [number, number];
23
+ color: string;
24
+ onMouseOver?: () => void;
25
+ children?: React.ReactElement[];
26
+ }[];
27
+ export {};
@@ -1,4 +1,4 @@
1
- import { default as DenseMotif } from './dense';
2
- import { DenseMotifProps, SquishMotifProps } from './types';
3
- import { default as SquishMotif } from './squish';
4
- export { DenseMotif, SquishMotif, type DenseMotifProps, type SquishMotifProps };
1
+ import { default as Motif, MotifProps, MotifOptions, DefaultMotif } from './motif';
2
+ export { Motif };
3
+ export type { MotifProps, MotifOptions };
4
+ export { DefaultMotif };
@@ -0,0 +1,33 @@
1
+ import { TrackType, DisplayMode } from '../types';
2
+ import { Rect } from './types';
3
+ import { Domain } from '../../../utils/types';
4
+ export type MotifProps = {
5
+ displayMode: DisplayMode;
6
+ width: number;
7
+ height: number;
8
+ id: string;
9
+ domain: Domain;
10
+ data?: Rect[];
11
+ title: string;
12
+ titleSize: number;
13
+ trackMargin: number;
14
+ };
15
+ export type MotifOptions = {
16
+ transform?: string;
17
+ peakColor?: string;
18
+ color?: string;
19
+ peaks?: Rect[];
20
+ svgRef?: React.RefObject<SVGSVGElement>;
21
+ rowHeight?: number;
22
+ onHeightChanged?: (height: number) => void;
23
+ canDrag?: boolean;
24
+ };
25
+ export declare const DefaultMotif: {
26
+ trackType: TrackType;
27
+ titleSize: number;
28
+ trackMargin: number;
29
+ height: number;
30
+ displayMode: DisplayMode;
31
+ canDrag: boolean;
32
+ };
33
+ export default function Motif(props: MotifProps & MotifOptions): import("react/jsx-runtime").JSX.Element | null;
@@ -8,7 +8,6 @@ export type DenseMotifProps = {
8
8
  width: number;
9
9
  height: number;
10
10
  id?: string;
11
- transform?: string;
12
11
  color?: string;
13
12
  peakColor?: string;
14
13
  domain: Domain;
@@ -16,6 +15,8 @@ export type DenseMotifProps = {
16
15
  peaks?: Rect[];
17
16
  svgRef?: React.RefObject<SVGSVGElement>;
18
17
  onHeightChanged?: (height: number) => void;
18
+ canDrag?: boolean;
19
+ hoverColor?: string;
19
20
  };
20
21
  export type SquishMotifProps = {
21
22
  data?: Rect[];
@@ -23,10 +24,11 @@ export type SquishMotifProps = {
23
24
  width: number;
24
25
  rowHeight: number;
25
26
  id?: string;
26
- transform?: string;
27
27
  color?: string;
28
28
  peakColor?: string;
29
29
  domain: Domain;
30
30
  svgRef?: React.RefObject<SVGSVGElement>;
31
31
  onHeightChanged?: (height: number) => void;
32
+ canDrag?: boolean;
33
+ hoverColor?: string;
32
34
  };
@@ -2,6 +2,10 @@ import { OperationVariables, LazyQueryExecFunction } from '@apollo/client';
2
2
  import { BigBedOptions, BigWigOptions } from '../../lib';
3
3
  import { TranscriptOptions } from './transcripts';
4
4
  import { Rect } from './bigbed/types';
5
+ import { ImportanceTrackAnnotation, ImportanceTrackDataPoint } from './importance/importanceTrack';
6
+ import { Rect as MotifRect } from './motif/types';
7
+ import { MotifOptions } from './motif/motif';
8
+ import { ImportanceOptions } from './importance/importance';
5
9
  /**
6
10
  * Display modes for tracks
7
11
  */
@@ -21,6 +25,7 @@ export declare enum TrackType {
21
25
  RULER = "ruler",
22
26
  BIGWIG = "bigwig",
23
27
  BIGBED = "bigbed",
28
+ IMPORTANCE = "importance",
24
29
  TRANSCRIPT = "transcript",
25
30
  BAM = "bam",
26
31
  MOTIF = "motif",
@@ -39,7 +44,8 @@ export type BaseTrack = {
39
44
  trackMargin: number;
40
45
  displayMode: DisplayMode;
41
46
  trackType: TrackType;
42
- data?: any[];
47
+ data?: any;
48
+ loading?: boolean;
43
49
  hoverColor?: string;
44
50
  error?: string;
45
51
  refetch?: LazyQueryExecFunction<any, OperationVariables>;
@@ -75,4 +81,27 @@ export type TranscriptTrackProps = {
75
81
  version: TranscriptHumanVersion | TranscriptMouseVersion;
76
82
  props?: TranscriptOptions;
77
83
  } & BaseTrack;
78
- export type TrackProps = BigWigTrackProps | BigBedTrackProps | TranscriptTrackProps;
84
+ export type ImportanceTrackProps = {
85
+ signalURL: string;
86
+ onSequenceLoaded?: (sequence: string) => void;
87
+ transform?: string;
88
+ allowSelection?: boolean;
89
+ onSelectionEnd?: (coordinates: [number, number], values: ImportanceTrackDataPoint[]) => void;
90
+ onBaseMousedOver?: (x: ImportanceTrackDataPoint, i: number) => void;
91
+ onBaseClicked?: (x: ImportanceTrackDataPoint, i: number) => void;
92
+ onBaseMousedOut?: () => void;
93
+ svgRef?: React.RefObject<SVGSVGElement>;
94
+ zeroLineProps?: React.SVGProps<SVGLineElement>;
95
+ annotations?: ImportanceTrackAnnotation[];
96
+ props?: ImportanceOptions;
97
+ } & BaseTrack;
98
+ export type MotifTrackProps = {
99
+ assembly: string;
100
+ consensusRegex: string;
101
+ peaksAccession: string;
102
+ peaks?: MotifRect[];
103
+ occurences: boolean;
104
+ rowHeight?: number;
105
+ props?: MotifOptions;
106
+ } & BaseTrack;
107
+ export type TrackProps = BigWigTrackProps | BigBedTrackProps | TranscriptTrackProps | MotifTrackProps | ImportanceTrackProps;