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
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 :results code
203 (pubmed-parse-medline "23162369")
207 #+BEGIN_SRC emacs-lisp
208 (("PMID" . "23162369")
210 ("STAT" . "Publisher")
212 ("IS" . "1040-726X (Print)")
213 ("IS" . "1040-726X (Linking)")
217 ("TI" . "Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core \n Methods.")
219 ("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.")
220 ("FAU" . "Slavich, George M")
221 ("AU" . "Slavich GM")
222 ("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.")
223 ("FAU" . "Zimbardo, Philip G")
224 ("AU" . "Zimbardo PG")
226 ("GR" . "R01 AG026364/AG/NIA NIH HHS/United States")
227 ("GR" . "T32 MH019925/MH/NIMH NIH HHS/United States")
228 ("PT" . "JOURNAL ARTICLE")
230 ("TA" . "Educ Psychol Rev")
231 ("JT" . "Educational psychology review")
233 ("PMC" . "PMC3498956")
234 ("MID" . "NIHMS395714")
235 ("EDAT" . "2012/11/20 06:00")
236 ("MHDA" . "2012/11/20 06:00")
237 ("CRDT" . "2012/11/20 06:00")
238 ("PHST" . "2012/07/24 [epublish]")
239 ("AID" . "10.1007/s10648-012-9199-6 [doi]")
244 ** PMID to bibtex entry
245 The point of parsing the MEDLINE text is so we can make bibtex entries. We only support Journal articles for now.
247 #+BEGIN_SRC emacs-lisp
248 (defun pubmed-pmid-to-bibtex (pmid)
249 "Convert a PMID to a bibtex entry."
250 (let* ((data (pubmed-parse-medline pmid))
251 (type (cdr (assoc "PT" data)))
252 (title (cdr (assoc "TI" data)))
253 (authors (mapconcat 'cdr
255 (string= (car x) "FAU"))
258 (abstract (cdr (assoc "AB" data)))
259 (volume (cdr (assoc "VI" data)))
260 (issue (cdr (assoc "IP" data)))
261 (journal (cdr (assoc "JT" data)))
262 (year (cdr (assoc "DP" data)))
263 (pages (cdr (assoc "PG" data)))
264 (aid (cdr (assoc "AID" data))))
267 ((string= type "JOURNAL ARTICLE")
269 author = {" authors "},
271 abstract = {" abstract "},
272 journal = {" journal "},
273 volume = {" volume "},
274 number = {" issue "},
275 year = {" (car (split-string year)) "},
277 doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "},
280 (message "No conversion for type: %s" type)))))
284 : pubmed-pmid-to-bibtex
286 #+BEGIN_SRC emacs-lisp :tangle no
287 (pubmed-pmid-to-bibtex "23162369")
293 author = {Slavich, George M and Zimbardo, Philip G},
294 title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
296 abstract = {Approaches to classroom instruction have evolved considerably over the past 50
297 years. This progress has been spurred by the development of several learning
298 principles and methods of instruction, including active learning,
299 student-centered learning, collaborative learning, experiential learning, and
300 problem-based learning. In the present paper, we suggest that these seemingly
301 different strategies share important underlying characteristics and can be viewed
302 as complimentary components of a broader approach to classroom instruction called
303 transformational teaching. Transformational teaching involves creating dynamic
304 relationships between teachers, students, and a shared body of knowledge to
305 promote student learning and personal growth. From this perspective, instructors
306 are intellectual coaches who create teams of students who collaborate with each
307 other and with their teacher to master bodies of information. Teachers assume the
308 traditional role of facilitating students' acquisition of key course concepts,
309 but do so while enhancing students' personal development and attitudes toward
310 learning. They accomplish these goals by establishing a shared vision for a
311 course, providing modeling and mastery experiences, challenging and encouraging
312 students, personalizing attention and feedback, creating experiential lessons
313 that transcend the boundaries of the classroom, and promoting ample opportunities
314 for preflection and reflection. We propose that these methods are synergistically
315 related and, when used together, maximize students' potential for intellectual
316 and personal growth.},
317 journal = {Educational psychology review},
322 doi = {10.1007/s10648-012-9199-6},
326 And we probably want to be able to insert a bibtex entry
328 #+BEGIN_SRC emacs-lisp
329 (defun pubmed-insert-bibtex-from-pmid (pmid)
330 "Insert a bibtex entry at point derived from PMID.
331 You must clean the entry after insertion."
332 (interactive "sPMID: ")
333 (insert (pubmed-pmid-to-bibtex pmid)))
337 : pubmed-insert-bibtex-from-pmid
339 Here is an example of a cleaned entry:
340 #+BEGIN_SRC bibtex :tangle no
341 @article{slavich-2012-trans-teach,
342 author = {Slavich, George M and Zimbardo, Philip G},
343 title = {Transformational Teaching: Theoretical
344 Underpinnings, Basic Principles, and Core Methods.},
345 journal = {Educational psychology review},
350 doi = {10.1007/s10648-012-9199-6},
351 abstract = {Approaches to classroom instruction have evolved
352 considerably over the past 50 years. This progress
353 has been spurred by the development of several
354 learning principles and methods of instruction,
355 including active learning, student-centered
356 learning, collaborative learning, experiential
357 learning, and problem-based learning. In the present
358 paper, we suggest that these seemingly different
359 strategies share important underlying
360 characteristics and can be viewed as complimentary
361 components of a broader approach to classroom
362 instruction called transformational
363 teaching. Transformational teaching involves
364 creating dynamic relationships between teachers,
365 students, and a shared body of knowledge to promote
366 student learning and personal growth. From this
367 perspective, instructors are intellectual coaches
368 who create teams of students who collaborate with
369 each other and with their teacher to master bodies
370 of information. Teachers assume the traditional role
371 of facilitating students' acquisition of key course
372 concepts, but do so while enhancing students'
373 personal development and attitudes toward
374 learning. They accomplish these goals by
375 establishing a shared vision for a course, providing
376 modeling and mastery experiences, challenging and
377 encouraging students, personalizing attention and
378 feedback, creating experiential lessons that
379 transcend the boundaries of the classroom, and
380 promoting ample opportunities for preflection and
381 reflection. We propose that these methods are
382 synergistically related and, when used together,
383 maximize students' potential for intellectual and
389 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.
391 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
392 (defun pubmed-get-medline-xml (pmid)
393 "Get MEDLINE xml for PMID as a string."
396 (url-retrieve-synchronously
397 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
398 (goto-char (point-min))
399 (while (search-forward "<" nil t)
401 (goto-char (point-min))
402 (while (search-forward ">" nil t)
404 (goto-char (point-min))
406 (let ((p1 (search-forward "<pre>"))
407 (p2 (search-forward "</pre>")))
408 (buffer-substring (+ 1 p1) (- p2 6)))))
412 : pubmed-get-medline-xml
414 #+BEGIN_SRC emacs-lisp :tangle no
415 (pubmed-get-medline-xml "23162369")
421 <MedlineCitation Status="Publisher" Owner="NLM">
422 <PMID Version="1">23162369</PMID>
428 <Article PubModel="Print-Electronic">
430 <ISSN IssnType="Print">1040-726X</ISSN>
431 <JournalIssue CitedMedium="Print">
439 <Title>Educational psychology review</Title>
440 <ISOAbbreviation>Educ Psychol Rev</ISOAbbreviation>
442 <ArticleTitle>Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.</ArticleTitle>
444 <MedlinePgn>569-608</MedlinePgn>
447 <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>
451 <LastName>Slavich</LastName>
452 <ForeName>George M</ForeName>
453 <Initials>GM</Initials>
455 <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>
459 <LastName>Zimbardo</LastName>
460 <ForeName>Philip G</ForeName>
461 <Initials>PG</Initials>
464 <Language>ENG</Language>
467 <GrantID>R01 AG026364</GrantID>
468 <Acronym>AG</Acronym>
469 <Agency>NIA NIH HHS</Agency>
470 <Country>United States</Country>
473 <GrantID>T32 MH019925</GrantID>
474 <Acronym>MH</Acronym>
475 <Agency>NIMH NIH HHS</Agency>
476 <Country>United States</Country>
479 <PublicationTypeList>
480 <PublicationType UI="">JOURNAL ARTICLE</PublicationType>
481 </PublicationTypeList>
482 <ArticleDate DateType="Electronic">
489 <MedlineTA>Educ Psychol Rev</MedlineTA>
490 <NlmUniqueID>9885342</NlmUniqueID>
491 <ISSNLinking>1040-726X</ISSNLinking>
492 </MedlineJournalInfo>
496 <PubMedPubDate PubStatus="epublish">
501 <PubMedPubDate PubStatus="entrez">
508 <PubMedPubDate PubStatus="pubmed">
515 <PubMedPubDate PubStatus="medline">
523 <PublicationStatus>ppublish</PublicationStatus>
525 <ArticleId IdType="doi">10.1007/s10648-012-9199-6</ArticleId>
526 <ArticleId IdType="pubmed">23162369</ArticleId>
527 <ArticleId IdType="pmc">PMC3498956</ArticleId>
528 <ArticleId IdType="mid">NIHMS395714</ArticleId>
536 * Pubmed Central (PMC) link
537 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.
539 Here we define a new link. Clicking on it simply opens a webpage to the article.
541 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
545 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string)))
547 (lambda (keyword desc format)
550 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/%s\">pmcid:%s</a>" keyword keyword))
552 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/%s}" keyword)))))
556 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.
558 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
562 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string)))
564 (lambda (keyword desc format)
567 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s\">nihmsid:%s</a>" keyword keyword))
569 ;; write out the latex command
570 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
577 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
582 This code will tangle the elisp code out to pubmed.el and load it.
584 [[elisp:(org-babel-load-file "pubmed.org")]]