Skip to content

Commit

Permalink
Merge branch 'use-jmes-path' of https://github.com/biothings/api-resp…
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Oct 19, 2023
2 parents 23182bc + 549e415 commit dbf8aac
Show file tree
Hide file tree
Showing 27 changed files with 351 additions and 112 deletions.
4 changes: 2 additions & 2 deletions __test__/base_transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ describe("test base transformer", () => {
}
})

test("Test pairInputWithAPIResponse function", () => {
test("Test pairInputWithAPIResponse function", async () => {
const tf = new base_tf(input, {});
const res = tf.pairCurieWithAPIResponse();
const res = await tf.pairCurieWithAPIResponse();
expect(res).toHaveProperty("DOID:9562");
expect(res["DOID:9562"]).toHaveLength(1);
})
Expand Down
38 changes: 19 additions & 19 deletions __test__/biolink_transformers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, expect, test} from '@jest/globals';

import biolink_tf from "../src/transformers/biolink_transformer";
import jq_tf from "../built/transformers/jq_transformer";
import fs from "fs";
import path from "path";
import { JSONDoc } from '../src/json_transform/types';
Expand All @@ -21,24 +21,24 @@ describe("test biolink transformer", () => {
}
})

test("test biolink wrapper", () => {
let tf = new biolink_tf(input, {});
let res = tf.wrap(response);
test("test biolink wrapper", async () => {
let tf = new jq_tf(input, { type: "biolink" });
let res = await tf.wrap(response);
expect(res.associations[0].object.HGNC).toBe("10956");
expect(res.associations[0].publications[0].id).toBe("21685912");
expect(res.associations[1]).not.toHaveProperty("publications");
expect(res.associations[1]).not.toHaveProperty("provided_by");
});

test("test biolink wrapper if no association field as root key", () => {
let tf = new biolink_tf(input, {});
let res = tf.wrap({ "data": [] });
test("test biolink wrapper if no association field as root key", async () => {
let tf = new jq_tf(input, { type: "biolink" });
let res = await tf.wrap({ "data": [] });
expect(res).toEqual({ "data": [] })
});

test("test biolink wrapper if no object id should be prefixed", () => {
const tf = new biolink_tf(input, {});
const res = tf.wrap(
test("test biolink wrapper if no object id should be prefixed", async () => {
const tf = new jq_tf(input, { type: "biolink" });
const res = await tf.wrap(
{
associations: [
{
Expand All @@ -51,8 +51,8 @@ describe("test biolink transformer", () => {
expect(res.associations[0].object.MONDO).toEqual("MONDO:12345")
});

test("test biolink wrapper if no object field present", () => {
const tf = new biolink_tf(input, {});
test("test biolink wrapper if no object field present", async () => {
const tf = new jq_tf(input, { type: "biolink" });
const fake_response = {
associations: [
{
Expand All @@ -62,12 +62,12 @@ describe("test biolink transformer", () => {
}
]
}
const res = tf.wrap(fake_response);
const res = await tf.wrap(fake_response);
expect(res).toEqual(fake_response)
});

test("test biolink wrapper if no object.id field present", () => {
const tf = new biolink_tf(input, {});
test("test biolink wrapper if no object.id field present", async () => {
const tf = new jq_tf(input, { type: "biolink" });
const fake_response = {
associations: [
{
Expand All @@ -77,13 +77,13 @@ describe("test biolink transformer", () => {
}
]
}
const res = tf.wrap(fake_response);
const res = await tf.wrap(fake_response);
expect(res).toEqual(fake_response)
});

test("test biolink jsonTransform function", () => {
let tf = new biolink_tf(input, {});
const wrapped_response = tf.wrap(response);
test("test biolink jsonTransform function", async () => {
let tf = new jq_tf(input, { type: "biolink" });
const wrapped_response = await tf.wrap(response);
let res: JSONDoc = tf.jsonTransform(wrapped_response);
expect(res).toHaveProperty("related_to");
expect(res.related_to[0].HGNC).toEqual("10956");
Expand Down
22 changes: 11 additions & 11 deletions __test__/biothings_transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import biothings_tf from "../src/transformers/biothings_transformer";
import jq_tf from "../src/transformers/jq_transformer";
import {describe, expect, test} from '@jest/globals';
import fs from "fs";
import path from "path";
Expand All @@ -21,9 +21,9 @@ describe("test biothings transformer", () => {
}
})

test("test biothings wrapper", () => {
let tf = new biothings_tf(input, {});
let res = tf.pairCurieWithAPIResponse();
test("test biothings wrapper", async () => {
let tf = new jq_tf(input, {type: "biothings"});
let res = await tf.pairCurieWithAPIResponse();
expect(Object.keys(res)).toHaveLength(2);
expect(res).toHaveProperty("DRUGBANK:DB00188");
expect(res["DRUGBANK:DB00188"]).toHaveLength(2);
Expand All @@ -46,16 +46,16 @@ describe("test biothings transformer", () => {
}
})

test("test biothings wrapper", () => {
let tf = new biothings_tf(input, {});
let res = tf.pairCurieWithAPIResponse();
test("test biothings wrapper", async () => {
let tf = new jq_tf(input, {type: "biothings"});
let res = await tf.pairCurieWithAPIResponse();
expect(Object.keys(res)).toHaveLength(1);
expect(res).toHaveProperty("NCBIGene:1017");
expect(res["NCBIGene:1017"]).toHaveLength(1);
})

test("test biothings transform", async () => {
let tf = new biothings_tf(input, {});
let tf = new jq_tf(input, {type: "biothings"});
let res = await tf.transform();
expect(res).toHaveLength(27);
expect(res[0]).not.toHaveProperty('ref_pmid');
Expand All @@ -78,9 +78,9 @@ describe("test biothings transformer", () => {
}
})

test("test biothings wrapper", () => {
let tf = new biothings_tf(input, {});
let res = tf.pairCurieWithAPIResponse();
test("test biothings wrapper", async () => {
let tf = new jq_tf(input, {type: "biothings"});
let res = await tf.pairCurieWithAPIResponse();
expect(Object.keys(res)).toHaveLength(1);
expect(res).toHaveProperty("PUBCHEM:11373846");
expect(res["PUBCHEM:11373846"]).toHaveLength(1);
Expand Down
23 changes: 11 additions & 12 deletions __test__/ctd_transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {describe, expect, test} from '@jest/globals';
import fs from "fs";
import path from "path";

import ctd_tf from "../src/transformers/ctd_transformer";
import jq_tf from "../built/transformers/jq_transformer";

describe("test ctd transformer", () => {

Expand All @@ -20,36 +19,36 @@ describe("test ctd transformer", () => {
}
})

test("test ctd wrapper", () => {
let tf = new ctd_tf(input, {});
let res = tf.wrap(response);
test("test ctd wrapper", async () => {
let tf = new jq_tf(input, { type: "ctd" });
let res = await tf.wrap(response);
expect(res).toHaveProperty("data");
expect(res.data).toHaveLength(2);
expect(res.data[0].PubMedIDs).toEqual(["21559390"]);
expect(res.data[0].DiseaseID).toEqual("D008545");
expect(res.data[0].DiseaseID).toEqual("MESH:D008545");
})

test("test ctd wrapper if pubmed id field is not string", () => {
const tf = new ctd_tf(input, {});
test("test ctd wrapper if pubmed id field is not string", async () => {
const tf = new jq_tf(input, { type: "ctd" });
const fake = [
{
DiseaseID: "MESH:D008545"
}
]
const res = tf.wrap(fake);
const res = await tf.wrap(fake);
expect(res).toHaveProperty("data");
expect(res.data).toHaveLength(1);
expect(res.data[0].PubMedIDs).toBeUndefined;
})

test("test ctd wrapper if disease id field is not string", () => {
const tf = new ctd_tf(input, {});
test("test ctd wrapper if disease id field is not string", async () => {
const tf = new jq_tf(input, { type: "ctd" });
const fake = [
{
PubMedID: "12345"
}
]
const res = tf.wrap(fake);
const res = await tf.wrap(fake);
expect(res).toHaveProperty("data");
expect(res.data).toHaveLength(1);
expect(res.data[0].DiseaseIDs).toBeUndefined;
Expand Down
2 changes: 1 addition & 1 deletion __test__/data/biothings/drug_response_example_edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"size": "1000"
},
"_supportBatch": false,
"method": "get",
"_method": "get",
"_pathParams": [],
"_server": "https://biothings.ncats.io/drug_response_kp",
"_path": "/query",
Expand Down
2 changes: 1 addition & 1 deletion __test__/data/biothings/mychem_example_edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"_supportBatch": true,
"_inputSeparator": ",",
"method": "post",
"_method": "post",
"_pathParams": [],
"_server": "https://mychem.info/v1",
"_path": "/query",
Expand Down
2 changes: 1 addition & 1 deletion __test__/data/biothings/mygene_example_edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"_supportBatch": true,
"_inputSeparator": ",",
"method": "post",
"_method": "post",
"_pathParams": [],
"_server": "https://mygene.info/v3",
"_path": "/query",
Expand Down
8 changes: 4 additions & 4 deletions __test__/ebi_protein_transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import fs from "fs";
import path from "path";
import ebi_tf from "../src/transformers/ebi_protein_transformer";
import jq_tf from "../src/transformers/jq_transformer";

describe("test EBI Protein transformer", () => {
let response;
Expand All @@ -18,9 +18,9 @@ describe("test EBI Protein transformer", () => {
};
});

test("test ebi wrapper", () => {
let tf = new ebi_tf(input, {});
let res = tf.wrap(response);
test("test ebi wrapper", async () => {
let tf = new jq_tf(input, {type: "ebi"});
let res = await tf.wrap(response);
expect(res.comments[0].reaction.dbReferences).toHaveLength(1);
});
});
14 changes: 7 additions & 7 deletions __test__/opentarget_transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {describe, expect, test} from '@jest/globals';
import jq_tf from "../built/transformers/jq_transformer";
import fs from "fs";
import path from "path";
import opentarget_tf from "../src/transformers/opentarget_transformer";

describe("test opentarget transformer", () => {

Expand All @@ -20,15 +20,15 @@ describe("test opentarget transformer", () => {
})

// skip these tests since we're not ingesting opentargets right now
test.skip("test opentarget wrapper", () => {
let tf = new opentarget_tf(input, {});
let res = tf.wrap(response);
test.skip("test opentarget wrapper", async () => {
let tf = new jq_tf(input, { type: "opentarget" });
let res = await tf.wrap(response);
expect(res).toHaveProperty("data");
expect(res.data[0].drug.id).toEqual("CHEMBL220492");
})

test.skip("test opentarget wrapper if id field is not chembl", () => {
let tf = new opentarget_tf(input, {});
test.skip("test opentarget wrapper if id field is not chembl", async () => {
let tf = new jq_tf(input, { type: "opentarget" });
const fake = {
data: [
{
Expand All @@ -38,7 +38,7 @@ describe("test opentarget transformer", () => {
}
]
}
let res = tf.wrap(fake);
let res = await tf.wrap(fake);
expect(res).toHaveProperty("data");
expect(res.data[0].drug.id).toEqual("http://identifiers.org/drugbank/DB0001");
})
Expand Down
6 changes: 3 additions & 3 deletions __test__/semmed_transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ describe("test semmed transformer", () => {
}
})

test("test semmed pairCurieWithAPIResponse", () => {
test("test semmed pairCurieWithAPIResponse", async () => {
let tf = new semmed_tf(input, {});
let res = tf.pairCurieWithAPIResponse();
let res = await tf.pairCurieWithAPIResponse();
expect(res["UMLS:C1332823"][0]['umls']).toBe("C1332823");
expect(res).toHaveProperty('UMLS:C1332823');
expect(res["UMLS:123"]).toBeUndefined();
Expand All @@ -39,7 +39,7 @@ describe("test semmed transformer", () => {

test("add edge info", async () => {
let tf = new semmed_tf(input, {});
let res = tf.pairCurieWithAPIResponse();
let res = await tf.pairCurieWithAPIResponse();
let rec = res["UMLS:C1332823"][0];
rec = tf.wrap(rec);
let result = await tf.formatRecords("UMLS:C1332823", rec["positively_regulates"][0]);
Expand Down
4 changes: 2 additions & 2 deletions __test__/transformers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ describe("test biothings transformer", () => {
}
});

test("test biothings pairCurieWithAPIResponse", () => {
test("test biothings pairCurieWithAPIResponse", async () => {
let tf = new biothings_tf(input, {});
let res = tf.pairCurieWithAPIResponse();
let res = await tf.pairCurieWithAPIResponse();
expect(res["UMLS:C1332823"][0]['umls']).toBe("C1332823");
expect(res).toHaveProperty('UMLS:C1332823');
expect(res["123"]).toBeUndefined();
Expand Down
22 changes: 22 additions & 0 deletions data/jq/pair/biothings.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if $edge.query_operation._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
if $edge.input | type == "object" then
generateCurieWithInputs($edge.association.input_id; $item.query; $edge.input.queryInputs) as $curie | .[$curie] = .[$curie] + [$item]
else
generateCurieWithInputs($edge.association.input_id; $item.query; $edge.input | toArray) as $curie | .[$curie] = .[$curie] + [$item]
end
end
)
else
if ($edge.input | type) == "object" then
.response as $res | generateCurie($edge.association.input_id; $edge.input.queryInputs) as $curie | {} | .[$curie] = [$res]
else
.response as $res | generateCurie($edge.association.input_id; ($edge.input | toArray)[0]) as $curie | {} | .[$curie] = [$res]
end
end
23 changes: 23 additions & 0 deletions data/jq/pair/ctd.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
reduce .response[] as $item (
{}; .[(
if ($edge.input | type) == "object" then
($edge.input.queryInputs | toArray)[]
else
($edge.input | toArray)[]
end
)
| select(($item.Input | ascii_upcase | split(":") | last) == (. | ascii_upcase))
| generateCurie($edge.association.input_id; .)
] = []
+ .[(
if ($edge.input | type) == "object" then
($edge.input.queryInputs | toArray)[]
else
($edge.input | toArray)[]
end
)
| select(($item.Input | ascii_upcase | split(":") | last) == (. | ascii_upcase))
| generateCurie($edge.association.input_id; .)
]
+ [$item]
) | map_values([.])
Loading

0 comments on commit dbf8aac

Please sign in to comment.