JSFiddle - React, Tailwind, and code Playground

by Graham Fairweather

JavaScript

function parse(string) {
    if (typeof string !== "string") {
        throw new TypeError("Attribute must be a string.");
    }

    var props = ["parens", "sRNAstart", "sRNAend", "mRNAstart", "mRNAend", "netEnergy", "bindingEnergy", "sRNAOpenEnergy", "mRNAOpenEnergy", "sequences"],
        array = string.split(/[)]?\s+[(:=+]?\s*|,/),
        object = {},
        value;

    if (array.length !== props.length) {
        throw new Error("String could not be converted.");
    }
    
    do {
        value = array.shift();
        object[props.shift()] = +value || value;
    } while (props.length);
    
    return object;
}

var ref = "(((((((((.(((((.&.)))))))))))))) 11,26 : 6,20 (-9.37 = -16.05 + 6.56 + 0.13) vGCCAACUGACGUUGUU&AAUAAUUCAGUUGGU";

for(var i = 0; i < 3; i += 1) {
    console.log(ref, parse(ref));
    ref = ref.replace(/(\s+)/g, function (all, whitespace) {
        return whitespace + " ";
    });
}