免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1497 | 回复: 0
打印 上一主题 下一主题

pubfind.el, search/get pubmed/hubmed bibtex entry [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-28 10:40 |只看该作者 |倒序浏览
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
;; according 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 "^[         ]*$" 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 "^[         ]*$" journal)
       (string-match "^[         ]*$" volume)
       (string-match "^[         ]*$" 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 "[         ]+" 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


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/5433/showart_18073.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP