pubmed_api 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pubmed_api/parsers.rb +4 -1
- data/lib/pubmed_api/version.rb +1 -1
- data/lib/pubmed_api.rb +20 -5
- data/spec/lib/pubmed_api_spec.rb +26 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd746c28ff6467d98cc9453f4099ebb3a51be2f5
|
4
|
+
data.tar.gz: 466279c7008a90605975055c48e1e011818b4ab8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b886ca7fc3aa85f3a60dfd33653b6fff9c8152034550c6b78f2884f74a25dc391b9c00b6f14faf21feab79bb97460a9b4f728029621a7d10b1a2b2078e98b294
|
7
|
+
data.tar.gz: 93b6be04e8817a988b8c710d35c22db2c606e98fa6834ef9f08af98b33191c8aba6e4b4779a2a05e0b157245aa9ccbeaa0b69ee327baadc1696a5a2890e3752f
|
data/lib/pubmed_api/parsers.rb
CHANGED
@@ -9,6 +9,7 @@ module PubmedAPI
|
|
9
9
|
results = SearchResult.new
|
10
10
|
results.pmids = []
|
11
11
|
results.mesh_terms = []
|
12
|
+
results.phrases_not_found = []
|
12
13
|
|
13
14
|
results.count = doc.xpath('/eSearchResult/Count').first.content.to_i
|
14
15
|
|
@@ -21,7 +22,9 @@ module PubmedAPI
|
|
21
22
|
end
|
22
23
|
|
23
24
|
doc.xpath('/eSearchResult/ErrorList/PhraseNotFound').each {|n| results.phrases_not_found << n.content }
|
24
|
-
|
25
|
+
|
26
|
+
|
27
|
+
results
|
25
28
|
|
26
29
|
end
|
27
30
|
|
data/lib/pubmed_api/version.rb
CHANGED
data/lib/pubmed_api.rb
CHANGED
@@ -14,10 +14,10 @@ module PubmedAPI
|
|
14
14
|
:database => 'pubmed', #which database eq pubmed/nlmcatalog
|
15
15
|
:verb => 'search', #which API verb to use e.g. search/fetch
|
16
16
|
:email => '',
|
17
|
-
|
17
|
+
#:reldate => 90, #How far back shall we go in days
|
18
18
|
:retmax => 100000,
|
19
19
|
:retstart => 0,
|
20
|
-
:load_all_pmids =>
|
20
|
+
:load_all_pmids => true }
|
21
21
|
|
22
22
|
|
23
23
|
URI_TEMPLATE = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/e{verb}.fcgi?db={database}&tool={tool}&email={email}'+
|
@@ -86,7 +86,6 @@ module PubmedAPI
|
|
86
86
|
|
87
87
|
#Maked the HTTP request and return the responce
|
88
88
|
#TODO handle failures
|
89
|
-
#Log API calls?
|
90
89
|
def make_api_request(options)
|
91
90
|
url = expand_uri(URI_TEMPLATE, options)
|
92
91
|
Nokogiri::XML( open url )
|
@@ -94,11 +93,10 @@ module PubmedAPI
|
|
94
93
|
|
95
94
|
|
96
95
|
#Some journals have odd NLMIDs that need to be searched for rarther than accessed directly.
|
97
|
-
#TODO combine into single API request
|
98
96
|
def convert_odd_journal_ids(id)
|
99
97
|
|
100
98
|
new_id = nil
|
101
|
-
results = search(id, {:database => 'nlmcatalog'
|
99
|
+
results = search(id, {:database => 'nlmcatalog'})
|
102
100
|
if results.pmids.length ==1
|
103
101
|
new_id = results.pmids[0]
|
104
102
|
else
|
@@ -107,6 +105,23 @@ module PubmedAPI
|
|
107
105
|
new_id.to_s
|
108
106
|
end
|
109
107
|
|
108
|
+
|
109
|
+
def get_journal_id_from_issn(issn)
|
110
|
+
|
111
|
+
id = nil
|
112
|
+
term = issn + "[ISSN]+AND+ncbijournals[filter]"
|
113
|
+
|
114
|
+
results = search(term, {:database => 'nlmcatalog'})
|
115
|
+
if results.pmids.length ==1
|
116
|
+
id = results.pmids[0]
|
117
|
+
else
|
118
|
+
puts "failed to find " + issn.to_s
|
119
|
+
end
|
120
|
+
|
121
|
+
id.to_s
|
122
|
+
end
|
123
|
+
|
124
|
+
|
110
125
|
# 300ms minimum wait.
|
111
126
|
def wait
|
112
127
|
sleep WAIT_TIME
|
data/spec/lib/pubmed_api_spec.rb
CHANGED
@@ -4,19 +4,25 @@ describe PubmedAPI do
|
|
4
4
|
|
5
5
|
|
6
6
|
it "should perform a search" do
|
7
|
-
|
8
|
-
expect(
|
7
|
+
results = PubmedAPI::Interface.search("quantum physics", {:reldate => 90})
|
8
|
+
expect(results.pmids.length).to be > 10
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should handle phrases not found" do
|
12
|
+
title = "Electron-Vibrational Coupling in the Fenna-Matthews-Olson Complex of Prosthecochloris a estuarii Determined by Temperature-Dependent Absorption and Fluorescence Line-Narrowing Measurements"
|
13
|
+
results = PubmedAPI::Interface.search( title, {:load_all_pmids => true})
|
14
|
+
expect(results.phrases_not_found).to eql(["estuarii"])
|
9
15
|
end
|
10
16
|
|
11
17
|
it "should make an API call" do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
records = doc.xpath('
|
18
|
+
options = PubmedAPI::Interface::DEFAULT_OPTIONS
|
19
|
+
options = options.merge({:query => 'term=scrotum'})
|
20
|
+
|
21
|
+
doc = PubmedAPI::Interface.make_api_request(options)
|
22
|
+
records = doc.xpath('/eSearchResult/IdList/Id')
|
17
23
|
count = doc.xpath('/eSearchResult/Count').first.content.to_i
|
18
|
-
expect(count > 0
|
19
|
-
expect(records.length
|
24
|
+
expect(count).to be > 0
|
25
|
+
expect(records.length).to eql(count)
|
20
26
|
end
|
21
27
|
|
22
28
|
|
@@ -25,8 +31,8 @@ describe PubmedAPI do
|
|
25
31
|
title = "Completing the picture for the smallest eigenvalue of real Wishart matrices."
|
26
32
|
strucs = PubmedAPI::Interface.fetch_papers([id])
|
27
33
|
paper = strucs[0]
|
28
|
-
expect(paper.title.eql
|
29
|
-
expect(paper.pmid.eql
|
34
|
+
expect(paper.title).to eql(title)
|
35
|
+
expect(paper.pmid).to eql(id)
|
30
36
|
end
|
31
37
|
|
32
38
|
it "should fetch a journal" do
|
@@ -34,13 +40,18 @@ describe PubmedAPI do
|
|
34
40
|
title = 'Physical review letters.'
|
35
41
|
strucs = PubmedAPI::Interface.fetch_journals([id])
|
36
42
|
j = strucs[0]
|
37
|
-
expect(j.title_long.eql
|
38
|
-
expect(j.nlmid.eql
|
43
|
+
expect(j.title_long).to eql(title)
|
44
|
+
expect(j.nlmid).to eql(id)
|
39
45
|
end
|
40
46
|
|
41
47
|
it "it should fix strange journal ids" do
|
42
|
-
fixed = PubmedAPI::Interface.convert_odd_journal_ids('
|
43
|
-
expect(
|
48
|
+
fixed = PubmedAPI::Interface.convert_odd_journal_ids('19620690R')
|
49
|
+
expect(fixed).to eql('100381')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "it should get journal id from issn" do
|
53
|
+
fixed = PubmedAPI::Interface.get_journal_id_from_issn('1361-6633')
|
54
|
+
expect(fixed).to eql('100381')
|
44
55
|
end
|
45
56
|
|
46
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubmed_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kieran Higgins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|