bio 1.5.2 → 1.6.0.pre.20181210

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 (93) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +12 -11
  3. data/ChangeLog +14 -3106
  4. data/{gemfiles/Gemfile.travis-ruby2.2 → Gemfile} +0 -1
  5. data/KNOWN_ISSUES.rdoc +0 -5
  6. data/README.rdoc +11 -18
  7. data/RELEASE_NOTES.rdoc +34 -291
  8. data/Rakefile +13 -9
  9. data/appveyor.yml +21 -0
  10. data/bioruby.gemspec +7 -78
  11. data/bioruby.gemspec.erb +8 -27
  12. data/doc/ChangeLog-1.5.0 +2919 -0
  13. data/doc/RELEASE_NOTES-1.5.0.rdoc +285 -0
  14. data/doc/Tutorial.rd +6 -108
  15. data/doc/Tutorial.rd.html +19 -98
  16. data/gemfiles/Gemfile.travis-jruby1.8 +3 -5
  17. data/gemfiles/Gemfile.travis-jruby1.9 +0 -3
  18. data/gemfiles/Gemfile.travis-rbx +0 -1
  19. data/gemfiles/Gemfile.travis-ruby1.8 +4 -4
  20. data/gemfiles/Gemfile.travis-ruby1.9 +0 -1
  21. data/gemfiles/prepare-gemspec.rb +4 -0
  22. data/lib/bio.rb +0 -10
  23. data/lib/bio/data/codontable.rb +99 -3
  24. data/lib/bio/io/togows.rb +5 -5
  25. data/lib/bio/version.rb +6 -8
  26. data/sample/test_restriction_enzyme_long.rb +1 -1
  27. data/test/unit/bio/data/test_codontable.rb +3 -0
  28. metadata +11 -77
  29. data/bin/bioruby +0 -47
  30. data/bin/br_biofetch.rb +0 -71
  31. data/bin/br_bioflat.rb +0 -293
  32. data/bin/br_biogetseq.rb +0 -45
  33. data/bin/br_pmfetch.rb +0 -422
  34. data/lib/bio/db/biosql/biosql_to_biosequence.rb +0 -78
  35. data/lib/bio/db/biosql/sequence.rb +0 -444
  36. data/lib/bio/db/phyloxml/phyloxml.xsd +0 -582
  37. data/lib/bio/db/phyloxml/phyloxml_elements.rb +0 -1197
  38. data/lib/bio/db/phyloxml/phyloxml_parser.rb +0 -1001
  39. data/lib/bio/db/phyloxml/phyloxml_writer.rb +0 -227
  40. data/lib/bio/io/biosql/ar-biosql.rb +0 -257
  41. data/lib/bio/io/biosql/biosql.rb +0 -39
  42. data/lib/bio/io/biosql/config/database.yml +0 -21
  43. data/lib/bio/io/sql.rb +0 -79
  44. data/lib/bio/shell.rb +0 -44
  45. data/lib/bio/shell/core.rb +0 -578
  46. data/lib/bio/shell/demo.rb +0 -146
  47. data/lib/bio/shell/interface.rb +0 -217
  48. data/lib/bio/shell/irb.rb +0 -94
  49. data/lib/bio/shell/object.rb +0 -71
  50. data/lib/bio/shell/plugin/blast.rb +0 -42
  51. data/lib/bio/shell/plugin/codon.rb +0 -218
  52. data/lib/bio/shell/plugin/das.rb +0 -58
  53. data/lib/bio/shell/plugin/emboss.rb +0 -23
  54. data/lib/bio/shell/plugin/entry.rb +0 -137
  55. data/lib/bio/shell/plugin/flatfile.rb +0 -101
  56. data/lib/bio/shell/plugin/midi.rb +0 -430
  57. data/lib/bio/shell/plugin/ncbirest.rb +0 -68
  58. data/lib/bio/shell/plugin/obda.rb +0 -45
  59. data/lib/bio/shell/plugin/psort.rb +0 -56
  60. data/lib/bio/shell/plugin/seq.rb +0 -248
  61. data/lib/bio/shell/plugin/togows.rb +0 -40
  62. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/bioruby_generator.rb +0 -29
  63. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_classes.rhtml +0 -4
  64. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_log.rhtml +0 -27
  65. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_methods.rhtml +0 -11
  66. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_modules.rhtml +0 -4
  67. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_variables.rhtml +0 -7
  68. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-bg.gif +0 -0
  69. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-gem.png +0 -0
  70. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-link.gif +0 -0
  71. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.css +0 -368
  72. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.rhtml +0 -47
  73. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb +0 -144
  74. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_helper.rb +0 -47
  75. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/commands.rhtml +0 -8
  76. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/history.rhtml +0 -10
  77. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/index.rhtml +0 -26
  78. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/spinner.gif +0 -0
  79. data/lib/bio/shell/script.rb +0 -25
  80. data/lib/bio/shell/setup.rb +0 -108
  81. data/lib/bio/shell/web.rb +0 -102
  82. data/sample/test_phyloxml_big.rb +0 -205
  83. data/test/data/phyloxml/apaf.xml +0 -666
  84. data/test/data/phyloxml/bcl_2.xml +0 -2097
  85. data/test/data/phyloxml/made_up.xml +0 -144
  86. data/test/data/phyloxml/ncbi_taxonomy_mollusca_short.xml +0 -65
  87. data/test/data/phyloxml/phyloxml_examples.xml +0 -415
  88. data/test/unit/bio/db/biosql/tc_biosql.rb +0 -114
  89. data/test/unit/bio/db/biosql/ts_suite_biosql.rb +0 -8
  90. data/test/unit/bio/db/test_phyloxml.rb +0 -821
  91. data/test/unit/bio/db/test_phyloxml_writer.rb +0 -334
  92. data/test/unit/bio/shell/plugin/test_seq.rb +0 -187
  93. data/test/unit/bio/test_shell.rb +0 -20
@@ -1,39 +0,0 @@
1
- #require 'dm-ar-finders'
2
- #require 'dm-core'
3
- require 'erb'
4
- require 'composite_primary_keys'
5
-
6
- module Bio
7
- class SQL
8
- class DummyBase < ActiveRecord::Base
9
- #NOTE: Using postgresql, not setting sequence name, system will discover the name by default.
10
- #NOTE: this class will not establish the connection automatically
11
- self.abstract_class = true
12
- self.pluralize_table_names = false
13
- #prepend table name to the usual id, avoid to specify primary id for every table
14
- self.primary_key_prefix_type = :table_name_with_underscore
15
- #biosql_configurations=YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__),'./config', 'database.yml'))).result)
16
- #self.configurations=biosql_configurations
17
- #self.establish_connection "development"
18
- end #DummyBase
19
-
20
- require 'bio/io/biosql/ar-biosql'
21
-
22
- # #no check is made
23
- def self.establish_connection(configurations, env)
24
- # #configurations is an hash similar what YAML returns.
25
-
26
- #configurations.assert_valid_keys('development', 'production','test')
27
- #configurations[env].assert_valid_keys('hostname','database','adapter','username','password')
28
- DummyBase.configurations = configurations
29
- connection = DummyBase.establish_connection "#{env}"
30
- #Init of basis terms and ontologies
31
- Ontology.first(:conditions => ["name = ?", 'Annotation Tags']) || Ontology.create({:name => 'Annotation Tags'})
32
- Ontology.first(:conditions => ["name = ?", 'SeqFeature Keys']) || Ontology.create({:name => 'SeqFeature Keys'})
33
- Ontology.first(:conditions => ["name = ?", 'SeqFeature Sources']) ||Ontology.create({:name => 'SeqFeature Sources'})
34
- Term.first(:conditions => ["name = ?", 'EMBLGenBankSwit']) || Term.create({:name => 'EMBLGenBankSwit', :ontology => Ontology.first(:conditions => ["name = ?", 'SeqFeature Sources'])})
35
- connection
36
- end #establish_connection
37
-
38
- end #SQL
39
- end #Bio
@@ -1,21 +0,0 @@
1
- #This is the database configuration specific for BioSQL
2
- #User can configure it's db here
3
-
4
- development:
5
- adapter: jdbcmysql
6
- database: bioseq
7
- username: febo
8
- password:
9
- hostname: localhost
10
-
11
- test:
12
- adapter: postgresql
13
- database: biorails_test
14
- username: rails
15
- password:
16
-
17
- production:
18
- adapter: postgresql
19
- database: biorails_production
20
- username: rails
21
- password:
@@ -1,79 +0,0 @@
1
- #module Bio
2
- # class SQL
3
- # #no check is made
4
- # def self.establish_connection(configurations, env)
5
- # #configurations is an hash similar what YAML returns.
6
- # #{:database=>"biorails_development", :adapter=>"postgresql", :username=>"rails", :password=>nil}
7
- # configurations.assert_valid_keys('development', 'production','test')
8
- # configurations[env].assert_valid_keys('hostname','database','adapter','username','password')
9
- # DummyBase.configurations = configurations
10
- # DummyBase.establish_connection "#{env}"
11
- #end
12
-
13
-
14
- #require 'rubygems'
15
- #require 'composite_primary_keys'
16
- #require 'erb'
17
- # BiosqlPlug
18
-
19
- =begin
20
- Ok Hilmar gives to me some clarification
21
- 1) "EMBL/GenBank/SwissProt" name in term table, is only a convention assuming data loaded by genbank embl ans swissprot formats.
22
- If your features come from others ways for example blast or alignment ... whatever.. the user as to take care about the source.
23
-
24
-
25
- =end
26
- =begin
27
- TODO:
28
- 1) source_term_id => surce_term and check before if the source term is present or not and the level, the root should always be something "EMBL/GenBank/SwissProt" or contestualized.
29
- 2) Into DummyBase class delete connection there and use Bio::ArSQL.establish_connection which reads info from a yml file.
30
- 3) Chk Locations in Biofeatures ArSQL
31
- =end
32
- module Bio
33
- class SQL
34
-
35
- require 'bio/io/biosql/biosql'
36
- autoload :Sequence, 'bio/db/biosql/sequence'
37
-
38
- def self.fetch_id(id)
39
- Bio::SQL::Bioentry.find(id)
40
- end
41
-
42
- def self.fetch_accession(accession)
43
- # Bio::SQL::Bioentry.exists?(:accession => accession) ? Bio::SQL::Sequence.new(:entry=>Bio::SQL::Bioentry.find_by_accession(accession)) : nil
44
- Bio::SQL::Sequence.new(:entry=>Bio::SQL::Bioentry.find_by_accession(accession.upcase))
45
- end
46
-
47
- def self.exists_accession(accession)
48
- # Bio::SQL::Bioentry.find_by_accession(accession.upcase).nil? ? false : true
49
- !Bio::SQL::Bioentry.find_by_accession(accession.upcase).nil?
50
- end
51
-
52
- def self.exists_database(name)
53
- # Bio::SQL::Biodatabase.find_by_name(name).nil? ? false : true
54
- !Bio::SQL::Biodatabase.first(:name=>name).nil?
55
- end
56
-
57
- def self.list_entries
58
- Bio::SQL::Bioentry.all.collect do|entry|
59
- {:id=>entry.bioentry_id, :accession=>entry.accession}
60
- end
61
- end
62
-
63
- def self.list_databases
64
- Bio::SQL::Biodatabase.all.collect do|entry|
65
- {:id=>entry.biodatabase_id, :name => entry.name}
66
- end
67
- end
68
-
69
- def self.delete_entry_id(id)
70
- Bio::SQL::Bioentry.delete(id)
71
- end
72
-
73
- def self.delete_entry_accession(accession)
74
- Bio::SQL::Bioentry.find_by_accession(accession.upcase).destroy!
75
- end
76
-
77
- end #biosql
78
-
79
- end #Bio
@@ -1,44 +0,0 @@
1
- #
2
- # = bio/shell.rb - Loading all BioRuby shell features
3
- #
4
- # Copyright:: Copyright (C) 2005, 2006
5
- # Toshiaki Katayama <k@bioruby.org>
6
- # License:: The Ruby License
7
- #
8
- # $Id:$
9
- #
10
-
11
- require 'bio'
12
- require 'yaml'
13
- require 'open-uri'
14
- require 'fileutils'
15
- require 'pp'
16
-
17
- module Bio::Shell
18
-
19
- require 'bio/shell/setup'
20
- require 'bio/shell/irb'
21
- require 'bio/shell/web'
22
- require 'bio/shell/script'
23
- require 'bio/shell/core'
24
- require 'bio/shell/interface'
25
- require 'bio/shell/object'
26
- require 'bio/shell/demo'
27
- require 'bio/shell/plugin/entry'
28
- require 'bio/shell/plugin/seq'
29
- require 'bio/shell/plugin/midi'
30
- require 'bio/shell/plugin/codon'
31
- require 'bio/shell/plugin/flatfile'
32
- require 'bio/shell/plugin/obda'
33
- require 'bio/shell/plugin/das'
34
- require 'bio/shell/plugin/emboss'
35
- require 'bio/shell/plugin/blast'
36
- require 'bio/shell/plugin/psort'
37
- require 'bio/shell/plugin/ncbirest'
38
- require 'bio/shell/plugin/togows'
39
-
40
- extend Ghost
41
-
42
- end
43
-
44
-
@@ -1,578 +0,0 @@
1
- #
2
- # = bio/shell/core.rb - internal methods for the BioRuby shell
3
- #
4
- # Copyright:: Copyright (C) 2005, 2006
5
- # Toshiaki Katayama <k@bioruby.org>
6
- # License:: The Ruby License
7
- #
8
- #
9
-
10
- module Bio::Shell::Core
11
-
12
- SHELLDIR = "shell"
13
- DATADIR = "data"
14
- SESSION = File.join(SHELLDIR, "session")
15
- PLUGIN = File.join(SHELLDIR, "plugin")
16
- SCRIPT = File.join(SHELLDIR, "script.rb")
17
- CONFIG = File.join(SESSION, "config")
18
- OBJECT = File.join(SESSION, "object")
19
- HISTORY = File.join(SESSION, "history")
20
- BIOFLAT = File.join(DATADIR, "bioflat")
21
-
22
- MARSHAL = [ Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION ]
23
-
24
- MESSAGE = "...BioRuby in the shell..."
25
-
26
- ESC_SEQ = {
27
- :k => "\e[30m", :black => "\e[30m",
28
- :r => "\e[31m", :red => "\e[31m", :ruby => "\e[31m",
29
- :g => "\e[32m", :green => "\e[32m",
30
- :y => "\e[33m", :yellow => "\e[33m",
31
- :b => "\e[34m", :blue => "\e[34m",
32
- :m => "\e[35m", :magenta => "\e[35m",
33
- :c => "\e[36m", :cyan => "\e[36m",
34
- :w => "\e[37m", :white => "\e[37m",
35
- :n => "\e[00m", :none => "\e[00m", :reset => "\e[00m",
36
- }
37
-
38
- def colors
39
- ESC_SEQ
40
- end
41
-
42
- def shell_dir
43
- File.join(@cache[:savedir], SHELLDIR)
44
- end
45
-
46
- def data_dir
47
- File.join(@cache[:savedir], DATADIR)
48
- end
49
-
50
- def session_dir
51
- File.join(@cache[:savedir], SESSION)
52
- end
53
-
54
- def plugin_dir
55
- File.join(@cache[:savedir], PLUGIN)
56
- end
57
-
58
- def script_file
59
- File.join(@cache[:savedir], SCRIPT)
60
- end
61
-
62
- def script_dir
63
- File.dirname(script_file)
64
- end
65
-
66
- def config_file
67
- File.join(@cache[:savedir], CONFIG)
68
- end
69
-
70
- def object_file
71
- File.join(@cache[:savedir], OBJECT)
72
- end
73
-
74
- def history_file
75
- File.join(@cache[:savedir], HISTORY)
76
- end
77
-
78
- def bioflat_dir
79
- File.join(@cache[:savedir], BIOFLAT)
80
- end
81
-
82
- def ask_yes_or_no(message)
83
- loop do
84
- STDERR.print "#{message}"
85
- answer = gets
86
- if answer.nil?
87
- # readline support might be broken
88
- return false
89
- elsif /^\s*[Nn]/.match(answer)
90
- return false
91
- elsif /^\s*[Yy]/.match(answer)
92
- return true
93
- else
94
- # loop
95
- end
96
- end
97
- end
98
-
99
- end
100
-
101
-
102
- module Bio::Shell::Ghost
103
-
104
- include Bio::Shell::Core
105
-
106
- # A hash to store persistent configurations
107
- attr_accessor :config
108
-
109
- # A hash to store temporal (per session) configurations
110
- attr_accessor :cache
111
-
112
- ### save/restore the environment
113
-
114
- def configure(savedir)
115
- @config = {}
116
- @cache = {
117
- :savedir => savedir,
118
- :workdir => Dir.pwd,
119
- }
120
- create_save_dir
121
- load_config
122
- load_plugin
123
- end
124
-
125
- def load_session
126
- load_object
127
- unless @cache[:mode] == :script
128
- load_history
129
- opening_splash
130
- open_history
131
- end
132
- end
133
-
134
- def save_session
135
- unless @cache[:mode] == :script
136
- closing_splash
137
- end
138
- if create_save_dir_ask
139
- #save_history # changed to use our own...
140
- close_history
141
- save_object
142
- save_config
143
- end
144
- #STDERR.puts "Leaving directory '#{@cache[:workdir]}'"
145
- end
146
-
147
- ### directories
148
-
149
- def create_save_dir
150
- create_real_dir(session_dir)
151
- create_real_dir(plugin_dir)
152
- create_real_dir(data_dir)
153
- end
154
-
155
- def create_save_dir_ask
156
- if File.directory?(session_dir)
157
- @cache[:save] = true
158
- end
159
- unless @cache[:save]
160
- if ask_yes_or_no("Save session in '#{@cache[:workdir]}' directory? [y/n] ")
161
- create_real_dir(session_dir)
162
- create_real_dir(plugin_dir)
163
- create_real_dir(data_dir)
164
- create_real_dir(bioflat_dir)
165
- @cache[:save] = true
166
- else
167
- @cache[:save] = false
168
- end
169
- end
170
- return @cache[:save]
171
- end
172
-
173
- def create_real_dir(dir)
174
- unless File.directory?(dir)
175
- begin
176
- STDERR.print "Creating directory (#{dir}) ... "
177
- FileUtils.makedirs(dir)
178
- STDERR.puts "done"
179
- rescue
180
- warn "Error: Failed to create directory (#{dir}) : #{$!}"
181
- end
182
- end
183
- end
184
-
185
- ### bioflat
186
-
187
- def create_flat_dir(dbname)
188
- dir = File.join(bioflat_dir, dbname.to_s.strip)
189
- unless File.directory?(dir)
190
- FileUtils.makedirs(dir)
191
- end
192
- return dir
193
- end
194
-
195
- def find_flat_dir(dbname)
196
- dir = File.join(bioflat_dir, dbname.to_s.strip)
197
- if File.exist?(dir)
198
- return dir
199
- else
200
- return nil
201
- end
202
- end
203
-
204
- ### config
205
-
206
- def load_config
207
- load_config_file(config_file)
208
- end
209
-
210
- def load_config_file(file)
211
- if File.exist?(file)
212
- STDERR.print "Loading config (#{file}) ... "
213
- if hash = YAML.load(File.read(file))
214
- @config.update(hash)
215
- end
216
- STDERR.puts "done"
217
- end
218
- end
219
-
220
- def save_config
221
- save_config_file(config_file)
222
- end
223
-
224
- def save_config_file(file)
225
- begin
226
- STDERR.print "Saving config (#{file}) ... "
227
- File.open(file, "w") do |f|
228
- f.puts @config.to_yaml
229
- end
230
- STDERR.puts "done"
231
- rescue
232
- warn "Error: Failed to save (#{file}) : #{$!}"
233
- end
234
- end
235
-
236
- def config_show
237
- @config.each do |k, v|
238
- STDERR.puts "#{k}\t= #{v.inspect}"
239
- end
240
- end
241
-
242
- def config_echo
243
- bind = Bio::Shell.cache[:binding]
244
- flag = ! @config[:echo]
245
- @config[:echo] = IRB.conf[:ECHO] = flag
246
- eval("conf.echo = #{flag}", bind)
247
- STDERR.puts "Echo #{flag ? 'on' : 'off'}"
248
- end
249
-
250
- def config_color
251
- bind = Bio::Shell.cache[:binding]
252
- flag = ! @config[:color]
253
- @config[:color] = flag
254
- if flag
255
- IRB.conf[:PROMPT_MODE] = :BIORUBY_COLOR
256
- eval("conf.prompt_mode = :BIORUBY_COLOR", bind)
257
- else
258
- IRB.conf[:PROMPT_MODE] = :BIORUBY
259
- eval("conf.prompt_mode = :BIORUBY", bind)
260
- end
261
- end
262
-
263
- def config_pager(cmd = nil)
264
- @config[:pager] = cmd
265
- end
266
-
267
- def config_splash
268
- flag = ! @config[:splash]
269
- @config[:splash] = flag
270
- STDERR.puts "Splash #{flag ? 'on' : 'off'}"
271
- opening_splash
272
- end
273
-
274
- def config_message(str = nil)
275
- str ||= MESSAGE
276
- @config[:message] = str
277
- opening_splash
278
- end
279
-
280
- ### plugin
281
-
282
- def load_plugin
283
- load_plugin_dir(plugin_dir)
284
- end
285
-
286
- def load_plugin_dir(dir)
287
- if File.directory?(dir)
288
- Dir.glob("#{dir}/*.rb").sort.each do |file|
289
- STDERR.print "Loading plugin (#{file}) ... "
290
- load file
291
- STDERR.puts "done"
292
- end
293
- end
294
- end
295
-
296
- ### object
297
-
298
- def check_marshal
299
- if @config[:marshal] and @config[:marshal] != MARSHAL
300
- raise "Marshal version mismatch"
301
- end
302
- end
303
-
304
- def load_object
305
- begin
306
- check_marshal
307
- load_object_file(object_file)
308
- rescue
309
- warn "Error: Load aborted : #{$!}"
310
- end
311
- end
312
-
313
- def load_object_file(file)
314
- if File.exist?(file)
315
- STDERR.print "Loading object (#{file}) ... "
316
- begin
317
- bind = Bio::Shell.cache[:binding]
318
- hash = Marshal.load(File.read(file))
319
- hash.each do |k, v|
320
- begin
321
- Thread.current[:restore_value] = v
322
- eval("#{k} = Thread.current[:restore_value]", bind)
323
- rescue
324
- STDERR.puts "Warning: object '#{k}' couldn't be loaded : #{$!}"
325
- end
326
- end
327
- rescue
328
- warn "Error: Failed to load (#{file}) : #{$!}"
329
- end
330
- STDERR.puts "done"
331
- end
332
- end
333
-
334
- def save_object
335
- save_object_file(object_file)
336
- end
337
-
338
- def save_object_file(file)
339
- begin
340
- STDERR.print "Saving object (#{file}) ... "
341
- File.rename(file, "#{file}.old") if File.exist?(file)
342
- File.open(file, "w") do |f|
343
- bind = Bio::Shell.cache[:binding]
344
- list = eval("local_variables", bind)
345
- list.collect! { |x| x.to_s }
346
- list -= ["_"]
347
- hash = {}
348
- list.each do |elem|
349
- value = eval(elem, bind)
350
- if value
351
- begin
352
- Marshal.dump(value)
353
- hash[elem] = value
354
- rescue
355
- # value could not be dumped.
356
- end
357
- end
358
- end
359
- Marshal.dump(hash, f)
360
- @config[:marshal] = MARSHAL
361
- end
362
- STDERR.puts "done"
363
- rescue
364
- File.rename("#{file}.old", file) if File.exist?("#{file}.old")
365
- warn "Error: Failed to save (#{file}) : #{$!}"
366
- end
367
- end
368
-
369
- ### history
370
-
371
- def open_history
372
- @cache[:histfile] = File.open(history_file, "a")
373
- @cache[:histfile].sync = true
374
- end
375
-
376
- def store_history(line)
377
- Bio::Shell.cache[:histfile].puts "# #{Time.now}"
378
- Bio::Shell.cache[:histfile].puts line
379
- end
380
-
381
- def close_history
382
- if @cache[:histfile]
383
- STDERR.print "Saving history (#{history_file}) ... "
384
- @cache[:histfile].close
385
- STDERR.puts "done"
386
- end
387
- end
388
-
389
- def load_history
390
- if @cache[:readline]
391
- load_history_file(history_file)
392
- end
393
- end
394
-
395
- def load_history_file(file)
396
- if File.exist?(file)
397
- STDERR.print "Loading history (#{file}) ... "
398
- File.open(file).each do |line|
399
- unless line[/^# /]
400
- Readline::HISTORY.push line.chomp
401
- end
402
- end
403
- STDERR.puts "done"
404
- end
405
- end
406
-
407
- # not used (use open_history/close_history instead)
408
- def save_history
409
- if @cache[:readline]
410
- save_history_file(history_file)
411
- end
412
- end
413
-
414
- def save_history_file(file)
415
- begin
416
- STDERR.print "Saving history (#{file}) ... "
417
- File.open(file, "w") do |f|
418
- f.puts Readline::HISTORY.to_a
419
- end
420
- STDERR.puts "done"
421
- rescue
422
- warn "Error: Failed to save (#{file}) : #{$!}"
423
- end
424
- end
425
-
426
- ### script
427
-
428
- def script(mode = nil)
429
- case mode
430
- when :begin, "begin", :start, "start"
431
- @cache[:script] = true
432
- script_begin
433
- when :end, "end", :stop, "stop"
434
- @cache[:script] = false
435
- script_end
436
- save_script
437
- else
438
- if @cache[:script]
439
- @cache[:script] = false
440
- script_end
441
- save_script
442
- else
443
- @cache[:script] = true
444
- script_begin
445
- end
446
- end
447
- end
448
-
449
- def script_begin
450
- STDERR.puts "-- 8< -- 8< -- 8< -- Script -- 8< -- 8< -- 8< --"
451
- @script_begin = Readline::HISTORY.size
452
- end
453
-
454
- def script_end
455
- STDERR.puts "-- >8 -- >8 -- >8 -- Script -- >8 -- >8 -- >8 --"
456
- @script_end = Readline::HISTORY.size - 2
457
- end
458
-
459
- def save_script
460
- if @script_begin and @script_end and @script_begin <= @script_end
461
- if File.exist?(script_file)
462
- message = "Overwrite script file (#{script_file})? [y/n] "
463
- else
464
- message = "Save script file (#{script_file})? [y/n] "
465
- end
466
- if ask_yes_or_no(message)
467
- save_script_file(script_file)
468
- else
469
- STDERR.puts " ... save aborted."
470
- end
471
- elsif @script_begin and @script_end and @script_begin - @script_end == 1
472
- STDERR.puts " ... script aborted."
473
- else
474
- STDERR.puts "Error: Script range #{@script_begin}..#{@script_end} is invalid"
475
- end
476
- end
477
-
478
- def save_script_file(file)
479
- begin
480
- STDERR.print "Saving script (#{file}) ... "
481
- File.open(file, "w") do |f|
482
- f.puts "#!/usr/bin/env bioruby"
483
- f.puts
484
- f.puts Readline::HISTORY.to_a[@script_begin..@script_end]
485
- f.puts
486
- end
487
- STDERR.puts "done"
488
- rescue
489
- @script_begin = nil
490
- warn "Error: Failed to save (#{file}) : #{$!}"
491
- end
492
- end
493
-
494
- ### splash
495
-
496
- def splash_message
497
- @config[:message] ||= MESSAGE
498
- @config[:message].to_s.split(//).join(" ")
499
- end
500
-
501
- def splash_message_color
502
- str = splash_message
503
- ruby = colors[:ruby]
504
- none = colors[:none]
505
- return str.sub(/R u b y/) { "#{ruby}R u b y#{none}" }
506
- end
507
-
508
- def splash_message_action(message = nil)
509
- s = message || splash_message
510
- l = s.length
511
- x = " "
512
- 0.step(l,2) do |i|
513
- l1 = l-i; l2 = l1/2; l4 = l2/2
514
- STDERR.print "#{s[0,i]}#{x*l1}#{s[i,1]}\r"
515
- sleep(0.001)
516
- STDERR.print "#{s[0,i]}#{x*l2}#{s[i,1]}#{x*(l1-l2)}\r"
517
- sleep(0.002)
518
- STDERR.print "#{s[0,i]}#{x*l4}#{s[i,1]}#{x*(l2-l4)}\r"
519
- sleep(0.004)
520
- STDERR.print "#{s[0,i+1]}#{x*l4}\r"
521
- sleep(0.008)
522
- end
523
- end
524
-
525
- def splash_message_action_color(message = nil)
526
- s = message || splash_message
527
- l = s.length
528
- c = colors
529
- x = " "
530
- 0.step(l,2) do |i|
531
- l1 = l-i; l2 = l1/2; l4 = l2/2
532
- STDERR.print "#{c[:n]}#{s[0,i]}#{x*l1}#{c[:y]}#{s[i,1]}\r"
533
- sleep(0.001)
534
- STDERR.print "#{c[:n]}#{s[0,i]}#{x*l2}#{c[:g]}#{s[i,1]}#{x*(l1-l2)}\r"
535
- sleep(0.002)
536
- STDERR.print "#{c[:n]}#{s[0,i]}#{x*l4}#{c[:r]}#{s[i,1]}#{x*(l2-l4)}\r"
537
- sleep(0.004)
538
- STDERR.print "#{c[:n]}#{s[0,i+1]}#{x*l4}\r"
539
- sleep(0.008)
540
- end
541
- end
542
-
543
- def opening_splash
544
- STDERR.puts
545
- if @config[:splash]
546
- if @config[:color]
547
- splash_message_action_color
548
- else
549
- splash_message_action
550
- end
551
- end
552
- if @config[:color]
553
- STDERR.print splash_message_color
554
- else
555
- STDERR.print splash_message
556
- end
557
- STDERR.puts
558
- STDERR.puts
559
- STDERR.print " Version : BioRuby #{Bio::BIORUBY_VERSION_ID}"
560
- STDERR.print " / Ruby #{RUBY_VERSION}"
561
- STDERR.puts
562
- STDERR.puts
563
- end
564
-
565
- def closing_splash
566
- STDERR.puts
567
- STDERR.puts
568
- if @config[:color]
569
- STDERR.print splash_message_color
570
- else
571
- STDERR.print splash_message
572
- end
573
- STDERR.puts
574
- STDERR.puts
575
- end
576
-
577
- end
578
-