Skip to content

Instantly share code, notes, and snippets.

@quwubin
Created February 24, 2013 13:39
Show Gist options
  • Save quwubin/5023882 to your computer and use it in GitHub Desktop.
Save quwubin/5023882 to your computer and use it in GitHub Desktop.
Parse and statistics Medline (PubMed) abstract files
require 'bio'
# Input is abstract file in Medline format.
year_count = Hash.new(0)
File.read(ARGV[0]).split("\n\n").each do |article_block|
article = Bio::MEDLINE.new(article_block)
year_count[article.year] += 1
end
year_count.each do |year, count|
puts "#{year}, #{count}"
end
p year_count.values.inject{|sum, x| sum + x}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment