Last active
October 25, 2015 22:43
-
-
Save nimezhu/2484cd9157a1feb7bfeb to your computer and use it in GitHub Desktop.
render pubmed search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h2 { | |
padding:4px; | |
color:#fff; | |
margin:0; | |
background-color:black; | |
font-size: 10pt; /* or whatever */ | |
} | |
body { | |
width: 100%; | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
background-color: #FAFAFA; | |
font: 12pt "Tahoma"; | |
} | |
* { | |
box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
} | |
.page { | |
width: 210mm; | |
min-height: 297mm; | |
padding: 20mm; | |
margin: 10mm auto; | |
border: 1px #D3D3D3 solid; | |
border-radius: 5px; | |
background: white; | |
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1); | |
} | |
.subpage { | |
padding: 1cm; | |
border: 5px red solid; | |
height: 257mm; | |
outline: 2cm #FFEAEA solid; | |
} | |
@page { | |
size: A4; | |
margin: 0; | |
} | |
@media print { | |
html, body { | |
width: 210mm; | |
height: 297mm; | |
} | |
.page { | |
margin: 0; | |
border: initial; | |
border-radius: initial; | |
width: initial; | |
min-height: initial; | |
box-shadow: initial; | |
background: initial; | |
page-break-after: always; | |
} | |
} | |
#brief { | |
width:168mm; | |
padding:5mm; | |
border-spacing: 10px; | |
} | |
#name { | |
font-size:largest; | |
padding: 2mm; | |
font-family:STKaiti; | |
} | |
table { | |
padding:5mm | |
} | |
.pdiv { | |
padding: 2mm; | |
font-size: small; | |
} | |
h1 { | |
text-align: center; | |
font-size:largest; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>Publications</title> | |
<link rel="stylesheet" type="text/css" href="cv.css"> | |
<script src="../lib/jquery.min.js"></script> | |
<script src="./pub.js" charset="utf-8"></script> | |
<script type="text/javascript"> | |
var tableName="publications"; | |
function getUrlParam(name) { | |
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null; | |
} | |
( function($,P){ | |
var q = getUrlParam("q"); | |
var h = getUrlParam("h"); | |
if (!h) { h=""}; | |
if (!q) { q="Xiaopeng Zhu[AU] and (Runsheng Chen[AU] || Manuel Garber[AU])" ; h="Zhu X"}; | |
var render_pubs=function(pubs) { | |
var s="" | |
pubs.forEach(function(p){ | |
var c = []; | |
p.Authors.forEach(function(n,i) { | |
if (n==h) {p.Authors[i]="<b>"+n+"</b>"} | |
}) | |
s+="<li>"+p.Title+" "+p.Authors+" <i>"+p.Journal+"</i> "+p.PubDate+" pubmed:<a href='http:http://www.ncbi.nlm.nih.gov/pubmed/"+p.PubmedId+"'>"+p.PubmedId+"</a></li>" | |
}); | |
$("#list").html(s) | |
} | |
console.log(P) | |
P.query(q,render_pubs); | |
})(jQuery,pub); | |
</script> | |
<style> | |
</style> | |
</head> | |
<body><div id="chart_div" class="page"><ul id="list"></ul></div></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pub = pub || {}; | |
(function(P,$) { | |
P.query = function(q,callback) { | |
$.ajax( { | |
url: "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term="+q+"&retmax=3000", | |
dataType: "xml", | |
success: function(data){ | |
console.log(data) | |
var s=[]; | |
$(data).find("IdList").each(function(){ | |
$(this).find("Id").each(function(){s.push($(this).text())}) | |
}); | |
var ss=s.join(",") | |
url2 = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id="+ss; | |
render(url2,callback); | |
}, | |
error: function(XMLHttpRequest, textStatus, errorThrown) { | |
alert("Status: " + textStatus); alert("Error: " + errorThrown); | |
} | |
}); | |
} | |
var render = function(url,callback) { | |
$.ajax({ url:url, | |
dataType: "xml", | |
success : function(data) { | |
var pubs = []; | |
console.log(data); | |
$(data).find("DocSum").each(function() { | |
var d={} | |
d.Title=$(this).find("Item[Name=\"Title\"]").text() | |
d.Authors=[] | |
$(this).find("Item[Name=\"AuthorList\"]").each(function() { | |
$(this).find("Item[Name=\"Author\"]").each(function() { | |
d.Authors.push($(this).text()); | |
}) | |
}) | |
d.Journal = $(this).find("Item[Name=\"FullJournalName\"]").text(); | |
d.SO = $(this).find("Item[Name=\"SO\"]").text(); | |
d.PubDate = $(this).find("Item[Name=\"PubDate\"]").text(); | |
$(this).find("Item[Name=\"ArticleIds\"]").each( | |
function(){ | |
d.PubmedId = $(this).find("Item[Name=\"pubmed\"]").text() | |
}) | |
pubs.push(d); | |
}) | |
callback(pubs); | |
}, | |
error: function(XMLHttpRequest, textStatus, errorThrown) { | |
alert("Status: " + textStatus); alert("Error: " + errorThrown); | |
} | |
})} | |
}(pub,jQuery)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>Publications</title> | |
<script src="../lib/jquery.min.js"></script> | |
<script src="../lib/d3.v3.min.js"></script> | |
<script src="./pub.js"></script> | |
<script type="text/javascript" src="../lib/keshif.js" charset="utf-8"></script> | |
<link rel="stylesheet" href="../css/keshif.css"/ type="text/css"> | |
<link rel="stylesheet" href="../pub.css"/ type="text/css"> | |
<script type="text/javascript"> | |
var tableName="publications"; | |
var postCols = { | |
Title: 0, | |
AuthorList: 1, | |
PubDate: 2, | |
SO: 3, | |
Journal: 4, | |
PubmedId: 5 | |
}; | |
function getUrlParam(name) { | |
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null; | |
} | |
var q = getUrlParam("q"); | |
var h = getUrlParam("h"); | |
if (!h) { h=""}; | |
if (!q) { q="Xiaopeng Zhu[AU] and (Runsheng Chen[AU] || Manuel Garber[AU])" ; h="Zhu X"}; | |
function loadData(browser){ | |
pub.query(q,render_pubs); | |
} | |
var render_pubs = function(data) { | |
browser.primaryTableName = tableName; | |
kshf.dt_ColNames[tableName] = postCols; | |
kshf.dt[tableName] = []; | |
var arr = kshf.dt[tableName]; | |
var posts = data; | |
posts.forEach(function(p){ | |
var c = []; | |
c[postCols.Title] = p.Title; | |
c[postCols.PubDate] = p.PubDate; | |
c[postCols.Journal] = p.Journal; | |
c[postCols.AuthorList] = p.Authors; | |
c[postCols.SO] = p.SO; | |
c[postCols.PubmedId] = p.PubmedId; | |
var item = new kshf.Item(c,postCols.Title,true); | |
item.browser = browser; | |
arr.push(item); | |
}); | |
browser.items = arr; | |
browser.itemsSelectedCt = kshf.dt[tableName].Title; | |
var id_table = {}; | |
arr.forEach(function(r){id_table[r.id()] = r;}) | |
kshf.dt_id[tableName] = id_table; | |
$(".kshf.layout_infobox div.status_text span").text("Creating browser"); | |
$(".kshf.layout_infobox div.status_text div").text(""); | |
window.setTimeout(function() { browser.loadCharts(); }, 50); | |
} | |
$(document).ready( function(){ | |
browser = new kshf.Browser({ | |
domID : "#chart_div", | |
itemName: "Publications", | |
dirRoot: "./", | |
categoryTextWidth: 160, | |
showDataSource : false, | |
source: { callback : loadData }, | |
charts : [ | |
{ | |
facetTitle: "Publication", | |
catItemMap: function(d) { return "Publications" }, | |
timeTitle: "PubDate", | |
timeItemMap: function(d){ | |
var year=d.data[postCols.PubDate].substring(0,4); | |
var date= new Date(d.data[postCols.PubDate]); | |
return date; | |
} | |
}, | |
{ facetTitle: "PubDate", | |
catItemMap : function(d){ | |
return d.data[postCols.PubDate].substring(0,4) | |
}, | |
catLabelText: function(d){ return d.data[1] }, | |
sortingOpts: [ { | |
name:"numeric", | |
no_resort: true, | |
func: function(a,b) {return b.data[1] - a.data[1];} | |
}, {name:"by Freq"}], | |
}, | |
{ | |
facetTitle: "Journal" | |
} | |
], | |
list: { | |
sortColWidth: 100, | |
sortingOpts : [ { name: 'PubDate', inverse: true } ], | |
textSearch : "Title", | |
contentFunc : function(d){ | |
var str="<span class='title'>"; | |
str+=d.data[postCols.Title]+"</span><br>" | |
str+="<span class='authorlist'>" | |
for(var i in d.data[postCols.AuthorList]) | |
{ | |
if (i>0) { str+=","} | |
if (d.data[postCols.AuthorList][i].toLowerCase()==h.replace("%20"," ").toLowerCase()) | |
{ | |
str+="<span class='highlight'>"+d.data[postCols.AuthorList][i]+"</span>" | |
} | |
else | |
{ | |
str+=d.data[postCols.AuthorList][i] | |
} | |
} | |
str+="</span><br><span class='journal'>"; | |
str+=d.data[postCols.Journal]+" </span>" | |
str+="<span class='SO'>"+d.data[postCols.SO]+"<span>"; | |
str+="<br><a href='http://www.ncbi.nlm.nih.gov/pubmed/?term="+d.data[postCols.PubmedId]+"'>pubmed</a><br><br>"; | |
return str; | |
} | |
} | |
}); | |
}); | |
</script> | |
<style> | |
#chart_div { | |
width: 988px; | |
height: 600px; | |
} | |
.title { | |
color: #000099; | |
} | |
.journal { | |
font-style: italic; | |
} | |
.SO { | |
font-size: smaller; | |
} | |
.highlight { | |
font-style: italic; | |
color:#3333CC | |
} | |
.authorlist { | |
font-size: smaller; | |
} | |
</style> | |
</head> | |
<body><div id="chart_div"></div></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment