pubfind.el, search/get pubmed/hubmed bibtex entry

发表于:2007-07-04来源:作者:点击数: 标签:
pubfind.el 是用于emacs中的PubMed/HubMed客户端。 pubfind.el is a PubMed/HubMed client in emacs. 这是我第一个elisp脚本。现在我可以不离开emacs而检索PubMed并通过HubMed的cgi程序获得文献的bibtex信息。文件源码如下: This is my first elisp script. N
pubfind.el 是用于emacs中的PubMed/HubMed客户端。
pubfind.el is a PubMed/HubMed client in emacs.

这是我第一个elisp脚本。现在我可以不离开emacs而检索PubMed并通过HubMed的cgi程序获得文献的bibtex信息。文件源码如下:
This is my first elisp script. Now I can search pubmed then get bibtex entry from cgi of hubmed in emacs. I attached the source code below:

;;; pubfind.el --- Client to search/get BibTeX entries from the web

;; Copyright 2005 by Tao Liu
;; Author: Tao Liu
;; Created: Jan 18, 2005
;; Url: http://www.freewebs.com/liut/src/pubfind.el
;; RCS $Id: pubfind.el,v 1.4 2005/01/20 03:03:12 fred Exp fred $

;; 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.


;;; Commentary:
;; This packages provides an Emacs Lisp interface to
;; searching/obtaining BibTeX entry from the online source.
;; Currently concerned source isv
;;
;; o NCBI entrez
;; o HubMed
;;
;; On invocation, the function pubfind-get-by-query queries the user
;; for a journal, volume and page, then return the corresponding
;; BibTeX entry. While pubfind-get-by-id fetches the BibteX entry
;; aclearcase/" target="_blank" >ccording to the given pubmed id. The result will be a bibtex-mode
;; buffer with the results parsed out.

;;; Usage:
;;
;; byte-compile-file and put it in your load-path. In your
;; initialization file:
;;
;; (require 'pubfind)
;;
;; M-x pubfind-get-by-id/pubfind-get-by-query invokes the interface.

;;; Acknowledge:
;; This work is inspired by Nevin Kapur's `bibfind.el'.
;; You can download it here:
;; http://www.cs.caltech.edu/~nkapur/emacs/bibfind.el


;;; Code:
;;(require 'url-handlers)
(require 'url-cookie)
(require 'bibtex)

(defconst pubfind-version "1.03.1"
"pubfind version.")

(defvar pubfind-bibtex-buffer "*Pubfind bibTeX Results*"
"Buffer for Pubfind bibTeX Results.")

(defvar pubfind-use-font-lock t
"Whether to fontify the results.")

(defconst pubfind-journal-sources
'("Science" "Cell"
"Nature" "Nat Rev Genet" "Nat Genet" "Nat Biotech"
"Bioinformatics" "Nucl Acids Res" "Genome Res"
"PNAS" "Science"
)
"List of common journal abbreviations to search:
Science Science
Cell Cell
Nature Nature
Nat Rev Genet Nature Review Genetics
Nat Genet Nature Genetics
Nat Biotechnol Nature Biotechnology
Bioinformatics Bioinformatics
Nucl Acids Res Nucleic Acids Research
PNAS Proceedings of the National Academy of Sciences of the United States of America
Genome Res Genome Research
")

;;;###autoload
(defun pubfind-get-by-id ()
"Get bibTeX entry interactively."
(interactive)
(let* ((pubmed-id (read-string "pubmed-id: "))
(completion-ignore-case t))
(cond
((string-match "^[ \t]*$" pubmed-id)
(error
"pubfind error: pubmed id must be given."))
((pubfind-get-run pubmed-id)))))

;;;###autoload
(defun pubfind-get-by-query ()
"Search then get entry interactively."
(interactive)
(let* ((journal (completing-read "Journal (TAB for some completion): "
(mapcar 'list pubfind-journal-sources)))
(volume (read-string "Volume: "))
(page (read-string "Page: "))
(completion-igore-case t))
(cond
((or
(string-match "^[ \t]*$" journal)
(string-match "^[ \t]*$" volume)
(string-match "^[ \t]*$" page))
(error
"pubsearch error: None of journal, volume or page should be blank."))
((pubfind-search-run journal volume page)))))

;; Talk to HubMed/PubMed.
(defun pubfind-get-run ( pubmed-id )
"Run the HubMed client."
(pop-to-buffer pubfind-bibtex-buffer)
(erase-buffer)
(if (string= pubmed-id "0")
(insert "Sorry, no matches")
(progn
(pubfind-get-fetch pubmed-id)
(pubfind-treat-buffer pubfind-bibtex-buffer))))

(defun pubfind-search-run ( journal volume page)
"Run the NCBI search client."
(pop-to-buffer pubfind-bibtex-buffer)
(erase-buffer)
(pubfind-search-query journal volume page)
(pubfind-search-wash))

;; Clients
(defun pubfind-get-fetch ( pubmed-id )
"Fetch data and print it in the current buffer."
(let* ((url (concat
"http://www.hubmed.org/export/bibtex.cgi?";
"uids=" pubmed-id)))
(url-insert-file-contents url)))

(defun pubfind-search-query ( journal volume page)
"Query and print in the current buffer."
(let* ((url (pubfind-format
(concat
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&;retmax=1&"
"term="
journal "[ta]"
volume "[vi]"
page "[pg]"))))
;; I don't want the followingi two lines, but the windoz proxy server
;; in BGI needs one more fuck to be activated! Any good idea?
(url-insert-file-contents url)
(erase-buffer)

(url-insert-file-contents url)))

;; Wash functions

(defun pubfind-search-wash ()
"Wash the search result."
(goto-char (point-min))
(let ((case-fold-search t))
;; I only keep the first hit.
(if (re-search-forward "\([0-9]+\)" nil t)
(let* ((searched-id (match-string 1)))
(pubfind-get-run searched-id))
(let* ((searched-id "0"))
(pubfind-get-run searched-id)))))

;; Utility functions

(defun pubfind-format (url)
"Replace ' ' with '%20'"
(while (string-match "[ \t]+" url)
(setq url (replace-match "%20" nil t url)))
(eval url))

(defun pubfind-treat-buffer (buffer)
"Treat buffer with bib entries."
(with-current-buffer buffer
(bibtex-mode)
(when pubfind-use-font-lock
(font-lock-fontify-buffer))
(goto-char (point-min))
(setq buffer-file-name nil)))

(provide 'pubfind)

;;; pubfind.el ends here


原文转自:http://www.ltesting.net