Module: Entrez

Extended by:
QueryLimit
Includes:
HTTParty
Defined in:
lib/entrez.rb,
lib/entrez/version.rb,
lib/entrez/query_limit.rb

Defined Under Namespace

Modules: QueryLimit Classes: UnknownOperator

Constant Summary collapse

VERSION =
"0.5.8.2"

Class Method Summary collapse

Class Method Details

.convert_search_term_hash(hash, operator = 'AND') ⇒ Object

Take a ruby hash and convert it to an ENTREZ search term. E.g. convert_search_term_hash ‘low coverage’, SEQS: ‘inprogress’ #=> ‘low coverageANDinprogress

Raises:



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/entrez.rb', line 48

def convert_search_term_hash(hash, operator = 'AND')
  raise UnknownOperator.new(operator) unless ['AND', 'OR'].include?(operator)
  str = hash.map do |field, value|
    value = value.join(',') if value.is_a?(Array)
    "#{value}[#{field}]"
  end.join("+#{operator}+")
  if operator == 'OR'
    str = "(#{str})"
  end
  str
end

.EFetch(db, params = {}) ⇒ Object

E.g. Entrez.EFetch(‘snp’, id: 123, retmode: :xml)



18
19
20
# File 'lib/entrez.rb', line 18

def EFetch(db, params = {})
  perform '/efetch.fcgi', db, params
end

.EInfo(db, params = {}) ⇒ Object

E.g. Entrez.EInfo(‘gene’, retmode: :xml)



23
24
25
# File 'lib/entrez.rb', line 23

def EInfo(db, params = {})
  perform '/einfo.fcgi', db, params
end

.ESearch(db, search_terms = {}, params = {}) ⇒ Object

E.g. Entrez.ESearch(‘genomeprj’, ‘hapmap’, SEQS: ‘inprogress’, retmode: :xml) search_terms can also be string literal.



29
30
31
32
33
# File 'lib/entrez.rb', line 29

def ESearch(db, search_terms = {}, params = {})
  params[:term] = search_terms.is_a?(Hash) ? convert_search_term_hash(search_terms) : search_terms
  response = perform '/esearch.fcgi', db, params
  response
end

.ESummary(db, params = {}) ⇒ Object

E.g. Entrez.ESummary(‘snp’, id: 123, retmode: :xml)



36
37
38
# File 'lib/entrez.rb', line 36

def ESummary(db, params = {})
  perform '/esummary.fcgi', db, params
end

.perform(utility_path, db, params = {}) ⇒ Object



40
41
42
43
# File 'lib/entrez.rb', line 40

def perform(utility_path, db, params = {})
  respect_query_limit unless ignore_query_limit?
  get utility_path, :query => {db: db}.merge(params)
end