From 83591adf2d154c45ecf5e64c87e4ba1635e874b6 Mon Sep 17 00:00:00 2001 From: Brent Pedersen Date: Mon, 24 Jul 2023 09:24:15 +0200 Subject: [PATCH] start of CSQ code see #146 --- docker/Dockerfile | 2 +- js/csq.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 js/csq.js diff --git a/docker/Dockerfile b/docker/Dockerfile index 451d784..b2bd723 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -52,7 +52,7 @@ RUN cd / && \ export PATH=/nim/bin:$PATH && \ git clone https://github.com/iffy/nim-argparse && cd nim-argparse && git checkout v0.10.1 && nimble install -y && \ cd .. && rm -rf nim-argparse && \ - git clone --depth 1 git://github.com/brentp/slivar.git && \ + git clone --depth 1 https://github.com/brentp/slivar.git && \ cd slivar && \ sed -i 's/-no-pie//' nim.cfg && \ nimble install -y && \ diff --git a/js/csq.js b/js/csq.js new file mode 100644 index 0000000..09e5cbe --- /dev/null +++ b/js/csq.js @@ -0,0 +1,34 @@ +var CSQ = function (info_csq, csq_names, numeric_fields) { + var csq = this; + csq._values = info_csq.split('|'); + csq._numeric_fields = numeric_fields; + // create an object of key => index from vcf_csq + csq._names = {}; + csq_names.forEach(function (name, index) { csq._names[name] = index; }); + + 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); + } + + return result + } + throw "unknown CSQ field: " + name; + } + }); +}; + +function CSQs(csq_string, vcf_csq, numeric_fields) { + // if numeric fields is an array, turn it into an object + if (Array.isArray(numeric_fields)) { + var numeric_fields_obj = {}; + numeric_fields.forEach(function (field) { numeric_fields_obj[field] = true; }); + numeric_fields = numeric_fields_obj; + } + + csqs = csq_string.split(','); + return csqs.map(function (csq) { return new CSQ(csq, vcf_csq, numeric_fields); }); +} \ No newline at end of file