class Bio::PubMed

Description

The Bio::PubMed class provides several ways to retrieve bibliographic information from the PubMed database at NCBI.

Basically, two types of queries are possible:

Since BioRuby 1.5, all implementations uses NCBI E-Utilities services. The different methods within the same group still remain because specifications of arguments and/or return values are different. The search, query, and pmfetch will be obsoleted in the future.

Additional information about the MEDLINE format and PubMed programmable APIs can be found on the following websites:

Usage

require 'bio'

# If you don't know the pubmed ID:
Bio::PubMed.esearch("(genome AND analysis) OR bioinformatics").each do |x|
  p x
end

Bio::PubMed.search("(genome AND analysis) OR bioinformatics").each do |x|
  p x
end

# To retrieve the MEDLINE entry for a given PubMed ID:
Bio::PubMed.efetch("10592173").each { |x| puts x }
puts Bio::PubMed.query("10592173")
puts Bio::PubMed.pmfetch("10592173")

# To retrieve MEDLINE entries for given PubMed IDs:
Bio::PubMed.efetch([ "10592173", "14693808" ]).each { |x| puts x }
puts Bio::PubMed.query("10592173", "14693808") # returns a String

# This can be converted into a Bio::MEDLINE object:
manuscript = Bio::PubMed.query("10592173")
medline = Bio::MEDLINE.new(manuscript)

Public Class Methods

efetch(*args) click to toggle source

The same as Bio::PubMed.new.efetch(*args).

# File lib/bio/io/pubmed.rb, line 190
def self.efetch(*args)
  self.new.efetch(*args)
end
esearch(*args) click to toggle source

The same as Bio::PubMed.new.esearch(*args).

# File lib/bio/io/pubmed.rb, line 185
def self.esearch(*args)
  self.new.esearch(*args)
end
pmfetch(*args) click to toggle source

This method will be DEPRECATED. Use efetch method.

The same as Bio::PubMed.new.pmfetch(*args).

# File lib/bio/io/pubmed.rb, line 211
def self.pmfetch(*args)
  self.new.pmfetch(*args)
end
query(*args) click to toggle source

This method will be DEPRECATED. Use efetch method.

The same as Bio::PubMed.new.query(*args).

# File lib/bio/io/pubmed.rb, line 204
def self.query(*args)
  self.new.query(*args)
end

Public Instance Methods

efetch(ids, hash = {}) click to toggle source

Retrieve PubMed entry by PMID and returns MEDLINE formatted string using entrez efetch. Multiple PubMed IDs can be provided:

Bio::PubMed.efetch(123)
Bio::PubMed.efetch([123,456,789])

Arguments:

  • ids: list of PubMed IDs (required)

  • hash: hash of E-Utils options

    • _“retmode”_: “xml”, “html”, …

    • _“rettype”_: “medline”, …

    • _“retmax”_: integer (default 100)

    • _“retstart”_: integer

    • _“field”_

    • _“reldate”_

    • _“mindate”_

    • _“maxdate”_

    • _“datetype”_

Returns

Array of MEDLINE formatted String

Calls superclass method Bio::NCBI::REST#efetch
# File lib/bio/io/pubmed.rb, line 116
def efetch(ids, hash = {})
  opts = { "db" => "pubmed", "rettype"  => "medline" }
  opts.update(hash)
  result = super(ids, opts)
  if !opts["retmode"] or opts["retmode"] == "text"
    result = result.split(/\n\n+/)
  end
  result
end
esearch(str, hash = {}) click to toggle source

Search the PubMed database by given keywords using E-Utils and returns an array of PubMed IDs.

For information on the possible arguments, see eutils.ncbi.nlm.nih.gov/entrez/query/static/esearch_help.html#PubMed


Arguments:

  • str: query string (required)

  • hash: hash of E-Utils options

    • _“retmode”_: “xml”, “html”, …

    • _“rettype”_: “medline”, …

    • _“retmax”_: integer (default 100)

    • _“retstart”_: integer

    • _“field”_

    • _“reldate”_

    • _“mindate”_

    • _“maxdate”_

    • _“datetype”_

Returns

array of PubMed IDs or a number of results

Calls superclass method Bio::NCBI::REST#esearch
# File lib/bio/io/pubmed.rb, line 92
def esearch(str, hash = {})
  opts = { "db" => "pubmed" }
  opts.update(hash)
  super(str, opts)
end
pmfetch(id) click to toggle source

This method will be DEPRECATED in the future.

Retrieve PubMed entry by PMID and returns MEDLINE formatted string.


Arguments:

Returns

MEDLINE formatted String

# File lib/bio/io/pubmed.rb, line 173
def pmfetch(id)
  warn "Bio::PubMed#pmfetch internally use Bio::PubMed#efetch. Using Bio::PubMed#efetch is recommended." if $VERBOSE

  ret = efetch(id)
  if ret && ret.size > 0 then
    ret.join("\n\n") + "\n"
  else
    ""
  end
end
query(*ids) click to toggle source

This method will be DEPRECATED in the future.

Retrieve PubMed entry by PMID and returns MEDLINE formatted string using entrez query.


Arguments:

Returns

MEDLINE formatted String

# File lib/bio/io/pubmed.rb, line 155
def query(*ids)
  warn "Bio::PubMed#query internally uses Bio::PubMed#efetch. Using Bio::PubMed#efetch is recommended." if $VERBOSE
  ret = efetch(ids)
  if ret && ret.size > 0 then
    ret.join("\n\n") + "\n"
  else
    ""
  end
end