Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

biomedical-id-autocomplete

Package Overview
Dependencies
Maintainers
3
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

biomedical-id-autocomplete - npm Package Compare versions

Comparing version 1.2.5 to 1.3.0

45

index.js

@@ -57,11 +57,12 @@ const ID_RESOLVING_APIS = require('./config').ID_RESOLVING_APIS;

exports.construct_q = (input, query_fields) => {
let res = '';
query_fields.split(',').map(field => {
res = res + field + ':' + input.toString() + '* OR ';
})
return res.slice(0, -4);
}
// exports.construct_q = (input, query_fields) => {
// let res = '';
// query_fields.split(',').map(field => {
// res = `${res}${field}:"${input.toString()}*" OR `;
// })
// return res.slice(0, -5);
// }
exports.construct_single_query = (semantic_type, input) => {
//wide - whether or not to match wider results with a *
exports.construct_single_query = (semantic_type, input, wide=false) => {
const base_url = ID_RESOLVING_APIS[semantic_type]["url"] + '/query';

@@ -74,2 +75,3 @@ let query_fields;

}
return axios({

@@ -79,3 +81,4 @@ method: 'get',

params: {
q: this.construct_q(input, query_fields),
q: wide ? `${input}*` : `"${input}"`,
// q: this.construct_q(input, query_fields),
fields: query_fields,

@@ -90,3 +93,3 @@ species: 'human',

exports.make_queries = (input) => {
exports.make_queries = (input, wide=false) => {
let semantic_types = Object.keys(ID_RESOLVING_APIS);

@@ -98,3 +101,3 @@ let queries = [];

}
queries.push(this.construct_single_query(semantic_type, input))
queries.push(this.construct_single_query(semantic_type, input, wide))
};

@@ -146,4 +149,6 @@ return axios.all(queries);

let responses = [];
//attempt to get exact matches first
try {
responses = await this.make_queries(input);
responses = await this.make_queries(input, false);
} catch (e) {

@@ -153,2 +158,18 @@ console.warn(e);

//if there are no results attempt wider matching
let response_empty = true;
for (let res of responses) {
if (res.data.total > 0) {
response_empty = false;
break;
}
}
if (response_empty) {
try {
responses = await this.make_queries(input, true);
} catch (e) {
console.warn(e);
}
}
let result = {};

@@ -155,0 +176,0 @@ for (let res of responses) {

{
"name": "biomedical-id-autocomplete",
"version": "1.2.5",
"version": "1.3.0",
"description": "autocomplete biomedical ids",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -32,4 +32,4 @@ const main = require('../index');

return main.construct_single_query('Gene', 'CXCR4').then(data => {
expect(data.data.hits[0]['HGNC']).toBe('2561');
expect(data.data.hits[0]['ensembl.gene']).toBe('ENSG00000121966');
expect(JSON.stringify(data)).toContain('2561');
expect(JSON.stringify(data)).toContain('ENSG00000121966');
})

@@ -41,7 +41,24 @@ })

const res = main.parse_single_response(data)['Gene'];
expect(res[0]['SYMBOL']).toBe('CXCR4');
expect(res[0]['ENSEMBL']).toBe('ENSG00000121966');
expect(res[0]['NCBIGene']).toBe('7852');
expect(res[0]['primary']['identifier']).toBe('NCBIGene');
expect(JSON.stringify(res)).toContain('CXCR4');
for (let result of res) {
if (result['SYMBOL'] === 'CXCR4') {
expect(result['SYMBOL']).toBe('CXCR4');
expect(result['ENSEMBL']).toBe('ENSG00000121966');
expect(result['NCBIGene']).toBe('7852');
expect(result['primary']['identifier']).toBe('NCBIGene');
}
}
})
test('test autocomplete with id', async () => {
const res = await main.autocomplete('MONDO:0005737');
expect(res.Disease.length).toBeGreaterThan(0);
})
test('test autocomplete with "multiple sclerosis"', async () => {
const res = await main.autocomplete('multiple sclerosis');
expect(res.Disease.length).toBeGreaterThan(0);
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc