varri-js 1.0.0
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/LICENSE +21 -0
- package/README.html +156 -0
- package/README.md +599 -0
- package/dist/vaRRI.min.js +5 -0
- package/dist/vaRRI.min.js.map +7 -0
- package/fornac/README.md +10 -0
- package/fornac/d3.LICENSE.txt +13 -0
- package/fornac/d3.js +9215 -0
- package/fornac/fornac.LICENSE.txt +201 -0
- package/fornac/fornac.css +212 -0
- package/fornac/fornac.css.map +1 -0
- package/fornac/fornac.js +3 -0
- package/fornac/fornac.js.map +1 -0
- package/package.json +68 -0
- package/src/README.md +229 -0
- package/src/vaRRI.js +3957 -0
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "varri-js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Browser library for visualising and annotating RNA-RNA interactions",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Bioinformatics Group, University of Freiburg",
|
|
7
|
+
"homepage": "https://backofenlab.github.io/vaRRI-js/",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/BackofenLab/vaRRI-js.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/BackofenLab/vaRRI-js/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"bioinformatics",
|
|
17
|
+
"rna",
|
|
18
|
+
"rna-rna-interaction",
|
|
19
|
+
"visualisation",
|
|
20
|
+
"visualization"
|
|
21
|
+
],
|
|
22
|
+
"main": "src/vaRRI.js",
|
|
23
|
+
"browser": "src/vaRRI.js",
|
|
24
|
+
"unpkg": "dist/vaRRI.min.js",
|
|
25
|
+
"jsdelivr": "dist/vaRRI.min.js",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./src/vaRRI.js",
|
|
28
|
+
"./vaRRI.js": "./src/vaRRI.js",
|
|
29
|
+
"./dist/vaRRI.min.js": "./dist/vaRRI.min.js",
|
|
30
|
+
"./dist/vaRRI.min.js.map": "./dist/vaRRI.min.js.map",
|
|
31
|
+
"./fornac/d3.js": "./fornac/d3.js",
|
|
32
|
+
"./fornac/fornac.js": "./fornac/fornac.js",
|
|
33
|
+
"./fornac/fornac.js.map": "./fornac/fornac.js.map",
|
|
34
|
+
"./fornac/fornac.css": "./fornac/fornac.css",
|
|
35
|
+
"./fornac/fornac.css.map": "./fornac/fornac.css.map",
|
|
36
|
+
"./package.json": "./package.json"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist/",
|
|
40
|
+
"fornac/",
|
|
41
|
+
"src/README.md",
|
|
42
|
+
"src/vaRRI.js"
|
|
43
|
+
],
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"provenance": true
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "esbuild src/vaRRI.js --minify --sourcemap --outfile=dist/vaRRI.min.js",
|
|
50
|
+
"test": "jest",
|
|
51
|
+
"test:ci": "jest --runInBand",
|
|
52
|
+
"prepack": "npm run build"
|
|
53
|
+
},
|
|
54
|
+
"jest": {
|
|
55
|
+
"globalSetup": "<rootDir>/tests/jest-global-setup.js",
|
|
56
|
+
"testEnvironment": "node",
|
|
57
|
+
"testPathIgnorePatterns": [
|
|
58
|
+
"/node_modules/"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"canvas": "^3.2.3",
|
|
63
|
+
"esbuild": "^0.25.9",
|
|
64
|
+
"jest": "^30.4.2",
|
|
65
|
+
"jest-environment-jsdom": "^30.4.1",
|
|
66
|
+
"marked": "^18.0.9"
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/README.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# vaRRI-js JavaScript API
|
|
2
|
+
|
|
3
|
+
`src/vaRRI.js` exposes one global object, `window.vaRRI`. In CommonJS test
|
|
4
|
+
code, `require('./src/vaRRI.js')` returns the same object.
|
|
5
|
+
|
|
6
|
+
Load Fornac and D3 before vaRRI:
|
|
7
|
+
|
|
8
|
+
```html
|
|
9
|
+
<link rel="stylesheet" href="fornac/fornac.css" />
|
|
10
|
+
<script src="fornac/d3.js"></script>
|
|
11
|
+
<script src="fornac/fornac.js"></script>
|
|
12
|
+
<script src="dist/vaRRI.min.js"></script>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Use `src/vaRRI.js` instead of the minified file while developing.
|
|
16
|
+
|
|
17
|
+
## Core workflow
|
|
18
|
+
|
|
19
|
+
### `vaRRI.validate(args)`
|
|
20
|
+
|
|
21
|
+
Validates and normalizes input, applies optional end cropping, and returns the
|
|
22
|
+
object expected by `render()`.
|
|
23
|
+
|
|
24
|
+
| Property | Type | Default | Description |
|
|
25
|
+
|---|---|---|---|
|
|
26
|
+
| `sequence` | `string` | required | IUPAC sequence; separate two molecules with `&`. |
|
|
27
|
+
| `structure` | `string` | required | Dot-bracket structure; separate two molecules with `&`. |
|
|
28
|
+
| `startIndex1` | `string\|number` | `1` | First index of molecule 1; zero is invalid. |
|
|
29
|
+
| `startIndex2` | `string\|number` | `1` | First index of molecule 2; zero is invalid. |
|
|
30
|
+
| `cropping` | `string\|number` | `-1` | Negative disables cropping; non-negative values retain that many terminal unpaired bases. |
|
|
31
|
+
| `labelInterval` | `string\|number` | `10` | Interval between index labels. |
|
|
32
|
+
| `coloring` | `string` | `strand` | `strand` or `loop`. |
|
|
33
|
+
| `highlighting` | `string` | `region` | `nothing`, `basepairs`, or `region`. |
|
|
34
|
+
| `backgroundhighlighting` | `string` | `basepairs` | `nothing`, `basepairs`, or `region`. |
|
|
35
|
+
| `distinctBpTypes` | `boolean` | `true` | Render G-U pairs with dashed links. |
|
|
36
|
+
| `subsequenceHighlights` | `Array` | `[]` | Subsequence highlight definitions. |
|
|
37
|
+
| `regionHighlights` | `Array` | `[]` | Region highlight definitions. |
|
|
38
|
+
| `pointMutations` | `Array` | `[]` | Point-mutation definitions. |
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
const validated = vaRRI.validate({
|
|
42
|
+
sequence: 'ACGU&UGCA',
|
|
43
|
+
structure: '((((&))))',
|
|
44
|
+
startIndex1: -2,
|
|
45
|
+
startIndex2: 10,
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### `vaRRI.render(containerId, validated, options?)`
|
|
50
|
+
|
|
51
|
+
Creates a Fornac visualization, then applies labels, coloring, annotations,
|
|
52
|
+
profiles, and link styling. It returns a promise resolving to
|
|
53
|
+
`{ cancelled: boolean }`. Starting a newer render cancels pending
|
|
54
|
+
post-processing from the previous render.
|
|
55
|
+
|
|
56
|
+
`vaRRI.cancelActiveRender()` stops the active force simulation, removes
|
|
57
|
+
linear-layout listeners, and resolves any pending render as cancelled.
|
|
58
|
+
|
|
59
|
+
| Option | Type | Default | Description |
|
|
60
|
+
|---|---|---|---|
|
|
61
|
+
| `forceLayout` | `boolean` | `false` | Enable Fornac force-layout animation. |
|
|
62
|
+
| `forceLayoutLinearStructure` | `boolean` | `false` | Apply a rigid two-rail constraint independently to intramolecular stems containing bulges or interior loops. Requires `forceLayout`. |
|
|
63
|
+
| `forceLayoutLinearRRI` | `boolean` | `false` | Keep a noncrossing RRI helix on two parallel rails and rotate the complete two-molecule interaction so its axis is horizontal. Requires `forceLayout`. |
|
|
64
|
+
| `freeTrailingEnds` | `boolean` | `false` | Relax the external-loop closure scaffold when force layout is active. |
|
|
65
|
+
| `pullPseudoknotBasepairs` | `boolean` | `false` | Increase pseudoknot link strength when force layout is active. |
|
|
66
|
+
| `accessData` | `Object<number, number>\|null` | `null` | Node-ID to probability map. |
|
|
67
|
+
| `accessColors` | `Object\|null` | `null` | Optional `sequence1` and `sequence2` overlay colors. |
|
|
68
|
+
| `accessColorMode` | `Object\|null` | `null` | Optional `sequence1RepresentsOne` and `sequence2RepresentsOne` flags. |
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
const state = await vaRRI.render('rendering-canvas', validated, {
|
|
72
|
+
forceLayout: true,
|
|
73
|
+
forceLayoutLinearStructure: true,
|
|
74
|
+
forceLayoutLinearRRI: true,
|
|
75
|
+
accessData: { 1: 0.8, 2: 0.3 },
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Rotation
|
|
80
|
+
|
|
81
|
+
- `vaRRI.normaliseRotationDegrees(degrees)` returns an angle in `[-180, 180]`.
|
|
82
|
+
- `vaRRI.rotateVisualization(containerId, degrees, options?)` rotates the
|
|
83
|
+
current SVG. `options.mode` is `delta` by default or `absolute`.
|
|
84
|
+
|
|
85
|
+
Text labels are counter-rotated to remain readable.
|
|
86
|
+
|
|
87
|
+
## Colors
|
|
88
|
+
|
|
89
|
+
- `vaRRI.getColors()` returns a copy of the current color settings.
|
|
90
|
+
- `vaRRI.setColors(overrides)` updates only the supplied keys.
|
|
91
|
+
|
|
92
|
+
Supported keys are `sequence1`, `sequence2`, `seq1profileColor`,
|
|
93
|
+
`seq2profileColor`, `mutationColor`, `intermolecularHighlight`,
|
|
94
|
+
`backgroundHighlight`, `subsequenceHighlight`, and `basepair`.
|
|
95
|
+
|
|
96
|
+
## Annotation registries
|
|
97
|
+
|
|
98
|
+
The UI registries return clones, so mutating a returned object does not modify
|
|
99
|
+
library state. IDs start at `1` and reset after the corresponding `clear...()`
|
|
100
|
+
call.
|
|
101
|
+
|
|
102
|
+
### Subsequence highlights
|
|
103
|
+
|
|
104
|
+
A definition has `{ sequence, range, color?, alpha? }`. `sequence` is `1` or
|
|
105
|
+
`2`; `range` is a `"start-end"` string, a comma-separated range string, or an
|
|
106
|
+
array of `[start, end]` pairs.
|
|
107
|
+
|
|
108
|
+
- `vaRRI.createSubsequenceHighlight(input, sequenceContext?)`
|
|
109
|
+
- `vaRRI.registerSubsequenceHighlight(input, sequenceContext?)`
|
|
110
|
+
- `vaRRI.updateSubsequenceHighlight(id, patch, sequenceContext?)`
|
|
111
|
+
- `vaRRI.removeSubsequenceHighlight(id)`
|
|
112
|
+
- `vaRRI.clearSubsequenceHighlights()`
|
|
113
|
+
- `vaRRI.getSubsequenceHighlights()`
|
|
114
|
+
|
|
115
|
+
### Region highlights
|
|
116
|
+
|
|
117
|
+
A definition has
|
|
118
|
+
`{ sequence1Range, sequence2Range, color?, alpha?, generated? }`. Each range is
|
|
119
|
+
a `"start-end"` string or `[start, end]` pair.
|
|
120
|
+
|
|
121
|
+
- `vaRRI.createRegionHighlight(input, sequenceContext?)`
|
|
122
|
+
- `vaRRI.registerRegionHighlight(input, sequenceContext?)`
|
|
123
|
+
- `vaRRI.registerGeneratedRegionHighlight(validated, spec)`
|
|
124
|
+
- `vaRRI.updateRegionHighlight(id, patch, sequenceContext?)`
|
|
125
|
+
- `vaRRI.removeRegionHighlight(id)`
|
|
126
|
+
- `vaRRI.clearRegionHighlights()`
|
|
127
|
+
- `vaRRI.getRegionHighlights()`
|
|
128
|
+
- `vaRRI.computeBackgroundRegionRanges(validated)`
|
|
129
|
+
- `vaRRI.getRegionHighlightNodePath(validated, highlight)`
|
|
130
|
+
|
|
131
|
+
Generated highlights represent the automatic whole-RRI background region and
|
|
132
|
+
can be excluded from persisted user state.
|
|
133
|
+
|
|
134
|
+
### Point mutations
|
|
135
|
+
|
|
136
|
+
A definition has `{ sequence, position, replacement, color? }`.
|
|
137
|
+
|
|
138
|
+
- `vaRRI.normaliseMutationPosition(position, sequenceContext?)`
|
|
139
|
+
- `vaRRI.createPointMutation(input, sequenceContext?)`
|
|
140
|
+
- `vaRRI.registerPointMutation(input, sequenceContext?)`
|
|
141
|
+
- `vaRRI.updatePointMutation(id, patch, sequenceContext?)`
|
|
142
|
+
- `vaRRI.removePointMutation(id)`
|
|
143
|
+
- `vaRRI.clearPointMutations()`
|
|
144
|
+
- `vaRRI.getPointMutations()`
|
|
145
|
+
|
|
146
|
+
A `sequenceContext` uses molecule keys and visible sequence metadata:
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
const sequenceContext = {
|
|
150
|
+
'1': { id: 'Sequence 1', offset: -2, length: 4, sequence: 'ACGU' },
|
|
151
|
+
'2': { id: 'Sequence 2', offset: 10, length: 4, sequence: 'UGCA' },
|
|
152
|
+
};
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Validation and formatting helpers
|
|
156
|
+
|
|
157
|
+
| Function | Purpose |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `checkStructureInputSimple(structure)` | Check bracket balance for `()`, `[]`, `{}`, and `<>`. |
|
|
160
|
+
| `findBasePairs(structure)` | Return zero-based matched bracket pairs. |
|
|
161
|
+
| `formatSequence(sequence)` | Return Fornac-ready sequence fields for one or two molecules. |
|
|
162
|
+
| `formatStructure(structure)` | Return Fornac-ready structure fields for one or two molecules. |
|
|
163
|
+
| `getIndexDictionary(validated)` | Map Fornac node IDs to molecule IDs and biological positions. |
|
|
164
|
+
| `getMolecules(validated)` | Return `"1"` or `"2"`. |
|
|
165
|
+
| `getSequenceIndices(seqId, offset, length)` | Generate biological indices while skipping zero. |
|
|
166
|
+
| `parseSubsequences(input, startIndex?, sequenceLength?)` | Parse and optionally bounds-check range strings. |
|
|
167
|
+
| `splitAtAmpersand(value)` | Split once and always return two strings. |
|
|
168
|
+
| `validateBackgroundhighlighting(value)` | Validate a background-highlighting mode. |
|
|
169
|
+
| `validateCroppingInput(structure, cropping)` | Validate and normalize cropping. |
|
|
170
|
+
| `validateHighlighting(value)` | Validate a nucleotide-highlighting mode. |
|
|
171
|
+
| `validateOffset(value)` | Parse a non-zero biological index. |
|
|
172
|
+
| `validateSequenceInput(sequence)` | Validate IUPAC sequence input. |
|
|
173
|
+
| `validateStructureInput(structure, sequence)` | Validate structure syntax and sequence-length parity. |
|
|
174
|
+
|
|
175
|
+
## Base-pair utilities
|
|
176
|
+
|
|
177
|
+
- `vaRRI.getIntermolBasepairRegion(structure1, structure2)`
|
|
178
|
+
- `vaRRI.getLinearRriConstraintSpecs(validated)`
|
|
179
|
+
- `vaRRI.getLinearStructureConstraintSpecs(validated)`
|
|
180
|
+
- `vaRRI.listBasepairs(structureDictionary)`
|
|
181
|
+
- `vaRRI.listIntermolNodes(structure, shift?)`
|
|
182
|
+
- `vaRRI.listIntermolPairs(validated)`
|
|
183
|
+
- `vaRRI.listRriLoopBoundaryPairs(validated)`
|
|
184
|
+
- `vaRRI.listStructureLoopBoundaryPairs(validated)`
|
|
185
|
+
- `vaRRI.sequenceColoring(sequence1, sequence2)`
|
|
186
|
+
|
|
187
|
+
## DOM modification helpers
|
|
188
|
+
|
|
189
|
+
These advanced functions operate on the current Fornac SVG. Normal consumers
|
|
190
|
+
should call `render()` and let it coordinate them.
|
|
191
|
+
|
|
192
|
+
| Function | Purpose |
|
|
193
|
+
|---|---|
|
|
194
|
+
| `addElement(elementType, attributes)` | Insert an SVG element in the plot. |
|
|
195
|
+
| `addStyleToNodes(nodeIds, style)` | Append inline style to nucleotide nodes. |
|
|
196
|
+
| `applyLinearHelixSprings(container, validated, options?)` | Apply requested RRI and/or intramolecular two-rail constraints to an active Fornac force layout. |
|
|
197
|
+
| `applyPointMutations(validated)` | Apply validated mutation overlays. |
|
|
198
|
+
| `applyRegionHighlights(validated)` | Draw registered or validated region polygons. |
|
|
199
|
+
| `applySubsequenceHighlights(validated)` | Draw validated subsequence overlays. |
|
|
200
|
+
| `backgroundhighlightBasepairs(validated)` | Draw backgrounds around intermolecular stacks. |
|
|
201
|
+
| `backgroundhighlightRegion(validated)` | Draw the automatic whole-RRI background. |
|
|
202
|
+
| `changeBackgroundColor(validated)` | Apply strand colors. |
|
|
203
|
+
| `closePolygonPoints(points)` | Close a polygon point list. |
|
|
204
|
+
| `getPositionOfNode(nodeId)` | Read a node's `[x, y]` coordinates. |
|
|
205
|
+
| `highlightBasepairs(validated)` | Highlight individual intermolecular nodes. |
|
|
206
|
+
| `highlightRegion(validated)` | Highlight the intermolecular region. |
|
|
207
|
+
| `highlightSubsequence(validated, sequence, ranges, color, alpha)` | Draw a subsequence overlay. |
|
|
208
|
+
| `polyline(indices, style, attributes?)` | Draw an SVG polyline through node IDs. |
|
|
209
|
+
| `removeDummyNodes(sequence)` | Remove Fornac gap nodes. |
|
|
210
|
+
| `removeSecondLink()` | Remove duplicate intermolecular links. |
|
|
211
|
+
| `setAttributeForElements(targetAttr, targetValue, attr, value)` | Update matching DOM elements. |
|
|
212
|
+
| `setIndexLabels(validated)` | Configure biological index labels. |
|
|
213
|
+
| `setLabelsId()` | Assign stable IDs to Fornac labels. |
|
|
214
|
+
| `setLinksId()` | Assign endpoint metadata to Fornac links. |
|
|
215
|
+
| `styleBasepairs(validated)` | Apply base-pair colors and G-U dashing. |
|
|
216
|
+
| `updateLinkTooltips(validated)` | Add biological positions to link tooltips. |
|
|
217
|
+
| `updateNodeToolTips(validated)` | Add biological positions to node tooltips. |
|
|
218
|
+
| `visualiseAccessibility(data, sequence1Length, colors?, colorMode?)` | Draw probability overlays. |
|
|
219
|
+
|
|
220
|
+
## Export
|
|
221
|
+
|
|
222
|
+
- `vaRRI.buildSVGString(containerId)` returns a self-contained SVG string with
|
|
223
|
+
computed presentation styles and explicit dimensions.
|
|
224
|
+
- `vaRRI.downloadSVG(containerId, filename = 'vaRRI_output.svg')` downloads the
|
|
225
|
+
self-contained SVG.
|
|
226
|
+
- `vaRRI.downloadPNG(containerId, filename = 'vaRRI_output.png', scale = 2)`
|
|
227
|
+
rasterizes the same SVG onto a white canvas and downloads a PNG.
|
|
228
|
+
|
|
229
|
+
All three functions throw if the container does not contain an SVG.
|