Skip to content

Commit

Permalink
Merge pull request #38 from biothings/use-jmes-path
Browse files Browse the repository at this point in the history
Use JQ
  • Loading branch information
tokebe authored Oct 24, 2023
2 parents e8a3085 + 17496d8 commit b4188d3
Show file tree
Hide file tree
Showing 43 changed files with 25,208 additions and 24,604 deletions.
4 changes: 2 additions & 2 deletions __test__/base_transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,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
37 changes: 19 additions & 18 deletions __test__/biolink_transformers.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import jq_tf from "../built/transformers/jq_transformer";
import biolink_tf from "../src/transformers/biolink_transformer";
import fs from "fs";
import path from "path";
Expand All @@ -18,24 +19,24 @@ describe("test biolink transformer", () => {
};
});

test("test biolink wrapper", () => {
const tf = new biolink_tf(input, {});
const res = tf.wrap(response);
test("test biolink wrapper", async () => {
const tf = new jq_tf(input, { type: "biolink" });
const 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", () => {
const tf = new biolink_tf(input, {});
const res = tf.wrap({ data: [] });
test("test biolink wrapper if no association field as root key", async () => {
const tf = new jq_tf(input, { type: "biolink" });
const 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: [
{
object: {
Expand All @@ -47,8 +48,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 @@ -58,12 +59,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 @@ -73,13 +74,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", () => {
const tf = new biolink_tf(input, {});
const wrapped_response = tf.wrap(response);
test("test biolink jsonTransform function", async () => {
const tf = new jq_tf(input, { type: "biolink" });
const wrapped_response = await tf.wrap(response);
const res: JSONDoc = tf.jsonTransform(wrapped_response);
expect(res).toHaveProperty("related_to");
expect(res.related_to[0].HGNC).toEqual("10956");
Expand Down
24 changes: 12 additions & 12 deletions __test__/biothings_transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import jq_tf from "../src/transformers/jq_transformer";
import biothings_tf from "../src/transformers/biothings_transformer";
import fs from "fs";
import path from "path";
Expand All @@ -18,9 +19,9 @@ describe("test biothings transformer", () => {
};
});

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

test("test biothings wrapper", () => {
const tf = new biothings_tf(input, {});
const res = tf.pairCurieWithAPIResponse();
test("test biothings wrapper", async () => {
const tf = new jq_tf(input, { type: "biothings" });
const 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 () => {
const tf = new biothings_tf(input, {});
const tf = new jq_tf(input, { type: "biothings" });
const res = await tf.transform();
expect(res).toHaveLength(27);
expect(res[0]).not.toHaveProperty("ref_pmid");
// TODO: re-enable when this is handled properly
// expect(res[0]).toHaveProperty("publications", ["PMID:21873635"]);
expect(res[0]).toHaveProperty("publications", ["PMID:21873635"]);
});
});

Expand All @@ -76,9 +76,9 @@ describe("test biothings transformer", () => {
};
});

test("test biothings wrapper", () => {
const tf = new biothings_tf(input, {});
const res = tf.pairCurieWithAPIResponse();
test("test biothings wrapper", async () => {
const tf = new jq_tf(input, { type: "biothings" });
const 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,7 +1,6 @@
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", () => {
let response;
Expand All @@ -18,36 +17,36 @@ describe("test ctd transformer", () => {
};
});

test("test ctd wrapper", () => {
const tf = new ctd_tf(input, {});
const res = tf.wrap(response);
test("test ctd wrapper", async () => {
const tf = new jq_tf(input, { type: "ctd" });
const 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
96 changes: 42 additions & 54 deletions __test__/data/biolink/edge.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@
{
"input": "DOID:678",
"query_operation": {
"params": {
"disease_id": "{inputs[0]}",
"rows": 200
},
"path": "/bioentity/disease/{disease_id}/genes",
"path_params": [
"disease_id"
],
"method": "get",
"server": "https://api.monarchinitiative.org/api",
"tags": [
"anatomy",
"disease",
"gene",
"phenotype",
"pathway",
"annotation",
"query",
"translator",
"biolink"
],
"supportBatch": false
"input": "DOID:678",
"query_operation": {
"params": {
"disease_id": "{inputs[0]}",
"rows": 200
},
"association": {
"input_id": "MONDO",
"input_type": "Disease",
"output_id": "HGNC",
"output_type": "Gene",
"predicate": "related_to",
"api_name": "BioLink API",
"smartapi": {
"id": "d22b657426375a5295e7da8a303b9893",
"meta": {
"ETag": "62f25b12c5457f6924db7929d91e7d5a2e70de291e7672aebf06fa08d1526d9d",
"github_username": "newgene",
"timestamp": "2020-05-28T00:02:40.483712",
"uptime_status": "good",
"uptime_ts": "2020-06-11T00:05:38.030503",
"url": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/master/biolink/openapi.yml"
}
}
},
"response_mapping": {
"related_to": {
"HGNC": "associations.object.HGNC",
"pubmed": "associations.publications.id",
"relation": "associations.relation.label",
"source": "associations.provided_by",
"taxid": "associations.object.taxon.id"
}
},
"id": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"
}
"path": "/bioentity/disease/{disease_id}/genes",
"path_params": ["disease_id"],
"method": "get",
"server": "https://api.monarchinitiative.org/api",
"tags": ["anatomy", "disease", "gene", "phenotype", "pathway", "annotation", "query", "translator", "biolink"],
"supportBatch": false
},
"association": {
"input_id": "MONDO",
"input_type": "Disease",
"output_id": "HGNC",
"output_type": "Gene",
"predicate": "related_to",
"api_name": "BioLink API",
"smartapi": {
"id": "d22b657426375a5295e7da8a303b9893",
"meta": {
"ETag": "62f25b12c5457f6924db7929d91e7d5a2e70de291e7672aebf06fa08d1526d9d",
"github_username": "newgene",
"timestamp": "2020-05-28T00:02:40.483712",
"uptime_status": "good",
"uptime_ts": "2020-06-11T00:05:38.030503",
"url": "https://raw.githubusercontent.com/NCATS-Tangerine/translator-api-registry/master/biolink/openapi.yml"
}
}
},
"response_mapping": {
"related_to": {
"HGNC": "associations.object.HGNC",
"pubmed": "associations.publications.id",
"relation": "associations.relation.label",
"source": "associations.provided_by",
"taxid": "associations.object.taxon.id"
}
},
"id": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"
}
Loading

0 comments on commit b4188d3

Please sign in to comment.