diff --git a/data/jq/pair/semmed.jq b/data/jq/pair/semmed.jq new file mode 100644 index 0000000..1b61745 --- /dev/null +++ b/data/jq/pair/semmed.jq @@ -0,0 +1,23 @@ +if $edge.query.method == "post" then + # if response is not an array, then use response.hits + if (.response | type) == "array" then .response else .response.hits end | + reduce .[] as $item ({}; + # if the item is notfound, then proceed to next item & keep current object + if ($item | keys | contains(["notfound"])) then + . + else + generateCurieWithInputs( + $edge.input.id; + $item.query; + $edge.input.curies + | toArray + | map(. | split(":") | last) + ) as $curie | .[$curie] += [$item] + end + ) +else + .response as $res | generateCurie( + $edge.input.id; + ($edge.input.curies | toArray | map(. | split(":") | last) | first) + ) as $curie | {} | .[$curie] = [$res] +end diff --git a/data/jq/wrap/semmed.jq b/data/jq/wrap/semmed.jq new file mode 100644 index 0000000..8ee6b68 --- /dev/null +++ b/data/jq/wrap/semmed.jq @@ -0,0 +1,29 @@ +# finds start/end index of sub in main string +# ie. "ab" in "12abcd" will return "2|3" +def index_text(main; sub): (main|index(sub)|tostring)+"|"+((main|index(sub)) + (sub|length) | tostring); + + +.["edge-attributes"] = ([.predication | group_by(.pmid) | .[] | .[0] | +# create edge attributes for each publication +{ + "attribute_type_id": "biolink:has_supporting_study_result", + "attributes": [ + { + "attribute_type_id": "biolink:supporting_text", + "value": .sentence, + }, + { + "attribute_type_id": "biolink:publications", + "value": ( "PMID:"+(.pmid|tostring) ), + }, + { + "attribute_type_id": "biolink:subject_location_in_text", + "value": ( .subject_text as $text | index_text(.sentence; $text) ), + }, + { + "attribute_type_id": "biolink:object_location_in_text", + "value": ( .object_text as $text | index_text(.sentence; $text) ), + } + ], + "value": ( .predication_id | tostring ), +}] | .[:50]) diff --git a/src/index.ts b/src/index.ts index 68b99fd..cde90e7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,6 +50,8 @@ export default class Transformer { } else if (api === "EBI Proteins API") { // this.tf = new EBIProteinTransformer(this.data, this.config) this.tf = new JQTransformer(this.data, { ...this.config, type: "ebi" }); + } else if (api === "BioThings SEMMEDDB API") { + this.tf = new JQTransformer(this.data, { ...this.config, type: "semmed" }); } else if (tags.includes("biothings")) { this.tf = new JQTransformer(this.data, { ...this.config, type: "biothings" }); } else if (tags.includes("ctd")) {