#+TITLE: Links and functions for Pubmed and NIH databases #+AUTHOR: John Kitchin #+DATE: January 5, 2015 * Introduction This document is an experiment at creating a literate program to provide functions for interacting with pubmed databases. This library provides links that go to pubmed resources, e.g. pmcid:PMC3498956 pmid:23162369 and nihmsid:NIHMS395714 See http://www.ncbi.nlm.nih.gov/pmc/about/public-access-info/#p3 for details of these identifiers. For PMID there is one interactive function that inserts a bibtex entry: pubmed-insert-bibtex-from-pmid. This library is complementary to [[./doi-utils.org]]. * Header #+BEGIN_SRC emacs-lisp :tangle pubmed.el ;;; pubmed.el --- Links and functions to interact with pubmed databases. ;; Copyright(C) 2015 John Kitchin ;; Author: John Kitchin ;; This file is not currently part of GNU Emacs. ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program ; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; ;; Lisp code to interact with pubmed databases, links to pubmed ;; identifiers. See pubmed.org. ;;; ;; This library provides links that go to pubmed resources, e.g. ;; ;; pmcid:PMC3498956 ;; ;; pmid:23162369 ;; ;; and nihmsid:NIHMS395714 ;; ;; See http://www.ncbi.nlm.nih.gov/pmc/about/public-access-info/#p3 for details of these identifiers. ;; ;; For PMID there is one interactive function that inserts a bibtex ;; entry: `pubmed-insert-bibtex-from-pmid`. #+END_SRC * PMID (from PubMed) link and functions 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. #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent (org-add-link-type "pmid" ;; clicking (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pubmed/%s" link-string))) ;; formatting (lambda (keyword desc format) (cond ((eq format 'html) (format "pmid:%s" keyword keyword)); no output for html ((eq format 'latex) ;; write out the latex command (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword))))) #+END_SRC ** Get MEDLINE metadata We can get bibliographic metadata from a pmid. Here we get the MEDLINE text. The website wraps the data in
 tags.


#+BEGIN_SRC emacs-lisp :tangle pubmed.el
(defun pubmed-get-medline (pmid)
  "Get MEDLINE text for PMID as a string."
  (with-current-buffer
    (url-retrieve-synchronously
     (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=medline&format=text" pmid))
    (goto-char (point-min))
    (let ((p1 (search-forward "
"))
	  (p2 (search-forward "
"))) (buffer-substring (+ 1 p1) (- p2 6))))) #+END_SRC #+RESULTS: : pubmed-get-medline Here is sample output: #+BEGIN_SRC emacs-lisp (pubmed-get-medline "23162369") #+END_SRC #+RESULTS: #+begin_example PMID- 23162369 OWN - NLM STAT- Publisher DA - 20121119 IS - 1040-726X (Print) IS - 1040-726X (Linking) VI - 24 IP - 4 DP - 2012 Dec TI - Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods. PG - 569-608 AB - 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. FAU - Slavich, George M AU - Slavich GM AD - 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. FAU - Zimbardo, Philip G AU - Zimbardo PG LA - ENG GR - R01 AG026364/AG/NIA NIH HHS/United States GR - T32 MH019925/MH/NIMH NIH HHS/United States PT - JOURNAL ARTICLE DEP - 20120724 TA - Educ Psychol Rev JT - Educational psychology review JID - 9885342 PMC - PMC3498956 MID - NIHMS395714 EDAT- 2012/11/20 06:00 MHDA- 2012/11/20 06:00 CRDT- 2012/11/20 06:00 PHST- 2012/07/24 [epublish] AID - 10.1007/s10648-012-9199-6 [doi] PST - ppublish SO - Educ Psychol Rev. 2012 Dec;24(4):569-608. Epub 2012 Jul 24. #+end_example ** Parse the PMID MEDLINE data We can parse this into a data structure #+BEGIN_SRC emacs-lisp :tangle pubmed.el (defun pubmed-parse-medline (pmid) "Parse the medline text for PMID and return a list of cons cells." (let ((data '()) (p1) (p2) (tag) (value)) (with-temp-buffer (insert (pubmed-get-medline pmid)) (goto-char (point-min)) (while (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t) (setq tag (match-string 1)) ;; point is at end of the search (setq p1 (point)) ;; now go to next tag (re-search-forward "\\(^[A-Z]\\{2,4\\}\\)\\s-*- " nil t) (setq p2 (- (match-beginning 1) 1)) (setq value (buffer-substring p1 p2)) (setq data (append data (list (cons tag value)))) ;; now go back to last tag to get the next one (goto-char p1))) data)) #+END_SRC #+RESULTS: : pubmed-parse-medline #+BEGIN_SRC emacs-lisp :results code (pubmed-parse-medline "23162369") #+END_SRC #+RESULTS: #+BEGIN_SRC emacs-lisp (("PMID" . "23162369") ("OWN" . "NLM") ("STAT" . "Publisher") ("DA" . "20121119") ("IS" . "1040-726X (Print)") ("IS" . "1040-726X (Linking)") ("VI" . "24") ("IP" . "4") ("DP" . "2012 Dec") ("TI" . "Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core \n Methods.") ("PG" . "569-608") ("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.") ("FAU" . "Slavich, George M") ("AU" . "Slavich GM") ("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.") ("FAU" . "Zimbardo, Philip G") ("AU" . "Zimbardo PG") ("LA" . "ENG") ("GR" . "R01 AG026364/AG/NIA NIH HHS/United States") ("GR" . "T32 MH019925/MH/NIMH NIH HHS/United States") ("PT" . "JOURNAL ARTICLE") ("DEP" . "20120724") ("TA" . "Educ Psychol Rev") ("JT" . "Educational psychology review") ("JID" . "9885342") ("PMC" . "PMC3498956") ("MID" . "NIHMS395714") ("EDAT" . "2012/11/20 06:00") ("MHDA" . "2012/11/20 06:00") ("CRDT" . "2012/11/20 06:00") ("PHST" . "2012/07/24 [epublish]") ("AID" . "10.1007/s10648-012-9199-6 [doi]") ("PST" . "ppublish") ("SO" . "\nSO - ")) #+END_SRC ** PMID to bibtex entry The point of parsing the MEDLINE text is so we can make bibtex entries. We only support Journal articles for now. #+BEGIN_SRC emacs-lisp (defun pubmed-pmid-to-bibtex (pmid) "Convert a PMID to a bibtex entry." (let* ((data (pubmed-parse-medline pmid)) (type (cdr (assoc "PT" data))) (title (cdr (assoc "TI" data))) (authors (mapconcat 'cdr (-filter (lambda (x) (string= (car x) "FAU")) data) " and ")) (abstract (cdr (assoc "AB" data))) (volume (cdr (assoc "VI" data))) (issue (cdr (assoc "IP" data))) (journal (cdr (assoc "JT" data))) (year (cdr (assoc "DP" data))) (pages (cdr (assoc "PG" data))) (aid (cdr (assoc "AID" data)))) (cond ((string= type "JOURNAL ARTICLE") (concat "@article{, author = {" authors "}, title = {" title "}, abstract = {" abstract "}, journal = {" journal "}, volume = {" volume "}, number = {" issue "}, year = {" (car (split-string year)) "}, pages = {" pages "}, doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "}, }")) (t (message "No conversion for type: %s" type))))) #+END_SRC #+RESULTS: : pubmed-pmid-to-bibtex #+BEGIN_SRC emacs-lisp :tangle no (pubmed-pmid-to-bibtex "23162369") #+END_SRC #+RESULTS: #+begin_example @article{, author = {Slavich, George M and Zimbardo, Philip G}, title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.}, abstract = {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.}, journal = {Educational psychology review}, volume = {24}, number = {4}, year = {2012}, pages = {569-608}, doi = {10.1007/s10648-012-9199-6}, } #+end_example And we probably want to be able to insert a bibtex entry #+BEGIN_SRC emacs-lisp (defun pubmed-insert-bibtex-from-pmid (pmid) "Insert a bibtex entry at point derived from PMID. You must clean the entry after insertion." (interactive "sPMID: ") (insert (pubmed-pmid-to-bibtex pmid))) #+END_SRC #+RESULTS: : pubmed-insert-bibtex-from-pmid Here is an example of a cleaned entry: #+BEGIN_SRC bibtex :tangle no @article{slavich-2012-trans-teach, author = {Slavich, George M and Zimbardo, Philip G}, title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.}, journal = {Educational psychology review}, volume = 24, number = 4, pages = {569-608}, year = 2012, doi = {10.1007/s10648-012-9199-6}, abstract = {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.}, } #+END_SRC ** PMID to xml We can also get xml of the MEDLINE data. The web page here also wraps the xml in a
 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.

#+BEGIN_SRC emacs-lisp :tangle pubmed.el
(defun pubmed-get-medline-xml (pmid)
  "Get MEDLINE xml for PMID as a string."
  (interactive)
  (with-current-buffer
    (url-retrieve-synchronously
     (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
    (goto-char (point-min))
    (while (search-forward "<" nil t)
      (replace-match "<"))
    (goto-char (point-min))
    (while (search-forward ">" nil t)
      (replace-match ">"))
    (goto-char (point-min))   
			   
    (let ((p1 (search-forward "
"))
	  (p2 (search-forward "
"))) (buffer-substring (+ 1 p1) (- p2 6))))) #+END_SRC #+RESULTS: : pubmed-get-medline-xml #+BEGIN_SRC emacs-lisp :tangle no (pubmed-get-medline-xml "23162369") #+END_SRC #+RESULTS: #+begin_example 23162369 2012 11 19
1040-726X 24 4 2012 Dec Educational psychology review Educ Psychol Rev Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods. 569-608 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. Slavich George M GM 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. Zimbardo Philip G PG ENG R01 AG026364 AG NIA NIH HHS United States T32 MH019925 MH NIMH NIH HHS United States JOURNAL ARTICLE 2012 7 24
Educ Psychol Rev 9885342 1040-726X
2012 7 24 2012 11 20 6 0 2012 11 20 6 0 2012 11 20 6 0 ppublish 10.1007/s10648-012-9199-6 23162369 PMC3498956 NIHMS395714
#+end_example * Pubmed Central (PMC) link 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. Here we define a new link. Clicking on it simply opens a webpage to the article. #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent (org-add-link-type "pmcid" ;; clicking (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string))) ;; formatting (lambda (keyword desc format) (cond ((eq format 'html) (format "pmcid:%s" keyword keyword)) ((eq format 'latex) (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/%s}" keyword))))) #+END_SRC * NIHMSID 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. #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent (org-add-link-type "nihmsid" ;; clicking (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string))) ;; formatting (lambda (keyword desc format) (cond ((eq format 'html) (format "nihmsid:%s" keyword keyword)) ((eq format 'latex) ;; write out the latex command (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword))))) #+END_SRC * End of code #+BEGIN_SRC emacs-lisp :tangle pubmed.el (provide 'pubmed) #+END_SRC * Build :noexport: This code will tangle the elisp code out to pubmed.el and load it. [[elisp:(org-babel-load-file "pubmed.org")]]