From a2dea9f2701b9cee62809b4cc4af3e73f1ede8c5 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:05:07 -0500 Subject: [PATCH] old biolink -> new monarch --- data/jq/pair/monarch.jq | 29 +++++++++++++++++++++++++++++ data/jq/wrap/biolink.jq | 18 ------------------ src/index.ts | 6 ++---- 3 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 data/jq/pair/monarch.jq delete mode 100644 data/jq/wrap/biolink.jq diff --git a/data/jq/pair/monarch.jq b/data/jq/pair/monarch.jq new file mode 100644 index 0000000..bf6d05a --- /dev/null +++ b/data/jq/pair/monarch.jq @@ -0,0 +1,29 @@ +generateCurie($edge.input.id; $edge.input.curies) as $input_curie +| .response.items = [ + .response.items[] + | select(. != null) + | select( + . as $item + | if $item.direction == "outgoing" + then $item.subject + else $item.object + end + | . as $input_curie + | if $item.direction == "outgoing" + then $item.object_namespace + else $item.subject_namespace + end + | . as $output_namespace + | $input_curie == $input_curie + and $output_namespace == $edge.output.id + ) + | .publications = [ + if .publications != null + then .publications + else [] + end + | .[] + | select(. | startswith("PMID:")) + ] +] +| { $input_curie: [.response] } diff --git a/data/jq/wrap/biolink.jq b/data/jq/wrap/biolink.jq deleted file mode 100644 index 696d9d1..0000000 --- a/data/jq/wrap/biolink.jq +++ /dev/null @@ -1,18 +0,0 @@ -.associations = ( - [ - ( - # take associations that aren't null - select(.associations != null) | .associations | .[] | - # split association object ids & take last (only for CHEMBL, REACT, HGNC) - select(.object.id != null) | (.object.id | split(":") | first) as $pref | .object[$pref] = (if $pref == "HGNC" or $pref == "NCBIGene" or $pref == "REACT" then (.object.id | split(":") | last) else .object.id end) | - # take publications with PMID & for IDs take last element after splitting by : - .publications = [foreach (.publications | .[]? | .id) as $pub ([]; []; if ($pub == null or ($pub | startswith("PMID") | not)) then empty else {id: ($pub | split(":") | last)} end)] - ) - # delete publications if empty array - | delifempty(.publications) - ] + - # include associations with null object ids - [select(.associations != null) | .associations | .[] | select(.object.id == null)] -) -# delete association if empty array -| delifempty(.associations) diff --git a/src/index.ts b/src/index.ts index 1337221..68b99fd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import BiolinkTransformer from "./transformers/biolink_transformer"; import BioThingsTransformer from "./transformers/biothings_transformer"; // import CordTransformer from "./transformers/cord_transformer"; import CTDTransformer from "./transformers/ctd_transformer"; @@ -46,9 +45,8 @@ export default class Transformer { this.tf = new TRAPITransformer(this.data, this.config); } else if (api.startsWith("SEMMED")) { this.tf = new SemmedTransformer(this.data, this.config); - } else if (api === "BioLink API") { - // this.tf = new BiolinkTransformer(this.data, this.config); - this.tf = new JQTransformer(this.data, { ...this.config, type: "biolink" }); + } else if (api === "Monarch API") { + this.tf = new JQTransformer(this.data, { ...this.config, type: "monarch" }); } else if (api === "EBI Proteins API") { // this.tf = new EBIProteinTransformer(this.data, this.config) this.tf = new JQTransformer(this.data, { ...this.config, type: "ebi" });