bio 0.7.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/bin/bioruby +71 -27
  2. data/bin/br_biofetch.rb +5 -17
  3. data/bin/br_bioflat.rb +14 -26
  4. data/bin/br_biogetseq.rb +6 -18
  5. data/bin/br_pmfetch.rb +6 -16
  6. data/doc/Changes-0.7.rd +35 -0
  7. data/doc/KEGG_API.rd +287 -172
  8. data/doc/KEGG_API.rd.ja +273 -160
  9. data/doc/Tutorial.rd +18 -9
  10. data/doc/Tutorial.rd.ja +656 -138
  11. data/lib/bio.rb +6 -24
  12. data/lib/bio/alignment.rb +5 -5
  13. data/lib/bio/appl/blast.rb +132 -98
  14. data/lib/bio/appl/blast/format0.rb +9 -19
  15. data/lib/bio/appl/blast/wublast.rb +5 -18
  16. data/lib/bio/appl/emboss.rb +40 -47
  17. data/lib/bio/appl/hmmer.rb +116 -82
  18. data/lib/bio/appl/hmmer/report.rb +509 -364
  19. data/lib/bio/appl/spidey/report.rb +7 -18
  20. data/lib/bio/data/na.rb +3 -21
  21. data/lib/bio/db.rb +3 -21
  22. data/lib/bio/db/aaindex.rb +147 -52
  23. data/lib/bio/db/embl/common.rb +27 -6
  24. data/lib/bio/db/embl/embl.rb +18 -10
  25. data/lib/bio/db/embl/sptr.rb +87 -67
  26. data/lib/bio/db/embl/swissprot.rb +32 -3
  27. data/lib/bio/db/embl/trembl.rb +32 -3
  28. data/lib/bio/db/embl/uniprot.rb +32 -3
  29. data/lib/bio/db/fasta.rb +327 -289
  30. data/lib/bio/db/medline.rb +25 -4
  31. data/lib/bio/db/nbrf.rb +12 -20
  32. data/lib/bio/db/pdb.rb +4 -1
  33. data/lib/bio/db/pdb/chemicalcomponent.rb +240 -0
  34. data/lib/bio/db/pdb/pdb.rb +13 -8
  35. data/lib/bio/db/rebase.rb +93 -97
  36. data/lib/bio/feature.rb +2 -31
  37. data/lib/bio/io/ddbjxml.rb +167 -139
  38. data/lib/bio/io/fastacmd.rb +89 -56
  39. data/lib/bio/io/flatfile.rb +994 -278
  40. data/lib/bio/io/flatfile/index.rb +257 -194
  41. data/lib/bio/io/flatfile/indexer.rb +37 -29
  42. data/lib/bio/reference.rb +147 -64
  43. data/lib/bio/sequence.rb +57 -417
  44. data/lib/bio/sequence/aa.rb +64 -0
  45. data/lib/bio/sequence/common.rb +175 -0
  46. data/lib/bio/sequence/compat.rb +68 -0
  47. data/lib/bio/sequence/format.rb +134 -0
  48. data/lib/bio/sequence/generic.rb +24 -0
  49. data/lib/bio/sequence/na.rb +189 -0
  50. data/lib/bio/shell.rb +9 -23
  51. data/lib/bio/shell/core.rb +130 -125
  52. data/lib/bio/shell/demo.rb +143 -0
  53. data/lib/bio/shell/{session.rb → interface.rb} +42 -40
  54. data/lib/bio/shell/object.rb +52 -0
  55. data/lib/bio/shell/plugin/codon.rb +4 -22
  56. data/lib/bio/shell/plugin/emboss.rb +23 -0
  57. data/lib/bio/shell/plugin/entry.rb +34 -25
  58. data/lib/bio/shell/plugin/flatfile.rb +5 -23
  59. data/lib/bio/shell/plugin/keggapi.rb +11 -24
  60. data/lib/bio/shell/plugin/midi.rb +5 -23
  61. data/lib/bio/shell/plugin/obda.rb +4 -22
  62. data/lib/bio/shell/plugin/seq.rb +6 -24
  63. data/lib/bio/shell/rails/Rakefile +10 -0
  64. data/lib/bio/shell/rails/app/controllers/application.rb +4 -0
  65. data/lib/bio/shell/rails/app/controllers/shell_controller.rb +94 -0
  66. data/lib/bio/shell/rails/app/helpers/application_helper.rb +3 -0
  67. data/lib/bio/shell/rails/app/models/shell_connection.rb +30 -0
  68. data/lib/bio/shell/rails/app/views/layouts/shell.rhtml +37 -0
  69. data/lib/bio/shell/rails/app/views/shell/history.rhtml +5 -0
  70. data/lib/bio/shell/rails/app/views/shell/index.rhtml +2 -0
  71. data/lib/bio/shell/rails/app/views/shell/show.rhtml +13 -0
  72. data/lib/bio/shell/rails/config/boot.rb +19 -0
  73. data/lib/bio/shell/rails/config/database.yml +85 -0
  74. data/lib/bio/shell/rails/config/environment.rb +53 -0
  75. data/lib/bio/shell/rails/config/environments/development.rb +19 -0
  76. data/lib/bio/shell/rails/config/environments/production.rb +19 -0
  77. data/lib/bio/shell/rails/config/environments/test.rb +19 -0
  78. data/lib/bio/shell/rails/config/routes.rb +19 -0
  79. data/lib/bio/shell/rails/doc/README_FOR_APP +2 -0
  80. data/lib/bio/shell/rails/public/404.html +8 -0
  81. data/lib/bio/shell/rails/public/500.html +8 -0
  82. data/lib/bio/shell/rails/public/dispatch.cgi +10 -0
  83. data/lib/bio/shell/rails/public/dispatch.fcgi +24 -0
  84. data/lib/bio/shell/rails/public/dispatch.rb +10 -0
  85. data/lib/bio/shell/rails/public/favicon.ico +0 -0
  86. data/lib/bio/shell/rails/public/images/icon.png +0 -0
  87. data/lib/bio/shell/rails/public/images/rails.png +0 -0
  88. data/lib/bio/shell/rails/public/index.html +277 -0
  89. data/lib/bio/shell/rails/public/javascripts/controls.js +750 -0
  90. data/lib/bio/shell/rails/public/javascripts/dragdrop.js +584 -0
  91. data/lib/bio/shell/rails/public/javascripts/effects.js +854 -0
  92. data/lib/bio/shell/rails/public/javascripts/prototype.js +1785 -0
  93. data/lib/bio/shell/rails/public/robots.txt +1 -0
  94. data/lib/bio/shell/rails/public/stylesheets/main.css +187 -0
  95. data/lib/bio/shell/rails/script/about +3 -0
  96. data/lib/bio/shell/rails/script/breakpointer +3 -0
  97. data/lib/bio/shell/rails/script/console +3 -0
  98. data/lib/bio/shell/rails/script/destroy +3 -0
  99. data/lib/bio/shell/rails/script/generate +3 -0
  100. data/lib/bio/shell/rails/script/performance/benchmarker +3 -0
  101. data/lib/bio/shell/rails/script/performance/profiler +3 -0
  102. data/lib/bio/shell/rails/script/plugin +3 -0
  103. data/lib/bio/shell/rails/script/process/reaper +3 -0
  104. data/lib/bio/shell/rails/script/process/spawner +3 -0
  105. data/lib/bio/shell/rails/script/process/spinner +3 -0
  106. data/lib/bio/shell/rails/script/runner +3 -0
  107. data/lib/bio/shell/rails/script/server +42 -0
  108. data/lib/bio/shell/rails/test/test_helper.rb +28 -0
  109. data/lib/bio/shell/web.rb +90 -0
  110. data/lib/bio/util/contingency_table.rb +231 -225
  111. data/sample/any2fasta.rb +59 -0
  112. data/test/data/HMMER/hmmpfam.out +64 -0
  113. data/test/data/HMMER/hmmsearch.out +88 -0
  114. data/test/data/aaindex/DAYM780301 +30 -0
  115. data/test/data/aaindex/PRAM900102 +20 -0
  116. data/test/data/bl2seq/cd8a_cd8b_blastp.bl2seq +53 -0
  117. data/test/data/bl2seq/cd8a_p53_e-5blastp.bl2seq +37 -0
  118. data/test/data/blast/{eco:b0002.faa → b0002.faa} +0 -0
  119. data/test/data/blast/{eco:b0002.faa.m0 → b0002.faa.m0} +2 -2
  120. data/test/data/blast/{eco:b0002.faa.m7 → b0002.faa.m7} +1 -1
  121. data/test/data/blast/{eco:b0002.faa.m8 → b0002.faa.m8} +0 -0
  122. data/test/unit/bio/appl/bl2seq/test_report.rb +134 -0
  123. data/test/unit/bio/appl/blast/test_report.rb +15 -12
  124. data/test/unit/bio/appl/blast/test_xmlparser.rb +4 -4
  125. data/test/unit/bio/appl/hmmer/test_report.rb +355 -0
  126. data/test/unit/bio/appl/test_blast.rb +5 -5
  127. data/test/unit/bio/data/test_na.rb +9 -18
  128. data/test/unit/bio/db/pdb/test_pdb.rb +169 -0
  129. data/test/unit/bio/db/test_aaindex.rb +197 -0
  130. data/test/unit/bio/io/test_fastacmd.rb +55 -0
  131. data/test/unit/bio/sequence/test_aa.rb +102 -0
  132. data/test/unit/bio/sequence/test_common.rb +178 -0
  133. data/test/unit/bio/sequence/test_compat.rb +82 -0
  134. data/test/unit/bio/sequence/test_na.rb +242 -0
  135. data/test/unit/bio/shell/plugin/test_seq.rb +29 -19
  136. data/test/unit/bio/test_alignment.rb +15 -7
  137. data/test/unit/bio/test_reference.rb +198 -0
  138. data/test/unit/bio/test_sequence.rb +4 -49
  139. data/test/unit/bio/test_shell.rb +2 -2
  140. metadata +118 -15
  141. data/lib/bio/io/brdb.rb +0 -103
  142. data/lib/bioruby.rb +0 -34
@@ -0,0 +1,189 @@
1
+ #
2
+ # = bio/sequence/na.rb - nucleic acid sequence class
3
+ #
4
+ # Copyright:: Copyright (C) 2006
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: Ruby's
7
+ #
8
+ # $Id: na.rb,v 1.2 2006/02/06 14:13:52 k Exp $
9
+ #
10
+
11
+ require 'bio/sequence/common'
12
+
13
+ module Bio
14
+
15
+ autoload :NucleicAcid, 'bio/data/na'
16
+ autoload :CodonTable, 'bio/data/codontable'
17
+
18
+ class Sequence
19
+
20
+
21
+ # Nucleic Acid sequence
22
+ class NA < String
23
+
24
+ include Bio::Sequence::Common
25
+
26
+ # Generate a nucleic acid sequence object from a string.
27
+ def initialize(str)
28
+ super
29
+ self.downcase!
30
+ self.tr!(" \t\n\r",'')
31
+ end
32
+
33
+ # This method depends on Locations class, see bio/location.rb
34
+ def splicing(position)
35
+ mRNA = super
36
+ if mRNA.rna?
37
+ mRNA.tr!('t', 'u')
38
+ else
39
+ mRNA.tr!('u', 't')
40
+ end
41
+ mRNA
42
+ end
43
+
44
+ # Returns complement sequence without reversing ("atgc" -> "tacg")
45
+ def forward_complement
46
+ s = self.class.new(self)
47
+ s.forward_complement!
48
+ s
49
+ end
50
+
51
+ # Convert to complement sequence without reversing ("atgc" -> "tacg")
52
+ def forward_complement!
53
+ if self.rna?
54
+ self.tr!('augcrymkdhvbswn', 'uacgyrkmhdbvswn')
55
+ else
56
+ self.tr!('atgcrymkdhvbswn', 'tacgyrkmhdbvswn')
57
+ end
58
+ self
59
+ end
60
+
61
+ # Returns reverse complement sequence ("atgc" -> "gcat")
62
+ def reverse_complement
63
+ s = self.class.new(self)
64
+ s.reverse_complement!
65
+ s
66
+ end
67
+
68
+ # Convert to reverse complement sequence ("atgc" -> "gcat")
69
+ def reverse_complement!
70
+ self.reverse!
71
+ self.forward_complement!
72
+ end
73
+
74
+ # Aliases for short
75
+ alias complement reverse_complement
76
+ alias complement! reverse_complement!
77
+
78
+
79
+ # Translate into the amino acid sequence from the given frame and the
80
+ # selected codon table. The table also can be a Bio::CodonTable object.
81
+ # The 'unknown' character is used for invalid/unknown codon (can be
82
+ # used for 'nnn' and/or gap translation in practice).
83
+ #
84
+ # Frame can be 1, 2 or 3 for the forward strand and -1, -2 or -3
85
+ # (4, 5 or 6 is also accepted) for the reverse strand.
86
+ def translate(frame = 1, table = 1, unknown = 'X')
87
+ if table.is_a?(Bio::CodonTable)
88
+ ct = table
89
+ else
90
+ ct = Bio::CodonTable[table]
91
+ end
92
+ naseq = self.dna
93
+ case frame
94
+ when 1, 2, 3
95
+ from = frame - 1
96
+ when 4, 5, 6
97
+ from = frame - 4
98
+ naseq.complement!
99
+ when -1, -2, -3
100
+ from = -1 - frame
101
+ naseq.complement!
102
+ else
103
+ from = 0
104
+ end
105
+ nalen = naseq.length - from
106
+ nalen -= nalen % 3
107
+ aaseq = naseq[from, nalen].gsub(/.{3}/) {|codon| ct[codon] or unknown}
108
+ return Bio::Sequence::AA.new(aaseq)
109
+ end
110
+
111
+ # Returns counts of the each codon in the sequence by Hash.
112
+ def codon_usage
113
+ hash = Hash.new(0)
114
+ self.window_search(3, 3) do |codon|
115
+ hash[codon] += 1
116
+ end
117
+ return hash
118
+ end
119
+
120
+ # Calculate the ratio of GC / ATGC bases in percent.
121
+ def gc_percent
122
+ count = self.composition
123
+ at = count['a'] + count['t'] + count['u']
124
+ gc = count['g'] + count['c']
125
+ gc = 100 * gc / (at + gc)
126
+ return gc
127
+ end
128
+
129
+ # Show abnormal bases other than 'atgcu'.
130
+ def illegal_bases
131
+ self.scan(/[^atgcu]/).sort.uniq
132
+ end
133
+
134
+ # Estimate the weight of this biological string molecule.
135
+ def molecular_weight
136
+ if self.rna?
137
+ Bio::NucleicAcid.weight(self, true)
138
+ else
139
+ Bio::NucleicAcid.weight(self)
140
+ end
141
+ end
142
+
143
+ # Convert the universal code string into the regular expression.
144
+ def to_re
145
+ if self.rna?
146
+ Bio::NucleicAcid.to_re(self.dna, true)
147
+ else
148
+ Bio::NucleicAcid.to_re(self)
149
+ end
150
+ end
151
+
152
+ # Convert the self string into the list of the names of the each base.
153
+ def names
154
+ array = []
155
+ self.each_byte do |x|
156
+ array.push(Bio::NucleicAcid.names[x.chr.upcase])
157
+ end
158
+ return array
159
+ end
160
+
161
+ # Output a DNA string by substituting 'u' to 't'.
162
+ def dna
163
+ self.tr('u', 't')
164
+ end
165
+
166
+ def dna!
167
+ self.tr!('u', 't')
168
+ end
169
+
170
+ # Output a RNA string by substituting 't' to 'u'.
171
+ def rna
172
+ self.tr('t', 'u')
173
+ end
174
+
175
+ def rna!
176
+ self.tr!('t', 'u')
177
+ end
178
+
179
+ def rna?
180
+ self.index('u')
181
+ end
182
+ protected :rna?
183
+
184
+ end # NA
185
+
186
+ end # Sequence
187
+
188
+ end # Bio
189
+
@@ -1,29 +1,11 @@
1
1
  #
2
2
  # = bio/shell.rb - Loading all BioRuby shell features
3
3
  #
4
- # Copyright:: Copyright (C) 2005
5
- # Toshiaki Katayama <k@bioruby.org>
6
- # License:: LGPL
4
+ # Copyright:: Copyright (C) 2005, 2006
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License: Ruby's
7
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
- #++
8
+ # $Id: shell.rb,v 1.15 2006/02/27 09:34:23 k Exp $
27
9
  #
28
10
 
29
11
  require 'bio'
@@ -34,7 +16,10 @@ require 'pp'
34
16
  module Bio::Shell
35
17
 
36
18
  require 'bio/shell/core'
37
- require 'bio/shell/session'
19
+ require 'bio/shell/interface'
20
+ require 'bio/shell/object'
21
+ require 'bio/shell/web'
22
+ require 'bio/shell/demo'
38
23
  require 'bio/shell/plugin/entry'
39
24
  require 'bio/shell/plugin/seq'
40
25
  require 'bio/shell/plugin/midi'
@@ -42,6 +27,7 @@ module Bio::Shell
42
27
  require 'bio/shell/plugin/flatfile'
43
28
  require 'bio/shell/plugin/obda'
44
29
  require 'bio/shell/plugin/keggapi'
30
+ require 'bio/shell/plugin/emboss'
45
31
 
46
32
  extend Ghost
47
33
  extend Private
@@ -1,44 +1,25 @@
1
1
  #
2
2
  # = bio/shell/core.rb - internal methods for the BioRuby shell
3
3
  #
4
- # Copyright:: Copyright (C) 2005
5
- # Toshiaki Katayama <k@bioruby.org>
6
- # License:: LGPL
4
+ # Copyright:: Copyright (C) 2005, 2006
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: Ruby's
7
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
- #++
8
+ # $Id: core.rb,v 1.21 2006/02/27 09:09:57 k Exp $
27
9
  #
28
10
 
11
+
29
12
  module Bio::Shell::Ghost
30
13
 
14
+ SAVEDIR = "session/"
31
15
  CONFIG = "config"
32
16
  OBJECT = "object"
33
17
  HISTORY = "history"
34
18
  SCRIPT = "script.rb"
35
19
  PLUGIN = "plugin/"
20
+ DATADIR = "data/"
36
21
  BIOFLAT = "bioflat/"
37
22
 
38
- SITEDIR = "/etc/bioinformatics/bioruby/"
39
- USERDIR = "#{ENV['HOME']}/.bioinformatics/bioruby/"
40
- SAVEDIR = ".bioruby/"
41
-
42
23
  MARSHAL = [ Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION ]
43
24
 
44
25
  MESSAGE = "...BioRuby in the shell..."
@@ -55,6 +36,14 @@ module Bio::Shell::Ghost
55
36
  :n => "\e[00m", :none => "\e[00m", :reset => "\e[00m",
56
37
  }
57
38
 
39
+ def history
40
+ SAVEDIR + HISTORY
41
+ end
42
+
43
+ def datadir
44
+ DATADIR
45
+ end
46
+
58
47
  def esc_seq
59
48
  ESC_SEQ
60
49
  end
@@ -76,48 +65,19 @@ module Bio::Shell::Ghost
76
65
  # A hash to store temporal (per session) configurations
77
66
  attr_accessor :cache
78
67
 
79
- def load
68
+ def load_session
80
69
  load_object
81
70
  load_history
82
71
  opening_splash
83
72
  end
84
73
 
85
- def save
74
+ def save_session
86
75
  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
76
+ if create_save_dir_ask
77
+ #save_history # changed to use our own...
78
+ save_object
79
+ save_config
119
80
  end
120
- puts message
121
81
  end
122
82
 
123
83
  ### setup
@@ -135,36 +95,44 @@ module Bio::Shell::Ghost
135
95
  end
136
96
 
137
97
  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
98
+ create_real_dir(SAVEDIR)
99
+ create_real_dir(DATADIR)
100
+ create_real_dir(PLUGIN)
143
101
  end
144
102
 
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
103
+ def create_save_dir_ask
104
+ if File.directory?(SAVEDIR)
105
+ @cache[:save] = true
106
+ end
107
+ if @cache[:save].nil?
108
+ if ask_yes_or_no("Save session in '#{SAVEDIR}' directory? [y/n] ")
109
+ create_real_dir(SAVEDIR)
110
+ create_real_dir(DATADIR)
111
+ create_real_dir(PLUGIN)
112
+ # create_real_dir(BIOFLAT)
113
+ @cache[:save] = true
114
+ else
115
+ @cache[:save] = false
116
+ end
117
+ end
118
+ return @cache[:save]
119
+ end
120
+
121
+ def ask_yes_or_no(message)
122
+ loop do
123
+ print "#{message}"
124
+ answer = gets
125
+ if answer.nil?
126
+ # readline support might be broken
127
+ return false
128
+ elsif /^\s*[Nn]/.match(answer)
129
+ return false
130
+ elsif /^\s*[Yy]/.match(answer)
131
+ return true
132
+ else
133
+ # loop
164
134
  end
165
- @cache[:savedir] = dir
166
135
  end
167
- return dir
168
136
  end
169
137
 
170
138
  def create_real_dir(dir)
@@ -174,7 +142,7 @@ module Bio::Shell::Ghost
174
142
  Dir.mkdir(dir)
175
143
  puts "done"
176
144
  rescue
177
- warn "Error: Failed to create #{dir} : #{$!}"
145
+ warn "Error: Failed to create directory (#{dir}) : #{$!}"
178
146
  end
179
147
  end
180
148
  end
@@ -182,16 +150,18 @@ module Bio::Shell::Ghost
182
150
  ### bioflat
183
151
 
184
152
  def create_flat_dir(dbname)
185
- if prefix = create_save_dir
186
- return prefix + BIOFLAT + dbname.to_s.strip
187
- else
188
- return nil
153
+ dir = BIOFLAT + dbname.to_s.strip
154
+ unless File.directory?(BIOFLAT)
155
+ Dir.mkdir(BIOFLAT)
189
156
  end
157
+ unless File.directory?(dir)
158
+ Dir.mkdir(dir)
159
+ end
160
+ return dir
190
161
  end
191
162
 
192
163
  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)
164
+ dir = BIOFLAT + dbname.to_s.strip
195
165
  if File.exists?(dir)
196
166
  return dir
197
167
  else
@@ -202,8 +172,6 @@ module Bio::Shell::Ghost
202
172
  ### config
203
173
 
204
174
  def load_config
205
- load_config_file(SITEDIR + CONFIG)
206
- load_config_file(USERDIR + CONFIG)
207
175
  load_config_file(SAVEDIR + CONFIG)
208
176
  end
209
177
 
@@ -218,8 +186,7 @@ module Bio::Shell::Ghost
218
186
  end
219
187
 
220
188
  def save_config
221
- dir = create_save_dir
222
- save_config_file(dir + CONFIG)
189
+ save_config_file(SAVEDIR + CONFIG)
223
190
  end
224
191
 
225
192
  def save_config_file(file)
@@ -265,17 +232,23 @@ module Bio::Shell::Ghost
265
232
  @config[:pager] = cmd
266
233
  end
267
234
 
235
+ def config_splash
236
+ flag = ! @config[:splash]
237
+ @config[:splash] = flag
238
+ puts "Splash #{flag ? 'on' : 'off'}"
239
+ opening_splash
240
+ end
241
+
268
242
  def config_message(str = nil)
269
243
  str ||= MESSAGE
270
244
  @config[:message] = str
245
+ opening_splash
271
246
  end
272
247
 
273
248
  ### plugin
274
249
 
275
250
  def load_plugin
276
- load_plugin_dir(SITEDIR + PLUGIN)
277
- load_plugin_dir(USERDIR + PLUGIN)
278
- load_plugin_dir(SAVEDIR + PLUGIN)
251
+ load_plugin_dir(PLUGIN)
279
252
  end
280
253
 
281
254
  def load_plugin_dir(dir)
@@ -291,8 +264,6 @@ module Bio::Shell::Ghost
291
264
  ### object
292
265
 
293
266
  def load_object
294
- load_object_file(SITEDIR + OBJECT)
295
- load_object_file(USERDIR + OBJECT)
296
267
  load_object_file(SAVEDIR + OBJECT)
297
268
  end
298
269
 
@@ -318,8 +289,7 @@ module Bio::Shell::Ghost
318
289
  end
319
290
 
320
291
  def save_object
321
- dir = create_save_dir
322
- save_object_file(dir + OBJECT)
292
+ save_object_file(SAVEDIR + OBJECT)
323
293
  end
324
294
 
325
295
  def save_object_file(file)
@@ -358,8 +328,6 @@ module Bio::Shell::Ghost
358
328
 
359
329
  def load_history
360
330
  if @cache[:readline]
361
- load_history_file(SITEDIR + HISTORY)
362
- load_history_file(USERDIR + HISTORY)
363
331
  load_history_file(SAVEDIR + HISTORY)
364
332
  end
365
333
  end
@@ -368,7 +336,9 @@ module Bio::Shell::Ghost
368
336
  if File.exists?(file)
369
337
  print "Loading history (#{file}) ... "
370
338
  File.open(file).each do |line|
371
- Readline::HISTORY.push line.chomp
339
+ #Readline::HISTORY.push line.chomp
340
+ date, hist = line.chomp.split("\t")
341
+ Readline::HISTORY.push hist if hist
372
342
  end
373
343
  puts "done"
374
344
  end
@@ -376,8 +346,7 @@ module Bio::Shell::Ghost
376
346
 
377
347
  def save_history
378
348
  if @cache[:readline]
379
- dir = create_save_dir
380
- save_history_file(dir + HISTORY)
349
+ save_history_file(SAVEDIR + HISTORY)
381
350
  end
382
351
  end
383
352
 
@@ -428,10 +397,20 @@ module Bio::Shell::Ghost
428
397
 
429
398
  def save_script
430
399
  if @script_begin and @script_end and @script_begin <= @script_end
431
- dir = create_save_dir
432
- save_script_file(dir + SCRIPT)
400
+ if File.exists?(SCRIPT)
401
+ message = "Overwrite script file (#{SCRIPT})? [y/n] "
402
+ else
403
+ message = "Save script file (#{SCRIPT})? [y/n] "
404
+ end
405
+ if ask_yes_or_no(message)
406
+ save_script_file(SCRIPT)
407
+ else
408
+ puts " ... save aborted."
409
+ end
410
+ elsif @script_begin and @script_end and @script_begin - @script_end == 1
411
+ puts " ... script aborted."
433
412
  else
434
- puts "Error: script range #{@script_begin}..#{@script_end} is invalid"
413
+ puts "Error: Script range #{@script_begin}..#{@script_end} is invalid"
435
414
  end
436
415
  end
437
416
 
@@ -439,10 +418,10 @@ module Bio::Shell::Ghost
439
418
  begin
440
419
  print "Saving script (#{file}) ... "
441
420
  File.open(file, "w") do |f|
442
- f.print "#!/usr/bin/env ruby\n\n"
443
- f.print "require 'bioruby'\n\n"
421
+ f.puts "#!/usr/bin/env bioruby"
422
+ f.puts
444
423
  f.puts Readline::HISTORY.to_a[@script_begin..@script_end]
445
- f.print "\n\n"
424
+ f.puts
446
425
  end
447
426
  puts "done"
448
427
  rescue
@@ -465,8 +444,25 @@ module Bio::Shell::Ghost
465
444
  return str.sub(/R u b y/) { "#{ruby}R u b y#{none}" }
466
445
  end
467
446
 
468
- def splash_message_action
469
- s = splash_message
447
+ def splash_message_action(message = nil)
448
+ s = message || splash_message
449
+ l = s.length
450
+ x = " "
451
+ 0.step(l,2) do |i|
452
+ l1 = l-i; l2 = l1/2; l4 = l2/2
453
+ STDERR.print "#{s[0,i]}#{x*l1}#{s[i,1]}\r"
454
+ sleep(0.001)
455
+ STDERR.print "#{s[0,i]}#{x*l2}#{s[i,1]}#{x*(l1-l2)}\r"
456
+ sleep(0.002)
457
+ STDERR.print "#{s[0,i]}#{x*l4}#{s[i,1]}#{x*(l2-l4)}\r"
458
+ sleep(0.004)
459
+ STDERR.print "#{s[0,i+1]}#{x*l4}\r"
460
+ sleep(0.008)
461
+ end
462
+ end
463
+
464
+ def splash_message_action_color(message = nil)
465
+ s = message || splash_message
470
466
  l = s.length
471
467
  c = ESC_SEQ
472
468
  x = " "
@@ -484,28 +480,37 @@ module Bio::Shell::Ghost
484
480
  end
485
481
 
486
482
  def opening_splash
487
- print "\n"
488
- if @config[:color]
489
- splash_message_action
483
+ puts
484
+ if @config[:splash]
485
+ if @config[:color]
486
+ splash_message_action_color
487
+ else
488
+ splash_message_action
489
+ end
490
490
  end
491
491
  if @config[:color]
492
492
  print splash_message_color
493
493
  else
494
494
  print splash_message
495
495
  end
496
- print "\n\n"
496
+ puts
497
+ puts
497
498
  print " Version : BioRuby #{Bio::BIORUBY_VERSION.join(".")}"
498
- print " / Ruby #{RUBY_VERSION}\n\n"
499
+ print " / Ruby #{RUBY_VERSION}"
500
+ puts
501
+ puts
499
502
  end
500
503
 
501
504
  def closing_splash
502
- print "\n\n"
505
+ puts
506
+ puts
503
507
  if @config[:color]
504
508
  print splash_message_color
505
509
  else
506
510
  print splash_message
507
511
  end
508
- print "\n\n"
512
+ puts
513
+ puts
509
514
  end
510
515
 
511
516
  end