Skip to content

Commit

Permalink
Merge 6c25a5a into f7d64c4
Browse files Browse the repository at this point in the history
  • Loading branch information
colleenXu committed Sep 7, 2021
2 parents f7d64c4 + 6c25a5a commit dd2b9d0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
4 changes: 2 additions & 2 deletions __tests__/integration/biolink_based_resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ describe("Test ID Resolver", () => {
expect(res['kkk:123'][0].primaryID).toEqual('kkk:123');
expect(res['kkk:123'][0].label).toEqual('kkk:123')
})

test("test large batch of inputs should be correctly resolved", async () => {
// not relevant?
test.skip("test large batch of inputs should be correctly resolved", async () => {
const fakeNCBIGeneInputs = [...Array(1990).keys()].map(item => 'NCBIGene:' + item.toString());
const fakeOMIMGeneInputs = [...Array(2300).keys()].map(item => "OMIM:" + item.toString());
const fakeDrugbankInputs = [...Array(3500).keys()].map(item => "DRUGBANK:DB00" + item.toString());
Expand Down
7 changes: 4 additions & 3 deletions __tests__/integration/default_resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ describe("Test ID Resolver", () => {
expect(res['kkk:123'][0].primaryID).toEqual('kkk:123');
expect(res['kkk:123'][0].label).toEqual('kkk:123')
})

test("test large batch of inputs should be correctly resolved", async () => {
// not relevant?
test.skip("test large batch of inputs should be correctly resolved", async () => {
const fakeNCBIGeneInputs = [...Array(1990).keys()].map(item => 'NCBIGene:' + item.toString());
const fakeOMIMGeneInputs = [...Array(2300).keys()].map(item => "OMIM:" + item.toString());
const fakeDrugbankInputs = [...Array(3500).keys()].map(item => "DRUGBANK:DB00" + item.toString());
Expand Down Expand Up @@ -170,7 +170,8 @@ describe("Test ID Resolver", () => {
expect(res['NCBIGene:1017'][1]).toBeInstanceOf(IrresolvableBioEntity);
})

test("Test chemical attributes are correctly retrieved", async () => {
// skip because new ID resolver doesn't retrieve attributes
test.skip("Test chemical attributes are correctly retrieved", async () => {
const resolver = new DefaultIDResolver();
const res = await resolver.resolve({ "SmallMolecule": ["CHEMBL.COMPOUND:CHEMBL744"] });
expect(res["CHEMBL.COMPOUND:CHEMBL744"][0].attributes.drugbank_taxonomy_class).toContain("Benzothiazoles");
Expand Down
46 changes: 35 additions & 11 deletions src/sri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ import axios from 'axios';
import { CURIE } from './config';
import { SRIResolverOutput, ResolverInput } from './common/types';
import Debug from 'debug';
const debug = Debug('biomedical-id-resolver:QueryBuilder');
import _ from 'lodash';
const debug = Debug('bte:biomedical-id-resolver:SRI');

//input: array of curies
async function query(api_input: string[]) {
let url: URL = new URL('https://nodenormalization-sri-dev.renci.org/1.1/get_normalized_nodes'); // TODO: change to non-dev version when ready
//@ts-ignore
url.search = new URLSearchParams(api_input.map(curie => ["curie", curie]));
let res = await axios.get(url.toString());
return res.data;

//SRI returns a 414 error if the length of the url query is greater than 65536, split into chunks of 1500 curies to be on the safe side (lower number if still running into 414 errors)
let chunked_input = _.chunk(api_input, 1500);

let axios_queries = chunked_input.map((input) => {
//@ts-ignore
url.search = new URLSearchParams(input.map(curie => ["curie", curie]));
return axios.get(url.toString());
});

//convert res array into single object with all curies
let res = await Promise.all(axios_queries);
res = res.map(r => r.data);
return Object.assign({}, ...res);
}

function transformResults(results, semanticType: string): SRIResolverOutput {
Expand All @@ -31,11 +42,11 @@ function transformResults(results, semanticType: string): SRIResolverOutput {
_leafSemanticType: semanticType,
semanticTypes: [semanticType],
dbIDs: {
[id_type]: CURIE.ALWAYS_PREFIXED.includes(id_type) ? key : key.split(":")[1],
[id_type]: [CURIE.ALWAYS_PREFIXED.includes(id_type) ? key : key.split(":")[1]],
name: [key]
},
_dbIDs: {
[id_type]: CURIE.ALWAYS_PREFIXED.includes(id_type) ? key : key.split(":")[1],
[id_type]: [CURIE.ALWAYS_PREFIXED.includes(id_type) ? key : key.split(":")[1]],
name: [key]
}
};
Expand All @@ -45,10 +56,13 @@ function transformResults(results, semanticType: string): SRIResolverOutput {
entry.label = entry.id.label || entry.id.identifier;
entry.attributes = {};
entry.semanticType = entry.type[0].split(":")[1]; // get first semantic type without biolink prefix
if (semanticType !== entry.semanticType) {
debug(`SRI resolved semantic type ${entry.semanticType} doesn't match input semantic type ${semanticType}`);
}
entry.semanticTypes = entry.type;
if (semanticType !== entry.semanticType && semanticType !== 'unknown') {
debug(`SRI resolved semantic type ${entry.semanticType} doesn't match input semantic type ${semanticType} for curie ${entry.primaryID}. Setting to ${semanticType}.`);
//replace semantic type with input semantic type
entry.semanticType = semanticType;
entry.semanticTypes[0] = semanticType;
}

let names = Array.from(new Set(entry.equivalent_identifiers.map(id_obj => id_obj.label))).filter((x) => (x != null));
let curies = Array.from(new Set(entry.equivalent_identifiers.map(id_obj => id_obj.identifier))).filter((x) => (x != null));
Expand Down Expand Up @@ -87,5 +101,15 @@ export async function _resolveSRI(userInput: ResolverInput): Promise<SRIResolver
return transformResults(query_results, semanticType);
}));

return Object.assign({}, ...results); //convert array of objects into single object
return results.reduce((result, currentObj) => {
for(let curie in currentObj) {
if (currentObj.hasOwnProperty(curie)) {
if (!result.hasOwnProperty(curie)) {
result[curie] = [];
}
result[curie] = [...result[curie], ...currentObj[curie]];
}
}
return result;
}, {}); //convert array of objects into single object
}

0 comments on commit dd2b9d0

Please sign in to comment.