Module: Entrez

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

Defined Under Namespace

Modules: QueryLimit Classes: UnknownOperator

Constant Summary collapse

VERSION =
"0.5.8"

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:



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

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)



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

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

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

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



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

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.



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

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)



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

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

.optionsObject



5
6
7
# File 'lib/entrez/options.rb', line 5

def options
  @options ||= {respect_query_limit: true}
end

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



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

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