-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
438 lines (386 loc) · 15.5 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<!doctype html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-433406-15"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-433406-15');
</script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>PubTrees</title>
<!-- Bootstrap core CSS -->
<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 rel="stylesheet" href="pmtree.css">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<!-- Custom styles for this template -->
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="">PubTrees</a>
<div class="navbar-nav ml-auto">
<a class="nav-item nav-link active" href="about.html">About PubTrees</a>
</div>
</nav>
<main role="main">
<!-- Main jumbotron for a primary marketing message or call to action -->
<div id="topbanner" class="jumbotron">
<div class="container">
<h1 class="display-3">PubTrees</h1>
</div>
</div>
<div class="container" id="mainsearch">
<!-- Example row of columns -->
<!--<div class="row">
<div class="col-12">
<h2>Your PubMed search</h2>
<form class="form-inline">
<div class="form-group mb-3">
<input type="text" class="form-control" id="search">
</div>
<button id="runsearch" class="btn btn-primary mb-2" type="button">Search</button>
</form>
</div>
</div>-->
<div class="row">
<div class="col-md-5">
<h3>Your PubMed search:</h3>
<div id="searchwords"></div>
<form class="form-inline">
<div class="form-group mb-2">
<input type="text" class="form-control" id="search" size="30">
</div>
<button id="runsearch" type="button" class="btn btn-primary mb-2">Search</button>
</form>
<form class="searchoptions">
<p class="optionlabel">Search term(s) in:</p>
<div class="custom-control custom-radio custom-control-inline searchoption">
<input type="radio" class="custom-control-input" id="type1" name="searchtype" value="tiab" checked>
<label class="custom-control-label" for="type1">Title and abstract</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="type2" name="searchtype" value="any">
<label class="custom-control-label" for="type2">Anywhere</label>
</div>
<p class="optionlabel">Dates to search:</p>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="years1" name="searchyears" value="ten" checked>
<label class="custom-control-label" for="years1">Last 10 years</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="years2" name="searchyears" value="all">
<label class="custom-control-label" for="years2">All</label>
</div>
<p class="optionlabel">Graph results:</p>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="sort1" name="searchsort" value="relevance" checked>
<label class="custom-control-label" for="sort1">Most relevant</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="sort2" name="searchsort" value="date">
<label class="custom-control-label" for="sort2">Most recent</label>
</div>
</form>
</div>
<div class="col-md-5" id="examplechart">
<h4>Visualize your search results!</h4>
<p>PubTrees enables you to explore the concepts in the documents returned by your PubMed search
by using the <a href="http://hint.fm/papers/wordtree_final2.pdf">Word Tree</a>
technique. <a href="about.html"><em>(more...)</em></a>
</p>
<img src="PubMed.PNG" alt="Example of a PubTrees chart" />
</div>
</div>
<div class="row">
<div class="col-md-8">
</div>
</div>
<div class="row">
<div class="col-md-10">
<h4>How it works...</h4>
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">1) Search your Terms</h5>
<p class="card-text">Search with any PubMed search terms you like. You can use anything from a couple of keywords to the most complex search you can manage.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">2) Choose your Root</h5>
<p class="card-text">Select one of your search terms (or choose any other word) to serve as the "root" of your tree. This term
will be at the center of your diagram.</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">3) View your Tree</h5>
<p class="card-text">Other words and phrases from the citations found will be graphed in
relation to the root of your tree. You can keep redrawing the graph by either changing the number of citations that are
graphed or by selecting a different root. You can also <em>interact</em> with the tree by selecting individual terms.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<hr>
</div> <!-- /container -->
<div id="chooseroot" class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-md-5">
<p>Your search returned <span id="returned"></span> PubMed results</p>
<p>Select one of your search terms to see it as root...</p>
<div id="searchwords"></div>
<div id="rootwords"></div>
<p>or choose your own different word:</p>
<form class="form-inline">
<div class="form-group mb-2">
<input type="text" class="form-control" id="customword" size="10">
</div>
<button id="ownword" type="button" class="btn btn-primary mb-2">Draw</button>
</form>
</div>
<div class="col-md-3">
<form class="searchoptions">
<p>Draw your tree with how many results?</p>
<div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="results1" name="howmany" value="50">
<label class="custom-control-label" for="results1">50</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="results2" name="howmany" value="100" checked>
<label class="custom-control-label" for="results2">100</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="results3" name="howmany" value="150">
<label class="custom-control-label" for="results3">150</label>
</div>
<!--<input type="radio" id="results1"
name="howmany" value="50">
<label for="results1">50</label>
<input type="radio" id="results1"
name="howmany" value="100" checked>
<label for="Choice2">100</label>
<input type="radio" id="Choice3"
name="howmany" value="150">
<label for="Choice3">150</label>-->
</div>
</form>
<button id="reset" type="button" class="btn btn-outline-danger">Try another search</button>
</div>
</div>
<hr>
</div> <!-- /container -->
<div id="please-wait" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Please wait!</h4>
</div>
<div class="modal-body">
<div class="loading">
<p>Fetching your results...</p>
<img src="loading-bars.svg">
</div>
</div>
</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> | Visualization tools from <a href="https://developers.google.com/chart/interactive/docs/gallery/wordtree" target="_blank">Google</a>
| See the code at <a href="https://github.com/esperr/pub-trees">GitHub</a></span></footer>
</body>
<script>
(function() {
var current_datetime = new Date();
var tenyearsago = new Date();
tenyearsago.setFullYear(tenyearsago.getFullYear() - 10);
var formatted_date = current_datetime.getFullYear() + "/" + (current_datetime.getMonth() + 1) + "/" + current_datetime.getDate();
var formatted_old_date = tenyearsago.getFullYear() + "/" + (tenyearsago.getMonth() + 1) + "/" + tenyearsago.getDate();
$( "#chooseroot" ).hide();
$('#search').val("");
var phrases = [];
var query_key;
var WebEnv;
$(document).keydown(function(e) {
if(e.keyCode == 13) {
//Because both IE and FF now "helpfully" ignore the spec and treat 'button' the same as 'submit'
e.preventDefault();
if($('#mainsearch').is(':visible')){
$( "#runsearch" ).trigger( "click" );
}
if($('#chooseroot').is(':visible')){
$( "#ownword" ).trigger( "click" );
}
}
});
$("#runsearch").click(function(){
searchstr = $("#search").val();
startSearch(searchstr);
});
$("#ownword").click(function(){
var myword = $("#customword").val();
var spacetest = myword.indexOf(' ');
if (spacetest > -1) {
alert("Sorry, you can only use one word as your root!");
$("#customword").val("");
} else {
getDocs( myword );
}
});
$( "#rootwords" ).on( "click", ".searchword", function() {
var myword = $(this).text();
getDocs( myword );
});
$( ".row" ).on( "click", "#reset", function() {
location.replace(location.pathname);
});
function startSearch(term) {
$('#returned').empty();
$( "#searchwords" ).empty();
$( "#wordtree_basic" ).empty();
$("#customword").val("");
//$( "#chooseroot" ).hide();
if ($( "input[name='searchtype']:checked" ).val() == "tiab") {
term = term + "[tiab]";
}
if ($( "input[name='searchyears']:checked" ).val() == "ten") {
term = term +' AND ("' + formatted_old_date + '"[PDAT] : "' + formatted_date + '"[PDAT])';
}
if ($( "input[name='searchsort']:checked" ).val() == "relevance") {
var sort = "relevance";
} else {
var sort = "most+recent";
}
esearch(term, sort)
.then(function( data ) {
var searchwords = searchstr.split(" ")
for (i=0; i<searchwords.length; i++) {
$( "#rootwords" ).append(" <span class='searchword'>" + searchwords[i] + "</span>");
}
query_key = data.esearchresult.querykey;
WebEnv = data.esearchresult.webenv;
count = Number(data.esearchresult.count);
if (count == 0) {
alert("Sorry! Nothing found for your search...");
location.reload();
}
$( "#returned" ).append(count.toLocaleString());
$( "#chooseroot" ).show();
$( "#mainsearch" ).hide();
$( "#chooseroot" ).after('<div class="container" id="wordtree_basic">');
var divWidth = $( "#chooseroot" ).innerWidth();
var chartwidth = divWidth*.9;
var chartheight = chartwidth*.8;
//if (chartwidth < 500) {
// alert("Minimum!");
// $( "#chooseroot" ).attr( "style", 'style="width: 700px; height: 560px;"' );
//} else {
// $( "#chooseroot" ).attr( "style", 'style="width: ' + chartwidth + '; px; height: ' + chartheight + ' px;"' );
//}
//var rootword = $("#search").val();
//getDocs( rootword );
});
}
function esearch(term, sort) {
return $.ajax({
url: 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi',
data: {
db: 'pubmed',
usehistory: 'y',
term: term,
sort: sort,
retmode: 'json',
retmax: 0,
email: '[email protected]',
tool: 'PubTrees'
}
});
}
function getDocs(rootword) {
var doccount = $( "input[name='howmany']:checked" ).val();
var efetchURL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi";
phrases.length = 0;
$("#please-wait").modal();
$.ajax({
url: efetchURL,
data: {
db: 'pubmed',
usehistory: 'y',
WebEnv: WebEnv,
query_key: query_key,
retmode: 'xml',
rettype: 'abstract',
retmax: doccount },
})
.done(function( xml ) {
$(xml).find('PubmedArticle').each(function(){
var title = $(this).find("ArticleTitle").text();
var abstract = $(this).find("AbstractText").text();
var mytext = title + abstract;
findMatch(mytext, rootword);
});
var myword = $("#search").val();
if (phrases.length > 0) {
drawChart( rootword );
} else {
alert("Sorry! Can't locate your word in the tree...");
location.reload();
}
});
}
function findMatch( teststring, rootword ) {
str1 = "[^\.\!\?]*[\.\!\?]";
var re = new RegExp(str1, "gi");
var res = teststring.match(re);
if ( res ) {
for (i=0; i < res.length; i++) {
var myphrase = [ res[i] ];
var retwo = new RegExp( rootword, "gi");
if (retwo.test(myphrase)) {
phrases.push(myphrase);
}
}
}
}
google.charts.load('current', {packages:['wordtree']});
function drawChart( myword ) {
var data = google.visualization.arrayToDataTable( phrases );
var options = {
wordtree: {
format: 'implicit',
type: 'double',
word: myword
}
};
var chart = new google.visualization.WordTree(document.getElementById('wordtree_basic'));
$('#please-wait').modal('hide');
chart.draw(data, options);
var element = document.getElementById("wordtree_basic");
element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});
//var t1 = document.getElementById('wordtree_basic');
if (document.getElementById('google-visualization-errors-all-1')) {
$('#wordtree_basic').empty();
alert("Your word cannot be found! Please choose another...");
}
}
})
();
</script>
</html>