bio-old-biofetch-emulator 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.travis.yml +13 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +20 -0
- data/README.md +47 -0
- data/README.rdoc +48 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/bio-old-biofetch-emulator.rb +12 -0
- data/lib/bio-old-biofetch-emulator/emulator.rb +415 -0
- data/test/helper.rb +35 -0
- data/test/test_bio-old-biofetch-emulator.rb +96 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1acb392f7fea461ab1f0be3309f787a0bcc12cd7
|
4
|
+
data.tar.gz: 7ea00a53bcfb15ff82c7a868bfba893153b50476
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b83d93062361505b405e173cc87a955ec946d3111273b278348f20d56ed275650e83f2c4eb7c3ef8f1f861572b06b9c75c82d3f0a8a5cfa8339cdf10999b6f60
|
7
|
+
data.tar.gz: ab26f02e799f83c75f7d849572312eca527d648db9f3a1420652c2b5673c134f847ba396852f370c67a08a6bf102d6404101b21b8dc9446290df4fc1f95952a1
|
data/.document
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.2
|
4
|
+
- 1.9.3
|
5
|
+
- jruby-19mode # JRuby in 1.9 mode
|
6
|
+
|
7
|
+
# - rbx-19mode
|
8
|
+
# - 1.8.7
|
9
|
+
# - jruby-18mode # JRuby in 1.8 mode
|
10
|
+
# - rbx-18mode
|
11
|
+
|
12
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
13
|
+
# script: bundle exec rspec spec
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "bio", ">= 1.4.2"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rake"
|
12
|
+
gem "rdoc"
|
13
|
+
gem "jeweler"
|
14
|
+
gem "bundler", ">= 1.0.21"
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Naohisa Goto
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# bio-old-biofetch-emulator
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/ngoto/bioruby-old-biofetch-emulator.png)](http://travis-ci.org/ngoto/bioruby-old-biofetch-emulator)
|
4
|
+
|
5
|
+
Full description goes here
|
6
|
+
|
7
|
+
Note: this software is under active development!
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```sh
|
12
|
+
gem install bio-old-biofetch-emulator
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'bio-old-biofetch-emulator'
|
19
|
+
```
|
20
|
+
|
21
|
+
The API doc is online. For more code examples see the test files in
|
22
|
+
the source tree.
|
23
|
+
|
24
|
+
## Project home page
|
25
|
+
|
26
|
+
Information on the source tree, documentation, examples, issues and
|
27
|
+
how to contribute, see
|
28
|
+
|
29
|
+
http://github.com/ngoto/bioruby-old-biofetch-emulator
|
30
|
+
|
31
|
+
The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
|
32
|
+
|
33
|
+
## Cite
|
34
|
+
|
35
|
+
If you use this software, please cite one of
|
36
|
+
|
37
|
+
* [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
|
38
|
+
* [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
|
39
|
+
|
40
|
+
## Biogems.info
|
41
|
+
|
42
|
+
This Biogem is published at (http://biogems.info/index.html#bio-old-biofetch-emulator)
|
43
|
+
|
44
|
+
## Copyright
|
45
|
+
|
46
|
+
Copyright (c) 2014 Naohisa Goto. See LICENSE.txt for further details.
|
47
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= bio-old-biofetch-emulator
|
2
|
+
|
3
|
+
{<img
|
4
|
+
src="https://secure.travis-ci.org/ngoto/bioruby-old-biofetch-emulator.png"
|
5
|
+
/>}[http://travis-ci.org/#!/ngoto/bioruby-old-biofetch-emulator]
|
6
|
+
|
7
|
+
Full description goes here
|
8
|
+
|
9
|
+
Note: this software is under active development!
|
10
|
+
|
11
|
+
== Installation
|
12
|
+
|
13
|
+
gem install bio-old-biofetch-emulator
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
== Developers
|
18
|
+
|
19
|
+
To use the library
|
20
|
+
|
21
|
+
require 'bio-old-biofetch-emulator'
|
22
|
+
|
23
|
+
The API doc is online. For more code examples see also the test files in
|
24
|
+
the source tree.
|
25
|
+
|
26
|
+
== Project home page
|
27
|
+
|
28
|
+
Information on the source tree, documentation, issues and how to contribute, see
|
29
|
+
|
30
|
+
http://github.com/ngoto/bioruby-old-biofetch-emulator
|
31
|
+
|
32
|
+
The BioRuby community is on IRC server: irc.freenode.org, channel: #bioruby.
|
33
|
+
|
34
|
+
== Cite
|
35
|
+
|
36
|
+
If you use this software, please cite one of
|
37
|
+
|
38
|
+
* [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
|
39
|
+
* [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
|
40
|
+
|
41
|
+
== Biogems.info
|
42
|
+
|
43
|
+
This Biogem is published at http://biogems.info/index.html#bio-old-biofetch-emulator
|
44
|
+
|
45
|
+
== Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2014 Naohisa Goto. See LICENSE.txt for further details.
|
48
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "bio-old-biofetch-emulator"
|
18
|
+
gem.homepage = "http://github.com/ngoto/bioruby-old-biofetch-emulator"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Emulates as if old BioRuby BioFetch alives}
|
21
|
+
gem.description = %Q{Emulator that emulates Bio::Fetch object in BioRuby as if old BioRuby BioFetch server were still alive. It overrides methods and objects in Bio::Fetch, and if the old BioRuby BioFetch server's URL is given, it intercepts all requests and converts them into existing web services such as TogoWS, KEGG REST API, NCBI E-Utilities, and GenomeNet(genome.jp).}
|
22
|
+
gem.email = "ng@bioruby.org"
|
23
|
+
gem.authors = ["Naohisa Goto"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Code coverage detail"
|
36
|
+
task :simplecov do
|
37
|
+
ENV['COVERAGE'] = "true"
|
38
|
+
Rake::Task['test'].execute
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rdoc/task'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "bio-old-biofetch-emulator #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Please require your code below, respecting the naming conventions in the
|
2
|
+
# bioruby directory tree.
|
3
|
+
#
|
4
|
+
# For example, say you have a plugin named bio-plugin, the only uncommented
|
5
|
+
# line in this file would be
|
6
|
+
#
|
7
|
+
# require 'bio/bio-plugin/plugin'
|
8
|
+
#
|
9
|
+
# In this file only require other files. Avoid other source code.
|
10
|
+
|
11
|
+
require 'bio-old-biofetch-emulator/emulator.rb'
|
12
|
+
|
@@ -0,0 +1,415 @@
|
|
1
|
+
|
2
|
+
require 'bio'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module Bio
|
6
|
+
|
7
|
+
module OldBioFetchEmulator
|
8
|
+
|
9
|
+
URL = "http://bioruby.org/cgi-bin/biofetch.rb".freeze
|
10
|
+
|
11
|
+
MAX_ID_NUM = 50
|
12
|
+
|
13
|
+
class Client < Bio::Fetch
|
14
|
+
|
15
|
+
# https://web.archive.org/web/20070803003306/http://www.genome.jp/about_genomenet/service.html
|
16
|
+
# https://web.archive.org/web/20110525080429/http://www.genome.jp/dbget/
|
17
|
+
|
18
|
+
# https://web.archive.org/web/20070306215757/http://bioruby.org/cgi-bin/biofetch.rb?info=dbs
|
19
|
+
# aa aax bl cpd dgenes dr ec eg emb embu epd est exp
|
20
|
+
# gb gbu genes gl gn gp gpu gss htgs ko ld lit mim nt
|
21
|
+
# og path pd pdb pdoc pf pir pmd pr prf ps rn rp rs
|
22
|
+
# rsaa rsnt sp str sts tr vg
|
23
|
+
|
24
|
+
Databases = {
|
25
|
+
# fetching via Bio::PubMed (NCBI E-Utilities)
|
26
|
+
"pubmed" => [ :PubMed, true ],
|
27
|
+
|
28
|
+
# fetching via TogoWS REST API
|
29
|
+
"genbank" => [ :TogoWS, "ncbi-nucleotide" ],
|
30
|
+
"gb" => "genbank",
|
31
|
+
|
32
|
+
"genpept" => [ :TogoWS, "ncbi-protein" ],
|
33
|
+
"gp" => "genpept",
|
34
|
+
|
35
|
+
"refseq" => [ :TogoWS, "ncbi-nucleotide", "ncbi-protein" ],
|
36
|
+
"rs" => "refseq",
|
37
|
+
"refnuc" => [ :TogoWS, "ncbi-nucleotide" ],
|
38
|
+
"rsnt" => "refnuc",
|
39
|
+
"refpep" => [ :TogoWS, "ncbi-protein" ],
|
40
|
+
"rsaa" => "refpep",
|
41
|
+
|
42
|
+
"embl" => [ :TogoWS, "ebi-ena" ],
|
43
|
+
"emb" => "embl",
|
44
|
+
|
45
|
+
"uniprot" => [ :TogoWS, true ],
|
46
|
+
"up" => "uniprot",
|
47
|
+
"swissprot" => "uniprot",
|
48
|
+
"sp" => "uniprot",
|
49
|
+
"trembl" => "uniprot",
|
50
|
+
"tr" => "uniprot",
|
51
|
+
|
52
|
+
"pdb" => [ :TogoWS, true ],
|
53
|
+
|
54
|
+
#"genes" => [ :TogoWS, "kegg-genes" ],
|
55
|
+
|
56
|
+
# fetching via KEGG REST API
|
57
|
+
"pathway" => [ :KEGG, true ],
|
58
|
+
"path" => "pathway",
|
59
|
+
"brite" => [ :KEGG, true ],
|
60
|
+
"br" => "brite",
|
61
|
+
"module" => [ :KEGG, true ],
|
62
|
+
"md" => "module",
|
63
|
+
"orthology" => [ :KEGG, true ],
|
64
|
+
"ko" => "orthology",
|
65
|
+
"genome" => [ :KEGG, true ],
|
66
|
+
"genomes" => [ :KEGG, true ],
|
67
|
+
"gn" => "genomes",
|
68
|
+
"genes" => [ :KEGG, true ],
|
69
|
+
"ligand" => [ :KEGG, true ],
|
70
|
+
"compound" => [ :KEGG, true ],
|
71
|
+
"cpd" => "compound",
|
72
|
+
"glycan" => [ :KEGG, true ],
|
73
|
+
"gl" => "glycan",
|
74
|
+
"reaction" => [ :KEGG, true ],
|
75
|
+
"rn" => "reaction",
|
76
|
+
"rpair" => [ :KEGG, true ],
|
77
|
+
"rp" => "rpair",
|
78
|
+
"rclass" => [ :KEGG, true ],
|
79
|
+
"rc" => "rclass",
|
80
|
+
"enzyme" => [ :KEGG, true ],
|
81
|
+
"ec" => "enzyme",
|
82
|
+
"disease" => [ :KEGG, true ],
|
83
|
+
"ds" => "disease",
|
84
|
+
"drug" => [ :KEGG, true ],
|
85
|
+
"dr" => "drug",
|
86
|
+
"dgroup" => [ :KEGG, true ],
|
87
|
+
"dg" => "dgroup",
|
88
|
+
"environ" => [ :KEGG, true ],
|
89
|
+
"ev" => "environ",
|
90
|
+
|
91
|
+
"expression" => [ nil ], #[ :KEGG, true ],
|
92
|
+
"ex" => "expression",
|
93
|
+
"exp" => "expression",
|
94
|
+
|
95
|
+
"dgenes" => [ :KEGG, true ],
|
96
|
+
"egenes" => [ :KEGG, true ],
|
97
|
+
"eg" => "egenes",
|
98
|
+
"mgenes" => [ nil ], #[ :KEGG, true ],
|
99
|
+
"mgenome" => [ nil ], #[ :KEGG, true ],
|
100
|
+
"mgnm" => "mgenome",
|
101
|
+
|
102
|
+
"vgenome" => [ :KEGG, true ],
|
103
|
+
"vgnm" => "vgenome",
|
104
|
+
"vgenes" => [ :KEGG, true ],
|
105
|
+
"vg" => "vgenes",
|
106
|
+
|
107
|
+
# fetching from GenemeNet
|
108
|
+
"aaindex" => [ :DBGET, true ],
|
109
|
+
"aax" => "aaindex",
|
110
|
+
"aaindex1" => [ :DBGET, true ],
|
111
|
+
"aax1" => "aaindex1",
|
112
|
+
"aaindex2" => [ :DBGET, true ],
|
113
|
+
"aax2" => "aaindex2",
|
114
|
+
"aaindex3" => [ :DBGET, true ],
|
115
|
+
"aax3" => "aaindex3",
|
116
|
+
|
117
|
+
# formerly can be get from GenomeNet but not available now
|
118
|
+
"prf" => [ nil ], #[ :DBGET, true ],
|
119
|
+
"litdb" => [ nil ], #[ :DBGET, true ],
|
120
|
+
"lit" => [ nil ], #"litdb",
|
121
|
+
|
122
|
+
"pdbstr" => [ nil ], # Protein sequence generated from PDB (GenomeNet)
|
123
|
+
|
124
|
+
"aa" => [ nil ], # nr-aa ???
|
125
|
+
#"aax" # AAindex (KEGG)
|
126
|
+
"bl" => [ nil ], # Blocks (http://blocks.fhcrc.org/)
|
127
|
+
#"cpd" # KEGG Compound
|
128
|
+
#"dgenes" # KEGG DGenes
|
129
|
+
#"dr" # KEGG Drug
|
130
|
+
#"ec" # KEGG Enzyme
|
131
|
+
#"eg" # KEGG EGenes
|
132
|
+
#"emb" # EMBL
|
133
|
+
"embu" => [ nil ], # EMBL UniGene ???
|
134
|
+
"epd" => [ nil ], # The Eukaryotic Promoter Database
|
135
|
+
"est" => [ nil ], # NCBI EST ???
|
136
|
+
#"gb" # GenBank
|
137
|
+
"gbu" => [ nil ], # NCBI UniGene ???
|
138
|
+
#"genes" # KEGG Genes
|
139
|
+
#"gl" # KEGG Glycan
|
140
|
+
#"gn" # KEGG Genomes
|
141
|
+
#"gp" # GenPept ???
|
142
|
+
"gpu" => [ nil ], # ???
|
143
|
+
"gss" => [ nil ], # NCBI GSS ???
|
144
|
+
"htgs" => [ nil ], # NCBI HTGS ???
|
145
|
+
#"ko" # KEGG Orthology
|
146
|
+
"ld" => [ nil ], # ???
|
147
|
+
#"lit" # PRF LitDB
|
148
|
+
"mim" => [ nil ], # ???
|
149
|
+
"nt" => [ nil ], # nr-nt ???
|
150
|
+
"og" => [ nil ], # ???
|
151
|
+
#"path" # KEGG Pathway
|
152
|
+
"pd" => [ nil ], # prodom
|
153
|
+
#"pdb" # PDB
|
154
|
+
"pdoc" => [ nil ], # Prosite literature (GenomeNet)
|
155
|
+
"pf" => [ nil ], # Pfam
|
156
|
+
"pir" => [ nil ], # pir
|
157
|
+
"pmd" => [ nil ], # Protein mutants (DDBJ) (GenomeNet)
|
158
|
+
"pr" => [ nil ], # prints
|
159
|
+
#"prf" # PRF (Protein Research Foundation)
|
160
|
+
"ps" => [ nil ], # prosite
|
161
|
+
#"rn" # KEGG Reaction
|
162
|
+
#"rp" # KEGG RPair
|
163
|
+
#"rs" # NCBI RefSeq
|
164
|
+
#"rsaa" # NCBI RefSeq Amino Acide
|
165
|
+
#"rsnt" # NCBI RefSeq NucleoTide
|
166
|
+
#"sp" # SwissProt
|
167
|
+
"str" => [ nil ], # ???
|
168
|
+
"sts" => [ nil ], # NCBI STS ???
|
169
|
+
#"tr" # TrEMBL
|
170
|
+
#"vg" # KEGG VGenes
|
171
|
+
}
|
172
|
+
|
173
|
+
def initialize(url = URL)
|
174
|
+
super
|
175
|
+
end
|
176
|
+
|
177
|
+
def fetch(db, id, style = 'raw', format = nil)
|
178
|
+
_fetch(:fetch, db, id, style, format)
|
179
|
+
end
|
180
|
+
|
181
|
+
def databases
|
182
|
+
Databases.collect do |key, val|
|
183
|
+
while val && val.is_a?(String)
|
184
|
+
val = Databases[val]
|
185
|
+
end
|
186
|
+
if val && val.is_a?(Array) && val[0] then
|
187
|
+
key
|
188
|
+
else
|
189
|
+
nil
|
190
|
+
end
|
191
|
+
end.compact
|
192
|
+
end
|
193
|
+
|
194
|
+
def formats(database = @database)
|
195
|
+
if database
|
196
|
+
[ "default" ]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def maxids
|
201
|
+
MAX_ID_NUM
|
202
|
+
end
|
203
|
+
|
204
|
+
private
|
205
|
+
def _fetch(cmd, db, id, style, format)
|
206
|
+
db_orig = db
|
207
|
+
db = db.to_s.downcase
|
208
|
+
while a = Databases[db]
|
209
|
+
case a
|
210
|
+
when Array
|
211
|
+
break
|
212
|
+
when String
|
213
|
+
db = a
|
214
|
+
else
|
215
|
+
break
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
if !a and /[a-z]{3}/ =~ db then
|
220
|
+
remote = :KEGG
|
221
|
+
dbs = [ 'genes' ]
|
222
|
+
id_prefix = db
|
223
|
+
elsif a.is_a?(Array) then
|
224
|
+
remote = a[0]
|
225
|
+
dbs = a[1..-1]
|
226
|
+
dbs.collect! { |x| x == true ? db : x }
|
227
|
+
end
|
228
|
+
|
229
|
+
if !remote then
|
230
|
+
return "ERROR 1 Unknown database [#{db_orig.inspect}]"
|
231
|
+
end
|
232
|
+
|
233
|
+
ids = id.strip.split(/(?:\s*\,\s*|\s+)/)
|
234
|
+
if ids.size > MAX_ID_NUM then
|
235
|
+
return "ERROR 5 Too many IDs [#{ids.size}]. Max [#{MAX_ID_NUM}] allowed."
|
236
|
+
end
|
237
|
+
if id_prefix then
|
238
|
+
ids.collect! { |x| "#{id_prefix}:#{x.strip}" }
|
239
|
+
end
|
240
|
+
|
241
|
+
case cmd
|
242
|
+
when :fetch
|
243
|
+
ret = case remote
|
244
|
+
when :TogoWS
|
245
|
+
_fetch_togows(cmd, dbs, ids)
|
246
|
+
when :KEGG
|
247
|
+
_fetch_kegg(cmd, dbs, ids)
|
248
|
+
when :DBGET
|
249
|
+
_fetch_dbget(cmd, dbs, ids)
|
250
|
+
when :PubMed
|
251
|
+
_fetch_pubmed(cmd, dbs, ids)
|
252
|
+
else
|
253
|
+
raise "Bug: unknown remote site #{remote.inspect}"
|
254
|
+
end
|
255
|
+
end
|
256
|
+
ret
|
257
|
+
end
|
258
|
+
|
259
|
+
def _fetch_pubmed(cmd, dbs, ids)
|
260
|
+
a = Bio::PubMed.efetch(ids)
|
261
|
+
if a && a.size > 0 then
|
262
|
+
a.join("\n\n") + "\n"
|
263
|
+
else
|
264
|
+
"Error 4 ID not found [#{ids.inspect}]"
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def _fetch_togows(cmd, dbs, ids)
|
269
|
+
all = []
|
270
|
+
ids.each do |id|
|
271
|
+
ret = nil
|
272
|
+
dbs.each do |db|
|
273
|
+
url = "http://togows.org/entry/#{CGI.escape(db)}/#{CGI.escape(id)}"
|
274
|
+
begin
|
275
|
+
ret = Bio::Command.read_uri(url)
|
276
|
+
rescue OpenURI::HTTPError
|
277
|
+
ret = nil
|
278
|
+
end
|
279
|
+
if ret && /\AError/ !~ ret && ret.strip.size > 0 then
|
280
|
+
break
|
281
|
+
else
|
282
|
+
ret = nil
|
283
|
+
end
|
284
|
+
end
|
285
|
+
all.push ret if ret
|
286
|
+
end
|
287
|
+
if all.empty?
|
288
|
+
return "Error 4 ID not found [#{ids.inspect}]"
|
289
|
+
else
|
290
|
+
return all.join("")
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
def _fetch_kegg(cmd, dbs, ids)
|
295
|
+
all = []
|
296
|
+
ids.each do |id|
|
297
|
+
ret = nil
|
298
|
+
dbs.each do |db|
|
299
|
+
if db == "genes" then
|
300
|
+
url = "http://rest.kegg.jp/get/#{CGI.escape(id)}"
|
301
|
+
else
|
302
|
+
url = "http://rest.kegg.jp/get/#{CGI.escape(db)}:#{CGI.escape(id)}"
|
303
|
+
end
|
304
|
+
begin
|
305
|
+
ret = Bio::Command.read_uri(url)
|
306
|
+
rescue OpenURI::HTTPError
|
307
|
+
ret = nil
|
308
|
+
end
|
309
|
+
if ret && ret.strip.size > 0 then
|
310
|
+
break
|
311
|
+
else
|
312
|
+
ret = nil
|
313
|
+
end
|
314
|
+
end
|
315
|
+
all.push ret if ret
|
316
|
+
end
|
317
|
+
if all.empty?
|
318
|
+
return "Error 4 ID not found [#{ids.inspect}]"
|
319
|
+
else
|
320
|
+
return all.join("")
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
def _fetch_dbget(cmd, dbs, ids)
|
325
|
+
all = []
|
326
|
+
ids.each do |id|
|
327
|
+
ret = nil
|
328
|
+
dbs.each do |db|
|
329
|
+
url = "http://www.genome.jp/dbget-bin/www_bget?#{CGI.escape(db)}:#{CGI.escape(id)}"
|
330
|
+
begin
|
331
|
+
ret = Bio::Command.read_uri(url)
|
332
|
+
rescue OpenURI::HTTPError
|
333
|
+
ret = nil
|
334
|
+
end
|
335
|
+
if ret then
|
336
|
+
ret = _scrape_dbget(ret)
|
337
|
+
break if ret
|
338
|
+
end
|
339
|
+
ret = nil
|
340
|
+
end
|
341
|
+
all.push ret if ret
|
342
|
+
end
|
343
|
+
if all.empty?
|
344
|
+
return "Error 4 ID not found [#{ids.inspect}]"
|
345
|
+
else
|
346
|
+
return all.join("")
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def _scrape_dbget(orig_str)
|
351
|
+
a = orig_str.split(/^\s*\<\!\-\- bget\:result \-\-\>$\s*/)
|
352
|
+
if a[1] then
|
353
|
+
str = a[1]
|
354
|
+
str.sub!(/\A\s*\<pre\>$\s*/, "")
|
355
|
+
str.sub!(/^\s*\<\/pre\>.*/m, "")
|
356
|
+
str.gsub!(/\<[^\>]+\>/, "")
|
357
|
+
return str
|
358
|
+
end
|
359
|
+
nil
|
360
|
+
end
|
361
|
+
|
362
|
+
end #class Client
|
363
|
+
|
364
|
+
module Query
|
365
|
+
# Shortcut for using BioRuby's BioFetch server. You can fetch an entry
|
366
|
+
# without creating an instance of BioFetch server. This method uses the
|
367
|
+
# default dbfetch server, which is http://bioruby.org/cgi-bin/biofetch.rb
|
368
|
+
#
|
369
|
+
# Example:
|
370
|
+
# puts Bio::Fetch.query('refseq','NM_123456')
|
371
|
+
#
|
372
|
+
# ---
|
373
|
+
# *Arguments*:
|
374
|
+
# * _database_: name of database to query (see Bio::Fetch#databases to get list of supported databases)
|
375
|
+
# * _id_: single ID or ID list separated by commas or white space
|
376
|
+
# * _style_: [raw|html] (default = 'raw')
|
377
|
+
# * _format_: name of output format (see Bio::Fetch#formats)
|
378
|
+
def query(*args)
|
379
|
+
Client.new.fetch(*args)
|
380
|
+
end
|
381
|
+
end #module Query
|
382
|
+
|
383
|
+
DONT_OVERRIDE = ::Bio::Fetch.const_defined?(:EBI) ?
|
384
|
+
[ Client, ::Bio::Fetch::EBI ] : [ Client ]
|
385
|
+
|
386
|
+
class << ::Bio::Fetch
|
387
|
+
|
388
|
+
alias_method :new_without_old_biofetch_emulator, :new
|
389
|
+
|
390
|
+
def new_with_old_biofetch_emulator(*arg)
|
391
|
+
tmp = self.ancestors
|
392
|
+
if (tmp - DONT_OVERRIDE).size == tmp.size then
|
393
|
+
$stderr.puts self
|
394
|
+
case arg.size
|
395
|
+
when 0
|
396
|
+
return Client.new
|
397
|
+
when 1
|
398
|
+
case arg[0]
|
399
|
+
when URL
|
400
|
+
return Client.new(*arg)
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
new_without_old_biofetch_emulator(*arg)
|
405
|
+
end
|
406
|
+
|
407
|
+
alias_method :new, :new_with_old_biofetch_emulator
|
408
|
+
|
409
|
+
include Query
|
410
|
+
|
411
|
+
end #class << Bio::Fetch
|
412
|
+
|
413
|
+
end #module OldBioFetchEmulator
|
414
|
+
|
415
|
+
end #module Bio
|
data/test/helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
#require 'simplecov'
|
3
|
+
#
|
4
|
+
#module SimpleCov::Configuration
|
5
|
+
# def clean_filters
|
6
|
+
# @filters = []
|
7
|
+
# end
|
8
|
+
#end
|
9
|
+
#
|
10
|
+
#SimpleCov.configure do
|
11
|
+
# clean_filters
|
12
|
+
# load_adapter 'test_frameworks'
|
13
|
+
#end
|
14
|
+
#
|
15
|
+
#ENV["COVERAGE"] && SimpleCov.start do
|
16
|
+
# add_filter "/.rvm/"
|
17
|
+
#end
|
18
|
+
require 'rubygems'
|
19
|
+
#require 'bundler'
|
20
|
+
#begin
|
21
|
+
# Bundler.setup(:default, :development)
|
22
|
+
#rescue Bundler::BundlerError => e
|
23
|
+
# $stderr.puts e.message
|
24
|
+
# $stderr.puts "Run `bundle install` to install missing gems"
|
25
|
+
# exit e.status_code
|
26
|
+
#end
|
27
|
+
require 'test/unit'
|
28
|
+
#require 'shoulda'
|
29
|
+
|
30
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
31
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
32
|
+
require 'bio-old-biofetch-emulator'
|
33
|
+
|
34
|
+
class Test::Unit::TestCase
|
35
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module FuncTestBioOldBiofetchEmulator
|
4
|
+
|
5
|
+
module CommonTestMethods
|
6
|
+
|
7
|
+
def fetch_and_check_ids(db, ids, regexp)
|
8
|
+
tmp_ids = ids.dup
|
9
|
+
str = @bf.fetch(db, ids.join(","))
|
10
|
+
str.scan(regexp) do |x|
|
11
|
+
assert_equal(tmp_ids.shift.to_s, $1)
|
12
|
+
end
|
13
|
+
assert(tmp_ids.empty?)
|
14
|
+
|
15
|
+
str2 = @bf.fetch(db, ids.join(" "))
|
16
|
+
assert_equal(str, str2)
|
17
|
+
end
|
18
|
+
private :fetch_and_check_ids
|
19
|
+
|
20
|
+
def test_fetch_pubmed
|
21
|
+
db = "pubmed"
|
22
|
+
ids = [ 20739307, 22332238 ]
|
23
|
+
regexp = /^PMID- +(\d+)/
|
24
|
+
fetch_and_check_ids(db, ids, regexp)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_fetch_refseq
|
28
|
+
db = "rs"
|
29
|
+
ids = [ "NM_123456", "NP_198907" ]
|
30
|
+
regexp = /^ACCESSION +([\_A-Z0-9]+)/
|
31
|
+
fetch_and_check_ids(db, ids, regexp)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_fetch_kegg_genes
|
35
|
+
db = "hal"
|
36
|
+
ids = [ "VNG1467G", "VNG6476G", "VNG2243G" ]
|
37
|
+
regexp = /^ENTRY +([A-Z0-9]+)/
|
38
|
+
fetch_and_check_ids(db, ids, regexp)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_fetch_aaindex
|
42
|
+
db = "aax"
|
43
|
+
ids = [ "PRAM900102", "DAYM780301" ] # (aaindex1, aaindex2)
|
44
|
+
regexp = /^H +([A-Z0-9]+)$/
|
45
|
+
fetch_and_check_ids(db, ids, regexp)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_class
|
49
|
+
assert_instance_of(Bio::OldBioFetchEmulator::Client, @bf)
|
50
|
+
assert_equal(Bio::OldBioFetchEmulator::Client, @bf.class)
|
51
|
+
end
|
52
|
+
end #module CommonTestMethods
|
53
|
+
|
54
|
+
class TestClient < Test::Unit::TestCase
|
55
|
+
include CommonTestMethods
|
56
|
+
|
57
|
+
def setup
|
58
|
+
Bio::NCBI.default_email ||= "staff@bioruby.org"
|
59
|
+
@bf = Bio::OldBioFetchEmulator::Client.new
|
60
|
+
end
|
61
|
+
end #class TestClient
|
62
|
+
|
63
|
+
class TestBioFetch < Test::Unit::TestCase
|
64
|
+
include CommonTestMethods
|
65
|
+
|
66
|
+
def setup
|
67
|
+
Bio::NCBI.default_email ||= "staff@bioruby.org"
|
68
|
+
@bf = Bio::Fetch.new
|
69
|
+
end
|
70
|
+
|
71
|
+
end #class TestClient
|
72
|
+
|
73
|
+
class TestBioFetchWithURL < Test::Unit::TestCase
|
74
|
+
include CommonTestMethods
|
75
|
+
|
76
|
+
def setup
|
77
|
+
Bio::NCBI.default_email ||= "staff@bioruby.org"
|
78
|
+
@bf = Bio::Fetch.new("http://bioruby.org/cgi-bin/biofetch.rb")
|
79
|
+
end
|
80
|
+
|
81
|
+
end #class TestClient
|
82
|
+
|
83
|
+
class TestBioFetchWithOtherURL < Test::Unit::TestCase
|
84
|
+
def setup
|
85
|
+
Bio::NCBI.default_email ||= "staff@bioruby.org"
|
86
|
+
@bf = Bio::Fetch.new("http://www.ebi.ac.uk/Tools/dbfetch/dbfetch")
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_class
|
90
|
+
assert_instance_of(Bio::Fetch, @bf)
|
91
|
+
assert_equal(Bio::Fetch, @bf.class)
|
92
|
+
end
|
93
|
+
end #class TestClient
|
94
|
+
|
95
|
+
end #module FuncTestBioOldBiofetchEmulator
|
96
|
+
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bio-old-biofetch-emulator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naohisa Goto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bio
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.0.21
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.0.21
|
83
|
+
description: Emulator that emulates Bio::Fetch object in BioRuby as if old BioRuby
|
84
|
+
BioFetch server were still alive. It overrides methods and objects in Bio::Fetch,
|
85
|
+
and if the old BioRuby BioFetch server's URL is given, it intercepts all requests
|
86
|
+
and converts them into existing web services such as TogoWS, KEGG REST API, NCBI
|
87
|
+
E-Utilities, and GenomeNet(genome.jp).
|
88
|
+
email: ng@bioruby.org
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files:
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- README.rdoc
|
95
|
+
files:
|
96
|
+
- ".document"
|
97
|
+
- ".travis.yml"
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- README.rdoc
|
102
|
+
- Rakefile
|
103
|
+
- VERSION
|
104
|
+
- lib/bio-old-biofetch-emulator.rb
|
105
|
+
- lib/bio-old-biofetch-emulator/emulator.rb
|
106
|
+
- test/helper.rb
|
107
|
+
- test/test_bio-old-biofetch-emulator.rb
|
108
|
+
homepage: http://github.com/ngoto/bioruby-old-biofetch-emulator
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.2.2
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Emulates as if old BioRuby BioFetch alives
|
132
|
+
test_files: []
|