Skip to content

Commit

Permalink
start of CSQ code
Browse files Browse the repository at this point in the history
see #146
  • Loading branch information
brentp committed Jul 24, 2023
1 parent 71a2bf2 commit 83591ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
34 changes: 34 additions & 0 deletions js/csq.js
Original file line number Diff line number Diff line change
@@ -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); });
}

0 comments on commit 83591ad

Please sign in to comment.