1 #+TITLE: Links and functions for Pubmed and NIH databases
3 #+DATE: January 5, 2015
7 This document is an experiment at creating a literate program to provide functions for interacting with pubmed databases.
9 This library provides links that go to pubmed resources, e.g.
15 and nihmsid:NIHMS395714
17 See http://www.ncbi.nlm.nih.gov/pmc/about/public-access-info/#p3 for details of these identifiers.
19 For PMID there is one interactive function that inserts a bibtex entry: pubmed-insert-bibtex-from-pmid.
21 This library is complementary to [[./doi-utils.org]].
24 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
25 ;;; pubmed.el --- Links and functions to interact with pubmed databases.
27 ;; Copyright(C) 2015 John Kitchin
29 ;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
30 ;; This file is not currently part of GNU Emacs.
32 ;; This program is free software; you can redistribute it and/or
33 ;; modify it under the terms of the GNU General Public License as
34 ;; published by the Free Software Foundation; either version 2, or (at
35 ;; your option) any later version.
37 ;; This program is distributed in the hope that it will be useful, but
38 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
39 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40 ;; General Public License for more details.
42 ;; You should have received a copy of the GNU General Public License
43 ;; along with this program ; see the file COPYING. If not, write to
44 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
45 ;; Boston, MA 02111-1307, USA.
49 ;; Lisp code to interact with pubmed databases, links to pubmed
50 ;; identifiers. See pubmed.org.
52 ;; This library provides links that go to pubmed resources, e.g.
58 ;; and nihmsid:NIHMS395714
60 ;; See http://www.ncbi.nlm.nih.gov/pmc/about/public-access-info/#p3 for details of these identifiers.
62 ;; For PMID there is one interactive function that inserts a bibtex
63 ;; entry: `pubmed-insert-bibtex-from-pmid`.
66 * PMID (from PubMed) link and functions
67 A PMID is a number that identifies an entry in the Pubmed database. The PMID is a unique reference number for PubMed citations. The PMID is a distinctly different number from the PMCID and is used only for PubMed records.
70 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
74 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pubmed/%s" link-string)))
76 (lambda (keyword desc format)
79 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s\">pmid:%s</a>" keyword keyword)); no output for html
81 ;; write out the latex command
82 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
87 ** Get MEDLINE metadata
88 We can get bibliographic metadata from a pmid. Here we get the MEDLINE text. The website wraps the data in <pre></pre> tags.
91 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
92 (defun pubmed-get-medline (pmid)
93 "Get MEDLINE text for PMID as a string."
95 (url-retrieve-synchronously
96 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=medline&format=text" pmid))
97 (goto-char (point-min))
98 (let ((p1 (search-forward "<pre>"))
99 (p2 (search-forward "</pre>")))
100 (buffer-substring (+ 1 p1) (- p2 6)))))
106 Here is sample output:
107 #+BEGIN_SRC emacs-lisp :tangle no
108 (pubmed-get-medline "23162369")
117 IS - 1040-726X (Print)
118 IS - 1040-726X (Linking)
122 TI - Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
125 AB - Approaches to classroom instruction have evolved considerably over the past 50
126 years. This progress has been spurred by the development of several learning
127 principles and methods of instruction, including active learning,
128 student-centered learning, collaborative learning, experiential learning, and
129 problem-based learning. In the present paper, we suggest that these seemingly
130 different strategies share important underlying characteristics and can be viewed
131 as complimentary components of a broader approach to classroom instruction called
132 transformational teaching. Transformational teaching involves creating dynamic
133 relationships between teachers, students, and a shared body of knowledge to
134 promote student learning and personal growth. From this perspective, instructors
135 are intellectual coaches who create teams of students who collaborate with each
136 other and with their teacher to master bodies of information. Teachers assume the
137 traditional role of facilitating students' acquisition of key course concepts,
138 but do so while enhancing students' personal development and attitudes toward
139 learning. They accomplish these goals by establishing a shared vision for a
140 course, providing modeling and mastery experiences, challenging and encouraging
141 students, personalizing attention and feedback, creating experiential lessons
142 that transcend the boundaries of the classroom, and promoting ample opportunities
143 for preflection and reflection. We propose that these methods are synergistically
144 related and, when used together, maximize students' potential for intellectual
146 FAU - Slavich, George M
148 AD - Cousins Center for Psychoneuroimmunology and Department of Psychiatry and
149 Biobehavioral Sciences, University of California, Los Angeles, UCLA Medical Plaza
150 300, Room 3156, Los Angeles, CA 90095-7076, USA.
151 FAU - Zimbardo, Philip G
154 GR - R01 AG026364/AG/NIA NIH HHS/United States
155 GR - T32 MH019925/MH/NIMH NIH HHS/United States
158 TA - Educ Psychol Rev
159 JT - Educational psychology review
163 EDAT- 2012/11/20 06:00
164 MHDA- 2012/11/20 06:00
165 CRDT- 2012/11/20 06:00
166 PHST- 2012/07/24 [epublish]
167 AID - 10.1007/s10648-012-9199-6 [doi]
169 SO - Educ Psychol Rev. 2012 Dec;24(4):569-608. Epub 2012 Jul 24.
172 ** Parse the PMID MEDLINE data
173 We can parse this into a data structure
175 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
176 (defun pubmed-parse-medline (pmid)
177 "Parse the medline text for PMID and return a list of cons cells."
183 (with-temp-buffer (insert (pubmed-get-medline pmid))
184 (goto-char (point-min))
185 (while (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
186 (setq tag (match-string 1))
187 ;; point is at end of the search
189 ;; now go to next tag
190 (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
191 (setq p2 (- (match-beginning 1) 1))
192 (setq value (buffer-substring p1 p2))
193 (setq data (append data (list (cons tag value))))
194 ;; now go back to last tag to get the next one
200 : pubmed-parse-medline
202 #+BEGIN_SRC emacs-lisp :tangle no
203 (pubmed-parse-medline "23162369")
208 ** PMID to bibtex entry
209 The point of parsing the MEDLINE text is so we can make bibtex entries. We only support Journal articles for now.
211 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
212 (defun pubmed-pmid-to-bibtex (pmid)
213 "Convert a PMID to a bibtex entry."
214 (let* ((data (pubmed-parse-medline pmid))
215 (type (cdr (assoc "PT" data)))
216 (title (cdr (assoc "TI" data)))
217 (authors (mapconcat 'cdr
219 (string= (car x) "FAU"))
222 (abstract (cdr (assoc "AB" data)))
223 (volume (cdr (assoc "VI" data)))
224 (issue (cdr (assoc "IP" data)))
225 (journal (cdr (assoc "JT" data)))
226 (year (cdr (assoc "DP" data)))
227 (pages (cdr (assoc "PG" data)))
228 (aid (cdr (assoc "AID" data))))
231 ((string= type "JOURNAL ARTICLE")
233 author = {" authors "},
235 abstract = {" abstract "},
236 journal = {" journal "},
237 volume = {" volume "},
238 number = {" issue "},
239 year = {" (car (split-string year)) "},
241 doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "},
244 (message "No conversion for type: %s" type)))))
248 : pubmed-pmid-to-bibtex
250 #+BEGIN_SRC emacs-lisp :tangle no
251 (pubmed-pmid-to-bibtex "23162369")
257 author = {Slavich, George M and Zimbardo, Philip G},
258 title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
260 abstract = {Approaches to classroom instruction have evolved considerably over the past 50
261 years. This progress has been spurred by the development of several learning
262 principles and methods of instruction, including active learning,
263 student-centered learning, collaborative learning, experiential learning, and
264 problem-based learning. In the present paper, we suggest that these seemingly
265 different strategies share important underlying characteristics and can be viewed
266 as complimentary components of a broader approach to classroom instruction called
267 transformational teaching. Transformational teaching involves creating dynamic
268 relationships between teachers, students, and a shared body of knowledge to
269 promote student learning and personal growth. From this perspective, instructors
270 are intellectual coaches who create teams of students who collaborate with each
271 other and with their teacher to master bodies of information. Teachers assume the
272 traditional role of facilitating students' acquisition of key course concepts,
273 but do so while enhancing students' personal development and attitudes toward
274 learning. They accomplish these goals by establishing a shared vision for a
275 course, providing modeling and mastery experiences, challenging and encouraging
276 students, personalizing attention and feedback, creating experiential lessons
277 that transcend the boundaries of the classroom, and promoting ample opportunities
278 for preflection and reflection. We propose that these methods are synergistically
279 related and, when used together, maximize students' potential for intellectual
280 and personal growth.},
281 journal = {Educational psychology review},
286 doi = {10.1007/s10648-012-9199-6},
290 And we probably want to be able to insert a bibtex entry
292 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
293 (defun pubmed-insert-bibtex-from-pmid (pmid)
294 "Insert a bibtex entry at point derived from PMID.
295 You must clean the entry after insertion."
296 (interactive "sPMID: ")
297 (insert (pubmed-pmid-to-bibtex pmid)))
301 : pubmed-insert-bibtex-from-pmid
303 Here is an example of a cleaned entry:
304 #+BEGIN_SRC bibtex :tangle no
305 @article{slavich-2012-trans-teach,
306 author = {Slavich, George M and Zimbardo, Philip G},
307 title = {Transformational Teaching: Theoretical
308 Underpinnings, Basic Principles, and Core Methods.},
309 journal = {Educational psychology review},
314 doi = {10.1007/s10648-012-9199-6},
315 abstract = {Approaches to classroom instruction have evolved
316 considerably over the past 50 years. This progress
317 has been spurred by the development of several
318 learning principles and methods of instruction,
319 including active learning, student-centered
320 learning, collaborative learning, experiential
321 learning, and problem-based learning. In the present
322 paper, we suggest that these seemingly different
323 strategies share important underlying
324 characteristics and can be viewed as complimentary
325 components of a broader approach to classroom
326 instruction called transformational
327 teaching. Transformational teaching involves
328 creating dynamic relationships between teachers,
329 students, and a shared body of knowledge to promote
330 student learning and personal growth. From this
331 perspective, instructors are intellectual coaches
332 who create teams of students who collaborate with
333 each other and with their teacher to master bodies
334 of information. Teachers assume the traditional role
335 of facilitating students' acquisition of key course
336 concepts, but do so while enhancing students'
337 personal development and attitudes toward
338 learning. They accomplish these goals by
339 establishing a shared vision for a course, providing
340 modeling and mastery experiences, challenging and
341 encouraging students, personalizing attention and
342 feedback, creating experiential lessons that
343 transcend the boundaries of the classroom, and
344 promoting ample opportunities for preflection and
345 reflection. We propose that these methods are
346 synergistically related and, when used together,
347 maximize students' potential for intellectual and
353 We can also get xml of the MEDLINE data. The web page here also wraps the xml in a <pre> block and escapes the <> with < and >, which we have to undo. I have not used this code for anything, so I am not sure how good the xml code is.
355 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
356 (defun pubmed-get-medline-xml (pmid)
357 "Get MEDLINE xml for PMID as a string."
360 (url-retrieve-synchronously
361 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
362 (goto-char (point-min))
363 (while (search-forward "<" nil t)
365 (goto-char (point-min))
366 (while (search-forward ">" nil t)
368 (goto-char (point-min))
370 (let ((p1 (search-forward "<pre>"))
371 (p2 (search-forward "</pre>")))
372 (buffer-substring (+ 1 p1) (- p2 6)))))
376 : pubmed-get-medline-xml
378 #+BEGIN_SRC emacs-lisp :tangle no
379 (pubmed-get-medline-xml "23162369")
385 <MedlineCitation Status="Publisher" Owner="NLM">
386 <PMID Version="1">23162369</PMID>
392 <Article PubModel="Print-Electronic">
394 <ISSN IssnType="Print">1040-726X</ISSN>
395 <JournalIssue CitedMedium="Print">
403 <Title>Educational psychology review</Title>
404 <ISOAbbreviation>Educ Psychol Rev</ISOAbbreviation>
406 <ArticleTitle>Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.</ArticleTitle>
408 <MedlinePgn>569-608</MedlinePgn>
411 <AbstractText>Approaches to classroom instruction have evolved considerably over the past 50 years. This progress has been spurred by the development of several learning principles and methods of instruction, including active learning, student-centered learning, collaborative learning, experiential learning, and problem-based learning. In the present paper, we suggest that these seemingly different strategies share important underlying characteristics and can be viewed as complimentary components of a broader approach to classroom instruction called transformational teaching. Transformational teaching involves creating dynamic relationships between teachers, students, and a shared body of knowledge to promote student learning and personal growth. From this perspective, instructors are intellectual coaches who create teams of students who collaborate with each other and with their teacher to master bodies of information. Teachers assume the traditional role of facilitating students' acquisition of key course concepts, but do so while enhancing students' personal development and attitudes toward learning. They accomplish these goals by establishing a shared vision for a course, providing modeling and mastery experiences, challenging and encouraging students, personalizing attention and feedback, creating experiential lessons that transcend the boundaries of the classroom, and promoting ample opportunities for preflection and reflection. We propose that these methods are synergistically related and, when used together, maximize students' potential for intellectual and personal growth.</AbstractText>
415 <LastName>Slavich</LastName>
416 <ForeName>George M</ForeName>
417 <Initials>GM</Initials>
419 <Affiliation>Cousins Center for Psychoneuroimmunology and Department of Psychiatry and Biobehavioral Sciences, University of California, Los Angeles, UCLA Medical Plaza 300, Room 3156, Los Angeles, CA 90095-7076, USA.</Affiliation>
423 <LastName>Zimbardo</LastName>
424 <ForeName>Philip G</ForeName>
425 <Initials>PG</Initials>
428 <Language>ENG</Language>
431 <GrantID>R01 AG026364</GrantID>
432 <Acronym>AG</Acronym>
433 <Agency>NIA NIH HHS</Agency>
434 <Country>United States</Country>
437 <GrantID>T32 MH019925</GrantID>
438 <Acronym>MH</Acronym>
439 <Agency>NIMH NIH HHS</Agency>
440 <Country>United States</Country>
443 <PublicationTypeList>
444 <PublicationType UI="">JOURNAL ARTICLE</PublicationType>
445 </PublicationTypeList>
446 <ArticleDate DateType="Electronic">
453 <MedlineTA>Educ Psychol Rev</MedlineTA>
454 <NlmUniqueID>9885342</NlmUniqueID>
455 <ISSNLinking>1040-726X</ISSNLinking>
456 </MedlineJournalInfo>
460 <PubMedPubDate PubStatus="epublish">
465 <PubMedPubDate PubStatus="entrez">
472 <PubMedPubDate PubStatus="pubmed">
479 <PubMedPubDate PubStatus="medline">
487 <PublicationStatus>ppublish</PublicationStatus>
489 <ArticleId IdType="doi">10.1007/s10648-012-9199-6</ArticleId>
490 <ArticleId IdType="pubmed">23162369</ArticleId>
491 <ArticleId IdType="pmc">PMC3498956</ArticleId>
492 <ArticleId IdType="mid">NIHMS395714</ArticleId>
500 * Pubmed Central (PMC) link
501 A PMCID starts with PMC and is followed by numbers. The PMCID is a unique reference number or identifier that is assigned to every article that is accepted into PMC. The PMCID is also used by recipients of NIH funding to demonstrate compliance with the NIH Public Access policy. The PMCID can be found in both PMC and PubMed.
503 Here we define a new link. Clicking on it simply opens a webpage to the article.
505 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
509 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string)))
511 (lambda (keyword desc format)
514 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/%s\">pmcid:%s</a>" keyword keyword))
516 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/%s}" keyword)))))
520 The NIHMSID is a preliminary article identifier that applies only to manuscripts deposited through the NIHMS system. The NIHMSID is only valid for compliance reporting for 90 days after the publication date of an article. Once the Web version of the NIHMS submission is approved for inclusion in PMC and the corresponding citation is in PubMed, the article will also be assigned a PMCID.
522 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
526 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string)))
528 (lambda (keyword desc format)
531 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s\">nihmsid:%s</a>" keyword keyword))
533 ;; write out the latex command
534 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
541 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
546 This code will tangle the elisp code out to pubmed.el and load it.
548 [[elisp:(org-babel-load-file "pubmed.org")]]