]> git.donarmstrong.com Git - org-ref.git/blob - pubmed.org
Added .cask to .gitignore.
[org-ref.git] / pubmed.org
1 #+TITLE: Links and functions for Pubmed and NIH databases
2 #+AUTHOR: John Kitchin
3 #+DATE: January 5, 2015
4
5 * Introduction
6
7 This document is an experiment at creating a literate program to provide functions for interacting with pubmed databases.
8
9 This library provides links that go to pubmed resources, e.g.
10
11 pmcid:PMC3498956
12
13 pmid:23162369
14
15 and nihmsid:NIHMS395714
16
17 See http://www.ncbi.nlm.nih.gov/pmc/about/public-access-info/#p3 for details of these identifiers.
18
19 For PMID there is one interactive function that inserts a bibtex entry: pubmed-insert-bibtex-from-pmid.
20
21 This library is complementary to [[./doi-utils.org]].
22
23 * Header
24 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
25 ;;; pubmed.el --- Links and functions to interact with pubmed databases.
26
27 ;; Copyright(C) 2015 John Kitchin
28
29 ;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
30 ;; This file is not currently part of GNU Emacs.
31
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.
36
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.
41
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.
46
47 ;;; Commentary:
48 ;;
49 ;; Lisp code to interact with pubmed databases, links to pubmed
50 ;; identifiers. See pubmed.org.
51 ;;;
52 ;; This library provides links that go to pubmed resources, e.g.
53 ;;
54 ;; pmcid:PMC3498956
55 ;;
56 ;; pmid:23162369
57 ;;
58 ;; and nihmsid:NIHMS395714
59 ;;
60 ;; See http://www.ncbi.nlm.nih.gov/pmc/about/public-access-info/#p3 for details of these identifiers.
61 ;;
62 ;; For PMID there is one interactive function that inserts a bibtex
63 ;; entry: `pubmed-insert-bibtex-from-pmid`.
64 #+END_SRC
65
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.
68
69
70 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
71 (org-add-link-type
72  "pmid"
73  ;; clicking
74  (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pubmed/%s" link-string)))
75  ;; formatting
76 (lambda (keyword desc format)
77    (cond
78     ((eq format 'html)
79      (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s\">pmid:%s</a>" keyword keyword)); no output for html
80     ((eq format 'latex)
81      ;; write out the latex command
82      (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
83 #+END_SRC
84
85
86
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.
89
90
91 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
92 (defun pubmed-get-medline (pmid)
93   "Get MEDLINE text for PMID as a string."
94   (with-current-buffer
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)))))
101 #+END_SRC
102
103 #+RESULTS:
104 : pubmed-get-medline
105
106 Here is sample output:
107 #+BEGIN_SRC emacs-lisp :tangle no
108 (pubmed-get-medline "23162369")
109 #+END_SRC
110
111 #+RESULTS:
112 #+begin_example
113 PMID- 23162369
114 OWN - NLM
115 STAT- Publisher
116 DA  - 20121119
117 IS  - 1040-726X (Print)
118 IS  - 1040-726X (Linking)
119 VI  - 24
120 IP  - 4
121 DP  - 2012 Dec
122 TI  - Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
123       Methods.
124 PG  - 569-608
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
145       and personal growth.
146 FAU - Slavich, George M
147 AU  - Slavich GM
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
152 AU  - Zimbardo PG
153 LA  - ENG
154 GR  - R01 AG026364/AG/NIA NIH HHS/United States
155 GR  - T32 MH019925/MH/NIMH NIH HHS/United States
156 PT  - JOURNAL ARTICLE
157 DEP - 20120724
158 TA  - Educ Psychol Rev
159 JT  - Educational psychology review
160 JID - 9885342
161 PMC - PMC3498956
162 MID - NIHMS395714
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]
168 PST - ppublish
169 SO  - Educ Psychol Rev. 2012 Dec;24(4):569-608. Epub 2012 Jul 24.
170 #+end_example
171
172 ** Parse the PMID MEDLINE data
173 We can parse this into a data structure
174
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."
178   (let ((data '())
179         (p1)
180         (p2)
181         (tag)
182         (value))
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
188                         (setq p1 (point))
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
195                         (goto-char p1)))
196     data))
197 #+END_SRC
198
199 #+RESULTS:
200 : pubmed-parse-medline
201
202 #+BEGIN_SRC emacs-lisp  :tangle no
203 (pubmed-parse-medline "23162369")
204 #+END_SRC
205
206
207
208 ** PMID to bibtex entry
209 The point of parsing the MEDLINE text is so we can make bibtex entries. We only support Journal articles for now.
210
211 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
212 (defun pubmed-pmid-to-bibtex (pmid)
213   "Convert a PMID to a bibtex entry."
214   (let* ((data (pubmed-parse-medline pmid))
215          (type (cdr (assoc "PT" data)))
216          (title (cdr (assoc "TI" data)))
217          (authors (mapconcat 'cdr
218                              (-filter (lambda (x)
219                                         (string= (car x) "FAU"))
220                                       data)
221                              " and "))
222          (abstract (cdr (assoc "AB" data)))
223          (volume (cdr (assoc "VI" data)))
224          (issue (cdr (assoc "IP" data)))
225          (journal (cdr (assoc "JT" data)))
226          (year (cdr (assoc "DP" data)))
227          (pages (cdr (assoc "PG" data)))
228          (aid (cdr (assoc "AID" data))))
229
230     (cond
231      ((string= type "JOURNAL ARTICLE")
232       (concat "@article{,
233  author = {" authors "},
234  title = {" title "},
235  abstract = {" abstract "},
236  journal = {" journal "},
237  volume = {" volume "},
238  number = {" issue "},
239  year = {" (car (split-string year)) "},
240  pages = {" pages "},
241  doi = {" (replace-regexp-in-string " \\[doi\\]" "" aid) "},
242 }"))
243     (t
244      (message "No conversion for type: %s" type)))))
245 #+END_SRC
246
247 #+RESULTS:
248 : pubmed-pmid-to-bibtex
249
250 #+BEGIN_SRC emacs-lisp :tangle no
251 (pubmed-pmid-to-bibtex "23162369")
252 #+END_SRC
253
254 #+RESULTS:
255 #+begin_example
256 @article{,
257  author = {Slavich, George M and Zimbardo, Philip G},
258  title = {Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core
259       Methods.},
260  abstract = {Approaches to classroom instruction have evolved considerably over the past 50
261       years. This progress has been spurred by the development of several learning
262       principles and methods of instruction, including active learning,
263       student-centered learning, collaborative learning, experiential learning, and
264       problem-based learning. In the present paper, we suggest that these seemingly
265       different strategies share important underlying characteristics and can be viewed
266       as complimentary components of a broader approach to classroom instruction called
267       transformational teaching. Transformational teaching involves creating dynamic
268       relationships between teachers, students, and a shared body of knowledge to
269       promote student learning and personal growth. From this perspective, instructors
270       are intellectual coaches who create teams of students who collaborate with each
271       other and with their teacher to master bodies of information. Teachers assume the
272       traditional role of facilitating students' acquisition of key course concepts,
273       but do so while enhancing students' personal development and attitudes toward
274       learning. They accomplish these goals by establishing a shared vision for a
275       course, providing modeling and mastery experiences, challenging and encouraging
276       students, personalizing attention and feedback, creating experiential lessons
277       that transcend the boundaries of the classroom, and promoting ample opportunities
278       for preflection and reflection. We propose that these methods are synergistically
279       related and, when used together, maximize students' potential for intellectual
280       and personal growth.},
281  journal = {Educational psychology review},
282  volume = {24},
283  number = {4},
284  year = {2012},
285  pages = {569-608},
286  doi = {10.1007/s10648-012-9199-6},
287 }
288 #+end_example
289
290 And we probably want to be able to insert a bibtex entry
291
292 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
293 (defun pubmed-insert-bibtex-from-pmid (pmid)
294  "Insert a bibtex entry at point derived from PMID.
295 You must clean the entry after insertion."
296  (interactive "sPMID: ")
297  (insert (pubmed-pmid-to-bibtex pmid)))
298 #+END_SRC
299
300 #+RESULTS:
301 : pubmed-insert-bibtex-from-pmid
302
303 Here is an example of a cleaned entry:
304 #+BEGIN_SRC bibtex :tangle no
305 @article{slavich-2012-trans-teach,
306   author =       {Slavich, George M and Zimbardo, Philip G},
307   title =        {Transformational Teaching: Theoretical
308                   Underpinnings, Basic Principles, and Core Methods.},
309   journal =      {Educational psychology review},
310   volume =       24,
311   number =       4,
312   pages =        {569-608},
313   year =         2012,
314   doi =          {10.1007/s10648-012-9199-6},
315   abstract =     {Approaches to classroom instruction have evolved
316                   considerably over the past 50 years. This progress
317                   has been spurred by the development of several
318                   learning principles and methods of instruction,
319                   including active learning, student-centered
320                   learning, collaborative learning, experiential
321                   learning, and problem-based learning. In the present
322                   paper, we suggest that these seemingly different
323                   strategies share important underlying
324                   characteristics and can be viewed as complimentary
325                   components of a broader approach to classroom
326                   instruction called transformational
327                   teaching. Transformational teaching involves
328                   creating dynamic relationships between teachers,
329                   students, and a shared body of knowledge to promote
330                   student learning and personal growth. From this
331                   perspective, instructors are intellectual coaches
332                   who create teams of students who collaborate with
333                   each other and with their teacher to master bodies
334                   of information. Teachers assume the traditional role
335                   of facilitating students' acquisition of key course
336                   concepts, but do so while enhancing students'
337                   personal development and attitudes toward
338                   learning. They accomplish these goals by
339                   establishing a shared vision for a course, providing
340                   modeling and mastery experiences, challenging and
341                   encouraging students, personalizing attention and
342                   feedback, creating experiential lessons that
343                   transcend the boundaries of the classroom, and
344                   promoting ample opportunities for preflection and
345                   reflection. We propose that these methods are
346                   synergistically related and, when used together,
347                   maximize students' potential for intellectual and
348                   personal growth.},
349 }
350 #+END_SRC
351
352 ** PMID to xml
353 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 &lt; and &gt;, which we have to undo. I have not used this code for anything, so I am not sure how good the xml code is.
354
355 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
356 (defun pubmed-get-medline-xml (pmid)
357   "Get MEDLINE xml for PMID as a string."
358   (interactive)
359   (with-current-buffer
360     (url-retrieve-synchronously
361      (format "http://www.ncbi.nlm.nih.gov/pubmed/%s/?report=xml&format=text" pmid))
362     (goto-char (point-min))
363     (while (search-forward "&lt;" nil t)
364       (replace-match "<"))
365     (goto-char (point-min))
366     (while (search-forward "&gt;" nil t)
367       (replace-match ">"))
368     (goto-char (point-min))
369
370     (let ((p1 (search-forward "<pre>"))
371           (p2 (search-forward "</pre>")))
372       (buffer-substring (+ 1 p1) (- p2 6)))))
373 #+END_SRC
374
375 #+RESULTS:
376 : pubmed-get-medline-xml
377
378 #+BEGIN_SRC emacs-lisp :tangle no
379 (pubmed-get-medline-xml "23162369")
380 #+END_SRC
381
382 #+RESULTS:
383 #+begin_example
384 <PubmedArticle>
385     <MedlineCitation Status="Publisher" Owner="NLM">
386         <PMID Version="1">23162369</PMID>
387         <DateCreated>
388             <Year>2012</Year>
389             <Month>11</Month>
390             <Day>19</Day>
391         </DateCreated>
392         <Article PubModel="Print-Electronic">
393             <Journal>
394                 <ISSN IssnType="Print">1040-726X</ISSN>
395                 <JournalIssue CitedMedium="Print">
396                     <Volume>24</Volume>
397                     <Issue>4</Issue>
398                     <PubDate>
399                         <Year>2012</Year>
400                         <Month>Dec</Month>
401                     </PubDate>
402                 </JournalIssue>
403                 <Title>Educational psychology review</Title>
404                 <ISOAbbreviation>Educ Psychol Rev</ISOAbbreviation>
405             </Journal>
406             <ArticleTitle>Transformational Teaching: Theoretical Underpinnings, Basic Principles, and Core Methods.</ArticleTitle>
407             <Pagination>
408                 <MedlinePgn>569-608</MedlinePgn>
409             </Pagination>
410             <Abstract>
411                 <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>
412             </Abstract>
413             <AuthorList>
414                 <Author>
415                     <LastName>Slavich</LastName>
416                     <ForeName>George M</ForeName>
417                     <Initials>GM</Initials>
418                     <AffiliationInfo>
419                         <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>
420                     </AffiliationInfo>
421                 </Author>
422                 <Author>
423                     <LastName>Zimbardo</LastName>
424                     <ForeName>Philip G</ForeName>
425                     <Initials>PG</Initials>
426                 </Author>
427             </AuthorList>
428             <Language>ENG</Language>
429             <GrantList>
430                 <Grant>
431                     <GrantID>R01 AG026364</GrantID>
432                     <Acronym>AG</Acronym>
433                     <Agency>NIA NIH HHS</Agency>
434                     <Country>United States</Country>
435                 </Grant>
436                 <Grant>
437                     <GrantID>T32 MH019925</GrantID>
438                     <Acronym>MH</Acronym>
439                     <Agency>NIMH NIH HHS</Agency>
440                     <Country>United States</Country>
441                 </Grant>
442             </GrantList>
443             <PublicationTypeList>
444                 <PublicationType UI="">JOURNAL ARTICLE</PublicationType>
445             </PublicationTypeList>
446             <ArticleDate DateType="Electronic">
447                 <Year>2012</Year>
448                 <Month>7</Month>
449                 <Day>24</Day>
450             </ArticleDate>
451         </Article>
452         <MedlineJournalInfo>
453             <MedlineTA>Educ Psychol Rev</MedlineTA>
454             <NlmUniqueID>9885342</NlmUniqueID>
455             <ISSNLinking>1040-726X</ISSNLinking>
456         </MedlineJournalInfo>
457     </MedlineCitation>
458     <PubmedData>
459         <History>
460             <PubMedPubDate PubStatus="epublish">
461                 <Year>2012</Year>
462                 <Month>7</Month>
463                 <Day>24</Day>
464             </PubMedPubDate>
465             <PubMedPubDate PubStatus="entrez">
466                 <Year>2012</Year>
467                 <Month>11</Month>
468                 <Day>20</Day>
469                 <Hour>6</Hour>
470                 <Minute>0</Minute>
471             </PubMedPubDate>
472             <PubMedPubDate PubStatus="pubmed">
473                 <Year>2012</Year>
474                 <Month>11</Month>
475                 <Day>20</Day>
476                 <Hour>6</Hour>
477                 <Minute>0</Minute>
478             </PubMedPubDate>
479             <PubMedPubDate PubStatus="medline">
480                 <Year>2012</Year>
481                 <Month>11</Month>
482                 <Day>20</Day>
483                 <Hour>6</Hour>
484                 <Minute>0</Minute>
485             </PubMedPubDate>
486         </History>
487         <PublicationStatus>ppublish</PublicationStatus>
488         <ArticleIdList>
489             <ArticleId IdType="doi">10.1007/s10648-012-9199-6</ArticleId>
490             <ArticleId IdType="pubmed">23162369</ArticleId>
491             <ArticleId IdType="pmc">PMC3498956</ArticleId>
492             <ArticleId IdType="mid">NIHMS395714</ArticleId>
493         </ArticleIdList>
494         <?nihms?>
495     </PubmedData>
496 </PubmedArticle>
497
498 #+end_example
499
500 * Pubmed Central (PMC) link
501 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.
502
503 Here we define a new link. Clicking on it simply opens a webpage to the article.
504
505 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
506 (org-add-link-type
507  "pmcid"
508  ;; clicking
509  (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/%s" link-string)))
510  ;; formatting
511 (lambda (keyword desc format)
512    (cond
513     ((eq format 'html)
514      (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/%s\">pmcid:%s</a>" keyword keyword))
515     ((eq format 'latex)
516      (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/%s}" keyword)))))
517 #+END_SRC
518
519 * NIHMSID
520 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.
521
522 #+BEGIN_SRC emacs-lisp :tangle pubmed.el :results silent
523 (org-add-link-type
524  "nihmsid"
525  ;; clicking
526  (lambda (link-string) (browse-url (format "http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s" link-string)))
527  ;; formatting
528 (lambda (keyword desc format)
529    (cond
530     ((eq format 'html)
531      (format "<a href=\"http://www.ncbi.nlm.nih.gov/pmc/articles/mid//%s\">nihmsid:%s</a>" keyword keyword))
532     ((eq format 'latex)
533      ;; write out the latex command
534      (format "\\url{http://www.ncbi.nlm.nih.gov/pmc/articles/mid/%s}" keyword)))))
535 #+END_SRC
536
537
538
539
540 * End of code
541 #+BEGIN_SRC emacs-lisp :tangle pubmed.el
542 (provide 'pubmed)
543 #+END_SRC
544
545 * Build                                                            :noexport:
546 This code will tangle the elisp code out to pubmed.el and load it.
547
548 [[elisp:(org-babel-load-file "pubmed.org")]]