Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > Linux > pubfind.el, search/get pubmed/hubmed bibtex entry
【标  题】:pubfind.el, search/get pubmed/hubmed bibtex entry
【关键字】:pubfind.el,search/get,pubmed/hubmed,bibtex,entry
【来  源】:http://blog.chinaunix.net/article.php?articleId=18073&blogId=5433

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

Your Ad Here 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 "^[ \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


《魔兽世界》教你做人的11条哲理:【上一篇】
webmin忘记密码怎么办呀:【下一篇】
【相关文章】
  • linux proc 文件系统下 entry 的解释
  • Linux系统中PortSentry的安装和配置
  • PortSentry实战
  • 简单算法——飘雪PXQQ V1.0(Softsentry保护)
  • 【随机文章】
  • 读VC++内幕之体悟 - 02
  • MQC on subinterface
  • QQ2005新春贺岁版详评(1)
  • 在P630中AIX5.1系统由64位转换成32位模式
  • 在VMWare中运行FreeBSD时的时钟同步问题
  • 比较一组数的大小,输出最大者
  • ISDN术语解释
  • 发现之旅!
  • NAND和NOR flash的区别
  • 关于Session的一点认识
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.