-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
246 lines (218 loc) · 8.87 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!doctype html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-12BB4EE414"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-12BB4EE414');
</script>
<link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="pmtest.css" rel="stylesheet">
<title>
PubMed Mapping Tester
</title>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PXS68WH"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<main role="main">
<!-- Main jumbotron for a primary marketing message or call to action -->
<div id="topbanner" class="jumbotron">
<div class="container">
<a id="about" class="btn btn-outline-secondary" href="about.html">About PubMed Mapping Tester</a>
<h1 class="display-3">PubMed Mapping Tester</h1>
</div>
</div>
<div class="container">
<div class="row" id="welcome">
<div class="col-md-10">
<div class="card mb-3">
<div class="card-body">
<div class="card-title">Compare 'Old' and 'New' PubMed results</div>
<p class="card-text">
The newest version of PubMed has brought a lot of changes, most notably the advent of the 'Best Match'
results sort. Another, less obvious change, is an update to how Automatic Term Mapping (ATM) works in the new
version. Curious about how the new version of ATM might change your earlier PubMed searches? Try it out in the search
box below! <em><a href="about.html">(see more)</a></em></p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-7">
<div class="card mb-3">
<div class="card-body">
<form class="form-inline" id="mainsearch">
<div class="form-group mb-2">
<input type="text" class="form-control" id="searchstr" size="50">
</div>
<button id="runsearch" class="btn btn-primary mb-2" type="button">Search</button>
</form>
</div>
</div>
</div>
</div>
<div class="row" id="resultscomparison">
<div class="col-md-6 pmresults">
<div class="card mb-3">
<div class="card-body">
<div class="card-title">'Old' PubMed Results</div>
<p class="card-text"><span class="counts">Count: </span><span id="oldcount"></span></p>
<p class="card-text"><span class="mapping">Mapping:</span></p>
<p><span id="oldmapping"></span></p>
</div>
</div>
</div>
<div class="col-md-6 pmresults">
<div class="card mb-3">
<div class="card-body">
<div class="card-title">'New' PubMed Results</div>
<p class="card-text"><span class="counts">Count: </span><span id="newcount"></span></p>
<p class="card-text"><span class="mapping">Mapping:</span></p>
<p><span id="newmapping"></span></p>
</div>
</div>
</div>
</div>
<div id="loadingModal">
<div>
<h2>Please wait!</h2>
<p>Fetching your two sets of results from NCBI...</p>
<p><img src="loading-bars.svg"></p>
</div>
</div>
</div>
</main>
<footer class="container">
<span class="text-muted">Design and contruction by <a href="https://esperr.github.io/about/">Ed Sperr, M.L.I.S.</a> |
Data from <a href="http://www.ncbi.nlm.nih.gov/">NCBI</a>
| See the code at <a href="https://github.com/esperr/mapping-tester">GitHub</a></span>
</footer>
</body>
</body>
<script>
const form = document.getElementById('mainsearch');
const searchterm = form.elements['searchstr'];
document.querySelector("#runsearch").addEventListener("click", (e) => { startSearch(); });
//document.querySelectorAll(".pmresults").forEach(box => { box.style.display = "none" });
document.querySelector("#resultscomparison").classList.add("invisible");
document.querySelector("#loadingModal").classList.add("invisible");
let oldCount;
let newCount;
let oldTranslation;
let newTranslation;
function startSearch() {
document.querySelector("#loadingModal").classList.remove("invisible");
let mysearchstr = searchterm.value;
getOldResults(mysearchstr);
getNewResults(mysearchstr);
}
function getOldResults(terms) {
oldCount = null;
fetch('https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?' + new URLSearchParams({
db: 'pubmed',
usehistory: 'y',
term: terms,
retmode: 'json',
retmax: 0,
email: '[email protected]',
tool: 'mappingtester',
}))
.then(response => {
// indicates whether the response is successful (status code 200-299) or not
if (!response.ok) {
throw new Error(`Request failed with status ${reponse.status}`)
}
return response.json()
})
.then(data => {
let myesearchresult = data.esearchresult;
oldCount = Number(myesearchresult.count);
oldTranslation = myesearchresult.querytranslation;
//checkdone();
})
.catch(error => console.log(error));
}
function getNewResults(terms) {
newCount = null;
fetch('https://eutilspreview.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?' + new URLSearchParams({
db: 'pubmed',
usehistory: 'y',
term: terms,
retmode: 'json',
retmax: 0,
email: '[email protected]',
tool: 'mappingtester',
}))
.then(response => {
// indicates whether the response is successful (status code 200-299) or not
if (!response.ok) {
throw new Error(`Request failed with status ${reponse.status}`)
}
return response.json()
})
.then(data => {
let myesearchresult = data.esearchresult;
newCount = Number(myesearchresult.count);
newTranslation = myesearchresult.querytranslation;
checkdone();
})
.catch(error => console.log(error));
}
function checkdone() {
if (oldCount == null || newCount == null) {
setTimeout(checkdone, 50);
} else { showResults(); }
}
function showResults() {
let x = document.getElementById("welcome");
if (!(window.getComputedStyle(x).display === "none")) {
document.querySelector("#welcome").style.display = "none";
}
document.querySelector("#loadingModal").classList.add("invisible");
document.querySelector("#resultscomparison").classList.remove("invisible");
//document.querySelectorAll(".pmresults").forEach(box => { box.style.display = "block" })
console.log(typeof oldCount);
document.querySelector("#oldcount").innerHTML = "<span class='totals'>" + oldCount.toLocaleString("en-US") + "<span>";
document.querySelector("#oldmapping").textContent = oldTranslation;
let newcountStr = "<span class='totals'>" + newCount.toLocaleString("en-US") + "</span>";
translationDiff();
if (oldCount != newCount) {
let countDiff = newCount - oldCount;
let percentDiff = roundToTwo(countDiff*100/oldCount);
newcountStr = newcountStr + " <span class='percentdiff'>(" + percentDiff + "% difference)</span>";
} else {
newcountStr = newcountStr + " <span class='percentdiff'>(Same result)</span>";
}
document.querySelector("#newcount").innerHTML = newcountStr;
}
function translationDiff() {
const regex = /\[(\w+)\s(\w+)\]/ig;
let unspacedOldTrans = oldTranslation.replaceAll(regex, '[$1 $2]');
let unspacedNewTrans = newTranslation.replaceAll(regex, '[$1 $2]');
let oldTransArray = unspacedOldTrans.split(' ');
let newTransArray = unspacedNewTrans.split(' ');
for (i = 0; i < newTransArray.length; i++) {
if (oldTransArray.includes(newTransArray[i])) {
} else {
newTransArray[i] = "<span class='hilite'>" + newTransArray[i] + "</span>"
}
}
document.querySelector("#newmapping").innerHTML = newTransArray.join(' ');
}
function roundToTwo(num) {
return +(Math.round(num + "e+2") + "e-2");
}
document.addEventListener("keydown", (e) => {
if(e.keyCode == 13) {
//Because FF "helpfully" ignores the spec and treats 'button' the same as 'submit'
e.preventDefault();
startSearch();
}
});
</script>
</html>