Class: Eutils
- Inherits:
-
Object
- Object
- Eutils
- Defined in:
- lib/eutils.rb
Overview
eutils.einfo
Constant Summary collapse
- EUTILS_HOST =
Global constants
-
EUTILS_INTERVAL
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/"
- EUTILS_INTERVAL =
1.0 / 3.0
- @@last_access =
nil
- @@last_access_mutex =
nil
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#tool ⇒ Object
Returns the value of attribute tool.
Instance Method Summary collapse
-
#efetch(db, webenv, query_key = 1, params = {}) ⇒ Object
EFetch: Retrieves records in the requested format from a list of one or more primary IDs or from the user’s environment.
-
#egquery(term) ⇒ Object
EGQuery: Provides Entrez database counts in XML for a single search using Global Query.
-
#einfo(db = nil) ⇒ Object
EInfo: Provides field index term counts, last update, and available links for each database.
-
#elink(ids, params = {}) ⇒ Object
ELink: Checks for the existence of an external or Related Articles link from a list of one or more primary IDs.
-
#epost(ids, db = "pubmed", params = {}) ⇒ Object
EPost: Posts a file containing a list of primary IDs for future use in the user’s environment to use with subsequent search strategies.
-
#esearch(term, db = "pubmed", params = {}) ⇒ Object
ESearch: Searches and retrieves primary IDs (for use in EFetch, ELink, and ESummary) and term translations and optionally retains results for future use in the user’s environment.
-
#espell(term) ⇒ Object
ESpell: Retrieves spelling suggestions.
-
#esummary(ids, db = "pubmed", params = {}) ⇒ Object
ESummary: Retrieves document summaries from a list of primary IDs or from the user’s environment.
-
#initialize(tool = nil, email = nil) ⇒ Eutils
constructor
A new instance of Eutils.
Constructor Details
#initialize(tool = nil, email = nil) ⇒ Eutils
Returns a new instance of Eutils.
20 21 22 |
# File 'lib/eutils.rb', line 20 def initialize(tool = nil, email = nil) @tool, @email = tool, email end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
17 18 19 |
# File 'lib/eutils.rb', line 17 def email @email end |
#tool ⇒ Object
Returns the value of attribute tool.
17 18 19 |
# File 'lib/eutils.rb', line 17 def tool @tool end |
Instance Method Details
#efetch(db, webenv, query_key = 1, params = {}) ⇒ Object
EFetch: Retrieves records in the requested format from a list of one or more primary IDs or from the user’s environment. See also: eutils.ncbi.nlm.nih.gov/corehtml/query/static/efetch_help.html
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/eutils.rb', line 77 def efetch(db, webenv, query_key = 1, params = {}) params["db"] = db params["WebEnv"] = webenv params["query_key"] = query_key params["retmode"] ||= "xml" params["retstart"] ||= 0 params["retmax"] ||= 10 server = EUTILS_HOST + "efetch.fcgi" response = post_eutils(server, params) if params["retmode"] == "xml" return Hash.from_xml(response) else return response end end |
#egquery(term) ⇒ Object
EGQuery: Provides Entrez database counts in XML for a single search using Global Query. See also: eutils.ncbi.nlm.nih.gov/corehtml/query/static/egquery_help.html
112 113 114 115 116 117 118 119 |
# File 'lib/eutils.rb', line 112 def egquery(term) term.strip! if term.class == String #server = EUTILS_HOST + "egquery.fcgi" server = "http://eutils.ncbi.nlm.nih.gov/gquery/" params = {"term" => term, "retmode" => "xml"} response = post_eutils(server, params) return Hash.from_xml(response)["Result"] end |
#einfo(db = nil) ⇒ Object
EInfo: Provides field index term counts, last update, and available links for each database. See also: eutils.ncbi.nlm.nih.gov/corehtml/query/static/einfo_help.html
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/eutils.rb', line 26 def einfo(db = nil) db.strip! if db.class == String server = EUTILS_HOST + "einfo.fcgi" params = {"db" => db} response = post_eutils(server, params) if db.nil? || db.empty? return response.scan(/<DbName>(\w+)<\/DbName>/).flatten else return Hash.from_xml(response)["eInfoResult"] end end |
#elink(ids, params = {}) ⇒ Object
ELink: Checks for the existence of an external or Related Articles link from a list of one or more primary IDs. Retrieves primary IDs and relevancy scores for links to Entrez databases or Related Articles; creates a hyperlink to the primary LinkOut provider for a specific ID and database, or lists LinkOut URLs and Attributes for multiple IDs. See also: eutils.ncbi.nlm.nih.gov/corehtml/query/static/elink_help.html
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/eutils.rb', line 95 def elink(ids, params = {}) params["id"] = ids.join(",") params["cmd"] ||= "neighbor" params["dbfrom"] ||= "pubmed" params["db"] ||= "pubmed" params["retmode"] ||= "xml" server = EUTILS_HOST + "elink.fcgi" response = post_eutils(server, params) if params["retmode"] == "xml" return Hash.from_xml(response)["eLinkResult"] else return response end end |
#epost(ids, db = "pubmed", params = {}) ⇒ Object
EPost: Posts a file containing a list of primary IDs for future use in the user’s environment to use with subsequent search strategies. See also: eutils.ncbi.nlm.nih.gov/corehtml/query/static/epost_help.html returns: webenv, querykey. Both nil for invalid epost.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/eutils.rb', line 54 def epost(ids, db = "pubmed", params = {}) params["id"] = ids.join(",") params["db"] = db server = EUTILS_HOST + "epost.fcgi" response = post_eutils(server, params) querykey = response.scan(/<QueryKey>(\d+)<\/QueryKey>/).flatten.first.to_i querykey = nil if querykey == 0 webenv = response.scan(/<WebEnv>(\S+)<\/WebEnv>/).flatten.first return webenv, querykey end |
#esearch(term, db = "pubmed", params = {}) ⇒ Object
ESearch: Searches and retrieves primary IDs (for use in EFetch, ELink, and ESummary) and term translations and optionally retains results for future use in the user’s environment. See also: eutils.ncbi.nlm.nih.gov/corehtml/query/static/esearch_help.html eutils.esearch(“autism”)
41 42 43 44 45 46 47 48 49 |
# File 'lib/eutils.rb', line 41 def esearch(term, db = "pubmed", params = {}) term.strip! if term.class == String params["term"] = term params["db"] = db params["usehistory"] ||= "y" server = EUTILS_HOST + "esearch.fcgi" response = post_eutils(server, params) return Hash.from_xml(response)["eSearchResult"] end |
#espell(term) ⇒ Object
ESpell: Retrieves spelling suggestions. See also: eutils.ncbi.nlm.nih.gov/corehtml/query/static/espell_help.html
123 124 125 126 127 128 129 130 131 |
# File 'lib/eutils.rb', line 123 def espell(term) term.strip! if term.class == String server = EUTILS_HOST + "espell.fcgi" params = {"db" => "pubmed", "term" => term} response = post_eutils(server, params) corrected = response.scan(/<CorrectedQuery>(.+)<\/CorrectedQuery>/).flatten.first.to_s corrected = term if corrected.empty? return corrected end |
#esummary(ids, db = "pubmed", params = {}) ⇒ Object
ESummary: Retrieves document summaries from a list of primary IDs or from the user’s environment. See also: eutils.ncbi.nlm.nih.gov/corehtml/query/static/esummary_help.html
67 68 69 70 71 72 73 |
# File 'lib/eutils.rb', line 67 def esummary(ids, db = "pubmed", params = {}) params["id"] = ids.join(",") params["db"] = db server = EUTILS_HOST + "esummary.fcgi" response = post_eutils(server, params) return Hash.from_xml(response)["eSummaryResult"] end |