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
@@ -0,0 +1,238 @@
1
+ #
2
+ # = bio/shell/plugin/seq.rb - plugin for biological sequence manipulations
3
+ #
4
+ # Copyright:: Copyright (C) 2005
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: LGPL
7
+ #
8
+ # $Id: seq.rb,v 1.16 2005/12/19 01:20: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
+ module Bio::Shell
30
+
31
+ private
32
+
33
+ # Convert sequence to colored HTML string
34
+ def htmlseq(str)
35
+ if str.kind_of?(Bio::Sequence)
36
+ seq = str
37
+ else
38
+ seq = seq(str)
39
+ end
40
+
41
+ if seq.is_a?(Bio::Sequence::AA)
42
+ scheme = Bio::ColorScheme::Taylor
43
+ else
44
+ scheme = Bio::ColorScheme::Nucleotide
45
+ end
46
+
47
+ html = %Q[<div style="font-family:monospace;">\n]
48
+ seq.fold(50).each_byte do |c|
49
+ case c.chr
50
+ when "\n"
51
+ html += "<br>\n"
52
+ else
53
+ color = scheme[c.chr]
54
+ html += %Q[<span style="background:\##{color};">#{c.chr}</span>\n]
55
+ end
56
+ end
57
+ html += "</div>\n"
58
+ return html
59
+ end
60
+
61
+
62
+ # Displays some basic properties of the sequence.
63
+ def seqstat(str)
64
+ max = 150
65
+ seq = seq(str)
66
+ rep = "\n* * * Sequence statistics * * *\n\n"
67
+ if seq.respond_to?(:complement)
68
+ fwd = seq
69
+ rev = seq.complement
70
+ if seq.length > max
71
+ dot = " ..."
72
+ fwd = fwd.subseq(1, max)
73
+ rev = rev.subseq(1, max)
74
+ end
75
+ rep << "5'->3' sequence : #{fwd.fold(70,20).strip}#{dot}\n"
76
+ rep << "3'->5' sequence : #{rev.fold(70,20).strip}#{dot}\n"
77
+ [ 1, 2, 3, -1, -2, -3 ].each do |frame|
78
+ pep = seq.subseq(1, max+2).translate(frame).fold(70,20).strip
79
+ rep << "Translation #{frame.to_s.rjust(2)} : #{pep}#{dot}\n"
80
+ end
81
+ rep << "Length : #{seq.length} bp\n"
82
+ rep << "GC percent : #{seq.gc_percent} %\n"
83
+
84
+ ary = []
85
+ seq.composition.sort.each do |base, num|
86
+ percent = format("%.2f", 100.0 * num / seq.length).rjust(6)
87
+ count = num.to_s.rjust(seq.length.to_s.length)
88
+ ary << " #{base} - #{count} (#{percent} %)\n"
89
+ end
90
+ rep << "Composition : #{ary.join.strip}\n"
91
+
92
+ rep << "Codon usage :\n"
93
+ hash = Hash.new("0.0%")
94
+ seq.codon_usage.sort.each do |codon, num|
95
+ percent = format("%.1f%", 100.0 * num / (seq.length / 3))
96
+ hash[codon] = percent
97
+ end
98
+ rep << codontable(1, hash).output
99
+
100
+ begin
101
+ rep << "Molecular weight : #{seq.molecular_weight}\n"
102
+ rescue
103
+ rep << "Molecular weight : #{$!}\n"
104
+ end
105
+ begin
106
+ rep << "Protein weight : #{seq.translate.chomp('*').molecular_weight}\n"
107
+ rescue
108
+ rep << "Protein weight : #{$!}\n"
109
+ end
110
+ else
111
+ pep = seq
112
+ if seq.length > max
113
+ dot = " ..."
114
+ pep = seq.subseq(1, max)
115
+ end
116
+ rep << "N->C sequence : #{pep.fold(70,20).strip}#{dot}\n"
117
+ rep << "Length : #{seq.length} aa\n"
118
+
119
+ names = Bio::AminoAcid.names
120
+ ary = []
121
+ seq.composition.sort.each do |aa, num|
122
+ percent = format("%.2f", 100.0 * num / seq.length).rjust(6)
123
+ count = num.to_s.rjust(seq.length.to_s.length)
124
+ code = names[aa]
125
+ name = names[names[aa]]
126
+ ary << " #{aa} #{code} - #{count} (#{percent} %) #{name}\n"
127
+ end
128
+ rep << "Composition : #{ary.join.strip}\n"
129
+
130
+ begin
131
+ rep << "Protein weight : #{seq.molecular_weight}\n"
132
+ rescue
133
+ rep << "Protein weight : #{$!}\n"
134
+ end
135
+ end
136
+ rep << "//\n"
137
+ puts rep
138
+ return rep
139
+ end
140
+
141
+ # Displays a DNA sequence by ascii art in B-type double helix.
142
+ # Argument need to be at least 16 bases in length.
143
+ def doublehelix(str)
144
+ seq = seq(str)
145
+ if str.length < 16
146
+ warn "Error: Sequence must be longer than 16 bases."
147
+ return
148
+ end
149
+ if ! seq.respond_to?(:complement)
150
+ warn "Error: Sequence must be a DNA sequence."
151
+ return
152
+ end
153
+ pairs = [ [5, 0], [4, 2], [3, 3], [2, 4],
154
+ [1, 4], [0, 3], [0, 2], [1, 0] ]
155
+ seq.window_search(16, 16) do |subseq|
156
+ pairs.each_with_index do |ij, x|
157
+ base = subseq[x, 1]
158
+ puts ' ' * ij[0] + base + '-' * ij[1] + base.complement + "\n"
159
+ end
160
+ pairs.reverse.each_with_index do |ij, x|
161
+ base = subseq[x + 8, 1]
162
+ puts ' ' * ij[0] + base.complement + '-' * ij[1] + base + "\n"
163
+ end
164
+ end
165
+ end
166
+
167
+ end
168
+
169
+
170
+ class String
171
+
172
+ def to_naseq
173
+ Bio::Sequence::NA.new(self)
174
+ end
175
+
176
+ def to_aaseq
177
+ Bio::Sequence::AA.new(self)
178
+ end
179
+
180
+ # folding both line end justified
181
+ def fold(fill_column = 72, indent = 0)
182
+ str = ''
183
+
184
+ # size : allowed length of the actual text
185
+ unless (size = fill_column - indent) > 0
186
+ warn "Error: indent > fill_column (indent is set to 0)"
187
+ size = fill_column
188
+ indent = 0
189
+ end
190
+
191
+ 0.step(self.length - 1, size) do |n|
192
+ str << ' ' * indent + self[n, size] + "\n"
193
+ end
194
+
195
+ return str
196
+ end
197
+
198
+ # folding with conscious about word boundaries with prefix string
199
+ def fill(fill_column = 80, indent = 0, separater = ' ', prefix = '', first_line_only = true)
200
+
201
+ # size : allowed length of the actual text
202
+ unless (size = fill_column - indent) > 0
203
+ warn "Error: indent > fill_column (indent is set to 0)"
204
+ size = fill_column
205
+ indent = 0
206
+ end
207
+
208
+ n = pos = 0
209
+ ary = []
210
+ while n < self.length
211
+ pos = self[n, size].rindex(separater)
212
+
213
+ if self[n, size].length < size # last line of the folded str
214
+ pos = nil
215
+ end
216
+
217
+ if pos
218
+ ary << self[n, pos+separater.length]
219
+ n += pos + separater.length
220
+ else # line too long or the last line
221
+ ary << self[n, size]
222
+ n += size
223
+ end
224
+ end
225
+ str = ary.join("\n")
226
+
227
+ str[0,0] = prefix + ' ' * (indent - prefix.length)
228
+ if first_line_only
229
+ head = ' ' * indent
230
+ else
231
+ head = prefix + ' ' * (indent - prefix.length)
232
+ end
233
+ str.gsub!("\n", "\n#{head}")
234
+
235
+ return str.chomp
236
+ end
237
+ end
238
+
@@ -0,0 +1,214 @@
1
+ #
2
+ # = bio/shell/session.rb - core user interface of the BioRuby shell
3
+ #
4
+ # Copyright:: Copyright (C) 2005
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: LGPL
7
+ #
8
+ # $Id: session.rb,v 1.11 2005/12/07 07:50:44 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
30
+
31
+ private
32
+
33
+ ### work space
34
+
35
+ def ls
36
+ list = eval("local_variables", conf.workspace.binding).reject { |x|
37
+ eval(x, conf.workspace.binding).nil?
38
+ }
39
+ puts list.inspect
40
+ end
41
+
42
+ def rm(name)
43
+ list = eval("local_variables", conf.workspace.binding).reject { |x|
44
+ eval(x, conf.workspace.binding).nil?
45
+ }
46
+ begin
47
+ if list.include?(name.to_s)
48
+ eval("#{name} = nil", conf.workspace.binding)
49
+ else
50
+ raise
51
+ end
52
+ rescue
53
+ warn "Usage: rm :var or rm 'var' (rm var is not valid)"
54
+ end
55
+ end
56
+
57
+ ### script
58
+
59
+ def script(mode = nil)
60
+ Bio::Shell.script(mode)
61
+ end
62
+
63
+ ### object
64
+
65
+ def reload_object
66
+ Bio::Shell.load_object
67
+ end
68
+
69
+ ### plugin
70
+
71
+ def reload_plugin
72
+ Bio::Shell.load_plugin
73
+ end
74
+
75
+ ### config
76
+
77
+ def config(mode = :show, *opts)
78
+ case mode
79
+ when :show, "show"
80
+ Bio::Shell.config_show
81
+ when :echo, "echo"
82
+ Bio::Shell.config_echo
83
+ when :color, "color"
84
+ Bio::Shell.config_color
85
+ when :pager, "pager"
86
+ Bio::Shell.config_pager(*opts)
87
+ when :message, "message"
88
+ Bio::Shell.config_message(*opts)
89
+ end
90
+ end
91
+
92
+ def reload_config
93
+ Bio::Shell.load_config
94
+ end
95
+
96
+ ### pager
97
+
98
+ def pager(cmd = nil)
99
+ unless Bio::Shell.config[:pager]
100
+ cmd = ENV['PAGER'] || cmd
101
+ end
102
+ Bio::Shell.config_pager(cmd)
103
+ puts "Pager is set to '#{cmd ? cmd : 'off'}'"
104
+ end
105
+
106
+ def display(*obj)
107
+ # The original idea is from http://sheepman.parfait.ne.jp/20050215.html
108
+ if Bio::Shell.config[:pager]
109
+ pg = IO.popen(Bio::Shell.config[:pager], "w")
110
+ begin
111
+ stdout_save = STDOUT.clone
112
+ STDOUT.reopen(pg)
113
+ puts(*obj)
114
+ ensure
115
+ STDOUT.reopen(stdout_save)
116
+ stdout_save.close
117
+ pg.close
118
+ end
119
+ else
120
+ puts(*obj)
121
+ end
122
+ end
123
+
124
+ def less(file)
125
+ pager = Bio::Shell.config[:pager] || ENV['PAGER'] || "less"
126
+ system("#{pager} #{file}")
127
+ end
128
+
129
+ def head(arg, num = 10)
130
+ str = ""
131
+ if File.exists?(arg)
132
+ File.open(arg) do |file|
133
+ num.times do
134
+ if line = file.gets
135
+ str << line
136
+ end
137
+ end
138
+ end
139
+ else
140
+ arg.to_s.each_with_index do |line, i|
141
+ break if i >= num
142
+ str << line
143
+ end
144
+ end
145
+ puts str
146
+ return str
147
+ end
148
+
149
+ ### file save
150
+
151
+ def savefile(file, *objs)
152
+ if File.exists?(file)
153
+ loop do
154
+ print "Overwrite existing #{file}? [y/n]: "
155
+ answer = gets
156
+ return if /^\s*[Nn]/.match(answer)
157
+ break if /^\s*[Yy]/.match(answer)
158
+ end
159
+ end
160
+ begin
161
+ print "Saving data (#{file}) ... "
162
+ File.open(file, "w") do |f|
163
+ objs.each do |obj|
164
+ f.puts obj.to_s
165
+ end
166
+ end
167
+ puts "done"
168
+ rescue
169
+ warn "Error: Failed to save (#{file}) : #{$!}"
170
+ end
171
+ end
172
+
173
+ ### file system
174
+
175
+ def cd(dir = ENV['HOME'])
176
+ if dir
177
+ Dir.chdir(dir)
178
+ end
179
+ puts Dir.pwd.inspect
180
+ end
181
+
182
+ def pwd
183
+ puts Dir.pwd.inspect
184
+ end
185
+
186
+ def dir(file = nil)
187
+ if file
188
+ if File.directory?(file)
189
+ files = Dir.glob("#{file}/*")
190
+ else
191
+ files = Dir.glob(file)
192
+ end
193
+ else
194
+ files = Dir.glob("*")
195
+ end
196
+ if files
197
+ str = " UGO Date Byte File\n"
198
+ str << "------ ---------------------------- ----------- ------------\n"
199
+ files.sort.each { |f|
200
+ stat = File.lstat(f)
201
+ mode = format("%6o", stat.mode)
202
+ date = stat.mtime
203
+ byte = stat.size
204
+ name = f.inspect
205
+ str << format("%s %s%13d %s\n", mode, date, byte, name)
206
+ }
207
+ puts str
208
+ return str
209
+ end
210
+ end
211
+
212
+ end
213
+
214
+