1 #+TITLE: Links and functions for Pubmed and NIH databases
5 This document is an experiment at creating a literate program to provide functions for interacting with pubmed databases.
7 This library provides links that go to pubmed resources, e.g.
13 and nihmsid:NIHMS395714
15 See http://www.ncbi.nlm.nih.gov/pmc/about/public-access-info/#p3 for details of these identifiers.
20 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
21 ;;; pubmed.el --- Links and functions to interact with pubmed databases.
23 ;; Copyright(C) 2015 John Kitchin
25 ;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
26 ;; This file is not currently part of GNU Emacs.
28 ;; This program is free software; you can redistribute it and/or
29 ;; modify it under the terms of the GNU General Public License as
30 ;; published by the Free Software Foundation; either version 2, or (at
31 ;; your option) any later version.
33 ;; This program is distributed in the hope that it will be useful, but
34 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 ;; General Public License for more details.
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with this program ; see the file COPYING. If not, write to
40 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41 ;; Boston, MA 02111-1307, USA.
45 ;; Lisp code to setup bibliography cite, ref and label org-mode links.
46 ;; also sets up reftex for org-mode. The links are clickable and do
47 ;; things that are useful. You should really read org-ref.org for details.
49 ;; Package-Requires: ((dash))
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
60 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pubmed/%s" link-string)))
62 (lambda (keyword desc format)
64 ((eq format 'html) (format "")); no output for html
66 ;; write out the latex command
67 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
70 ** Get MEDLINE metadata
71 We can get bibliographic metadata from a pmid. Here we get the MEDLINE text. The website wraps the data in <pre></pre> tags.
74 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
75 (defun pubmed-get-medline (pmid)
76 "Get MEDLINE text for PMID as a string."
78 (url-retrieve-synchronously
79 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=medline&format=text" pmid))
80 (goto-char (point-min))
81 (let ((p1 (search-forward "<pre>"))
82 (p2 (search-forward "</pre>")))
83 (buffer-substring (+ 1 p1) (- p2 6)))))
89 Here is sample output:
90 #+BEGIN_SRC emacs-lisp
91 (pubmed-get-medline "23162369")
100 IS - 1040-726X (Print)
101 IS - 1040-726X (Linking)
105 TI - Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
108 AB - Approaches to classroom instruction have evolved considerably over the past 50
109 years. This progress has been spurred by the development of several learning
110 principles and methods of instruction, including active learning,
111 student-centered learning, collaborative learning, experiential learning, and
112 problem-based learning. In the present paper, we suggest that these seemingly
113 different strategies share important underlying characteristics and can be viewed
114 as complimentary components of a broader approach to classroom instruction called
115 transformational teaching. Transformational teaching involves creating dynamic
116 relationships between teachers, students, and a shared body of knowledge to
117 promote student learning and personal growth. From this perspective, instructors
118 are intellectual coaches who create teams of students who collaborate with each
119 other and with their teacher to master bodies of information. Teachers assume the
120 traditional role of facilitating students' acquisition of key course concepts,
121 but do so while enhancing students' personal development and attitudes toward
122 learning. They accomplish these goals by establishing a shared vision for a
123 course, providing modeling and mastery experiences, challenging and encouraging
124 students, personalizing attention and feedback, creating experiential lessons
125 that transcend the boundaries of the classroom, and promoting ample opportunities
126 for preflection and reflection. We propose that these methods are synergistically
127 related and, when used together, maximize students' potential for intellectual
129 FAU - Slavich, George M
131 AD - Cousins Center for Psychoneuroimmunology and Department of Psychiatry and
132 Biobehavioral Sciences, University of California, Los Angeles, UCLA Medical Plaza
133 300, Room 3156, Los Angeles, CA 90095-7076, USA.
134 FAU - Zimbardo, Philip G
137 GR - R01 AG026364/AG/NIA NIH HHS/United States
138 GR - T32 MH019925/MH/NIMH NIH HHS/United States
141 TA - Educ Psychol Rev
142 JT - Educational psychology review
146 EDAT- 2012/11/20 06:00
147 MHDA- 2012/11/20 06:00
148 CRDT- 2012/11/20 06:00
149 PHST- 2012/07/24 [epublish]
150 AID - 10.1007/s10648-012-9199-6 [doi]
152 SO - Educ Psychol Rev. 2012 Dec;24(4):569-608. Epub 2012 Jul 24.
155 ** Parse the PMID MEDLINE data
156 We can parse this into a data structure
158 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
159 (defun pubmed-parse-medline (pmid)
160 "Parse the medline text for PMID and return a list of cons cells."
166 (with-temp-buffer (insert (pubmed-get-medline pmid))
167 (goto-char (point-min))
168 (while (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
169 (setq tag (match-string 1))
170 ;; point is at end of the search
172 ;; now go to next tag
173 (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t)
174 (setq p2 (- (match-beginning 1) 1))
175 (setq value (buffer-substring p1 p2))
176 (setq data (append data (list (cons tag value))))
177 ;; now go back to last tag to get the next one
183 : pubmed-parse-medline
185 #+BEGIN_SRC emacs-lisp :results code
186 (pubmed-parse-medline "23162369")
190 #+BEGIN_SRC emacs-lisp
191 (("PMID" . "23162369")
193 ("STAT" . "Publisher")
195 ("IS" . "1040-726X (Print)")
196 ("IS" . "1040-726X (Linking)")
200 ("TI" . "Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core \n Methods.")
202 ("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.")
203 ("FAU" . "Slavich, George M")
204 ("AU" . "Slavich GM")
205 ("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.")
206 ("FAU" . "Zimbardo, Philip G")
207 ("AU" . "Zimbardo PG")
209 ("GR" . "R01 AG026364/AG/NIA NIH HHS/United States")
210 ("GR" . "T32 MH019925/MH/NIMH NIH HHS/United States")
211 ("PT" . "JOURNAL ARTICLE")
213 ("TA" . "Educ Psychol Rev")
214 ("JT" . "Educational psychology review")
216 ("PMC" . "PMC3498956")
217 ("MID" . "NIHMS395714")
218 ("EDAT" . "2012/11/20 06:00")
219 ("MHDA" . "2012/11/20 06:00")
220 ("CRDT" . "2012/11/20 06:00")
221 ("PHST" . "2012/07/24 [epublish]")
222 ("AID" . "10.1007/s10648-012-9199-6 [doi]")
227 ** PMID to bibtex entry
228 The point of parsing the MEDLINE text is so we can make bibtex entries. We only support Journal articles for now.
231 1. The year is not quite right, it has the month in it.
232 2. I do not use all the fields.
234 #+BEGIN_SRC emacs-lisp
235 (defun pubmed-pmid-to-bibtex (pmid)
236 "Convert a PMID to a bibtex entry."
237 (let* ((data (org-ref-parse-medline pmid))
238 (type (cdr (assoc "PT" data)))
239 (title (cdr (assoc "TI" data)))
240 (authors (mapconcat 'cdr
242 (string= (car x) "FAU"))
245 (abstract (cdr (assoc "AB" data)))
246 (volume (cdr (assoc "VI" data)))
247 (issue (cdr (assoc "IP" data)))
248 (journal (cdr (assoc "JT" data)))
249 (year (cdr (assoc "DP" data)))
250 (pages (cdr (assoc "PG" data)))
251 (aid (cdr (assoc "AID" data))))
254 ((string= type "JOURNAL ARTICLE")
256 author = {" authors "},
258 abstract = {" abstract "},
259 journal = {" journal "},
260 volume = {" volume "},
261 number = {" issue "},
262 year = {" (car (split-string year)) "},
264 doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "},
267 (message "No conversion for type: %s" type)))))
271 : pubmed-pmid-to-bibtex
273 #+BEGIN_SRC emacs-lisp :tangle no
274 (pubmed-pmid-to-bibtex "23162369")
280 author = {Slavich, George M and Zimbardo, Philip G},
281 title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
283 abstract = {Approaches to classroom instruction have evolved considerably over the past 50
284 years. This progress has been spurred by the development of several learning
285 principles and methods of instruction, including active learning,
286 student-centered learning, collaborative learning, experiential learning, and
287 problem-based learning. In the present paper, we suggest that these seemingly
288 different strategies share important underlying characteristics and can be viewed
289 as complimentary components of a broader approach to classroom instruction called
290 transformational teaching. Transformational teaching involves creating dynamic
291 relationships between teachers, students, and a shared body of knowledge to
292 promote student learning and personal growth. From this perspective, instructors
293 are intellectual coaches who create teams of students who collaborate with each
294 other and with their teacher to master bodies of information. Teachers assume the
295 traditional role of facilitating students' acquisition of key course concepts,
296 but do so while enhancing students' personal development and attitudes toward
297 learning. They accomplish these goals by establishing a shared vision for a
298 course, providing modeling and mastery experiences, challenging and encouraging
299 students, personalizing attention and feedback, creating experiential lessons
300 that transcend the boundaries of the classroom, and promoting ample opportunities
301 for preflection and reflection. We propose that these methods are synergistically
302 related and, when used together, maximize students' potential for intellectual
303 and personal growth.},
304 journal = {Educational psychology review},
309 doi = {10.1007/s10648-012-9199-6},
313 And we probably want to be able to insert a bibtex entry
315 #+BEGIN_SRC emacs-lisp
316 (defun pubmed-insert-bibtex-from-pmid (pmid)
317 "Insert a bibtex entry at point derived from PMID.
318 You must clean the entry after insertion."
319 (interactive "sPMID: ")
320 (insert (pubmed-pmid-to-bibtex pmid)))
324 : pubmed-insert-bibtex-from-pmid
326 Here is an example of a cleaned entry:
327 #+BEGIN_SRC bibtex :tangle no
328 @article{slavich-2012-trans-teach,
329 author = {Slavich, George M and Zimbardo, Philip G},
330 title = {Transformational Teaching: Theoretical
331 Underpinnings, Basic Principles, and Core Methods.},
332 journal = {Educational psychology review},
337 doi = {10.1007/s10648-012-9199-6},
338 abstract = {Approaches to classroom instruction have evolved
339 considerably over the past 50 years. This progress
340 has been spurred by the development of several
341 learning principles and methods of instruction,
342 including active learning, student-centered
343 learning, collaborative learning, experiential
344 learning, and problem-based learning. In the present
345 paper, we suggest that these seemingly different
346 strategies share important underlying
347 characteristics and can be viewed as complimentary
348 components of a broader approach to classroom
349 instruction called transformational
350 teaching. Transformational teaching involves
351 creating dynamic relationships between teachers,
352 students, and a shared body of knowledge to promote
353 student learning and personal growth. From this
354 perspective, instructors are intellectual coaches
355 who create teams of students who collaborate with
356 each other and with their teacher to master bodies
357 of information. Teachers assume the traditional role
358 of facilitating students' acquisition of key course
359 concepts, but do so while enhancing students'
360 personal development and attitudes toward
361 learning. They accomplish these goals by
362 establishing a shared vision for a course, providing
363 modeling and mastery experiences, challenging and
364 encouraging students, personalizing attention and
365 feedback, creating experiential lessons that
366 transcend the boundaries of the classroom, and
367 promoting ample opportunities for preflection and
368 reflection. We propose that these methods are
369 synergistically related and, when used together,
370 maximize students' potential for intellectual and
376 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.
378 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
379 (defun pubmed-get-medline-xml (pmid)
380 "Get MEDLINE xml for PMID as a string."
383 (url-retrieve-synchronously
384 (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
385 (goto-char (point-min))
386 (while (search-forward "<" nil t)
388 (goto-char (point-min))
389 (while (search-forward ">" nil t)
391 (goto-char (point-min))
393 (let ((p1 (search-forward "<pre>"))
394 (p2 (search-forward "</pre>")))
395 (buffer-substring (+ 1 p1) (- p2 6)))))
399 : pubmed-get-medline-xml
401 #+BEGIN_SRC emacs-lisp :tangle no
402 (pubmed-get-medline-xml "23162369")
408 <MedlineCitation Status="Publisher" Owner="NLM">
409 <PMID Version="1">23162369</PMID>
415 <Article PubModel="Print-Electronic">
417 <ISSN IssnType="Print">1040-726X</ISSN>
418 <JournalIssue CitedMedium="Print">
426 <Title>Educational psychology review</Title>
427 <ISOAbbreviation>Educ Psychol Rev</ISOAbbreviation>
429 <ArticleTitle>Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.</ArticleTitle>
431 <MedlinePgn>569-608</MedlinePgn>
434 <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>
438 <LastName>Slavich</LastName>
439 <ForeName>George M</ForeName>
440 <Initials>GM</Initials>
442 <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>
446 <LastName>Zimbardo</LastName>
447 <ForeName>Philip G</ForeName>
448 <Initials>PG</Initials>
451 <Language>ENG</Language>
454 <GrantID>R01 AG026364</GrantID>
455 <Acronym>AG</Acronym>
456 <Agency>NIA NIH HHS</Agency>
457 <Country>United States</Country>
460 <GrantID>T32 MH019925</GrantID>
461 <Acronym>MH</Acronym>
462 <Agency>NIMH NIH HHS</Agency>
463 <Country>United States</Country>
466 <PublicationTypeList>
467 <PublicationType UI="">JOURNAL ARTICLE</PublicationType>
468 </PublicationTypeList>
469 <ArticleDate DateType="Electronic">
476 <MedlineTA>Educ Psychol Rev</MedlineTA>
477 <NlmUniqueID>9885342</NlmUniqueID>
478 <ISSNLinking>1040-726X</ISSNLinking>
479 </MedlineJournalInfo>
483 <PubMedPubDate PubStatus="epublish">
488 <PubMedPubDate PubStatus="entrez">
495 <PubMedPubDate PubStatus="pubmed">
502 <PubMedPubDate PubStatus="medline">
510 <PublicationStatus>ppublish</PublicationStatus>
512 <ArticleId IdType="doi">10.1007/s10648-012-9199-6</ArticleId>
513 <ArticleId IdType="pubmed">23162369</ArticleId>
514 <ArticleId IdType="pmc">PMC3498956</ArticleId>
515 <ArticleId IdType="mid">NIHMS395714</ArticleId>
523 * Pubmed Central (PMC) link
524 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.
526 Here we define a new link. Clicking on it simply opens a webpage to the article.
528 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
532 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string)))
534 (lambda (keyword desc format)
537 (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/%s\">" keyword))
539 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/%s}" keyword)))))
544 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.
546 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
550 (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string)))
552 (lambda (keyword desc format)
554 ((eq format 'html) (format "")); no output for html
556 ;; write out the latex command
557 (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s}" keyword)))))
561 | lambda | (link-string) | (browse-url (format http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s link-string)) |
562 | 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))) |
567 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
573 This code will tangle the elisp code out to pubmed.el and load it.
575 [[elisp:(org-babel-load-file "pubmed.org")]]