bio 0.7.0

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.
Files changed (201) hide show
  1. data/bin/bioruby +107 -0
  2. data/bin/br_biofetch.rb +59 -0
  3. data/bin/br_bioflat.rb +294 -0
  4. data/bin/br_biogetseq.rb +57 -0
  5. data/bin/br_pmfetch.rb +431 -0
  6. data/doc/BioRuby.rd.ja +225 -0
  7. data/doc/Changes-0.7.rd +236 -0
  8. data/doc/Design.rd.ja +341 -0
  9. data/doc/KEGG_API.rd +1437 -0
  10. data/doc/KEGG_API.rd.ja +1399 -0
  11. data/doc/TODO.rd.ja +138 -0
  12. data/doc/Tutorial.rd +1138 -0
  13. data/doc/Tutorial.rd.ja +2110 -0
  14. data/etc/bioinformatics/seqdatabase.ini +210 -0
  15. data/lib/bio.rb +256 -0
  16. data/lib/bio/alignment.rb +1906 -0
  17. data/lib/bio/appl/bl2seq/report.rb +350 -0
  18. data/lib/bio/appl/blast.rb +269 -0
  19. data/lib/bio/appl/blast/format0.rb +1402 -0
  20. data/lib/bio/appl/blast/format8.rb +95 -0
  21. data/lib/bio/appl/blast/report.rb +652 -0
  22. data/lib/bio/appl/blast/rexml.rb +151 -0
  23. data/lib/bio/appl/blast/wublast.rb +553 -0
  24. data/lib/bio/appl/blast/xmlparser.rb +222 -0
  25. data/lib/bio/appl/blat/report.rb +392 -0
  26. data/lib/bio/appl/clustalw.rb +191 -0
  27. data/lib/bio/appl/clustalw/report.rb +154 -0
  28. data/lib/bio/appl/emboss.rb +68 -0
  29. data/lib/bio/appl/fasta.rb +262 -0
  30. data/lib/bio/appl/fasta/format10.rb +428 -0
  31. data/lib/bio/appl/fasta/format6.rb +37 -0
  32. data/lib/bio/appl/genscan/report.rb +570 -0
  33. data/lib/bio/appl/hmmer.rb +129 -0
  34. data/lib/bio/appl/hmmer/report.rb +556 -0
  35. data/lib/bio/appl/mafft.rb +222 -0
  36. data/lib/bio/appl/mafft/report.rb +119 -0
  37. data/lib/bio/appl/psort.rb +555 -0
  38. data/lib/bio/appl/psort/report.rb +473 -0
  39. data/lib/bio/appl/sim4.rb +134 -0
  40. data/lib/bio/appl/sim4/report.rb +501 -0
  41. data/lib/bio/appl/sosui/report.rb +166 -0
  42. data/lib/bio/appl/spidey/report.rb +604 -0
  43. data/lib/bio/appl/targetp/report.rb +283 -0
  44. data/lib/bio/appl/tmhmm/report.rb +238 -0
  45. data/lib/bio/command.rb +166 -0
  46. data/lib/bio/data/aa.rb +354 -0
  47. data/lib/bio/data/codontable.rb +740 -0
  48. data/lib/bio/data/na.rb +226 -0
  49. data/lib/bio/db.rb +340 -0
  50. data/lib/bio/db/aaindex.rb +280 -0
  51. data/lib/bio/db/embl/common.rb +332 -0
  52. data/lib/bio/db/embl/embl.rb +446 -0
  53. data/lib/bio/db/embl/sptr.rb +954 -0
  54. data/lib/bio/db/embl/swissprot.rb +32 -0
  55. data/lib/bio/db/embl/trembl.rb +31 -0
  56. data/lib/bio/db/embl/uniprot.rb +32 -0
  57. data/lib/bio/db/fantom.rb +604 -0
  58. data/lib/bio/db/fasta.rb +869 -0
  59. data/lib/bio/db/genbank/common.rb +299 -0
  60. data/lib/bio/db/genbank/ddbj.rb +34 -0
  61. data/lib/bio/db/genbank/genbank.rb +354 -0
  62. data/lib/bio/db/genbank/genpept.rb +73 -0
  63. data/lib/bio/db/genbank/refseq.rb +31 -0
  64. data/lib/bio/db/gff.rb +106 -0
  65. data/lib/bio/db/go.rb +497 -0
  66. data/lib/bio/db/kegg/brite.rb +51 -0
  67. data/lib/bio/db/kegg/cell.rb +88 -0
  68. data/lib/bio/db/kegg/compound.rb +130 -0
  69. data/lib/bio/db/kegg/enzyme.rb +125 -0
  70. data/lib/bio/db/kegg/expression.rb +173 -0
  71. data/lib/bio/db/kegg/genes.rb +293 -0
  72. data/lib/bio/db/kegg/genome.rb +362 -0
  73. data/lib/bio/db/kegg/glycan.rb +213 -0
  74. data/lib/bio/db/kegg/keggtab.rb +418 -0
  75. data/lib/bio/db/kegg/kgml.rb +299 -0
  76. data/lib/bio/db/kegg/ko.rb +178 -0
  77. data/lib/bio/db/kegg/reaction.rb +97 -0
  78. data/lib/bio/db/litdb.rb +131 -0
  79. data/lib/bio/db/medline.rb +317 -0
  80. data/lib/bio/db/nbrf.rb +199 -0
  81. data/lib/bio/db/pdb.rb +38 -0
  82. data/lib/bio/db/pdb/atom.rb +60 -0
  83. data/lib/bio/db/pdb/chain.rb +117 -0
  84. data/lib/bio/db/pdb/model.rb +106 -0
  85. data/lib/bio/db/pdb/pdb.rb +1682 -0
  86. data/lib/bio/db/pdb/residue.rb +122 -0
  87. data/lib/bio/db/pdb/utils.rb +234 -0
  88. data/lib/bio/db/prosite.rb +616 -0
  89. data/lib/bio/db/rebase.rb +417 -0
  90. data/lib/bio/db/transfac.rb +387 -0
  91. data/lib/bio/feature.rb +201 -0
  92. data/lib/bio/io/brdb.rb +103 -0
  93. data/lib/bio/io/das.rb +471 -0
  94. data/lib/bio/io/dbget.rb +212 -0
  95. data/lib/bio/io/ddbjxml.rb +614 -0
  96. data/lib/bio/io/fastacmd.rb +123 -0
  97. data/lib/bio/io/fetch.rb +114 -0
  98. data/lib/bio/io/flatfile.rb +496 -0
  99. data/lib/bio/io/flatfile/bdb.rb +266 -0
  100. data/lib/bio/io/flatfile/index.rb +1308 -0
  101. data/lib/bio/io/flatfile/indexer.rb +778 -0
  102. data/lib/bio/io/higet.rb +92 -0
  103. data/lib/bio/io/keggapi.rb +863 -0
  104. data/lib/bio/io/pubmed.rb +189 -0
  105. data/lib/bio/io/registry.rb +308 -0
  106. data/lib/bio/io/soapwsdl.rb +114 -0
  107. data/lib/bio/io/sql.rb +428 -0
  108. data/lib/bio/location.rb +650 -0
  109. data/lib/bio/pathway.rb +991 -0
  110. data/lib/bio/reference.rb +308 -0
  111. data/lib/bio/sequence.rb +593 -0
  112. data/lib/bio/shell.rb +51 -0
  113. data/lib/bio/shell/core.rb +512 -0
  114. data/lib/bio/shell/plugin/codon.rb +228 -0
  115. data/lib/bio/shell/plugin/entry.rb +85 -0
  116. data/lib/bio/shell/plugin/flatfile.rb +119 -0
  117. data/lib/bio/shell/plugin/keggapi.rb +187 -0
  118. data/lib/bio/shell/plugin/midi.rb +448 -0
  119. data/lib/bio/shell/plugin/obda.rb +63 -0
  120. data/lib/bio/shell/plugin/seq.rb +238 -0
  121. data/lib/bio/shell/session.rb +214 -0
  122. data/lib/bio/util/color_scheme.rb +214 -0
  123. data/lib/bio/util/color_scheme/buried.rb +78 -0
  124. data/lib/bio/util/color_scheme/helix.rb +78 -0
  125. data/lib/bio/util/color_scheme/hydropathy.rb +83 -0
  126. data/lib/bio/util/color_scheme/nucleotide.rb +50 -0
  127. data/lib/bio/util/color_scheme/strand.rb +78 -0
  128. data/lib/bio/util/color_scheme/taylor.rb +69 -0
  129. data/lib/bio/util/color_scheme/turn.rb +78 -0
  130. data/lib/bio/util/color_scheme/zappo.rb +69 -0
  131. data/lib/bio/util/contingency_table.rb +337 -0
  132. data/lib/bio/util/sirna.rb +306 -0
  133. data/lib/bioruby.rb +34 -0
  134. data/sample/biofetch.rb +475 -0
  135. data/sample/color_scheme_na.rb +99 -0
  136. data/sample/dbget +37 -0
  137. data/sample/fasta2tab.rb +99 -0
  138. data/sample/fsplit.rb +51 -0
  139. data/sample/gb2fasta.rb +31 -0
  140. data/sample/gb2tab.rb +325 -0
  141. data/sample/gbtab2mysql.rb +161 -0
  142. data/sample/genes2nuc.rb +33 -0
  143. data/sample/genes2pep.rb +33 -0
  144. data/sample/genes2tab.rb +81 -0
  145. data/sample/genome2rb.rb +29 -0
  146. data/sample/genome2tab.rb +76 -0
  147. data/sample/goslim.rb +311 -0
  148. data/sample/gt2fasta.rb +47 -0
  149. data/sample/pmfetch.rb +42 -0
  150. data/sample/pmsearch.rb +42 -0
  151. data/sample/psortplot_html.rb +222 -0
  152. data/sample/ssearch2tab.rb +96 -0
  153. data/sample/tdiary.rb +158 -0
  154. data/sample/tfastx2tab.rb +100 -0
  155. data/sample/vs-genes.rb +212 -0
  156. data/test/data/SOSUI/sample.report +11 -0
  157. data/test/data/TMHMM/sample.report +21 -0
  158. data/test/data/blast/eco:b0002.faa +15 -0
  159. data/test/data/blast/eco:b0002.faa.m0 +128 -0
  160. data/test/data/blast/eco:b0002.faa.m7 +65 -0
  161. data/test/data/blast/eco:b0002.faa.m8 +1 -0
  162. data/test/data/embl/AB090716.embl +65 -0
  163. data/test/data/genscan/sample.report +63 -0
  164. data/test/data/prosite/prosite.dat +2233 -0
  165. data/test/data/refseq/nm_126355.entret +64 -0
  166. data/test/data/uniprot/p53_human.uniprot +1456 -0
  167. data/test/runner.rb +10 -0
  168. data/test/unit/bio/appl/blast/test_report.rb +427 -0
  169. data/test/unit/bio/appl/blast/test_xmlparser.rb +400 -0
  170. data/test/unit/bio/appl/genscan/test_report.rb +195 -0
  171. data/test/unit/bio/appl/sosui/test_report.rb +94 -0
  172. data/test/unit/bio/appl/targetp/test_report.rb +159 -0
  173. data/test/unit/bio/appl/test_blast.rb +159 -0
  174. data/test/unit/bio/appl/test_fasta.rb +142 -0
  175. data/test/unit/bio/appl/tmhmm/test_report.rb +139 -0
  176. data/test/unit/bio/data/test_aa.rb +103 -0
  177. data/test/unit/bio/data/test_codontable.rb +120 -0
  178. data/test/unit/bio/data/test_na.rb +89 -0
  179. data/test/unit/bio/db/embl/test_common.rb +130 -0
  180. data/test/unit/bio/db/embl/test_embl.rb +227 -0
  181. data/test/unit/bio/db/embl/test_sptr.rb +268 -0
  182. data/test/unit/bio/db/embl/test_uniprot.rb +44 -0
  183. data/test/unit/bio/db/kegg/test_genes.rb +58 -0
  184. data/test/unit/bio/db/test_fasta.rb +263 -0
  185. data/test/unit/bio/db/test_gff.rb +140 -0
  186. data/test/unit/bio/db/test_prosite.rb +1450 -0
  187. data/test/unit/bio/io/test_ddbjxml.rb +87 -0
  188. data/test/unit/bio/io/test_soapwsdl.rb +45 -0
  189. data/test/unit/bio/shell/plugin/test_seq.rb +175 -0
  190. data/test/unit/bio/test_alignment.rb +1028 -0
  191. data/test/unit/bio/test_command.rb +71 -0
  192. data/test/unit/bio/test_db.rb +109 -0
  193. data/test/unit/bio/test_feature.rb +128 -0
  194. data/test/unit/bio/test_location.rb +51 -0
  195. data/test/unit/bio/test_pathway.rb +485 -0
  196. data/test/unit/bio/test_sequence.rb +386 -0
  197. data/test/unit/bio/test_shell.rb +31 -0
  198. data/test/unit/bio/util/test_color_scheme.rb +45 -0
  199. data/test/unit/bio/util/test_contingency_table.rb +106 -0
  200. data/test/unit/bio/util/test_sirna.rb +258 -0
  201. metadata +295 -0
data/lib/bio/shell.rb ADDED
@@ -0,0 +1,51 @@
1
+ #
2
+ # = bio/shell.rb - Loading all BioRuby shell features
3
+ #
4
+ # Copyright:: Copyright (C) 2005
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: LGPL
7
+ #
8
+ # $Id: shell.rb,v 1.11 2005/12/07 05:12:06 k Exp $
9
+ #
10
+ #--
11
+ #
12
+ # This library is free software; you can redistribute it and/or
13
+ # modify it under the terms of the GNU Lesser General Public
14
+ # License as published by the Free Software Foundation; either
15
+ # version 2 of the License, or (at your option) any later version.
16
+ #
17
+ # This library is distributed in the hope that it will be useful,
18
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
+ # Lesser General Public License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Lesser General Public
23
+ # License along with this library; if not, write to the Free Software
24
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
+ #
26
+ #++
27
+ #
28
+
29
+ require 'bio'
30
+ require 'yaml'
31
+ require 'open-uri'
32
+ require 'pp'
33
+
34
+ module Bio::Shell
35
+
36
+ require 'bio/shell/core'
37
+ require 'bio/shell/session'
38
+ require 'bio/shell/plugin/entry'
39
+ require 'bio/shell/plugin/seq'
40
+ require 'bio/shell/plugin/midi'
41
+ require 'bio/shell/plugin/codon'
42
+ require 'bio/shell/plugin/flatfile'
43
+ require 'bio/shell/plugin/obda'
44
+ require 'bio/shell/plugin/keggapi'
45
+
46
+ extend Ghost
47
+ extend Private
48
+
49
+ end
50
+
51
+
@@ -0,0 +1,512 @@
1
+ #
2
+ # = bio/shell/core.rb - internal methods for the BioRuby shell
3
+ #
4
+ # Copyright:: Copyright (C) 2005
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: LGPL
7
+ #
8
+ # $Id: core.rb,v 1.16 2005/12/07 10:54:23 k Exp $
9
+ #
10
+ #--
11
+ #
12
+ # This library is free software; you can redistribute it and/or
13
+ # modify it under the terms of the GNU Lesser General Public
14
+ # License as published by the Free Software Foundation; either
15
+ # version 2 of the License, or (at your option) any later version.
16
+ #
17
+ # This library is distributed in the hope that it will be useful,
18
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
+ # Lesser General Public License for more details.
21
+ #
22
+ # You should have received a copy of the GNU Lesser General Public
23
+ # License along with this library; if not, write to the Free Software
24
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
+ #
26
+ #++
27
+ #
28
+
29
+ module Bio::Shell::Ghost
30
+
31
+ CONFIG = "config"
32
+ OBJECT = "object"
33
+ HISTORY = "history"
34
+ SCRIPT = "script.rb"
35
+ PLUGIN = "plugin/"
36
+ BIOFLAT = "bioflat/"
37
+
38
+ SITEDIR = "/etc/bioinformatics/bioruby/"
39
+ USERDIR = "#{ENV['HOME']}/.bioinformatics/bioruby/"
40
+ SAVEDIR = ".bioruby/"
41
+
42
+ MARSHAL = [ Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION ]
43
+
44
+ MESSAGE = "...BioRuby in the shell..."
45
+
46
+ ESC_SEQ = {
47
+ :k => "\e[30m", :black => "\e[30m",
48
+ :r => "\e[31m", :red => "\e[31m", :ruby => "\e[31m",
49
+ :g => "\e[32m", :green => "\e[32m",
50
+ :y => "\e[33m", :yellow => "\e[33m",
51
+ :b => "\e[34m", :blue => "\e[34m",
52
+ :m => "\e[35m", :magenta => "\e[35m",
53
+ :c => "\e[36m", :cyan => "\e[36m",
54
+ :w => "\e[37m", :white => "\e[37m",
55
+ :n => "\e[00m", :none => "\e[00m", :reset => "\e[00m",
56
+ }
57
+
58
+ def esc_seq
59
+ ESC_SEQ
60
+ end
61
+
62
+ ### save/restore the environment
63
+
64
+ def setup
65
+ @config = {}
66
+ @cache = {}
67
+ check_version
68
+ check_marshal
69
+ load_config
70
+ load_plugin
71
+ end
72
+
73
+ # A hash to store persistent configurations
74
+ attr_accessor :config
75
+
76
+ # A hash to store temporal (per session) configurations
77
+ attr_accessor :cache
78
+
79
+ def load
80
+ load_object
81
+ load_history
82
+ opening_splash
83
+ end
84
+
85
+ def save
86
+ closing_splash
87
+ save_history
88
+ save_object
89
+ save_config
90
+ end
91
+
92
+ #--
93
+ # *TODO* How to prevent terminal collapse and suppress loading messages?
94
+ #++
95
+ def load_thread
96
+ message = ''
97
+ begin
98
+ t1 = Thread.new do
99
+ require 'stringio'
100
+ sio = StringIO.new('')
101
+ begin
102
+ stdout_save = STDOUT.clone
103
+ STDOUT.reopen(sio)
104
+ load_object
105
+ load_history
106
+ ensure
107
+ STDOUT.reopen(stdout_save)
108
+ stdout_save.close
109
+ message = sio.read
110
+ sio.close
111
+ end
112
+ end
113
+ t2 = Thread.new do
114
+ opening_splash
115
+ end
116
+ t1.join
117
+ t2.join
118
+ rescue
119
+ end
120
+ puts message
121
+ end
122
+
123
+ ### setup
124
+
125
+ def check_version
126
+ if RUBY_VERSION < "1.8.2"
127
+ raise "BioRuby shell runs on Ruby version >= 1.8.2"
128
+ end
129
+ end
130
+
131
+ def check_marshal
132
+ if @config[:marshal] and @config[:marshal] != MARSHAL
133
+ raise "Marshal version mismatch"
134
+ end
135
+ end
136
+
137
+ def create_save_dir
138
+ dir = ask_save_dir
139
+ create_real_dir(dir)
140
+ create_real_dir(dir + PLUGIN)
141
+ create_real_dir(dir + BIOFLAT)
142
+ return dir
143
+ end
144
+
145
+ # 1. ask to save in SAVEDIR directory in the current directory
146
+ # 2. otherwise save in USERDIR directory
147
+ # 3. remember the choice in @cache[:savedir] once per session
148
+ def ask_save_dir
149
+ if @cache[:savedir]
150
+ dir = @cache[:savedir]
151
+ else
152
+ dir = SAVEDIR
153
+ if ! File.directory?(dir)
154
+ loop do
155
+ print "Save in \"#{dir}\" directory? [y/n]: "
156
+ answer = gets
157
+ if /^\s*[Yy]/.match(answer)
158
+ break
159
+ elsif /^\s*[Nn]/.match(answer)
160
+ dir = USERDIR
161
+ break
162
+ end
163
+ end
164
+ end
165
+ @cache[:savedir] = dir
166
+ end
167
+ return dir
168
+ end
169
+
170
+ def create_real_dir(dir)
171
+ unless File.directory?(dir)
172
+ begin
173
+ print "Creating directory (#{dir}) ... "
174
+ Dir.mkdir(dir)
175
+ puts "done"
176
+ rescue
177
+ warn "Error: Failed to create #{dir} : #{$!}"
178
+ end
179
+ end
180
+ end
181
+
182
+ ### bioflat
183
+
184
+ def create_flat_dir(dbname)
185
+ if prefix = create_save_dir
186
+ return prefix + BIOFLAT + dbname.to_s.strip
187
+ else
188
+ return nil
189
+ end
190
+ end
191
+
192
+ def find_flat_dir(dbname)
193
+ dir = SAVEDIR + BIOFLAT + dbname.to_s.strip
194
+ dir = USERDIR + BIOFLAT + dbname.to_s.strip unless File.exists?(dir)
195
+ if File.exists?(dir)
196
+ return dir
197
+ else
198
+ return nil
199
+ end
200
+ end
201
+
202
+ ### config
203
+
204
+ def load_config
205
+ load_config_file(SITEDIR + CONFIG)
206
+ load_config_file(USERDIR + CONFIG)
207
+ load_config_file(SAVEDIR + CONFIG)
208
+ end
209
+
210
+ def load_config_file(file)
211
+ if File.exists?(file)
212
+ print "Loading config (#{file}) ... "
213
+ if hash = YAML.load(File.read(file))
214
+ @config.update(hash)
215
+ end
216
+ puts "done"
217
+ end
218
+ end
219
+
220
+ def save_config
221
+ dir = create_save_dir
222
+ save_config_file(dir + CONFIG)
223
+ end
224
+
225
+ def save_config_file(file)
226
+ begin
227
+ print "Saving config (#{file}) ... "
228
+ File.open(file, "w") do |f|
229
+ f.puts @config.to_yaml
230
+ end
231
+ puts "done"
232
+ rescue
233
+ warn "Error: Failed to save (#{file}) : #{$!}"
234
+ end
235
+ end
236
+
237
+ def config_show
238
+ @config.each do |k, v|
239
+ puts "#{k}\t= #{v.inspect}"
240
+ end
241
+ end
242
+
243
+ def config_echo
244
+ bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
245
+ flag = ! @config[:echo]
246
+ @config[:echo] = IRB.conf[:ECHO] = flag
247
+ eval("conf.echo = #{flag}", bind)
248
+ puts "Echo #{flag ? 'on' : 'off'}"
249
+ end
250
+
251
+ def config_color
252
+ bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
253
+ flag = ! @config[:color]
254
+ @config[:color] = flag
255
+ if flag
256
+ IRB.conf[:PROMPT_MODE] = :BIORUBY_COLOR
257
+ eval("conf.prompt_mode = :BIORUBY_COLOR", bind)
258
+ else
259
+ IRB.conf[:PROMPT_MODE] = :BIORUBY
260
+ eval("conf.prompt_mode = :BIORUBY", bind)
261
+ end
262
+ end
263
+
264
+ def config_pager(cmd = nil)
265
+ @config[:pager] = cmd
266
+ end
267
+
268
+ def config_message(str = nil)
269
+ str ||= MESSAGE
270
+ @config[:message] = str
271
+ end
272
+
273
+ ### plugin
274
+
275
+ def load_plugin
276
+ load_plugin_dir(SITEDIR + PLUGIN)
277
+ load_plugin_dir(USERDIR + PLUGIN)
278
+ load_plugin_dir(SAVEDIR + PLUGIN)
279
+ end
280
+
281
+ def load_plugin_dir(dir)
282
+ if File.directory?(dir)
283
+ Dir.glob("#{dir}/*.rb").sort.each do |file|
284
+ print "Loading plugin (#{file}) ... "
285
+ load file
286
+ puts "done"
287
+ end
288
+ end
289
+ end
290
+
291
+ ### object
292
+
293
+ def load_object
294
+ load_object_file(SITEDIR + OBJECT)
295
+ load_object_file(USERDIR + OBJECT)
296
+ load_object_file(SAVEDIR + OBJECT)
297
+ end
298
+
299
+ def load_object_file(file)
300
+ if File.exists?(file)
301
+ print "Loading object (#{file}) ... "
302
+ begin
303
+ bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
304
+ hash = Marshal.load(File.read(file))
305
+ hash.each do |k, v|
306
+ begin
307
+ Thread.current[:restore_value] = v
308
+ eval("#{k} = Thread.current[:restore_value]", bind)
309
+ rescue
310
+ puts "Warning: object '#{k}' couldn't be loaded : #{$!}"
311
+ end
312
+ end
313
+ rescue
314
+ warn "Error: Failed to load (#{file}) : #{$!}"
315
+ end
316
+ puts "done"
317
+ end
318
+ end
319
+
320
+ def save_object
321
+ dir = create_save_dir
322
+ save_object_file(dir + OBJECT)
323
+ end
324
+
325
+ def save_object_file(file)
326
+ begin
327
+ print "Saving object (#{file}) ... "
328
+ File.open(file, "w") do |f|
329
+ begin
330
+ bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
331
+ list = eval("local_variables", bind)
332
+ list -= ["_"]
333
+ hash = {}
334
+ list.each do |elem|
335
+ value = eval(elem, bind)
336
+ if value
337
+ begin
338
+ Marshal.dump(value)
339
+ hash[elem] = value
340
+ rescue
341
+ # value could not be dumped.
342
+ end
343
+ end
344
+ end
345
+ Marshal.dump(hash, f)
346
+ @config[:marshal] = MARSHAL
347
+ rescue
348
+ warn "Error: Failed to dump (#{file}) : #{$!}"
349
+ end
350
+ end
351
+ puts "done"
352
+ rescue
353
+ warn "Error: Failed to save (#{file}) : #{$!}"
354
+ end
355
+ end
356
+
357
+ ### history
358
+
359
+ def load_history
360
+ if @cache[:readline]
361
+ load_history_file(SITEDIR + HISTORY)
362
+ load_history_file(USERDIR + HISTORY)
363
+ load_history_file(SAVEDIR + HISTORY)
364
+ end
365
+ end
366
+
367
+ def load_history_file(file)
368
+ if File.exists?(file)
369
+ print "Loading history (#{file}) ... "
370
+ File.open(file).each do |line|
371
+ Readline::HISTORY.push line.chomp
372
+ end
373
+ puts "done"
374
+ end
375
+ end
376
+
377
+ def save_history
378
+ if @cache[:readline]
379
+ dir = create_save_dir
380
+ save_history_file(dir + HISTORY)
381
+ end
382
+ end
383
+
384
+ def save_history_file(file)
385
+ begin
386
+ print "Saving history (#{file}) ... "
387
+ File.open(file, "w") do |f|
388
+ f.puts Readline::HISTORY.to_a
389
+ end
390
+ puts "done"
391
+ rescue
392
+ warn "Error: Failed to save (#{file}) : #{$!}"
393
+ end
394
+ end
395
+
396
+ ### script
397
+
398
+ def script(mode = nil)
399
+ case mode
400
+ when :begin, "begin", :start, "start"
401
+ @cache[:script] = true
402
+ script_begin
403
+ when :end, "end", :stop, "stop"
404
+ @cache[:script] = false
405
+ script_end
406
+ save_script
407
+ else
408
+ if @cache[:script]
409
+ @cache[:script] = false
410
+ script_end
411
+ save_script
412
+ else
413
+ @cache[:script] = true
414
+ script_begin
415
+ end
416
+ end
417
+ end
418
+
419
+ def script_begin
420
+ puts "-- 8< -- 8< -- 8< -- Script -- 8< -- 8< -- 8< --"
421
+ @script_begin = Readline::HISTORY.size
422
+ end
423
+
424
+ def script_end
425
+ puts "-- >8 -- >8 -- >8 -- Script -- >8 -- >8 -- >8 --"
426
+ @script_end = Readline::HISTORY.size - 2
427
+ end
428
+
429
+ def save_script
430
+ if @script_begin and @script_end and @script_begin <= @script_end
431
+ dir = create_save_dir
432
+ save_script_file(dir + SCRIPT)
433
+ else
434
+ puts "Error: script range #{@script_begin}..#{@script_end} is invalid"
435
+ end
436
+ end
437
+
438
+ def save_script_file(file)
439
+ begin
440
+ print "Saving script (#{file}) ... "
441
+ File.open(file, "w") do |f|
442
+ f.print "#!/usr/bin/env ruby\n\n"
443
+ f.print "require 'bioruby'\n\n"
444
+ f.puts Readline::HISTORY.to_a[@script_begin..@script_end]
445
+ f.print "\n\n"
446
+ end
447
+ puts "done"
448
+ rescue
449
+ @script_begin = nil
450
+ warn "Error: Failed to save (#{file}) : #{$!}"
451
+ end
452
+ end
453
+
454
+ ### splash
455
+
456
+ def splash_message
457
+ @config[:message] ||= MESSAGE
458
+ @config[:message].to_s.split(//).join(" ")
459
+ end
460
+
461
+ def splash_message_color
462
+ str = splash_message
463
+ ruby = ESC_SEQ[:ruby]
464
+ none = ESC_SEQ[:none]
465
+ return str.sub(/R u b y/) { "#{ruby}R u b y#{none}" }
466
+ end
467
+
468
+ def splash_message_action
469
+ s = splash_message
470
+ l = s.length
471
+ c = ESC_SEQ
472
+ x = " "
473
+ 0.step(l,2) do |i|
474
+ l1 = l-i; l2 = l1/2; l4 = l2/2
475
+ STDERR.print "#{c[:n]}#{s[0,i]}#{x*l1}#{c[:y]}#{s[i,1]}\r"
476
+ sleep(0.001)
477
+ STDERR.print "#{c[:n]}#{s[0,i]}#{x*l2}#{c[:g]}#{s[i,1]}#{x*(l1-l2)}\r"
478
+ sleep(0.002)
479
+ STDERR.print "#{c[:n]}#{s[0,i]}#{x*l4}#{c[:r]}#{s[i,1]}#{x*(l2-l4)}\r"
480
+ sleep(0.004)
481
+ STDERR.print "#{c[:n]}#{s[0,i+1]}#{x*l4}\r"
482
+ sleep(0.008)
483
+ end
484
+ end
485
+
486
+ def opening_splash
487
+ print "\n"
488
+ if @config[:color]
489
+ splash_message_action
490
+ end
491
+ if @config[:color]
492
+ print splash_message_color
493
+ else
494
+ print splash_message
495
+ end
496
+ print "\n\n"
497
+ print " Version : BioRuby #{Bio::BIORUBY_VERSION.join(".")}"
498
+ print " / Ruby #{RUBY_VERSION}\n\n"
499
+ end
500
+
501
+ def closing_splash
502
+ print "\n\n"
503
+ if @config[:color]
504
+ print splash_message_color
505
+ else
506
+ print splash_message
507
+ end
508
+ print "\n\n"
509
+ end
510
+
511
+ end
512
+