Class: PubmedSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/pubmed_search.rb

Constant Summary collapse

WAIT_TIME =

seconds

1
DEFAULT_OPTIONS =
{:retmax => 100000,
:retstart => 0,
:tool => 'ruby-pubmed_search',
:email => '',
:load_all_pmids => false }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#countObject

The Count field returned by your search. If pmids < count, then you need to look at your retmax or try load_all_pmids



13
14
15
# File 'lib/pubmed_search.rb', line 13

def count
  @count
end

#exploded_mesh_termsObject

Get the list of MeSH terms that PubMed exploded. For more information on MeSH term explosion, see www.pubmedcentral.nih.gov/articlerender.fcgi?artid=2651214#id443777



16
17
18
# File 'lib/pubmed_search.rb', line 16

def exploded_mesh_terms
  @exploded_mesh_terms
end

#phrases_not_foundObject

Get the list of PhraseNotFound terms returned by your search



19
20
21
# File 'lib/pubmed_search.rb', line 19

def phrases_not_found
  @phrases_not_found
end

#pmidsObject

Get the list of Pubmed IDs returned by this esearch as an Array of Numbers



10
11
12
# File 'lib/pubmed_search.rb', line 10

def pmids
  @pmids
end

Class Method Details

.search(term, options = {}) ⇒ Object

Performs a search to PubMed via eUtils with the given term String, and returns a PubmedSearch object modeling the response.

Accepts a Hash of options. Valid options are

  • :retmax - Defaults to 100,000 which is the largest retmax that PubMed will honor.

  • :retstart - Defaults to 0. Set higher if you need to page through results. You shouldn’t need to do that manually, because of the load_all_pmids option

  • :tool - Defaults to ‘ruby-pubmed_search’, set to the name of your tool per EUtils parameters specs

  • :email - Defaults to ”, set to your email address per EUtils parameters specs

  • :load_all_pmids - Defaults to false. If this is set true, then search will continue sending eSearches with an increasing retstart until the list of pmids == count. For instance, an eSearch for “Mus musculus” will return ~951134 results, but the highest retmax allowable is 100000. With load_all_pmids set true, search will automatically perform 10 eSearches and return the entire list of pmids in one go.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pubmed_search.rb', line 39

def search(term, options={})
  options = DEFAULT_OPTIONS.merge(options)

  results = do_search(new, term, options)

  if options[:load_all_pmids]
    # Send off subsequent requests to load all the PMIDs, add them to the results
    (options[:retmax]..results.count).step(options[:retmax]) do |step|
      do_search(results, term, options.merge({:retstart => step}))
    end 
  end

  results
end

.skip_wait=(setting) ⇒ Object

Setting this to true will prevent PubmedSearch from pausing before sending requests to PubMed. This is a fantastic way to get yourself banned from eUtils.

I only use this for testing.



63
64
65
# File 'lib/pubmed_search.rb', line 63

def skip_wait=(setting)
  @skip_wait = setting
end

.waitObject

As of May 2009, PubMed requires a 300ms pause between eUtils calls. It used to be 3 seconds. PubmedSearch pauses for 1 second just to be on the safe side.



56
57
58
# File 'lib/pubmed_search.rb', line 56

def wait
  sleep WAIT_TIME unless @skip_wait
end