biorubyPubMed.rb :

#!/usr/bin/env ruby
require 'rubygems'
# Import BioRuby package
require 'bio'

# USAGE:
#   ruby ./biorubyPubMed.rb BRCA1
# Where BRCA1 is some keyword. You can provide multiple space-separated keywords if you want.

# Retrieves pubmed records matching search terms


# grab words from command line, to make search-term string
terms = ARGV.join(' ')

# Options hash. Don't return records older than May 31, 2000,
# and max of 10 pubmed records.
options = {
  'maxdate' => '2000/05/31',
  'retmax' => 10
}

# Use PubMed esearch interface...give terms and options
$stderr.puts "STATUS: Contacting PubMed...hang on..."
results = Bio::PubMed.esearch(terms, options)
# Have list of id's, lets fetch the actual records
retrieved = Bio::PubMed.efetch(results)
# For each actual record, format as Medline reference and print some stuff.
retrieved.each { |entry|
  medline = Bio::MEDLINE.new(entry)
  ref = medline.reference
  puts "#{ref.authors}\t#{ref.title}\t#{ref.year}\t#{ref.journal}\n#{ref.abstract}\n\n"
}