jbrowse-testing/ncbi-api-test/index.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-02-04 17:17:48 -08:00
let searchQuery = "science[journal]+AND+breast+cancer+AND+2008[pdat]";
let url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils"
2023-02-04 14:49:44 -08:00
2023-02-04 17:17:48 -08:00
function testSearchPubmed(query) {
fetch(`${url}/esearch.fcgi?db=pubmed&term=${query}`)
.then((res) => {
res.blob().then(val => {
val.text().then(val => {
let xmlParser = (new DOMParser()).parseFromString(val, "text/xml");
let els = xmlParser.getElementsByTagName("Id");
let ids = [];
for (let i = 0; i < els.length; i++) {
ids.push(els[i].innerHTML);
}
console.log(ids);
return ids;
})
})
});
}
function testSearchGene(query) {
fetch(`${url}/esearch.fcgi?db=gene&term=${query}`)
2023-02-04 14:49:44 -08:00
.then((res) => {
2023-02-04 17:17:48 -08:00
res.blob().then(val => {
val.text().then(val => {
console.log(val);
})
})
});
}
function testLookupGeneById(ids) {
fetch(`${url}/esummary.fcgi?db=gene&id=${String(ids)}`)
.then(res => {
res.blob().then(val => {
val.text().then(val => {
console.log(val)
})
2023-02-04 14:49:44 -08:00
})
})
}
2023-02-04 17:17:48 -08:00
testLookupGeneById(7157);