pubmed_api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69035040fd451f5846e90b7512f6d5b2e68253a6
4
- data.tar.gz: ba519175eb78466e8030b06079e7269864b35a5c
3
+ metadata.gz: dd746c28ff6467d98cc9453f4099ebb3a51be2f5
4
+ data.tar.gz: 466279c7008a90605975055c48e1e011818b4ab8
5
5
  SHA512:
6
- metadata.gz: 68e45eb159acc8ed52bd9bc0641e12a745bb692a4289903222c7e979ac3a8825d5ab94d237eae211b504c0ebf38e6c91cae760607348ac054dae3d7a764d1844
7
- data.tar.gz: dadc39958aab5210b494547cfad68ab00a43b790ab84ee9f5723c468865241c84c9c6b2205bedaa81e5abf8870d8a468dd7931ece13076ff5dc998df5c1f76fb
6
+ metadata.gz: b886ca7fc3aa85f3a60dfd33653b6fff9c8152034550c6b78f2884f74a25dc391b9c00b6f14faf21feab79bb97460a9b4f728029621a7d10b1a2b2078e98b294
7
+ data.tar.gz: 93b6be04e8817a988b8c710d35c22db2c606e98fa6834ef9f08af98b33191c8aba6e4b4779a2a05e0b157245aa9ccbeaa0b69ee327baadc1696a5a2890e3752f
@@ -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
- results
25
+
26
+
27
+ results
25
28
 
26
29
  end
27
30
 
@@ -1,3 +1,3 @@
1
1
  module PubmedAPI
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
- :reldate => 90, #How far back shall we go in days
17
+ #:reldate => 90, #How far back shall we go in days
18
18
  :retmax => 100000,
19
19
  :retstart => 0,
20
- :load_all_pmids => false }
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', :reldate => '100000'})
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
@@ -4,19 +4,25 @@ describe PubmedAPI do
4
4
 
5
5
 
6
6
  it "should perform a search" do
7
- strucs = PubmedAPI::Interface.search("quantum physics", {:load_all_pmids => true, :reldate => 90})
8
- expect(strucs.length > 10)
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
- options = PubmedAPI::Interface::DEFAULT_OPTIONS
13
- options.merge({:query => 'term=scrotum'})
14
-
15
- doc = PubmedAPI::Interface.make_api_request(options)
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 == count)
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?(title))
29
- expect(paper.pmid.eql?(id))
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?(title))
38
- expect(j.nlmid.eql?(id))
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('16930290R')
43
- expect( fixed.eql?('100381'))
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.1
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-04-28 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler