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.
22 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
23 ;;; pubmed.el --- Links and functions to interact with pubmed databases.
25 ;; Copyright(C) 2015 John Kitchin
27 ;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
28 ;; This file is not currently part of GNU Emacs.
30 ;; This program is free software; you can redistribute it and/or
31 ;; modify it under the terms of the GNU General Public License as
32 ;; published by the Free Software Foundation; either version 2, or (at
33 ;; your option) any later version.
35 ;; This program is distributed in the hope that it will be useful, but
36 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
37 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38 ;; General Public License for more details.
40 ;; You should have received a copy of the GNU General Public License
41 ;; along with this program ; see the file COPYING. If not, write to
42 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
43 ;; Boston, MA 02111-1307, USA.
47 ;; Lisp code to setup bibliography cite, ref and label org-mode links.
48 ;; also sets up reftex for org-mode. The links are clickable and do
49 ;; things that are useful. You should really read org-ref.org for details.
51 ;; Package-Requires: ((dash))
54 * PMID (from PubMed) link and functions
55 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.
58 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
62 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pubmed/%s" link-string)))
64 (lambda (keyword desc format)
66 ((eq format 'html) (format "")); no output for html
68 ;; write out the latex command
69 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
72 ** Get MEDLINE metadata
73 We can get bibliographic metadata from a pmid. Here we get the MEDLINE text. The website wraps the data in <pre></pre> tags.
76 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
77 (defun pubmed-get-medline (pmid)
78 "Get MEDLINE text for PMID as a string."
80 (url-retrieve-synchronously
81 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=medline&format=text" pmid))
82 (goto-char (point-min))
83 (let ((p1 (search-forward "<pre>"))
84 (p2 (search-forward "</pre>")))
85 (buffer-substring (+ 1 p1) (- p2 6)))))
91 Here is sample output:
92 #+BEGIN_SRC emacs-lisp
93 (pubmed-get-medline "23162369")
102 IS - 1040-726X (Print)
103 IS - 1040-726X (Linking)
107 TI - Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
110 AB - Approaches to classroom instruction have evolved considerably over the past 50
111 years. This progress has been spurred by the development of several learning
112 principles and methods of instruction, including active learning,
113 student-centered learning, collaborative learning, experiential learning, and
114 problem-based learning. In the present paper, we suggest that these seemingly
115 different strategies share important underlying characteristics and can be viewed
116 as complimentary components of a broader approach to classroom instruction called
117 transformational teaching. Transformational teaching involves creating dynamic
118 relationships between teachers, students, and a shared body of knowledge to
119 promote student learning and personal growth. From this perspective, instructors
120 are intellectual coaches who create teams of students who collaborate with each
121 other and with their teacher to master bodies of information. Teachers assume the
122 traditional role of facilitating students' acquisition of key course concepts,
123 but do so while enhancing students' personal development and attitudes toward
124 learning. They accomplish these goals by establishing a shared vision for a
125 course, providing modeling and mastery experiences, challenging and encouraging
126 students, personalizing attention and feedback, creating experiential lessons
127 that transcend the boundaries of the classroom, and promoting ample opportunities
128 for preflection and reflection. We propose that these methods are synergistically
129 related and, when used together, maximize students' potential for intellectual
131 FAU - Slavich, George M
133 AD - Cousins Center for Psychoneuroimmunology and Department of Psychiatry and
134 Biobehavioral Sciences, University of California, Los Angeles, UCLA Medical Plaza
135 300, Room 3156, Los Angeles, CA 90095-7076, USA.
136 FAU - Zimbardo, Philip G
139 GR - R01 AG026364/AG/NIA NIH HHS/United States
140 GR - T32 MH019925/MH/NIMH NIH HHS/United States
143 TA - Educ Psychol Rev
144 JT - Educational psychology review
148 EDAT- 2012/11/20 06:00
149 MHDA- 2012/11/20 06:00
150 CRDT- 2012/11/20 06:00
151 PHST- 2012/07/24 [epublish]
152 AID - 10.1007/s10648-012-9199-6 [doi]
154 SO - Educ Psychol Rev. 2012 Dec;24(4):569-608. Epub 2012 Jul 24.
157 ** Parse the PMID MEDLINE data
158 We can parse this into a data structure
160 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
161 (defun pubmed-parse-medline (pmid)
162 "Parse the medline text for PMID and return a list of cons cells."
168 (with-temp-buffer (insert (pubmed-get-medline pmid))
169 (goto-char (point-min))
170 (while (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
171 (setq tag (match-string 1))
172 ;; point is at end of the search
174 ;; now go to next tag
175 (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
176 (setq p2 (- (match-beginning 1) 1))
177 (setq value (buffer-substring p1 p2))
178 (setq data (append data (list (cons tag value))))
179 ;; now go back to last tag to get the next one
185 : pubmed-parse-medline
187 #+BEGIN_SRC emacs-lisp :results code
188 (pubmed-parse-medline "23162369")
192 #+BEGIN_SRC emacs-lisp
193 (("PMID" . "23162369")
195 ("STAT" . "Publisher")
197 ("IS" . "1040-726X (Print)")
198 ("IS" . "1040-726X (Linking)")
202 ("TI" . "Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core \n Methods.")
204 ("AB" . "Approaches to classroom instruction have evolved considerably over the past 50\n years. This progress has been spurred by the development of several learning\n principles and methods of instruction, including active learning,\n student-centered learning, collaborative learning, experiential learning, and\n problem-based learning. In the present paper, we suggest that these seemingly\n different strategies share important underlying characteristics and can be viewed\n as complimentary components of a broader approach to classroom instruction called\n transformational teaching. Transformational teaching involves creating dynamic\n relationships between teachers, students, and a shared body of knowledge to\n promote student learning and personal growth. From this perspective, instructors \n are intellectual coaches who create teams of students who collaborate with each\n other and with their teacher to master bodies of information. Teachers assume the\n traditional role of facilitating students' acquisition of key course concepts,\n but do so while enhancing students' personal development and attitudes toward\n learning. They accomplish these goals by establishing a shared vision for a\n course, providing modeling and mastery experiences, challenging and encouraging\n students, personalizing attention and feedback, creating experiential lessons\n that transcend the boundaries of the classroom, and promoting ample opportunities\n for preflection and reflection. We propose that these methods are synergistically\n related and, when used together, maximize students' potential for intellectual\n and personal growth.")
205 ("FAU" . "Slavich, George M")
206 ("AU" . "Slavich GM")
207 ("AD" . "Cousins Center for Psychoneuroimmunology and Department of Psychiatry and\n Biobehavioral Sciences, University of California, Los Angeles, UCLA Medical Plaza\n 300, Room 3156, Los Angeles, CA 90095-7076, USA.")
208 ("FAU" . "Zimbardo, Philip G")
209 ("AU" . "Zimbardo PG")
211 ("GR" . "R01 AG026364/AG/NIA NIH HHS/United States")
212 ("GR" . "T32 MH019925/MH/NIMH NIH HHS/United States")
213 ("PT" . "JOURNAL ARTICLE")
215 ("TA" . "Educ Psychol Rev")
216 ("JT" . "Educational psychology review")
218 ("PMC" . "PMC3498956")
219 ("MID" . "NIHMS395714")
220 ("EDAT" . "2012/11/20 06:00")
221 ("MHDA" . "2012/11/20 06:00")
222 ("CRDT" . "2012/11/20 06:00")
223 ("PHST" . "2012/07/24 [epublish]")
224 ("AID" . "10.1007/s10648-012-9199-6 [doi]")
229 ** PMID to bibtex entry
230 The point of parsing the MEDLINE text is so we can make bibtex entries. We only support Journal articles for now.
233 1. The year is not quite right, it has the month in it.
234 2. I do not use all the fields.
236 #+BEGIN_SRC emacs-lisp
237 (defun pubmed-pmid-to-bibtex (pmid)
238 "Convert a PMID to a bibtex entry."
239 (let* ((data (org-ref-parse-medline pmid))
240 (type (cdr (assoc "PT" data)))
241 (title (cdr (assoc "TI" data)))
242 (authors (mapconcat 'cdr
244 (string= (car x) "FAU"))
247 (abstract (cdr (assoc "AB" data)))
248 (volume (cdr (assoc "VI" data)))
249 (issue (cdr (assoc "IP" data)))
250 (journal (cdr (assoc "JT" data)))
251 (year (cdr (assoc "DP" data)))
252 (pages (cdr (assoc "PG" data)))
253 (aid (cdr (assoc "AID" data))))
256 ((string= type "JOURNAL ARTICLE")
258 author = {" authors "},
260 abstract = {" abstract "},
261 journal = {" journal "},
262 volume = {" volume "},
263 number = {" issue "},
264 year = {" (car (split-string year)) "},
266 doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "},
269 (message "No conversion for type: %s" type)))))
273 : pubmed-pmid-to-bibtex
275 #+BEGIN_SRC emacs-lisp :tangle no
276 (pubmed-pmid-to-bibtex "23162369")
282 author = {Slavich, George M and Zimbardo, Philip G},
283 title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
285 abstract = {Approaches to classroom instruction have evolved considerably over the past 50
286 years. This progress has been spurred by the development of several learning
287 principles and methods of instruction, including active learning,
288 student-centered learning, collaborative learning, experiential learning, and
289 problem-based learning. In the present paper, we suggest that these seemingly
290 different strategies share important underlying characteristics and can be viewed
291 as complimentary components of a broader approach to classroom instruction called
292 transformational teaching. Transformational teaching involves creating dynamic
293 relationships between teachers, students, and a shared body of knowledge to
294 promote student learning and personal growth. From this perspective, instructors
295 are intellectual coaches who create teams of students who collaborate with each
296 other and with their teacher to master bodies of information. Teachers assume the
297 traditional role of facilitating students' acquisition of key course concepts,
298 but do so while enhancing students' personal development and attitudes toward
299 learning. They accomplish these goals by establishing a shared vision for a
300 course, providing modeling and mastery experiences, challenging and encouraging
301 students, personalizing attention and feedback, creating experiential lessons
302 that transcend the boundaries of the classroom, and promoting ample opportunities
303 for preflection and reflection. We propose that these methods are synergistically
304 related and, when used together, maximize students' potential for intellectual
305 and personal growth.},
306 journal = {Educational psychology review},
311 doi = {10.1007/s10648-012-9199-6},
315 And we probably want to be able to insert a bibtex entry
317 #+BEGIN_SRC emacs-lisp
318 (defun pubmed-insert-bibtex-from-pmid (pmid)
319 "Insert a bibtex entry at point derived from PMID.
320 You must clean the entry after insertion."
321 (interactive "sPMID: ")
322 (insert (pubmed-pmid-to-bibtex pmid)))
326 : pubmed-insert-bibtex-from-pmid
328 Here is an example of a cleaned entry:
329 #+BEGIN_SRC bibtex :tangle no
330 @article{slavich-2012-trans-teach,
331 author = {Slavich, George M and Zimbardo, Philip G},
332 title = {Transformational Teaching: Theoretical
333 Underpinnings, Basic Principles, and Core Methods.},
334 journal = {Educational psychology review},
339 doi = {10.1007/s10648-012-9199-6},
340 abstract = {Approaches to classroom instruction have evolved
341 considerably over the past 50 years. This progress
342 has been spurred by the development of several
343 learning principles and methods of instruction,
344 including active learning, student-centered
345 learning, collaborative learning, experiential
346 learning, and problem-based learning. In the present
347 paper, we suggest that these seemingly different
348 strategies share important underlying
349 characteristics and can be viewed as complimentary
350 components of a broader approach to classroom
351 instruction called transformational
352 teaching. Transformational teaching involves
353 creating dynamic relationships between teachers,
354 students, and a shared body of knowledge to promote
355 student learning and personal growth. From this
356 perspective, instructors are intellectual coaches
357 who create teams of students who collaborate with
358 each other and with their teacher to master bodies
359 of information. Teachers assume the traditional role
360 of facilitating students' acquisition of key course
361 concepts, but do so while enhancing students'
362 personal development and attitudes toward
363 learning. They accomplish these goals by
364 establishing a shared vision for a course, providing
365 modeling and mastery experiences, challenging and
366 encouraging students, personalizing attention and
367 feedback, creating experiential lessons that
368 transcend the boundaries of the classroom, and
369 promoting ample opportunities for preflection and
370 reflection. We propose that these methods are
371 synergistically related and, when used together,
372 maximize students' potential for intellectual and
378 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.
380 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
381 (defun pubmed-get-medline-xml (pmid)
382 "Get MEDLINE xml for PMID as a string."
385 (url-retrieve-synchronously
386 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
387 (goto-char (point-min))
388 (while (search-forward "<" nil t)
390 (goto-char (point-min))
391 (while (search-forward ">" nil t)
393 (goto-char (point-min))
395 (let ((p1 (search-forward "<pre>"))
396 (p2 (search-forward "</pre>")))
397 (buffer-substring (+ 1 p1) (- p2 6)))))
401 : pubmed-get-medline-xml
403 #+BEGIN_SRC emacs-lisp :tangle no
404 (pubmed-get-medline-xml "23162369")
410 <MedlineCitation Status="Publisher" Owner="NLM">
411 <PMID Version="1">23162369</PMID>
417 <Article PubModel="Print-Electronic">
419 <ISSN IssnType="Print">1040-726X</ISSN>
420 <JournalIssue CitedMedium="Print">
428 <Title>Educational psychology review</Title>
429 <ISOAbbreviation>Educ Psychol Rev</ISOAbbreviation>
431 <ArticleTitle>Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.</ArticleTitle>
433 <MedlinePgn>569-608</MedlinePgn>
436 <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>
440 <LastName>Slavich</LastName>
441 <ForeName>George M</ForeName>
442 <Initials>GM</Initials>
444 <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>
448 <LastName>Zimbardo</LastName>
449 <ForeName>Philip G</ForeName>
450 <Initials>PG</Initials>
453 <Language>ENG</Language>
456 <GrantID>R01 AG026364</GrantID>
457 <Acronym>AG</Acronym>
458 <Agency>NIA NIH HHS</Agency>
459 <Country>United States</Country>
462 <GrantID>T32 MH019925</GrantID>
463 <Acronym>MH</Acronym>
464 <Agency>NIMH NIH HHS</Agency>
465 <Country>United States</Country>
468 <PublicationTypeList>
469 <PublicationType UI="">JOURNAL ARTICLE</PublicationType>
470 </PublicationTypeList>
471 <ArticleDate DateType="Electronic">
478 <MedlineTA>Educ Psychol Rev</MedlineTA>
479 <NlmUniqueID>9885342</NlmUniqueID>
480 <ISSNLinking>1040-726X</ISSNLinking>
481 </MedlineJournalInfo>
485 <PubMedPubDate PubStatus="epublish">
490 <PubMedPubDate PubStatus="entrez">
497 <PubMedPubDate PubStatus="pubmed">
504 <PubMedPubDate PubStatus="medline">
512 <PublicationStatus>ppublish</PublicationStatus>
514 <ArticleId IdType="doi">10.1007/s10648-012-9199-6</ArticleId>
515 <ArticleId IdType="pubmed">23162369</ArticleId>
516 <ArticleId IdType="pmc">PMC3498956</ArticleId>
517 <ArticleId IdType="mid">NIHMS395714</ArticleId>
525 * Pubmed Central (PMC) link
526 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.
528 Here we define a new link. Clicking on it simply opens a webpage to the article.
530 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
534 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string)))
536 (lambda (keyword desc format)
539 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/%s\">" keyword))
541 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/%s}" keyword)))))
546 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.
548 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
552 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string)))
554 (lambda (keyword desc format)
556 ((eq format 'html) (format "")); no output for html
558 ;; write out the latex command
559 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s}" keyword)))))
563 | lambda | (link-string) | (browse-url (format http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s link-string)) |
564 | lambda | (keyword desc format) | (cond ((eq format (quote html)) (format )) ((eq format (quote latex)) (format \url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s} keyword))) |
569 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
575 This code will tangle the elisp code out to pubmed.el and load it.
577 [[elisp:(org-babel-load-file "pubmed.org")]]