bio-executables 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5589dde11154d41e1b5e57ae7a95881543b4c2f8
4
+ data.tar.gz: ec8e45140eda4d7a9cff61fdee7f25f4d7b59df6
5
+ SHA512:
6
+ metadata.gz: 548567973ee72e744c572498e3c063c9cdfebcc20325ecbbfb5cb024f1ebee12666fd39c58acd67fe74914c2878350a0da7af17cfb69b940122448591840ae2b
7
+ data.tar.gz: a01c3a332a2ee4a7d50234300a46307a740afe8bfd20b8ca19ed771e7f53fec323c15ac6ad091cf59a269500fc889aceca6a2479442e7a2adab82c142897a0db
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /rdoc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/BSDL ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ BioRuby is copyrighted free software by Toshiaki Katayama <k@bioruby.org>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -0,0 +1,51 @@
1
+ 本プログラムはフリーソフトウェアです.2-clause BSDL
2
+ または以下に示す条件で本プログラムを再配布できます
3
+ 2-clause BSDLについてはBSDLファイルを参照して下さい.
4
+
5
+ 1. 複製は制限なく自由です.
6
+
7
+ 2. 以下の条件のいずれかを満たす時に本プログラムのソースを
8
+ 自由に変更できます.
9
+
10
+ (a) ネットニューズにポストしたり,作者に変更を送付する
11
+ などの方法で,変更を公開する.
12
+
13
+ (b) 変更した本プログラムを自分の所属する組織内部だけで
14
+ 使う.
15
+
16
+ (c) 変更点を明示したうえ,ソフトウェアの名前を変更する.
17
+ そのソフトウェアを配布する時には変更前の本プログラ
18
+ ムも同時に配布する.または変更前の本プログラムのソー
19
+ スの入手法を明示する.
20
+
21
+ (d) その他の変更条件を作者と合意する.
22
+
23
+ 3. 以下の条件のいずれかを満たす時に本プログラムをコンパイ
24
+ ルしたオブジェクトコードや実行形式でも配布できます.
25
+
26
+ (a) バイナリを受け取った人がソースを入手できるように,
27
+ ソースの入手法を明示する.
28
+
29
+ (b) 機械可読なソースコードを添付する.
30
+
31
+ (c) 変更を行ったバイナリは名前を変更したうえ,オリジナ
32
+ ルのソースコードの入手法を明示する.
33
+
34
+ (d) その他の配布条件を作者と合意する.
35
+
36
+ 4. 他のプログラムへの引用はいかなる目的であれ自由です.た
37
+ だし,本プログラムに含まれる他の作者によるコードは,そ
38
+ れぞれの作者の意向による制限が加えられる場合があります.
39
+
40
+ それらファイルの一覧とそれぞれの配布条件などに付いては
41
+ LEGALファイルを参照してください.
42
+
43
+ 5. 本プログラムへの入力となるスクリプトおよび,本プログラ
44
+ ムからの出力の権利は本プログラムの作者ではなく,それぞ
45
+ れの入出力を生成した人に属します.また,本プログラムに
46
+ 組み込まれるための拡張ライブラリについても同様です.
47
+
48
+ 6. 本プログラムは無保証です.作者は本プログラムをサポート
49
+ する意志はありますが,プログラム自身のバグあるいは本プ
50
+ ログラムの実行などから発生するいかなる損害に対しても責
51
+ 任を持ちません.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bio-executables.gemspec
6
+ gemspec
data/LEGAL ADDED
@@ -0,0 +1,8 @@
1
+ LEGAL NOTICE INFORMATION
2
+ ------------------------
3
+
4
+ All the files in this distribution are covered under either the Ruby's
5
+ license (see the file COPYING) or public-domain except some files
6
+ mentioned below.
7
+
8
+ (no files)
@@ -0,0 +1,63 @@
1
+ # BioRuby Executables
2
+
3
+ [![Build Status](https://secure.travis-ci.org/bioruby/bio-executables.png)](http://travis-ci.org/bioruby/bio-executables)
4
+
5
+ bio-executables is a collection of miscellaneous utilities for bioinformatics
6
+ that were formerly part of the [BioRuby](http://bioruby.org/) core ("bio" gem).
7
+ Because of reducing complexity, they were moved to this gem.
8
+
9
+ This code has historically been part of
10
+ [the BioRuby gem](https://github.com/bioruby/bioruby),
11
+ but has been split into its own gem as part of an effort to
12
+ [modularize](http://bioruby.open-bio.org/wiki/Plugins) BioRuby.
13
+ bio-executables and many more plugins are available at
14
+ [biogems.info](http://www.biogems.info/).
15
+
16
+
17
+ ## Requirements
18
+
19
+ bio-executables uses `bio` and `bio-old-biofetch-emulator` gems.
20
+ They will automatically be installed during the installation of
21
+ `bio-executables` in normal cases.
22
+
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'bio-executables'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install bio-executables
39
+
40
+ ## Usage
41
+
42
+ See BioRuby documentation at https://github.com/bioruby/documentation
43
+
44
+ ## Development
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`.
47
+ To release a new version, update the version number in `version.rb`,
48
+ and then run `bundle exec rake release`, which will create a git tag
49
+ for the version, push git commits and tags, and push the `.gem` file
50
+ to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at
55
+ https://github.com/bioruby/bioruby-executables
56
+
57
+ ## Cite
58
+
59
+ If you use this software, please cite one of
60
+
61
+ * [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
62
+ * [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
63
+
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rdoc/task'
3
+ require 'rake/testtask'
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.test_files = FileList["test/**/test_*.rb"]
9
+ end
10
+
11
+ Rake::RDocTask.new do |r|
12
+ r.rdoc_dir = "rdoc"
13
+ r.rdoc_files.include("README.md",
14
+ "COPYING", "COPYING.ja", "BSDL", "LEGAL",
15
+ "lib/**/*.rb")
16
+ r.main = "README.md"
17
+ r.options << '--title' << 'BioRuby Executables API documentation'
18
+ r.options << '--line-numbers'
19
+ end
20
+
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = biofetch - BioFetch client
4
+ #
5
+ # Copyright:: Copyright (C) 2002
6
+ # Toshiaki Katayama <k@bioruby.org>
7
+ # License:: The Ruby License
8
+ #
9
+ #
10
+
11
+ begin
12
+ require 'rubygems'
13
+ rescue LoadError
14
+ end
15
+
16
+ require 'bio/io/fetch'
17
+
18
+ def require_bio_old_biofetch_emulator(mandatory = true)
19
+ begin
20
+ require 'bio-old-biofetch-emulator'
21
+ rescue LoadError
22
+ if mandatory then
23
+ $stderr.puts "Error: please install bio-old-biofetch-emulator gem."
24
+ exit 1
25
+ end
26
+ end
27
+ end
28
+
29
+ def default_url
30
+ 'http://bioruby.org/cgi-bin/biofetch.rb'
31
+ end
32
+
33
+ def another_url
34
+ 'http://www.ebi.ac.uk/cgi-bin/dbfetch'
35
+ end
36
+
37
+ def usage
38
+ puts "#{$0} [-s[erver] #{another_url}] db id [style] [format]"
39
+ puts " server : URL of the BioFetch CGI (default is #{default_url})"
40
+ puts " db : database name (embl, genbank, etc.)"
41
+ puts " id : entry id"
42
+ puts " style : 'raw' or 'html' (default is 'raw')"
43
+ puts " format : change the output format ('default', 'fasta', etc.)"
44
+ end
45
+
46
+ if ARGV.empty? or ARGV[0] =~ /^--?h/
47
+ usage
48
+ exit 1
49
+ end
50
+
51
+ case ARGV[0]
52
+ when /^--?s/ # User specified server
53
+ require_bio_old_biofetch_emulator(false)
54
+ ARGV.shift
55
+ serv = Bio::Fetch.new(ARGV.shift)
56
+ puts serv.fetch(*ARGV)
57
+ when /^--?e/ # EBI server
58
+ ARGV.shift
59
+ serv = Bio::Fetch.new(another_url)
60
+ puts serv.fetch(*ARGV)
61
+ when /^--?r/ # BioRuby server
62
+ require_bio_old_biofetch_emulator
63
+ ARGV.shift
64
+ serv = Bio::Fetch.new(default_url)
65
+ puts serv.fetch(*ARGV)
66
+ else # Default server
67
+ require_bio_old_biofetch_emulator
68
+ puts Bio::Fetch.query(*ARGV)
69
+ end
70
+
71
+
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = bioflat - OBDA flat file indexer (executable)
4
+ #
5
+ # Copyright:: Copyright (C) 2002
6
+ # Naohisa Goto <ng@bioruby.org>
7
+ # License:: The Ruby License
8
+ #
9
+ # $Id: br_bioflat.rb,v 1.17 2007/04/05 23:35:39 trevor Exp $
10
+ #
11
+
12
+ require 'bio'
13
+
14
+ def usage
15
+ print <<EOM
16
+ Search:
17
+ #{$0} [--search] [options...] [DIR/]DBNAME KEYWORDS
18
+ or
19
+ #{$0} [--search] --location DIR --dbname DBNAME [options...] KEYWORDS
20
+
21
+ Search options:
22
+ --namespace NAME set serch namespace to NAME
23
+ (or --name NAME) You can set this option many times to specify
24
+ more than one namespace.
25
+
26
+ Create index:
27
+ #{$0} --create --location DIR --dbname DBNAME [--format <genbank|embl|fasta>] [options...] [--files] FILES
28
+ Update index:
29
+ #{$0} --update --location DIR --dbname DBNAME [options...] [--files] FILES
30
+
31
+ Create index options:
32
+ --primary=UNIQUE set primary namespece to UNIQUE
33
+ Default primary/secondary namespaces depend on
34
+ each format of flatfiles.
35
+ --secondary=KEY set secondary namespaces.
36
+ You may use this option many times to specify
37
+ more than one namespace.
38
+ --add-secondary=KEY add secondary namespaces to default specification.
39
+ You can use this option many times.
40
+
41
+ Options only valid for --create (or --update) --type flat:
42
+ --sort=/path/to/sort use external sort program (e.g. /usr/bin/sort)
43
+ --sort=BUILTIN use builtin sort routine
44
+ (default: /usr/bin/sort or BUILTIN)
45
+ --env=/path/to/env use env program to run sort (default: /usr/bin/env)
46
+ --env-arg=XXXXXX argument given to the env program (default: LC_ALL=C)
47
+ (multiple --env-arg=XXXXXX can be specified)
48
+
49
+ Options only valid for --update:
50
+ --renew re-read all flatfiles and update whole index
51
+
52
+ Backward compatibility:
53
+ --makeindex DIR/DBNAME
54
+ same as --create --type flat --location DIR --dbname DBNAME
55
+ --makeindexBDB DIR/DBNAME
56
+ same as --create --type bdb --location DIR --dbname DBNAME
57
+ --format=CLASS
58
+ instead of genbank|embl|fasta, specifing a class name is allowed
59
+
60
+ Show namespaces:
61
+ #{$0} --show-namespaces [--location DIR --dbname DBNAME] [DIR/DBNAME]
62
+ or
63
+ #{$0} --show-namespaces [--format=CLASS]
64
+ or
65
+ #{$0} --show-namespaces --files file
66
+
67
+ EOM
68
+
69
+ end
70
+
71
+
72
+ def do_index(mode = :create)
73
+ case ARGV[0]
74
+ when /^\-\-?make/
75
+ dbpath = ARGV[1]
76
+ args = ARGV[2..-1]
77
+ is_bdb = nil
78
+ when /^\-\-?make.*bdb/i
79
+ dbname = ARGV[1]
80
+ args = ARGV[2..-1]
81
+ is_bdb = Bio::FlatFileIndex::MAGIC_BDB
82
+ when /^\-\-create/, /^\-\-update/
83
+ args = ARGV[1..-1]
84
+ else
85
+ usage
86
+ end
87
+
88
+ options = {}
89
+
90
+ while args.first =~ /^\-/
91
+ case x = args.shift
92
+
93
+ # OBDA stuff
94
+
95
+ when /^\-\-?format$/
96
+ args.shift
97
+ format = nil # throw this f*ckin' mess for auto detect :)
98
+ when /^\-\-?location/
99
+ location = args.shift.chomp('/')
100
+ when /^\-\-?dbname/
101
+ dbname = args.shift
102
+ when /^\-\-?(index)?type/
103
+ indextype = args.shift
104
+ case indextype
105
+ when /bdb/
106
+ is_bdb = Bio::FlatFileIndex::MAGIC_BDB
107
+ when /flat/
108
+ is_bdb = nil
109
+ else
110
+ usage
111
+ end
112
+
113
+ # BioRuby extension
114
+
115
+ when /^\-\-?files/i
116
+ break
117
+
118
+ when /^\-\-?format\=(.*)/i
119
+ format = $1
120
+
121
+ when /^\-\-?sort\=(.*)/i
122
+ options['sort_program'] = $1
123
+ options['onmemory'] = nil
124
+ when /^\-\-?no\-?te?mp/i
125
+ options['onmemory'] = true
126
+
127
+ when /^\-\-?env\=(.*)/i
128
+ options['env_program'] = $1
129
+
130
+ when /^\-\-?env-arg(?:ument)?\=(.*)/i
131
+ options['env_program_arguments'] ||= []
132
+ options['env_program_arguments'].push $1
133
+
134
+ when /^\-\-?primary.*\=(.*)/i
135
+ options['primary_namespace'] = $1
136
+
137
+ when /^\-\-?add-secondary.*\=(.*)/i
138
+ unless options['additional_secondary_namespaces'] then
139
+ options['additional_secondary_namespaces'] = []
140
+ end
141
+ options['additional_secondary_namespaces'] << $1 if $1.length > 0
142
+
143
+ when /^\-\-?secondary.*\=(.*)/i
144
+ unless options['secondary_namespaces'] then
145
+ options['secondary_namespaces'] = []
146
+ end
147
+ options['secondary_namespaces'] << $1 if $1.length > 0
148
+
149
+ when /^\-\-?renew/
150
+ options['renew'] = true
151
+
152
+ else
153
+ $stderr.print "Warning: ignoring invalid option #{x.inspect}\n"
154
+ end
155
+ end
156
+
157
+ dbpath = File.join(location, dbname) unless dbpath
158
+ if mode == :update then
159
+ Bio::FlatFileIndex::update_index(dbpath, format, options, *args)
160
+ else
161
+ Bio::FlatFileIndex::makeindex(is_bdb, dbpath, format, options, *args)
162
+ end
163
+ end
164
+
165
+
166
+ def do_search
167
+ dbname = nil
168
+ location = nil
169
+ names = []
170
+ while x = ARGV.shift
171
+ case x
172
+ when /\A\-\-?search/i
173
+ #do nothing
174
+ when /\A\-\-?location/i
175
+ location = ARGV.shift.to_s.chomp('/')
176
+ when /\A\-\-?dbname/i
177
+ dbname = ARGV.shift
178
+ when /\A\-\-?name(?:space)?(?:\=(.+))?/i
179
+ if $1 then
180
+ names << $1
181
+ elsif x = ARGV.shift
182
+ names << x
183
+ end
184
+ else
185
+ ARGV.unshift x
186
+ break
187
+ end
188
+ end
189
+ dbname = ARGV.shift unless dbname
190
+ dbname = File.join(location, dbname) unless location.to_s.empty?
191
+ db = Bio::FlatFileIndex.open(dbname)
192
+ ARGV.each do |key|
193
+ $stderr.print "Searching for \'#{key}\'...\n"
194
+ #r = db.search(key)
195
+ #$stderr.print "OK, #{r.size} entry found\n"
196
+ #if r.size > 0 then
197
+ # print r
198
+ #end
199
+ begin
200
+ if names.empty? then
201
+ r = db.include?(key)
202
+ else
203
+ r = db.include_in_namespaces?(key, *names)
204
+ end
205
+ rescue RuntimeError
206
+ $stderr.print "ERROR: #{$!}\n"
207
+ next
208
+ end
209
+ r = [] unless r
210
+ $stderr.print "OK, #{r.size} entry found\n"
211
+ r.each do |i|
212
+ print db.search_primary(i)
213
+ end
214
+ end
215
+ db.close
216
+ end
217
+
218
+
219
+ def do_show_namespaces
220
+ dbname = nil
221
+ location = nil
222
+ files = nil
223
+ format = nil
224
+ names = []
225
+ while x = ARGV.shift
226
+ case x
227
+ when /\A\-\-?(show\-)?name(space)?s/i
228
+ #do nothing
229
+ when /\A\-\-?location/i
230
+ location = ARGV.shift.to_s.chomp('/')
231
+ when /\A\-\-?dbname/i
232
+ dbname = ARGV.shift
233
+ when /\A\-\-?format(?:\=(.+))?/i
234
+ if $1 then
235
+ format = $1
236
+ elsif x = ARGV.shift
237
+ format = x
238
+ end
239
+ when /\A\-\-?files/i
240
+ files = ARGV
241
+ break
242
+ else
243
+ ARGV.unshift x
244
+ break
245
+ end
246
+ end
247
+ if files then
248
+ k = nil
249
+ files.each do |x|
250
+ k = Bio::FlatFile.autodetect_file(x)
251
+ break if k
252
+ end
253
+ if k then
254
+ $stderr.print "Format: #{k.to_s}\n"
255
+ format = k
256
+ else
257
+ $stderr.print "ERROR: couldn't determine file format\n"
258
+ return
259
+ end
260
+ end
261
+ $stderr.print "Namespaces: (first line: primary namespace)\n"
262
+ if format then
263
+ parser = Bio::FlatFileIndex::Indexer::Parser.new(format)
264
+ print parser.primary.name, "\n"
265
+ puts parser.secondary.keys
266
+ else
267
+ dbname = ARGV.shift unless dbname
268
+ dbname = File.join(location, dbname) unless location.to_s.empty?
269
+ db = Bio::FlatFileIndex.open(dbname)
270
+ puts db.namespaces
271
+ db.close
272
+ end
273
+ end
274
+
275
+ if ARGV.size > 1
276
+ case ARGV[0]
277
+ when /--make/, /--create/
278
+ Bio::FlatFileIndex::DEBUG.out = true
279
+ do_index
280
+ when /--update/
281
+ Bio::FlatFileIndex::DEBUG.out = true
282
+ do_index(:update)
283
+ when /\A\-\-?(show\-)?name(space)?s/i
284
+ do_show_namespaces
285
+ when /--search/
286
+ do_search
287
+ else #default is search
288
+ do_search
289
+ end
290
+ else
291
+ usage
292
+ end
293
+
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = biogetseq - OBDA sequence data retrieval (executable)
4
+ #
5
+ # Copyright:: Copyright (C) 2003
6
+ # Toshiaki Katayama <k@bioruby.org>
7
+ # License:: The Ruby License
8
+ #
9
+ # $Id: br_biogetseq.rb,v 1.4 2007/04/05 23:35:39 trevor Exp $
10
+ #
11
+
12
+ require 'bio'
13
+
14
+ def usage
15
+ print <<END
16
+ #{$0} --dbname <dbname> [--namespace <namespace>] entry_id [entry_id]
17
+ END
18
+ exit 1
19
+ end
20
+
21
+ if ARGV.size < 3
22
+ usage
23
+ end
24
+
25
+ while ARGV.first =~ /^-/
26
+ case ARGV.shift
27
+ when /^\-\-format/
28
+ ARGV.shift
29
+ raise NotImplementedError
30
+ when /^\-\-dbname/
31
+ dbname = ARGV.shift
32
+ when /^\-\-namespace/
33
+ namespace = ARGV.shift
34
+ end
35
+ end
36
+
37
+ reg = Bio::Registry.new
38
+ db = reg.get_database(dbname)
39
+ if namespace
40
+ db['namespace'] = namespace
41
+ end
42
+ ARGV.each do |entry|
43
+ puts db.get_by_id(entry)
44
+ end
45
+
@@ -0,0 +1,422 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = pmfetch - PubMed client
4
+ #
5
+ # Copyright:: Copyright (C) 2004, 2005
6
+ # Toshiaki Katayama <k@bioruby.org>
7
+ # License:: The Ruby License
8
+ #
9
+ # $Id:$
10
+ #
11
+
12
+ require 'bio'
13
+
14
+ PROG_VER = "Powered by BioRuby #{Bio::BIORUBY_VERSION_ID}"
15
+ PROG_NAME = File.basename($0)
16
+
17
+
18
+ require 'getoptlong'
19
+
20
+
21
+ ### formatting
22
+
23
+ class String
24
+ def fill(fill_column = 80, prefix = '', separater = ' ')
25
+ prefix = ' ' * prefix if prefix.is_a?(Integer)
26
+ maxlen = fill_column - prefix.length
27
+ raise "prefix is longer than fill_column" if maxlen <= 0
28
+
29
+ cursor = pos = 0
30
+ lines = []
31
+ while cursor < self.length
32
+ line = self[cursor, maxlen]
33
+ pos = line.rindex(separater)
34
+ pos = nil if line.length < maxlen
35
+ if pos
36
+ len = pos + separater.length
37
+ lines << self[cursor, len]
38
+ cursor += len
39
+ else
40
+ lines << self[cursor, maxlen]
41
+ cursor += maxlen
42
+ end
43
+ end
44
+ return lines.join("\n#{prefix}")
45
+ end
46
+ end
47
+
48
+
49
+ module Bio
50
+ class Reference
51
+ def report
52
+ if (num = @authors.size) > 10
53
+ authors = "#{@authors[0]} et al. (#{num} authors)"
54
+ elsif num > 4
55
+ sep = ',' * (num - 1)
56
+ authors = "#{@authors[0]}#{sep} #{@authors[-1]}"
57
+ else
58
+ authors = authors_join(' & ')
59
+ end
60
+ journal = "#{@journal} #{@year} #{@volume}(#{@issue}):#{@pages}"
61
+
62
+ indent = 8
63
+ prefix = ' ' * indent
64
+ [
65
+ "#{@pages[/\d+/]}".ljust(indent) + "#{@title}".fill(78, indent),
66
+ authors,
67
+ "#{journal} [PMID:#{@pubmed}]",
68
+ ].join("\n#{prefix}")
69
+ end
70
+ end
71
+ end
72
+
73
+
74
+ class PMFetch
75
+
76
+ class Examples < StandardError; end
77
+ class Version < StandardError; end
78
+ class Usage < StandardError; end
79
+
80
+ ### default options
81
+
82
+ def initialize
83
+ @format = 'rd'
84
+ @search_opts = {
85
+ 'retmax' => 20,
86
+ }
87
+ @query = nil
88
+ @query_opts = []
89
+ @pmid_list_only = false
90
+
91
+ pmfetch
92
+ end
93
+
94
+
95
+ ### main
96
+
97
+ def pmfetch
98
+ begin
99
+ set_options
100
+ parse_options
101
+ check_query
102
+ rescue PMFetch::Examples
103
+ puts examples
104
+ exit
105
+ rescue PMFetch::Version
106
+ puts version
107
+ exit
108
+ rescue PMFetch::Usage
109
+ puts usage
110
+ exit
111
+ rescue GetoptLong::MissingArgument, GetoptLong::InvalidOption
112
+ puts usage
113
+ exit
114
+ end
115
+
116
+ list = pm_esearch
117
+
118
+ if list.empty?
119
+ ;
120
+ elsif @pmid_list_only
121
+ puts list
122
+ else
123
+ pm_efetch(list)
124
+ end
125
+ end
126
+
127
+
128
+ ### help
129
+
130
+ def usage
131
+ %Q[
132
+ Usage: #{PROG_NAME} [options...] "query string"
133
+ or #{PROG_NAME} --query "query string" [other options...]
134
+
135
+ Options:
136
+ -q --query "genome AND virus" Query string for PubMed search
137
+ -t --title "mobile elements" Title of the article to search
138
+ -j --journal "genome res" Journal title to search
139
+ -v --volume # Journal volume to search
140
+ -i --issue # Journal issue to search
141
+ -p --page # First page number of the article to search
142
+ -a --author "Altschul SF" Author name to search
143
+ -m --mesh "SARS virus" MeSH term to search
144
+ -f --format bibtex Summary output format
145
+ --pmidlist Output only a list of PubMed IDs
146
+ -n --retmax # Number of articles to retrieve at the maximum
147
+ -N --retstart # Starting number of the articles to retrieve
148
+ -s --sort pub+date Sort method for the summary output
149
+ --reldate # Search articles published within recent # days
150
+ --mindate YYYY/MM/DD Search articles published after the date
151
+ --maxdate YYYY/MM/DD Search articles published before the date
152
+ --help Output this help, then exit
153
+ --examples Output examples, then exit
154
+ --version Output version number, then exit
155
+
156
+ Formats:
157
+ endnote, medline, bibitem, bibtex, report, rd,
158
+ nature, science, genome_res, genome_biol, nar, current, trends, cell
159
+
160
+ Sort:
161
+ author, journal, pub+date, page
162
+
163
+ See the following pages for the PubMed search options:
164
+ http://www.ncbi.nlm.nih.gov/entrez/query/static/help/pmhelp.html
165
+ http://www.ncbi.nlm.nih.gov/entrez/query/static/esearch_help.html
166
+
167
+ #{version}
168
+
169
+ ]
170
+ end
171
+
172
+ def version
173
+ PROG_VER
174
+ end
175
+
176
+ def examples
177
+ DATA.read.gsub('PMFetch', PROG_NAME)
178
+ end
179
+
180
+
181
+ private
182
+
183
+
184
+ ### options
185
+
186
+ def set_options
187
+ @parser = GetoptLong.new
188
+
189
+ @parser.set_options(
190
+ [ '--query', '-q', GetoptLong::REQUIRED_ARGUMENT ],
191
+ [ '--title', '-t', GetoptLong::REQUIRED_ARGUMENT ],
192
+ [ '--journal', '-j', GetoptLong::REQUIRED_ARGUMENT ],
193
+ [ '--volume', '-v', GetoptLong::REQUIRED_ARGUMENT ],
194
+ [ '--issue', '-i', GetoptLong::REQUIRED_ARGUMENT ],
195
+ [ '--page', '-p', GetoptLong::REQUIRED_ARGUMENT ],
196
+ [ '--author', '-a', GetoptLong::REQUIRED_ARGUMENT ],
197
+ [ '--mesh', '-m', GetoptLong::REQUIRED_ARGUMENT ],
198
+ [ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
199
+ [ '--pmidlist', GetoptLong::NO_ARGUMENT ],
200
+ [ '--retmax', '-n', GetoptLong::REQUIRED_ARGUMENT ],
201
+ [ '--retstart', '-N', GetoptLong::REQUIRED_ARGUMENT ],
202
+ [ '--sort', '-s', GetoptLong::REQUIRED_ARGUMENT ],
203
+ [ '--reldate', GetoptLong::REQUIRED_ARGUMENT ],
204
+ [ '--mindate', GetoptLong::REQUIRED_ARGUMENT ],
205
+ [ '--maxdate', GetoptLong::REQUIRED_ARGUMENT ],
206
+ [ '--examples', GetoptLong::NO_ARGUMENT ],
207
+ [ '--help', GetoptLong::NO_ARGUMENT ],
208
+ [ '--version', GetoptLong::NO_ARGUMENT ]
209
+ )
210
+ end
211
+
212
+ def parse_options
213
+ @parser.each_option do |optname, optarg|
214
+ case optname
215
+ when /--query/
216
+ @query = optarg
217
+ when /--title/
218
+ @query_opts << "#{optarg}[ti]"
219
+ when /--journal/
220
+ @query_opts << "#{optarg}[ta]"
221
+ when /--volume/
222
+ @query_opts << "#{optarg}[vi]"
223
+ when /--issue/
224
+ @query_opts << "#{optarg}[ip]"
225
+ when /--page/
226
+ @query_opts << "#{optarg}[pg]"
227
+ when /--author/
228
+ @query_opts << "#{optarg}[au]"
229
+ when /--mesh/
230
+ @query_opts << "#{optarg}[mh]"
231
+ when /--format/
232
+ @format = optarg
233
+ when /--pmidlist/
234
+ @pmid_list_only = true
235
+ when /--examples/
236
+ raise PMFetch::Examples
237
+ when /--help/
238
+ raise PMFetch::Usage
239
+ when /--version/
240
+ raise PMFetch::Version
241
+ when /--sort/
242
+ @sort = optarg
243
+ @search_opts["sort"] = @sort unless @sort == "page"
244
+ else
245
+ optname.delete!('-')
246
+ @search_opts[optname] = optarg
247
+ end
248
+ end
249
+ end
250
+
251
+
252
+ ### check query
253
+
254
+ def check_query
255
+ p @query if $DEBUG
256
+ @query ||= ARGV.join(" ") unless ARGV.empty?
257
+
258
+ p @query if $DEBUG
259
+ @query_str = [ @query, @query_opts ].flatten.compact.join(" AND ")
260
+
261
+ p @query_str if $DEBUG
262
+ if @query_str.empty?
263
+ raise PMFetch::Usage
264
+ end
265
+ end
266
+
267
+
268
+ ### search
269
+
270
+ def pm_esearch
271
+ return Bio::PubMed.esearch(@query_str, @search_opts)
272
+ end
273
+
274
+ def pm_efetch(list)
275
+ entries = Bio::PubMed.efetch(list)
276
+
277
+ if @format == 'medline'
278
+ medline_format(entries)
279
+ else
280
+ entries = parse_entries(entries)
281
+ if @sort == 'page'
282
+ entries = sort_entries(entries)
283
+ end
284
+ if @format == 'report'
285
+ report_format(entries)
286
+ else
287
+ other_format(entries)
288
+ end
289
+ end
290
+ end
291
+
292
+
293
+ ### output
294
+
295
+ def medline_format(entries)
296
+ entries.each do |entry|
297
+ puts entry
298
+ puts '//'
299
+ end
300
+ end
301
+
302
+ def parse_entries(entries)
303
+ entries.map { |entry| Bio::MEDLINE.new(entry) }
304
+ end
305
+
306
+ def sort_entries(entries)
307
+ if RUBY_VERSION > "1.8.0"
308
+ entries.sort_by { |x|
309
+ [ x.journal, x.volume.to_i, x.issue.to_i, x.pages.to_i ]
310
+ }
311
+ else
312
+ entries.map { |x|
313
+ [ x.journal, x.volume.to_i, x.issue.to_i, x.pages.to_i, x ]
314
+ }.sort { |a, b|
315
+ a[0..3] <=> b[0..3]
316
+ }.map { |y|
317
+ y.pop
318
+ }
319
+ end
320
+ end
321
+
322
+ def report_format(entries)
323
+ entries.each do |entry|
324
+ puts entry.reference.report
325
+ puts
326
+ end
327
+ end
328
+
329
+ def other_format(entries)
330
+ entries.each do |entry|
331
+ puts entry.reference.format(@format)
332
+ puts
333
+ end
334
+ end
335
+
336
+ end
337
+
338
+
339
+ PMFetch.new
340
+
341
+
342
+ __END__
343
+
344
+ = Examples : PubMed search
345
+
346
+ These four lines will do the same job.
347
+
348
+ % PMFetch transcription factor
349
+ % PMFetch "transcription factor"
350
+ % PMFetch --query "transcription factor"
351
+ % PMFetch -q "transcription factor"
352
+
353
+
354
+ Retrieve max 100 artiecles (20 is a NCBI's default) at a time, use --retmax as
355
+
356
+ % PMFetch -q "transcription factor" --retmax 100
357
+
358
+ and, to retrieve next 100 articles, use --retstart as
359
+
360
+ % PMFetch -q "transcription factor" --retmax 100 --retstart 100
361
+
362
+
363
+ You can narrow the search target for an issue of the journal.
364
+
365
+ % PMFetch --journal development --volume 131 --issue 3 transcription factor
366
+
367
+
368
+ Short options are also available.
369
+
370
+ % PMFetch -j development -v 131 -i 3 transcription factor
371
+
372
+
373
+ Search articles indexed in PubMed within these 90 days.
374
+
375
+ % PMFetch -q "transcription factor" --reldate 90
376
+
377
+
378
+ Search articles indexed in PubMed during the period of 2001/04/01 to 2001/08/31
379
+
380
+ % PMFetch -q "transcription factor" --mindate 2001/04/01 --maxdate 2001/08/31
381
+
382
+
383
+ Output format can be changed by --format option.
384
+
385
+ % PMFetch -q "transcription factor" -j development -v 131 -i 3 -f report
386
+ % PMFetch -q "transcription factor" -j development -v 131 -i 3 -f rd
387
+ % PMFetch -q "transcription factor" -j development -v 131 -i 3 -f endnote
388
+ % PMFetch -q "transcription factor" -j development -v 131 -i 3 -f medline
389
+ % PMFetch -q "transcription factor" -j development -v 131 -i 3 -f bibitem
390
+ % PMFetch -q "transcription factor" -j development -v 131 -i 3 -f bibtex
391
+ % PMFetch -q "transcription factor" -j development -v 131 -i 3 -f nature
392
+ % PMFetch -q "transcription factor" -j development -v 131 -i 3 -f science
393
+
394
+
395
+ Generate title listings for the journal report meeting (don't forget
396
+ to inclease the number of --retmax for fetching all titles).
397
+
398
+ % PMFetch -f report -j development -v 131 -i 3 -n 100
399
+
400
+
401
+ Search by author name.
402
+
403
+ % PMFetch -a "Karlin S"
404
+ % PMFetch -a "Koonin EV"
405
+
406
+
407
+ Search by MeSH term.
408
+
409
+ % PMFetch -m "computational biology"
410
+ % PMFetch -m "SARS virus"
411
+
412
+
413
+ Search by PubMed ID (PMID).
414
+
415
+ % PMFetch 12345
416
+
417
+
418
+ Output PMID only.
419
+
420
+ % PMFetch --pmidlist tardigrada
421
+
422
+
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bio-executables/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bio-executables"
8
+ spec.version = Bio::Executables::VERSION
9
+ spec.authors = ["BioRuby project"]
10
+ spec.email = ["staff@bioruby.org"]
11
+
12
+ spec.summary = %q{BioRuby executables: utilities bundled with BioRuby}
13
+ spec.description = %q{BioRuby executables is a collection of miscellaneous utilities for bioinformatics that were formerly part of the BioRuby core ("bio" gem). Because of reducing complexity, they were moved to this gem.}
14
+ spec.homepage = "https://github.com/bioruby/bioruby-executables"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "bio", ">= 1.5.1"
24
+ spec.add_runtime_dependency "bio-old-biofetch-emulator", ">= 0.0.1"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.15"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rdoc", "~> 5"
29
+ spec.add_development_dependency "test-unit", "~> 3"
30
+ end
@@ -0,0 +1,5 @@
1
+ module Bio
2
+ module Executables
3
+ VERSION = "0.0.0".freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bio-executables
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - BioRuby project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-15 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.5.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bio-old-biofetch-emulator
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3'
97
+ description: BioRuby executables is a collection of miscellaneous utilities for bioinformatics
98
+ that were formerly part of the BioRuby core ("bio" gem). Because of reducing complexity,
99
+ they were moved to this gem.
100
+ email:
101
+ - staff@bioruby.org
102
+ executables:
103
+ - br_biofetch.rb
104
+ - br_bioflat.rb
105
+ - br_biogetseq.rb
106
+ - br_pmfetch.rb
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - BSDL
112
+ - COPYING
113
+ - COPYING.ja
114
+ - Gemfile
115
+ - LEGAL
116
+ - README.md
117
+ - Rakefile
118
+ - bin/br_biofetch.rb
119
+ - bin/br_bioflat.rb
120
+ - bin/br_biogetseq.rb
121
+ - bin/br_pmfetch.rb
122
+ - bio-executables.gemspec
123
+ - lib/bio-executables/version.rb
124
+ homepage: https://github.com/bioruby/bioruby-executables
125
+ licenses: []
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.11
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: 'BioRuby executables: utilities bundled with BioRuby'
147
+ test_files: []