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.
234 1. The year is not quite right, it has the month in it.
235 2. I do not use all the fields.
237 #+BEGIN_SRC emacs-lisp
238 (defun pubmed-pmid-to-bibtex (pmid)
239 "Convert a PMID to a bibtex entry."
240 (let* ((data (pubmed-parse-medline pmid))
241 (type (cdr (assoc "PT" data)))
242 (title (cdr (assoc "TI" data)))
243 (authors (mapconcat 'cdr
245 (string= (car x) "FAU"))
248 (abstract (cdr (assoc "AB" data)))
249 (volume (cdr (assoc "VI" data)))
250 (issue (cdr (assoc "IP" data)))
251 (journal (cdr (assoc "JT" data)))
252 (year (cdr (assoc "DP" data)))
253 (pages (cdr (assoc "PG" data)))
254 (aid (cdr (assoc "AID" data))))
257 ((string= type "JOURNAL ARTICLE")
259 author = {" authors "},
261 abstract = {" abstract "},
262 journal = {" journal "},
263 volume = {" volume "},
264 number = {" issue "},
265 year = {" (car (split-string year)) "},
267 doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "},
270 (message "No conversion for type: %s" type)))))
274 : pubmed-pmid-to-bibtex
276 #+BEGIN_SRC emacs-lisp :tangle no
277 (pubmed-pmid-to-bibtex "23162369")
283 author = {Slavich, George M and Zimbardo, Philip G},
284 title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
286 abstract = {Approaches to classroom instruction have evolved considerably over the past 50
287 years. This progress has been spurred by the development of several learning
288 principles and methods of instruction, including active learning,
289 student-centered learning, collaborative learning, experiential learning, and
290 problem-based learning. In the present paper, we suggest that these seemingly
291 different strategies share important underlying characteristics and can be viewed
292 as complimentary components of a broader approach to classroom instruction called
293 transformational teaching. Transformational teaching involves creating dynamic
294 relationships between teachers, students, and a shared body of knowledge to
295 promote student learning and personal growth. From this perspective, instructors
296 are intellectual coaches who create teams of students who collaborate with each
297 other and with their teacher to master bodies of information. Teachers assume the
298 traditional role of facilitating students' acquisition of key course concepts,
299 but do so while enhancing students' personal development and attitudes toward
300 learning. They accomplish these goals by establishing a shared vision for a
301 course, providing modeling and mastery experiences, challenging and encouraging
302 students, personalizing attention and feedback, creating experiential lessons
303 that transcend the boundaries of the classroom, and promoting ample opportunities
304 for preflection and reflection. We propose that these methods are synergistically
305 related and, when used together, maximize students' potential for intellectual
306 and personal growth.},
307 journal = {Educational psychology review},
312 doi = {10.1007/s10648-012-9199-6},
316 And we probably want to be able to insert a bibtex entry
318 #+BEGIN_SRC emacs-lisp
319 (defun pubmed-insert-bibtex-from-pmid (pmid)
320 "Insert a bibtex entry at point derived from PMID.
321 You must clean the entry after insertion."
322 (interactive "sPMID: ")
323 (insert (pubmed-pmid-to-bibtex pmid)))
327 : pubmed-insert-bibtex-from-pmid
329 Here is an example of a cleaned entry:
330 #+BEGIN_SRC bibtex :tangle no
331 @article{slavich-2012-trans-teach,
332 author = {Slavich, George M and Zimbardo, Philip G},
333 title = {Transformational Teaching: Theoretical
334 Underpinnings, Basic Principles, and Core Methods.},
335 journal = {Educational psychology review},
340 doi = {10.1007/s10648-012-9199-6},
341 abstract = {Approaches to classroom instruction have evolved
342 considerably over the past 50 years. This progress
343 has been spurred by the development of several
344 learning principles and methods of instruction,
345 including active learning, student-centered
346 learning, collaborative learning, experiential
347 learning, and problem-based learning. In the present
348 paper, we suggest that these seemingly different
349 strategies share important underlying
350 characteristics and can be viewed as complimentary
351 components of a broader approach to classroom
352 instruction called transformational
353 teaching. Transformational teaching involves
354 creating dynamic relationships between teachers,
355 students, and a shared body of knowledge to promote
356 student learning and personal growth. From this
357 perspective, instructors are intellectual coaches
358 who create teams of students who collaborate with
359 each other and with their teacher to master bodies
360 of information. Teachers assume the traditional role
361 of facilitating students' acquisition of key course
362 concepts, but do so while enhancing students'
363 personal development and attitudes toward
364 learning. They accomplish these goals by
365 establishing a shared vision for a course, providing
366 modeling and mastery experiences, challenging and
367 encouraging students, personalizing attention and
368 feedback, creating experiential lessons that
369 transcend the boundaries of the classroom, and
370 promoting ample opportunities for preflection and
371 reflection. We propose that these methods are
372 synergistically related and, when used together,
373 maximize students' potential for intellectual and
379 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.
381 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
382 (defun pubmed-get-medline-xml (pmid)
383 "Get MEDLINE xml for PMID as a string."
386 (url-retrieve-synchronously
387 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
388 (goto-char (point-min))
389 (while (search-forward "<" nil t)
391 (goto-char (point-min))
392 (while (search-forward ">" nil t)
394 (goto-char (point-min))
396 (let ((p1 (search-forward "<pre>"))
397 (p2 (search-forward "</pre>")))
398 (buffer-substring (+ 1 p1) (- p2 6)))))
402 : pubmed-get-medline-xml
404 #+BEGIN_SRC emacs-lisp :tangle no
405 (pubmed-get-medline-xml "23162369")
411 <MedlineCitation Status="Publisher" Owner="NLM">
412 <PMID Version="1">23162369</PMID>
418 <Article PubModel="Print-Electronic">
420 <ISSN IssnType="Print">1040-726X</ISSN>
421 <JournalIssue CitedMedium="Print">
429 <Title>Educational psychology review</Title>
430 <ISOAbbreviation>Educ Psychol Rev</ISOAbbreviation>
432 <ArticleTitle>Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.</ArticleTitle>
434 <MedlinePgn>569-608</MedlinePgn>
437 <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>
441 <LastName>Slavich</LastName>
442 <ForeName>George M</ForeName>
443 <Initials>GM</Initials>
445 <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>
449 <LastName>Zimbardo</LastName>
450 <ForeName>Philip G</ForeName>
451 <Initials>PG</Initials>
454 <Language>ENG</Language>
457 <GrantID>R01 AG026364</GrantID>
458 <Acronym>AG</Acronym>
459 <Agency>NIA NIH HHS</Agency>
460 <Country>United States</Country>
463 <GrantID>T32 MH019925</GrantID>
464 <Acronym>MH</Acronym>
465 <Agency>NIMH NIH HHS</Agency>
466 <Country>United States</Country>
469 <PublicationTypeList>
470 <PublicationType UI="">JOURNAL ARTICLE</PublicationType>
471 </PublicationTypeList>
472 <ArticleDate DateType="Electronic">
479 <MedlineTA>Educ Psychol Rev</MedlineTA>
480 <NlmUniqueID>9885342</NlmUniqueID>
481 <ISSNLinking>1040-726X</ISSNLinking>
482 </MedlineJournalInfo>
486 <PubMedPubDate PubStatus="epublish">
491 <PubMedPubDate PubStatus="entrez">
498 <PubMedPubDate PubStatus="pubmed">
505 <PubMedPubDate PubStatus="medline">
513 <PublicationStatus>ppublish</PublicationStatus>
515 <ArticleId IdType="doi">10.1007/s10648-012-9199-6</ArticleId>
516 <ArticleId IdType="pubmed">23162369</ArticleId>
517 <ArticleId IdType="pmc">PMC3498956</ArticleId>
518 <ArticleId IdType="mid">NIHMS395714</ArticleId>
526 * Pubmed Central (PMC) link
527 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.
529 Here we define a new link. Clicking on it simply opens a webpage to the article.
531 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
535 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string)))
537 (lambda (keyword desc format)
540 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/%s\">pmcid:%s</a>" keyword keyword))
542 (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 :results silent
552 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string)))
554 (lambda (keyword desc format)
557 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s\">nihmsid:%s</a>" keyword keyword))
559 ;; write out the latex command
560 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
567 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
572 This code will tangle the elisp code out to pubmed.el and load it.
574 [[elisp:(org-babel-load-file "pubmed.org")]]