entrez 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +27 -7
- data/lib/entrez.rb +16 -0
- data/lib/entrez/version.rb +1 -1
- data/lib/query_string_normalizer.rb +12 -0
- data/spec/entrez_spec.rb +10 -5
- data/spec/query_string_normalizer_spec.rb +10 -0
- metadata +5 -2
data/README.rdoc
CHANGED
@@ -13,20 +13,39 @@ or if you use Bundler:
|
|
13
13
|
|
14
14
|
It requires httparty.
|
15
15
|
|
16
|
+
See 'Email & Tool' section below for setup.
|
17
|
+
|
16
18
|
== Usage
|
17
19
|
|
18
|
-
|
20
|
+
(You can copy/paste the resulting following request URLs into a browser to see what the response would be.)
|
21
|
+
|
22
|
+
=== EFetch, ESummary
|
23
|
+
|
24
|
+
args:
|
25
|
+
* database
|
26
|
+
* params hash
|
27
|
+
|
28
|
+
Entrez.EFetch('snp', id: 123, retmode: :xml)
|
29
|
+
#=> makes request to http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=snp&id=9268480&retmode=xml
|
30
|
+
#=> returns XML document with SNP rs9268480 data.
|
31
|
+
|
32
|
+
ESummary takes the same arguments.
|
19
33
|
|
20
|
-
|
34
|
+
=== ESearch
|
21
35
|
|
22
|
-
|
36
|
+
args:
|
37
|
+
* database
|
38
|
+
* term hash
|
39
|
+
* params hash
|
23
40
|
|
24
|
-
|
25
|
-
|
41
|
+
Entrez.ESearch('genomeprj', {WORD: 'hapmap', SEQS: 'inprogress'}, retmode: :xml)
|
42
|
+
#=> makes request to http://http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=genomeprj&term=hapmap[WORD]+AND+inprogress[SEQS]&retmode=xml
|
43
|
+
#=> returns XML document with list of Ids of genome projects that match the searc term criteria
|
44
|
+
#=> i.e. genome projects that have 'hapmap' in the description and whose sequencing status is 'inprogress'.
|
26
45
|
|
27
46
|
== Email & Tool
|
28
47
|
|
29
|
-
NCBI
|
48
|
+
NCBI asks that you supply the tool you are using and your email.
|
30
49
|
The Entrez gem uses 'ruby' as the tool.
|
31
50
|
Email is obtained from an environment variable ENTREZ_EMAIL on your computer.
|
32
51
|
I set mine in my ~/.bash_profile:
|
@@ -42,8 +61,9 @@ The amount of delay time is no more than what is necessary to make the next requ
|
|
42
61
|
|
43
62
|
* EFetch
|
44
63
|
* ESummary
|
64
|
+
* ESearch
|
45
65
|
|
46
|
-
Not yet implemented: EInfo, EPost,
|
66
|
+
Not yet implemented: EInfo, EPost, ELink, EGQuery, ESpell.
|
47
67
|
|
48
68
|
== Compatibility
|
49
69
|
|
data/lib/entrez.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'httparty'
|
2
|
+
require 'query_string_normalizer'
|
2
3
|
|
3
4
|
class Entrez
|
4
5
|
|
5
6
|
include HTTParty
|
6
7
|
base_uri 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils'
|
7
8
|
default_params tool: 'ruby', email: (ENV['ENTREZ_EMAIL'] || raise('please set ENTREZ_EMAIL environment variable'))
|
9
|
+
query_string_normalizer QueryStringNormalizer
|
8
10
|
|
9
11
|
class << self
|
10
12
|
|
@@ -16,6 +18,11 @@ class Entrez
|
|
16
18
|
perform '/esummary.fcgi', db, params
|
17
19
|
end
|
18
20
|
|
21
|
+
def ESearch(db, search_terms = {}, params = {})
|
22
|
+
params[:term] = convert_search_term_hash(search_terms)
|
23
|
+
perform '/esearch.fcgi', db, params
|
24
|
+
end
|
25
|
+
|
19
26
|
def perform(utility_path, db, params = {})
|
20
27
|
respect_query_limit
|
21
28
|
request_times << Time.now.to_f
|
@@ -40,6 +47,15 @@ class Entrez
|
|
40
47
|
@request_times ||= []
|
41
48
|
end
|
42
49
|
|
50
|
+
# Take a ruby hash and convert it to an ENTREZ search term.
|
51
|
+
# E.g. convert_search_term_hash {WORD: 'low coverage', SEQS: 'inprogress'}
|
52
|
+
# #=> 'low coverage[WORD]+AND+inprogress[SEQS]'
|
53
|
+
def convert_search_term_hash(hash)
|
54
|
+
hash.map do |field, value|
|
55
|
+
"#{value}[#{field}]"
|
56
|
+
end.join('+AND+')
|
57
|
+
end
|
58
|
+
|
43
59
|
end
|
44
60
|
|
45
61
|
end
|
data/lib/entrez/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
# We need a simple normalizer that will not URI escape []s.
|
2
|
+
QueryStringNormalizer = proc do |query_hash|
|
3
|
+
query_hash.map do |key, value|
|
4
|
+
value_string = case value
|
5
|
+
when Array
|
6
|
+
value.join(',')
|
7
|
+
else
|
8
|
+
value
|
9
|
+
end
|
10
|
+
"#{key}=#{value_string}"
|
11
|
+
end.join('&')
|
12
|
+
end
|
data/spec/entrez_spec.rb
CHANGED
@@ -8,17 +8,22 @@ describe Entrez do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it '#EFetch retrieves results' do
|
11
|
-
response = Entrez.EFetch('
|
12
|
-
response.
|
11
|
+
response = Entrez.EFetch('taxonomy', id: 9606, retmode: :xml)
|
12
|
+
response.body.should include('Homo sapiens')
|
13
13
|
end
|
14
14
|
|
15
15
|
it '#ESummary retrieves results' do
|
16
|
-
response = Entrez.ESummary('genomeprj',
|
17
|
-
response.
|
16
|
+
response = Entrez.ESummary('genomeprj', id: 28911)
|
17
|
+
response.body.should include('Hapmap')
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#ESearch retrieves results' do
|
21
|
+
response = Entrez.ESearch('genomeprj', {WORD: 'hapmap', SEQS: 'inprogress'}, retmode: :xml)
|
22
|
+
response.body.should include('28911')
|
18
23
|
end
|
19
24
|
|
20
25
|
it 'should respect query limit' do
|
21
|
-
requests = proc { 4.times { Entrez.EFetch('
|
26
|
+
requests = proc { 4.times { Entrez.EFetch('taxonomy', id: 9606) } }
|
22
27
|
requests.should take_longer_than(1.0)
|
23
28
|
end
|
24
29
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: entrez
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.4.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jared Ning
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-19 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -54,7 +54,9 @@ files:
|
|
54
54
|
- entrez.gemspec
|
55
55
|
- lib/entrez.rb
|
56
56
|
- lib/entrez/version.rb
|
57
|
+
- lib/query_string_normalizer.rb
|
57
58
|
- spec/entrez_spec.rb
|
59
|
+
- spec/query_string_normalizer_spec.rb
|
58
60
|
- spec/spec_helper.rb
|
59
61
|
- spec/support/macros.rb
|
60
62
|
- spec/support/matchers.rb
|
@@ -88,6 +90,7 @@ specification_version: 3
|
|
88
90
|
summary: HTTP requests to Entrez E-utilities
|
89
91
|
test_files:
|
90
92
|
- spec/entrez_spec.rb
|
93
|
+
- spec/query_string_normalizer_spec.rb
|
91
94
|
- spec/spec_helper.rb
|
92
95
|
- spec/support/macros.rb
|
93
96
|
- spec/support/matchers.rb
|