diff --git a/js/csq.js b/js/csq.js index 09e5cbe..c138f16 100644 --- a/js/csq.js +++ b/js/csq.js @@ -8,15 +8,21 @@ var CSQ = function (info_csq, csq_names, numeric_fields) { return new Proxy(csq, { get: function (target, name) { - if (name in target._names) { - var result = target._values[target._names[name]]; - if (target._numeric_fields[name]) { - result = parseFloat(result); - } + if (!(name in target._names)) { + throw "unknown CSQ field: " + name; + } - return result + var result = target._values[target._names[name]]; + if (target._numeric_fields[name]) { + if(result.length == 0 || isNaN(result)) { + result = NaN + } else { + try { + result = parseFloat(result); + } catch(e) { result = NaN } + } } - throw "unknown CSQ field: " + name; + return result } }); }; @@ -31,4 +37,4 @@ function CSQs(csq_string, vcf_csq, numeric_fields) { csqs = csq_string.split(','); return csqs.map(function (csq) { return new CSQ(csq, vcf_csq, numeric_fields); }); -} \ No newline at end of file +}