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.
23 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
24 ;;; pubmed.el --- Links and functions to interact with pubmed databases.
26 ;; Copyright(C) 2015 John Kitchin
28 ;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
29 ;; This file is not currently part of GNU Emacs.
31 ;; This program is free software; you can redistribute it and/or
32 ;; modify it under the terms of the GNU General Public License as
33 ;; published by the Free Software Foundation; either version 2, or (at
34 ;; your option) any later version.
36 ;; This program is distributed in the hope that it will be useful, but
37 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
38 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 ;; General Public License for more details.
41 ;; You should have received a copy of the GNU General Public License
42 ;; along with this program ; see the file COPYING. If not, write to
43 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
44 ;; Boston, MA 02111-1307, USA.
48 ;; Lisp code to interact with pubmed databases, links to pubmed
49 ;; identifiers. See pubmed.org.
52 * PMID (from PubMed) link and functions
53 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.
56 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
60 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pubmed/%s" link-string)))
62 (lambda (keyword desc format)
65 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s\">pmid:%s</a>" keyword keyword)); no output for html
67 ;; write out the latex command
68 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
73 ** Get MEDLINE metadata
74 We can get bibliographic metadata from a pmid. Here we get the MEDLINE text. The website wraps the data in <pre></pre> tags.
77 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
78 (defun pubmed-get-medline (pmid)
79 "Get MEDLINE text for PMID as a string."
81 (url-retrieve-synchronously
82 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=medline&format=text" pmid))
83 (goto-char (point-min))
84 (let ((p1 (search-forward "<pre>"))
85 (p2 (search-forward "</pre>")))
86 (buffer-substring (+ 1 p1) (- p2 6)))))
92 Here is sample output:
93 #+BEGIN_SRC emacs-lisp
94 (pubmed-get-medline "23162369")
103 IS - 1040-726X (Print)
104 IS - 1040-726X (Linking)
108 TI - Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
111 AB - Approaches to classroom instruction have evolved considerably over the past 50
112 years. This progress has been spurred by the development of several learning
113 principles and methods of instruction, including active learning,
114 student-centered learning, collaborative learning, experiential learning, and
115 problem-based learning. In the present paper, we suggest that these seemingly
116 different strategies share important underlying characteristics and can be viewed
117 as complimentary components of a broader approach to classroom instruction called
118 transformational teaching. Transformational teaching involves creating dynamic
119 relationships between teachers, students, and a shared body of knowledge to
120 promote student learning and personal growth. From this perspective, instructors
121 are intellectual coaches who create teams of students who collaborate with each
122 other and with their teacher to master bodies of information. Teachers assume the
123 traditional role of facilitating students' acquisition of key course concepts,
124 but do so while enhancing students' personal development and attitudes toward
125 learning. They accomplish these goals by establishing a shared vision for a
126 course, providing modeling and mastery experiences, challenging and encouraging
127 students, personalizing attention and feedback, creating experiential lessons
128 that transcend the boundaries of the classroom, and promoting ample opportunities
129 for preflection and reflection. We propose that these methods are synergistically
130 related and, when used together, maximize students' potential for intellectual
132 FAU - Slavich, George M
134 AD - Cousins Center for Psychoneuroimmunology and Department of Psychiatry and
135 Biobehavioral Sciences, University of California, Los Angeles, UCLA Medical Plaza
136 300, Room 3156, Los Angeles, CA 90095-7076, USA.
137 FAU - Zimbardo, Philip G
140 GR - R01 AG026364/AG/NIA NIH HHS/United States
141 GR - T32 MH019925/MH/NIMH NIH HHS/United States
144 TA - Educ Psychol Rev
145 JT - Educational psychology review
149 EDAT- 2012/11/20 06:00
150 MHDA- 2012/11/20 06:00
151 CRDT- 2012/11/20 06:00
152 PHST- 2012/07/24 [epublish]
153 AID - 10.1007/s10648-012-9199-6 [doi]
155 SO - Educ Psychol Rev. 2012 Dec;24(4):569-608. Epub 2012 Jul 24.
158 ** Parse the PMID MEDLINE data
159 We can parse this into a data structure
161 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
162 (defun pubmed-parse-medline (pmid)
163 "Parse the medline text for PMID and return a list of cons cells."
169 (with-temp-buffer (insert (pubmed-get-medline pmid))
170 (goto-char (point-min))
171 (while (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
172 (setq tag (match-string 1))
173 ;; point is at end of the search
175 ;; now go to next tag
176 (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
177 (setq p2 (- (match-beginning 1) 1))
178 (setq value (buffer-substring p1 p2))
179 (setq data (append data (list (cons tag value))))
180 ;; now go back to last tag to get the next one
186 : pubmed-parse-medline
188 #+BEGIN_SRC emacs-lisp :results code
189 (pubmed-parse-medline "23162369")
193 #+BEGIN_SRC emacs-lisp
194 (("PMID" . "23162369")
196 ("STAT" . "Publisher")
198 ("IS" . "1040-726X (Print)")
199 ("IS" . "1040-726X (Linking)")
203 ("TI" . "Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core \n Methods.")
205 ("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.")
206 ("FAU" . "Slavich, George M")
207 ("AU" . "Slavich GM")
208 ("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.")
209 ("FAU" . "Zimbardo, Philip G")
210 ("AU" . "Zimbardo PG")
212 ("GR" . "R01 AG026364/AG/NIA NIH HHS/United States")
213 ("GR" . "T32 MH019925/MH/NIMH NIH HHS/United States")
214 ("PT" . "JOURNAL ARTICLE")
216 ("TA" . "Educ Psychol Rev")
217 ("JT" . "Educational psychology review")
219 ("PMC" . "PMC3498956")
220 ("MID" . "NIHMS395714")
221 ("EDAT" . "2012/11/20 06:00")
222 ("MHDA" . "2012/11/20 06:00")
223 ("CRDT" . "2012/11/20 06:00")
224 ("PHST" . "2012/07/24 [epublish]")
225 ("AID" . "10.1007/s10648-012-9199-6 [doi]")
230 ** PMID to bibtex entry
231 The point of parsing the MEDLINE text is so we can make bibtex entries. We only support Journal articles for now.
233 #+BEGIN_SRC emacs-lisp
234 (defun pubmed-pmid-to-bibtex (pmid)
235 "Convert a PMID to a bibtex entry."
236 (let* ((data (pubmed-parse-medline pmid))
237 (type (cdr (assoc "PT" data)))
238 (title (cdr (assoc "TI" data)))
239 (authors (mapconcat 'cdr
241 (string= (car x) "FAU"))
244 (abstract (cdr (assoc "AB" data)))
245 (volume (cdr (assoc "VI" data)))
246 (issue (cdr (assoc "IP" data)))
247 (journal (cdr (assoc "JT" data)))
248 (year (cdr (assoc "DP" data)))
249 (pages (cdr (assoc "PG" data)))
250 (aid (cdr (assoc "AID" data))))
253 ((string= type "JOURNAL ARTICLE")
255 author = {" authors "},
257 abstract = {" abstract "},
258 journal = {" journal "},
259 volume = {" volume "},
260 number = {" issue "},
261 year = {" (car (split-string year)) "},
263 doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "},
266 (message "No conversion for type: %s" type)))))
270 : pubmed-pmid-to-bibtex
272 #+BEGIN_SRC emacs-lisp :tangle no
273 (pubmed-pmid-to-bibtex "23162369")
279 author = {Slavich, George M and Zimbardo, Philip G},
280 title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
282 abstract = {Approaches to classroom instruction have evolved considerably over the past 50
283 years. This progress has been spurred by the development of several learning
284 principles and methods of instruction, including active learning,
285 student-centered learning, collaborative learning, experiential learning, and
286 problem-based learning. In the present paper, we suggest that these seemingly
287 different strategies share important underlying characteristics and can be viewed
288 as complimentary components of a broader approach to classroom instruction called
289 transformational teaching. Transformational teaching involves creating dynamic
290 relationships between teachers, students, and a shared body of knowledge to
291 promote student learning and personal growth. From this perspective, instructors
292 are intellectual coaches who create teams of students who collaborate with each
293 other and with their teacher to master bodies of information. Teachers assume the
294 traditional role of facilitating students' acquisition of key course concepts,
295 but do so while enhancing students' personal development and attitudes toward
296 learning. They accomplish these goals by establishing a shared vision for a
297 course, providing modeling and mastery experiences, challenging and encouraging
298 students, personalizing attention and feedback, creating experiential lessons
299 that transcend the boundaries of the classroom, and promoting ample opportunities
300 for preflection and reflection. We propose that these methods are synergistically
301 related and, when used together, maximize students' potential for intellectual
302 and personal growth.},
303 journal = {Educational psychology review},
308 doi = {10.1007/s10648-012-9199-6},
312 And we probably want to be able to insert a bibtex entry
314 #+BEGIN_SRC emacs-lisp
315 (defun pubmed-insert-bibtex-from-pmid (pmid)
316 "Insert a bibtex entry at point derived from PMID.
317 You must clean the entry after insertion."
318 (interactive "sPMID: ")
319 (insert (pubmed-pmid-to-bibtex pmid)))
323 : pubmed-insert-bibtex-from-pmid
325 Here is an example of a cleaned entry:
326 #+BEGIN_SRC bibtex :tangle no
327 @article{slavich-2012-trans-teach,
328 author = {Slavich, George M and Zimbardo, Philip G},
329 title = {Transformational Teaching: Theoretical
330 Underpinnings, Basic Principles, and Core Methods.},
331 journal = {Educational psychology review},
336 doi = {10.1007/s10648-012-9199-6},
337 abstract = {Approaches to classroom instruction have evolved
338 considerably over the past 50 years. This progress
339 has been spurred by the development of several
340 learning principles and methods of instruction,
341 including active learning, student-centered
342 learning, collaborative learning, experiential
343 learning, and problem-based learning. In the present
344 paper, we suggest that these seemingly different
345 strategies share important underlying
346 characteristics and can be viewed as complimentary
347 components of a broader approach to classroom
348 instruction called transformational
349 teaching. Transformational teaching involves
350 creating dynamic relationships between teachers,
351 students, and a shared body of knowledge to promote
352 student learning and personal growth. From this
353 perspective, instructors are intellectual coaches
354 who create teams of students who collaborate with
355 each other and with their teacher to master bodies
356 of information. Teachers assume the traditional role
357 of facilitating students' acquisition of key course
358 concepts, but do so while enhancing students'
359 personal development and attitudes toward
360 learning. They accomplish these goals by
361 establishing a shared vision for a course, providing
362 modeling and mastery experiences, challenging and
363 encouraging students, personalizing attention and
364 feedback, creating experiential lessons that
365 transcend the boundaries of the classroom, and
366 promoting ample opportunities for preflection and
367 reflection. We propose that these methods are
368 synergistically related and, when used together,
369 maximize students' potential for intellectual and
375 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.
377 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
378 (defun pubmed-get-medline-xml (pmid)
379 "Get MEDLINE xml for PMID as a string."
382 (url-retrieve-synchronously
383 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
384 (goto-char (point-min))
385 (while (search-forward "<" nil t)
387 (goto-char (point-min))
388 (while (search-forward ">" nil t)
390 (goto-char (point-min))
392 (let ((p1 (search-forward "<pre>"))
393 (p2 (search-forward "</pre>")))
394 (buffer-substring (+ 1 p1) (- p2 6)))))
398 : pubmed-get-medline-xml
400 #+BEGIN_SRC emacs-lisp :tangle no
401 (pubmed-get-medline-xml "23162369")
407 <MedlineCitation Status="Publisher" Owner="NLM">
408 <PMID Version="1">23162369</PMID>
414 <Article PubModel="Print-Electronic">
416 <ISSN IssnType="Print">1040-726X</ISSN>
417 <JournalIssue CitedMedium="Print">
425 <Title>Educational psychology review</Title>
426 <ISOAbbreviation>Educ Psychol Rev</ISOAbbreviation>
428 <ArticleTitle>Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.</ArticleTitle>
430 <MedlinePgn>569-608</MedlinePgn>
433 <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>
437 <LastName>Slavich</LastName>
438 <ForeName>George M</ForeName>
439 <Initials>GM</Initials>
441 <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>
445 <LastName>Zimbardo</LastName>
446 <ForeName>Philip G</ForeName>
447 <Initials>PG</Initials>
450 <Language>ENG</Language>
453 <GrantID>R01 AG026364</GrantID>
454 <Acronym>AG</Acronym>
455 <Agency>NIA NIH HHS</Agency>
456 <Country>United States</Country>
459 <GrantID>T32 MH019925</GrantID>
460 <Acronym>MH</Acronym>
461 <Agency>NIMH NIH HHS</Agency>
462 <Country>United States</Country>
465 <PublicationTypeList>
466 <PublicationType UI="">JOURNAL ARTICLE</PublicationType>
467 </PublicationTypeList>
468 <ArticleDate DateType="Electronic">
475 <MedlineTA>Educ Psychol Rev</MedlineTA>
476 <NlmUniqueID>9885342</NlmUniqueID>
477 <ISSNLinking>1040-726X</ISSNLinking>
478 </MedlineJournalInfo>
482 <PubMedPubDate PubStatus="epublish">
487 <PubMedPubDate PubStatus="entrez">
494 <PubMedPubDate PubStatus="pubmed">
501 <PubMedPubDate PubStatus="medline">
509 <PublicationStatus>ppublish</PublicationStatus>
511 <ArticleId IdType="doi">10.1007/s10648-012-9199-6</ArticleId>
512 <ArticleId IdType="pubmed">23162369</ArticleId>
513 <ArticleId IdType="pmc">PMC3498956</ArticleId>
514 <ArticleId IdType="mid">NIHMS395714</ArticleId>
522 * Pubmed Central (PMC) link
523 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.
525 Here we define a new link. Clicking on it simply opens a webpage to the article.
527 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
531 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string)))
533 (lambda (keyword desc format)
536 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/%s\">pmcid:%s</a>" keyword keyword))
538 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/%s}" keyword)))))
542 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.
544 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
548 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string)))
550 (lambda (keyword desc format)
553 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s\">nihmsid:%s</a>" keyword keyword))
555 ;; write out the latex command
556 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
563 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
568 This code will tangle the elisp code out to pubmed.el and load it.
570 [[elisp:(org-babel-load-file "pubmed.org")]]