bio-shell 0.0.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 (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/BSDL +22 -0
  4. data/COPYING +56 -0
  5. data/COPYING.ja +51 -0
  6. data/Gemfile +6 -0
  7. data/LEGAL +8 -0
  8. data/README.md +62 -0
  9. data/Rakefile +20 -0
  10. data/bin/bioruby +44 -0
  11. data/bio-shell.gemspec +29 -0
  12. data/lib/bio/shell.rb +44 -0
  13. data/lib/bio/shell/core.rb +578 -0
  14. data/lib/bio/shell/demo.rb +146 -0
  15. data/lib/bio/shell/interface.rb +217 -0
  16. data/lib/bio/shell/irb.rb +94 -0
  17. data/lib/bio/shell/object.rb +71 -0
  18. data/lib/bio/shell/plugin/blast.rb +42 -0
  19. data/lib/bio/shell/plugin/codon.rb +218 -0
  20. data/lib/bio/shell/plugin/das.rb +58 -0
  21. data/lib/bio/shell/plugin/emboss.rb +23 -0
  22. data/lib/bio/shell/plugin/entry.rb +137 -0
  23. data/lib/bio/shell/plugin/flatfile.rb +101 -0
  24. data/lib/bio/shell/plugin/midi.rb +430 -0
  25. data/lib/bio/shell/plugin/ncbirest.rb +68 -0
  26. data/lib/bio/shell/plugin/obda.rb +45 -0
  27. data/lib/bio/shell/plugin/psort.rb +56 -0
  28. data/lib/bio/shell/plugin/seq.rb +248 -0
  29. data/lib/bio/shell/plugin/togows.rb +40 -0
  30. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/bioruby_generator.rb +29 -0
  31. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_classes.rhtml +4 -0
  32. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_log.rhtml +27 -0
  33. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_methods.rhtml +11 -0
  34. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_modules.rhtml +4 -0
  35. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_variables.rhtml +7 -0
  36. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-bg.gif +0 -0
  37. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-gem.png +0 -0
  38. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-link.gif +0 -0
  39. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.css +368 -0
  40. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.rhtml +47 -0
  41. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb +144 -0
  42. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_helper.rb +47 -0
  43. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/commands.rhtml +8 -0
  44. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/history.rhtml +10 -0
  45. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/index.rhtml +26 -0
  46. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/spinner.gif +0 -0
  47. data/lib/bio/shell/script.rb +25 -0
  48. data/lib/bio/shell/setup.rb +108 -0
  49. data/lib/bio/shell/version.rb +5 -0
  50. data/lib/bio/shell/web.rb +102 -0
  51. data/lib/bioruby.rb +34 -0
  52. metadata +165 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a00fbd14c9244b1c3bdde2a86815e7c0eae20db8
4
+ data.tar.gz: 78252c99bcdf7551b90ff80fd5222fb0c6369ee0
5
+ SHA512:
6
+ metadata.gz: f9f48890aa062bceeb71948418e32c137f25595e17c21b440335546ff1b1ca2d9f07594ab9b8385952131a80d677522e2fed981716235f0196a4bf5aae1a6cf8
7
+ data.tar.gz: f85f4804b5605247de07c4dcf992fbc0ef040144b3036d2dfbfc8edf0feded9220414c611f2cc572e96a6c500e0e9d606a647f8c69157761f68d060a22e7f3f4
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /pkg/
7
+ /spec/reports/
8
+ /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-shell.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,62 @@
1
+ # BioRuby Shell
2
+
3
+ [![Build Status](https://secure.travis-ci.org/bioruby/bio-shell.png)](http://travis-ci.org/bioruby/bio-shell)
4
+
5
+ bio-shell, providing BioRuby Shell, is a command-line interface for
6
+ [BioRuby](http://bioruby.org/), an open source bioinformatics library
7
+ for Ruby.
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-shell and many more plugins are available at
14
+ [biogems.info](http://www.biogems.info/).
15
+
16
+
17
+ ## Requirements
18
+
19
+ bio-shell uses the `bio` gem. It will automatically be installed
20
+ during the installation of `bio-shell` in normal cases.
21
+
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'bio-shell'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install bio-shell
38
+
39
+ ## Usage
40
+
41
+ See BioRuby documentation at https://github.com/bioruby/documentation
42
+
43
+ ## Development
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`.
46
+ To release a new version, update the version number in `version.rb`,
47
+ and then run `bundle exec rake release`, which will create a git tag
48
+ for the version, push git commits and tags, and push the `.gem` file
49
+ to [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at
54
+ https://github.com/bioruby/bio-shell
55
+
56
+ ## Cite
57
+
58
+ If you use this software, please cite one of
59
+
60
+ * [BioRuby: bioinformatics software for the Ruby programming language](http://dx.doi.org/10.1093/bioinformatics/btq475)
61
+ * [Biogem: an effective tool-based approach for scaling up open source software development in bioinformatics](http://dx.doi.org/10.1093/bioinformatics/bts080)
62
+
@@ -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/unit/**/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' << 'Bio::Shell API documentation'
18
+ r.options << '--line-numbers'
19
+ end
20
+
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # = BioRuby shell - command line interface for the BioRuby library
4
+ #
5
+ # Copyright:: Copyright (C) 2005, 2006, 2007
6
+ # Toshiaki Katayama <k@bioruby.org>
7
+ # License:: The Ruby License
8
+ #
9
+ # $Id:$
10
+ #
11
+
12
+ gem 'bio-shell'
13
+ gem 'bio', '>=1.5.1'
14
+
15
+ require 'bio/shell'
16
+
17
+ # required to run commands (getseq, ls etc.)
18
+ include Bio::Shell
19
+
20
+ # setup command line options, working directory, and irb configurations
21
+ Bio::Shell::Setup.new
22
+
23
+ # loading workspace and command history
24
+ Bio::Shell.load_session
25
+
26
+ # sets default email address for Entrez eUtils.
27
+ Bio::NCBI.default_email ||= 'staff@bioruby.org'
28
+
29
+ # main loop
30
+ if Bio::Shell.cache[:rails]
31
+ Bio::Shell.cache[:rails].join
32
+ else
33
+ Signal.trap("SIGINT") do
34
+ Bio::Shell.cache[:irb].signal_handle
35
+ end
36
+
37
+ catch(:IRB_EXIT) do
38
+ Bio::Shell.cache[:irb].eval_input
39
+ end
40
+ end
41
+
42
+ # saving workspace, command history and configuration before exit
43
+ Bio::Shell.save_session
44
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bio/shell/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bio-shell"
8
+ spec.version = Bio::Shell::VERSION
9
+ spec.authors = ["BioRuby project"]
10
+ spec.email = ["staff@bioruby.org"]
11
+
12
+ spec.summary = %q{BioRuby Shell: interactive analysis environment for BioRuby}
13
+ spec.description = %q{BioRuby Shell is a command-line based interacitve analysis enviroment for BioRuby open source bioinformatics library.}
14
+ spec.homepage = "https://github.com/bioruby/bioruby-shell"
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
+
25
+ spec.add_development_dependency "bundler", "~> 1.15"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rdoc", "~> 5"
28
+ spec.add_development_dependency "test-unit", "~> 3"
29
+ end
@@ -0,0 +1,44 @@
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
+
@@ -0,0 +1,578 @@
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
+