Skip to content

Instantly share code, notes, and snippets.

@neilfws
Last active July 5, 2017 14:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neilfws/d5330c7c7da3268698f6 to your computer and use it in GitHub Desktop.
Save neilfws/d5330c7c7da3268698f6 to your computer and use it in GitHub Desktop.
BioRuby: convert a PubMed PMID to BibTeX citation format
# pmid2bibtex.rb
# convert a PubMed PMID to BibTeX citation format
# updated version of http://chrisamiller.com/science/2010/12/13/using-bioruby-to-fetch-citations-from-pubmed/
# works as of 2015-03-18
require 'bio'
Bio::NCBI.default_email = "me@me.com" # required for EUtils
id = "18265351"
pm = Bio::PubMed::efetch(id) # array of MEDLINE-formatted string
med = Bio::MEDLINE.new(pm[0]) # MEDLINE object
bib = med.reference.format("bibtex") # format is a method of Reference object
# "@article{PMID:18265351,\n author = {Brown, T. and Mackey, K. and Du, T.},\n title = {Analysis of RNA by northern
# and slot blot hybridization.},\n journal = {Curr Protoc Mol Biol},\n year = {2004},\n volume = {Chapter
# 4},\n pages = {Unit 4.9},\n url = {http://www.ncbi.nlm.nih.gov/pubmed/18265351},\n}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment