Include src/vaRRI.js after the Fornac dependencies. The library exposes a
single global object vaRRI with the following functions.
Validates all user-supplied input parameters and returns a normalised
validated dictionary ready for vaRRI.render().
Parameters (args object):
| Property | Type | Default | Description |
|---|---|---|---|
structure |
string |
(required) | Dot-bracket structure string. May contain & to separate two molecules. |
sequence |
string |
(required) | RNA/DNA sequence (IUPAC characters). May contain &. |
startIndex1 |
string|number |
"1" |
Start index for molecule 1. |
startIndex2 |
string|number |
"1" |
Start index for molecule 2. |
labelInterval |
string|number |
"10" |
Interval for displayed index labels. |
coloring |
string |
"strand" |
"strand" or "loop". |
highlighting |
string |
"region" |
"nothing", "basepairs", or "region". |
backgroundhighlighting |
string |
"basepairs" |
"nothing", "basepairs", or "region". |
guBasepairs |
boolean |
true |
Show G-U basepairs as dashed lines. |
highlightSubseq1 |
string|null |
null |
Comma-separated start-end range(s) for molecule 1. |
highlightSubseq2 |
string|null |
null |
Comma-separated start-end range(s) for molecule 2. |
Returns: A validated parameter object.
Throws: Error on any invalid input.
const v = vaRRI.validate({
structure: '..((((...))))...((...((...((..&............))...))...))..',
sequence: 'ACGAUCAGAGAUCAGAGCAUACGACAGCAG&ACGAAAAAAAGAGCAUACGACAGCAG',
});Builds the Fornac visualisation and applies all vaRRI modifications.
Parameters:
| Parameter | Type | Description |
|---|---|---|
containerId |
string |
The id of the DOM element that will host the Fornac SVG. The element must already exist in the DOM. |
v |
Object |
Validated parameter dictionary from vaRRI.validate(). |
options |
Object |
Optional settings (see below). |
options properties:
| Property | Type | Default | Description |
|---|---|---|---|
animation |
boolean |
false |
Enable Fornac force-layout animation. When true and background highlighting is active, the highlight polygon is redrawn on every animation frame to stay in sync with the force layout. |
accessData |
Object|null |
null |
Accessibility data: { nodeId: probability, … }. |
const container = document.getElementById('rna_ss');
container.innerHTML = '';
const v = vaRRI.validate({ structure: '((...))', sequence: 'GGGCCC' });
vaRRI.render('rna_ss', v);These functions are used internally by validate() but are also exported for
advanced use.
Checks bracket balance for (), [], {}, <>. Throws Error on mismatch.
Validates IUPAC sequence characters. Returns the sequence or throws Error.
Validates structure string and checks length parity with sequence.
Parses and validates a start-index string. Rejects "0".
Returns value if it is "nothing", "basepairs", or "region".
Same as above for background highlighting.
Splits a string at the first &. Always returns two strings.
Returns zero-based [open, close] index pairs for all matched brackets.
Returns { structure1, structure2, structure, structure_dict } after applying
the Fornac &... fix.
Returns { sequence1, sequence2, sequence, sequence_dict } after applying
the Fornac &... fix.
Returns "2" if validated.sequence2 is non-empty, otherwise "1".
Builds a Fornac-node-ID → [sequenceId, position] mapping that accounts for
gap nodes and RNA-style numbering (no zero).
Produces (seqId, index) tuples starting at offset, skipping 0.
Parses a comma-separated list of "start-end" strings into numeric pairs.
These functions directly manipulate the live DOM SVG produced by Fornac. They
are called automatically by render() but can also be invoked individually for
fine-grained control.
Parses Fornac tooltip text on <line> elements and assigns start/end attributes.
Assigns sequential label_gnum / label_num IDs to label elements.
Colors all nucleotide circles using strand coloring (mol. 1 = lightblue, mol. 2 = #F4BB44).
Updates <title> text of each node circle to show seqId[position].
Updates <title> text of each link line to show correct indices.
Displays index labels at sequence boundaries, basepair region boundaries, and
every labelInterval-th position.
Adds a red stroke to all nodes in the intermolecular basepair region.
Adds a red stroke to individual intermolecular basepair nodes.
Draws a translucent red polyline over the entire intermolecular region.
Draws translucent red polylines around individual basepair stacks.
Applies a dashed stroke to G-U basepair links.
Draws a purple polyline or circle over the specified subsequence range.
seq is "1" or "2".
Removes the Fornac gap nodes that separate two molecules.
Removes duplicate basepair links (keeps only link where start < end).
Appends style to the style attribute of the specified node circles.
Draws an SVG polyline connecting the given Fornac node positions.
An optional extraAttrs object (e.g. { 'data-varri-bg': 'true' }) sets additional attributes on the created <polyline> element.
Inserts a new SVG element with the given attributes at the top of the Fornac plot group.
Returns the [x, y] coordinates of a Fornac node by reading its transform attribute.
Sets an attribute on all elements matching [targetAttr="targetValue"].
Overlays coloured circles encoding accessibility probability.
accessData is { nodeId: probability } with values in [0, 1].
Nodes in sequence 1 (index <= lenSeq) are colored purple; sequence 2 nodes red.
Higher probability → lower opacity.
Downloads a self-contained SVG file. Embedded Fornac CSS is included in a
<style> block so the file renders correctly when opened standalone.
Parameters:
| Parameter | Type | Default |
|---|---|---|
containerId |
string |
(required) |
filename |
string |
"vaRRI_output.svg" |
Rasterises the SVG to a <canvas> and triggers a PNG download.
| Parameter | Type | Default |
|---|---|---|
containerId |
string |
(required) |
filename |
string |
"vaRRI_output.png" |
scale |
number |
2 (retina quality) |
Returns the full SVG markup as a string without triggering a download. Useful for programmatic use (e.g., posting to a server or displaying in another element).
Identifies positions of intermolecular basepairs in a dot-bracket structure.
Returns sorted [1-based index, bracket-char] pairs.
Returns [start, end] ranges of the intermolecular basepair region for each structure.
Returns all intermolecular basepair [open, close] index pairs from the
combined structure.
Parses basepairs from a {position: bracket} structure dictionary.
Returns a color array: "lightblue" for each character of seq1,
"#F4BB44" for each character of seq2.