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.
51 ;; This library provides links that go to pubmed resources, e.g.
57 ;; and nihmsid:NIHMS395714
59 ;; See http://www.ncbi.nlm.nih.gov/pmc/about/public-access-info/#p3 for details of these identifiers.
61 ;; For PMID there is one interactive function that inserts a bibtex
62 ;; entry: `pubmed-insert-bibtex-from-pmid`.
65 * PMID (from PubMed) link and functions
66 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.
69 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
73 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pubmed/%s" link-string)))
75 (lambda (keyword desc format)
78 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s\">pmid:%s</a>" keyword keyword)); no output for html
80 ;; write out the latex command
81 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
86 ** Get MEDLINE metadata
87 We can get bibliographic metadata from a pmid. Here we get the MEDLINE text. The website wraps the data in <pre></pre> tags.
90 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
91 (defun pubmed-get-medline (pmid)
92 "Get MEDLINE text for PMID as a string."
94 (url-retrieve-synchronously
95 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=medline&format=text" pmid))
96 (goto-char (point-min))
97 (let ((p1 (search-forward "<pre>"))
98 (p2 (search-forward "</pre>")))
99 (buffer-substring (+ 1 p1) (- p2 6)))))
105 Here is sample output:
106 #+BEGIN_SRC emacs-lisp
107 (pubmed-get-medline "23162369")
116 IS - 1040-726X (Print)
117 IS - 1040-726X (Linking)
121 TI - Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
124 AB - Approaches to classroom instruction have evolved considerably over the past 50
125 years. This progress has been spurred by the development of several learning
126 principles and methods of instruction, including active learning,
127 student-centered learning, collaborative learning, experiential learning, and
128 problem-based learning. In the present paper, we suggest that these seemingly
129 different strategies share important underlying characteristics and can be viewed
130 as complimentary components of a broader approach to classroom instruction called
131 transformational teaching. Transformational teaching involves creating dynamic
132 relationships between teachers, students, and a shared body of knowledge to
133 promote student learning and personal growth. From this perspective, instructors
134 are intellectual coaches who create teams of students who collaborate with each
135 other and with their teacher to master bodies of information. Teachers assume the
136 traditional role of facilitating students' acquisition of key course concepts,
137 but do so while enhancing students' personal development and attitudes toward
138 learning. They accomplish these goals by establishing a shared vision for a
139 course, providing modeling and mastery experiences, challenging and encouraging
140 students, personalizing attention and feedback, creating experiential lessons
141 that transcend the boundaries of the classroom, and promoting ample opportunities
142 for preflection and reflection. We propose that these methods are synergistically
143 related and, when used together, maximize students' potential for intellectual
145 FAU - Slavich, George M
147 AD - Cousins Center for Psychoneuroimmunology and Department of Psychiatry and
148 Biobehavioral Sciences, University of California, Los Angeles, UCLA Medical Plaza
149 300, Room 3156, Los Angeles, CA 90095-7076, USA.
150 FAU - Zimbardo, Philip G
153 GR - R01 AG026364/AG/NIA NIH HHS/United States
154 GR - T32 MH019925/MH/NIMH NIH HHS/United States
157 TA - Educ Psychol Rev
158 JT - Educational psychology review
162 EDAT- 2012/11/20 06:00
163 MHDA- 2012/11/20 06:00
164 CRDT- 2012/11/20 06:00
165 PHST- 2012/07/24 [epublish]
166 AID - 10.1007/s10648-012-9199-6 [doi]
168 SO - Educ Psychol Rev. 2012 Dec;24(4):569-608. Epub 2012 Jul 24.
171 ** Parse the PMID MEDLINE data
172 We can parse this into a data structure
174 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
175 (defun pubmed-parse-medline (pmid)
176 "Parse the medline text for PMID and return a list of cons cells."
182 (with-temp-buffer (insert (pubmed-get-medline pmid))
183 (goto-char (point-min))
184 (while (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
185 (setq tag (match-string 1))
186 ;; point is at end of the search
188 ;; now go to next tag
189 (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
190 (setq p2 (- (match-beginning 1) 1))
191 (setq value (buffer-substring p1 p2))
192 (setq data (append data (list (cons tag value))))
193 ;; now go back to last tag to get the next one
199 : pubmed-parse-medline
201 #+BEGIN_SRC emacs-lisp :results code
202 (pubmed-parse-medline "23162369")
206 #+BEGIN_SRC emacs-lisp
207 (("PMID" . "23162369")
209 ("STAT" . "Publisher")
211 ("IS" . "1040-726X (Print)")
212 ("IS" . "1040-726X (Linking)")
216 ("TI" . "Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core \n Methods.")
218 ("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.")
219 ("FAU" . "Slavich, George M")
220 ("AU" . "Slavich GM")
221 ("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.")
222 ("FAU" . "Zimbardo, Philip G")
223 ("AU" . "Zimbardo PG")
225 ("GR" . "R01 AG026364/AG/NIA NIH HHS/United States")
226 ("GR" . "T32 MH019925/MH/NIMH NIH HHS/United States")
227 ("PT" . "JOURNAL ARTICLE")
229 ("TA" . "Educ Psychol Rev")
230 ("JT" . "Educational psychology review")
232 ("PMC" . "PMC3498956")
233 ("MID" . "NIHMS395714")
234 ("EDAT" . "2012/11/20 06:00")
235 ("MHDA" . "2012/11/20 06:00")
236 ("CRDT" . "2012/11/20 06:00")
237 ("PHST" . "2012/07/24 [epublish]")
238 ("AID" . "10.1007/s10648-012-9199-6 [doi]")
243 ** PMID to bibtex entry
244 The point of parsing the MEDLINE text is so we can make bibtex entries. We only support Journal articles for now.
246 #+BEGIN_SRC emacs-lisp
247 (defun pubmed-pmid-to-bibtex (pmid)
248 "Convert a PMID to a bibtex entry."
249 (let* ((data (pubmed-parse-medline pmid))
250 (type (cdr (assoc "PT" data)))
251 (title (cdr (assoc "TI" data)))
252 (authors (mapconcat 'cdr
254 (string= (car x) "FAU"))
257 (abstract (cdr (assoc "AB" data)))
258 (volume (cdr (assoc "VI" data)))
259 (issue (cdr (assoc "IP" data)))
260 (journal (cdr (assoc "JT" data)))
261 (year (cdr (assoc "DP" data)))
262 (pages (cdr (assoc "PG" data)))
263 (aid (cdr (assoc "AID" data))))
266 ((string= type "JOURNAL ARTICLE")
268 author = {" authors "},
270 abstract = {" abstract "},
271 journal = {" journal "},
272 volume = {" volume "},
273 number = {" issue "},
274 year = {" (car (split-string year)) "},
276 doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "},
279 (message "No conversion for type: %s" type)))))
283 : pubmed-pmid-to-bibtex
285 #+BEGIN_SRC emacs-lisp :tangle no
286 (pubmed-pmid-to-bibtex "23162369")
292 author = {Slavich, George M and Zimbardo, Philip G},
293 title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
295 abstract = {Approaches to classroom instruction have evolved considerably over the past 50
296 years. This progress has been spurred by the development of several learning
297 principles and methods of instruction, including active learning,
298 student-centered learning, collaborative learning, experiential learning, and
299 problem-based learning. In the present paper, we suggest that these seemingly
300 different strategies share important underlying characteristics and can be viewed
301 as complimentary components of a broader approach to classroom instruction called
302 transformational teaching. Transformational teaching involves creating dynamic
303 relationships between teachers, students, and a shared body of knowledge to
304 promote student learning and personal growth. From this perspective, instructors
305 are intellectual coaches who create teams of students who collaborate with each
306 other and with their teacher to master bodies of information. Teachers assume the
307 traditional role of facilitating students' acquisition of key course concepts,
308 but do so while enhancing students' personal development and attitudes toward
309 learning. They accomplish these goals by establishing a shared vision for a
310 course, providing modeling and mastery experiences, challenging and encouraging
311 students, personalizing attention and feedback, creating experiential lessons
312 that transcend the boundaries of the classroom, and promoting ample opportunities
313 for preflection and reflection. We propose that these methods are synergistically
314 related and, when used together, maximize students' potential for intellectual
315 and personal growth.},
316 journal = {Educational psychology review},
321 doi = {10.1007/s10648-012-9199-6},
325 And we probably want to be able to insert a bibtex entry
327 #+BEGIN_SRC emacs-lisp
328 (defun pubmed-insert-bibtex-from-pmid (pmid)
329 "Insert a bibtex entry at point derived from PMID.
330 You must clean the entry after insertion."
331 (interactive "sPMID: ")
332 (insert (pubmed-pmid-to-bibtex pmid)))
336 : pubmed-insert-bibtex-from-pmid
338 Here is an example of a cleaned entry:
339 #+BEGIN_SRC bibtex :tangle no
340 @article{slavich-2012-trans-teach,
341 author = {Slavich, George M and Zimbardo, Philip G},
342 title = {Transformational Teaching: Theoretical
343 Underpinnings, Basic Principles, and Core Methods.},
344 journal = {Educational psychology review},
349 doi = {10.1007/s10648-012-9199-6},
350 abstract = {Approaches to classroom instruction have evolved
351 considerably over the past 50 years. This progress
352 has been spurred by the development of several
353 learning principles and methods of instruction,
354 including active learning, student-centered
355 learning, collaborative learning, experiential
356 learning, and problem-based learning. In the present
357 paper, we suggest that these seemingly different
358 strategies share important underlying
359 characteristics and can be viewed as complimentary
360 components of a broader approach to classroom
361 instruction called transformational
362 teaching. Transformational teaching involves
363 creating dynamic relationships between teachers,
364 students, and a shared body of knowledge to promote
365 student learning and personal growth. From this
366 perspective, instructors are intellectual coaches
367 who create teams of students who collaborate with
368 each other and with their teacher to master bodies
369 of information. Teachers assume the traditional role
370 of facilitating students' acquisition of key course
371 concepts, but do so while enhancing students'
372 personal development and attitudes toward
373 learning. They accomplish these goals by
374 establishing a shared vision for a course, providing
375 modeling and mastery experiences, challenging and
376 encouraging students, personalizing attention and
377 feedback, creating experiential lessons that
378 transcend the boundaries of the classroom, and
379 promoting ample opportunities for preflection and
380 reflection. We propose that these methods are
381 synergistically related and, when used together,
382 maximize students' potential for intellectual and
388 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.
390 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
391 (defun pubmed-get-medline-xml (pmid)
392 "Get MEDLINE xml for PMID as a string."
395 (url-retrieve-synchronously
396 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
397 (goto-char (point-min))
398 (while (search-forward "<" nil t)
400 (goto-char (point-min))
401 (while (search-forward ">" nil t)
403 (goto-char (point-min))
405 (let ((p1 (search-forward "<pre>"))
406 (p2 (search-forward "</pre>")))
407 (buffer-substring (+ 1 p1) (- p2 6)))))
411 : pubmed-get-medline-xml
413 #+BEGIN_SRC emacs-lisp :tangle no
414 (pubmed-get-medline-xml "23162369")
420 <MedlineCitation Status="Publisher" Owner="NLM">
421 <PMID Version="1">23162369</PMID>
427 <Article PubModel="Print-Electronic">
429 <ISSN IssnType="Print">1040-726X</ISSN>
430 <JournalIssue CitedMedium="Print">
438 <Title>Educational psychology review</Title>
439 <ISOAbbreviation>Educ Psychol Rev</ISOAbbreviation>
441 <ArticleTitle>Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.</ArticleTitle>
443 <MedlinePgn>569-608</MedlinePgn>
446 <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>
450 <LastName>Slavich</LastName>
451 <ForeName>George M</ForeName>
452 <Initials>GM</Initials>
454 <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>
458 <LastName>Zimbardo</LastName>
459 <ForeName>Philip G</ForeName>
460 <Initials>PG</Initials>
463 <Language>ENG</Language>
466 <GrantID>R01 AG026364</GrantID>
467 <Acronym>AG</Acronym>
468 <Agency>NIA NIH HHS</Agency>
469 <Country>United States</Country>
472 <GrantID>T32 MH019925</GrantID>
473 <Acronym>MH</Acronym>
474 <Agency>NIMH NIH HHS</Agency>
475 <Country>United States</Country>
478 <PublicationTypeList>
479 <PublicationType UI="">JOURNAL ARTICLE</PublicationType>
480 </PublicationTypeList>
481 <ArticleDate DateType="Electronic">
488 <MedlineTA>Educ Psychol Rev</MedlineTA>
489 <NlmUniqueID>9885342</NlmUniqueID>
490 <ISSNLinking>1040-726X</ISSNLinking>
491 </MedlineJournalInfo>
495 <PubMedPubDate PubStatus="epublish">
500 <PubMedPubDate PubStatus="entrez">
507 <PubMedPubDate PubStatus="pubmed">
514 <PubMedPubDate PubStatus="medline">
522 <PublicationStatus>ppublish</PublicationStatus>
524 <ArticleId IdType="doi">10.1007/s10648-012-9199-6</ArticleId>
525 <ArticleId IdType="pubmed">23162369</ArticleId>
526 <ArticleId IdType="pmc">PMC3498956</ArticleId>
527 <ArticleId IdType="mid">NIHMS395714</ArticleId>
535 * Pubmed Central (PMC) link
536 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.
538 Here we define a new link. Clicking on it simply opens a webpage to the article.
540 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
544 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string)))
546 (lambda (keyword desc format)
549 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/%s\">pmcid:%s</a>" keyword keyword))
551 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/%s}" keyword)))))
555 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.
557 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
561 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string)))
563 (lambda (keyword desc format)
566 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s\">nihmsid:%s</a>" keyword keyword))
568 ;; write out the latex command
569 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
576 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
581 This code will tangle the elisp code out to pubmed.el and load it.
583 [[elisp:(org-babel-load-file "pubmed.org")]]