bio 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/bioruby +107 -0
- data/bin/br_biofetch.rb +59 -0
- data/bin/br_bioflat.rb +294 -0
- data/bin/br_biogetseq.rb +57 -0
- data/bin/br_pmfetch.rb +431 -0
- data/doc/BioRuby.rd.ja +225 -0
- data/doc/Changes-0.7.rd +236 -0
- data/doc/Design.rd.ja +341 -0
- data/doc/KEGG_API.rd +1437 -0
- data/doc/KEGG_API.rd.ja +1399 -0
- data/doc/TODO.rd.ja +138 -0
- data/doc/Tutorial.rd +1138 -0
- data/doc/Tutorial.rd.ja +2110 -0
- data/etc/bioinformatics/seqdatabase.ini +210 -0
- data/lib/bio.rb +256 -0
- data/lib/bio/alignment.rb +1906 -0
- data/lib/bio/appl/bl2seq/report.rb +350 -0
- data/lib/bio/appl/blast.rb +269 -0
- data/lib/bio/appl/blast/format0.rb +1402 -0
- data/lib/bio/appl/blast/format8.rb +95 -0
- data/lib/bio/appl/blast/report.rb +652 -0
- data/lib/bio/appl/blast/rexml.rb +151 -0
- data/lib/bio/appl/blast/wublast.rb +553 -0
- data/lib/bio/appl/blast/xmlparser.rb +222 -0
- data/lib/bio/appl/blat/report.rb +392 -0
- data/lib/bio/appl/clustalw.rb +191 -0
- data/lib/bio/appl/clustalw/report.rb +154 -0
- data/lib/bio/appl/emboss.rb +68 -0
- data/lib/bio/appl/fasta.rb +262 -0
- data/lib/bio/appl/fasta/format10.rb +428 -0
- data/lib/bio/appl/fasta/format6.rb +37 -0
- data/lib/bio/appl/genscan/report.rb +570 -0
- data/lib/bio/appl/hmmer.rb +129 -0
- data/lib/bio/appl/hmmer/report.rb +556 -0
- data/lib/bio/appl/mafft.rb +222 -0
- data/lib/bio/appl/mafft/report.rb +119 -0
- data/lib/bio/appl/psort.rb +555 -0
- data/lib/bio/appl/psort/report.rb +473 -0
- data/lib/bio/appl/sim4.rb +134 -0
- data/lib/bio/appl/sim4/report.rb +501 -0
- data/lib/bio/appl/sosui/report.rb +166 -0
- data/lib/bio/appl/spidey/report.rb +604 -0
- data/lib/bio/appl/targetp/report.rb +283 -0
- data/lib/bio/appl/tmhmm/report.rb +238 -0
- data/lib/bio/command.rb +166 -0
- data/lib/bio/data/aa.rb +354 -0
- data/lib/bio/data/codontable.rb +740 -0
- data/lib/bio/data/na.rb +226 -0
- data/lib/bio/db.rb +340 -0
- data/lib/bio/db/aaindex.rb +280 -0
- data/lib/bio/db/embl/common.rb +332 -0
- data/lib/bio/db/embl/embl.rb +446 -0
- data/lib/bio/db/embl/sptr.rb +954 -0
- data/lib/bio/db/embl/swissprot.rb +32 -0
- data/lib/bio/db/embl/trembl.rb +31 -0
- data/lib/bio/db/embl/uniprot.rb +32 -0
- data/lib/bio/db/fantom.rb +604 -0
- data/lib/bio/db/fasta.rb +869 -0
- data/lib/bio/db/genbank/common.rb +299 -0
- data/lib/bio/db/genbank/ddbj.rb +34 -0
- data/lib/bio/db/genbank/genbank.rb +354 -0
- data/lib/bio/db/genbank/genpept.rb +73 -0
- data/lib/bio/db/genbank/refseq.rb +31 -0
- data/lib/bio/db/gff.rb +106 -0
- data/lib/bio/db/go.rb +497 -0
- data/lib/bio/db/kegg/brite.rb +51 -0
- data/lib/bio/db/kegg/cell.rb +88 -0
- data/lib/bio/db/kegg/compound.rb +130 -0
- data/lib/bio/db/kegg/enzyme.rb +125 -0
- data/lib/bio/db/kegg/expression.rb +173 -0
- data/lib/bio/db/kegg/genes.rb +293 -0
- data/lib/bio/db/kegg/genome.rb +362 -0
- data/lib/bio/db/kegg/glycan.rb +213 -0
- data/lib/bio/db/kegg/keggtab.rb +418 -0
- data/lib/bio/db/kegg/kgml.rb +299 -0
- data/lib/bio/db/kegg/ko.rb +178 -0
- data/lib/bio/db/kegg/reaction.rb +97 -0
- data/lib/bio/db/litdb.rb +131 -0
- data/lib/bio/db/medline.rb +317 -0
- data/lib/bio/db/nbrf.rb +199 -0
- data/lib/bio/db/pdb.rb +38 -0
- data/lib/bio/db/pdb/atom.rb +60 -0
- data/lib/bio/db/pdb/chain.rb +117 -0
- data/lib/bio/db/pdb/model.rb +106 -0
- data/lib/bio/db/pdb/pdb.rb +1682 -0
- data/lib/bio/db/pdb/residue.rb +122 -0
- data/lib/bio/db/pdb/utils.rb +234 -0
- data/lib/bio/db/prosite.rb +616 -0
- data/lib/bio/db/rebase.rb +417 -0
- data/lib/bio/db/transfac.rb +387 -0
- data/lib/bio/feature.rb +201 -0
- data/lib/bio/io/brdb.rb +103 -0
- data/lib/bio/io/das.rb +471 -0
- data/lib/bio/io/dbget.rb +212 -0
- data/lib/bio/io/ddbjxml.rb +614 -0
- data/lib/bio/io/fastacmd.rb +123 -0
- data/lib/bio/io/fetch.rb +114 -0
- data/lib/bio/io/flatfile.rb +496 -0
- data/lib/bio/io/flatfile/bdb.rb +266 -0
- data/lib/bio/io/flatfile/index.rb +1308 -0
- data/lib/bio/io/flatfile/indexer.rb +778 -0
- data/lib/bio/io/higet.rb +92 -0
- data/lib/bio/io/keggapi.rb +863 -0
- data/lib/bio/io/pubmed.rb +189 -0
- data/lib/bio/io/registry.rb +308 -0
- data/lib/bio/io/soapwsdl.rb +114 -0
- data/lib/bio/io/sql.rb +428 -0
- data/lib/bio/location.rb +650 -0
- data/lib/bio/pathway.rb +991 -0
- data/lib/bio/reference.rb +308 -0
- data/lib/bio/sequence.rb +593 -0
- data/lib/bio/shell.rb +51 -0
- data/lib/bio/shell/core.rb +512 -0
- data/lib/bio/shell/plugin/codon.rb +228 -0
- data/lib/bio/shell/plugin/entry.rb +85 -0
- data/lib/bio/shell/plugin/flatfile.rb +119 -0
- data/lib/bio/shell/plugin/keggapi.rb +187 -0
- data/lib/bio/shell/plugin/midi.rb +448 -0
- data/lib/bio/shell/plugin/obda.rb +63 -0
- data/lib/bio/shell/plugin/seq.rb +238 -0
- data/lib/bio/shell/session.rb +214 -0
- data/lib/bio/util/color_scheme.rb +214 -0
- data/lib/bio/util/color_scheme/buried.rb +78 -0
- data/lib/bio/util/color_scheme/helix.rb +78 -0
- data/lib/bio/util/color_scheme/hydropathy.rb +83 -0
- data/lib/bio/util/color_scheme/nucleotide.rb +50 -0
- data/lib/bio/util/color_scheme/strand.rb +78 -0
- data/lib/bio/util/color_scheme/taylor.rb +69 -0
- data/lib/bio/util/color_scheme/turn.rb +78 -0
- data/lib/bio/util/color_scheme/zappo.rb +69 -0
- data/lib/bio/util/contingency_table.rb +337 -0
- data/lib/bio/util/sirna.rb +306 -0
- data/lib/bioruby.rb +34 -0
- data/sample/biofetch.rb +475 -0
- data/sample/color_scheme_na.rb +99 -0
- data/sample/dbget +37 -0
- data/sample/fasta2tab.rb +99 -0
- data/sample/fsplit.rb +51 -0
- data/sample/gb2fasta.rb +31 -0
- data/sample/gb2tab.rb +325 -0
- data/sample/gbtab2mysql.rb +161 -0
- data/sample/genes2nuc.rb +33 -0
- data/sample/genes2pep.rb +33 -0
- data/sample/genes2tab.rb +81 -0
- data/sample/genome2rb.rb +29 -0
- data/sample/genome2tab.rb +76 -0
- data/sample/goslim.rb +311 -0
- data/sample/gt2fasta.rb +47 -0
- data/sample/pmfetch.rb +42 -0
- data/sample/pmsearch.rb +42 -0
- data/sample/psortplot_html.rb +222 -0
- data/sample/ssearch2tab.rb +96 -0
- data/sample/tdiary.rb +158 -0
- data/sample/tfastx2tab.rb +100 -0
- data/sample/vs-genes.rb +212 -0
- data/test/data/SOSUI/sample.report +11 -0
- data/test/data/TMHMM/sample.report +21 -0
- data/test/data/blast/eco:b0002.faa +15 -0
- data/test/data/blast/eco:b0002.faa.m0 +128 -0
- data/test/data/blast/eco:b0002.faa.m7 +65 -0
- data/test/data/blast/eco:b0002.faa.m8 +1 -0
- data/test/data/embl/AB090716.embl +65 -0
- data/test/data/genscan/sample.report +63 -0
- data/test/data/prosite/prosite.dat +2233 -0
- data/test/data/refseq/nm_126355.entret +64 -0
- data/test/data/uniprot/p53_human.uniprot +1456 -0
- data/test/runner.rb +10 -0
- data/test/unit/bio/appl/blast/test_report.rb +427 -0
- data/test/unit/bio/appl/blast/test_xmlparser.rb +400 -0
- data/test/unit/bio/appl/genscan/test_report.rb +195 -0
- data/test/unit/bio/appl/sosui/test_report.rb +94 -0
- data/test/unit/bio/appl/targetp/test_report.rb +159 -0
- data/test/unit/bio/appl/test_blast.rb +159 -0
- data/test/unit/bio/appl/test_fasta.rb +142 -0
- data/test/unit/bio/appl/tmhmm/test_report.rb +139 -0
- data/test/unit/bio/data/test_aa.rb +103 -0
- data/test/unit/bio/data/test_codontable.rb +120 -0
- data/test/unit/bio/data/test_na.rb +89 -0
- data/test/unit/bio/db/embl/test_common.rb +130 -0
- data/test/unit/bio/db/embl/test_embl.rb +227 -0
- data/test/unit/bio/db/embl/test_sptr.rb +268 -0
- data/test/unit/bio/db/embl/test_uniprot.rb +44 -0
- data/test/unit/bio/db/kegg/test_genes.rb +58 -0
- data/test/unit/bio/db/test_fasta.rb +263 -0
- data/test/unit/bio/db/test_gff.rb +140 -0
- data/test/unit/bio/db/test_prosite.rb +1450 -0
- data/test/unit/bio/io/test_ddbjxml.rb +87 -0
- data/test/unit/bio/io/test_soapwsdl.rb +45 -0
- data/test/unit/bio/shell/plugin/test_seq.rb +175 -0
- data/test/unit/bio/test_alignment.rb +1028 -0
- data/test/unit/bio/test_command.rb +71 -0
- data/test/unit/bio/test_db.rb +109 -0
- data/test/unit/bio/test_feature.rb +128 -0
- data/test/unit/bio/test_location.rb +51 -0
- data/test/unit/bio/test_pathway.rb +485 -0
- data/test/unit/bio/test_sequence.rb +386 -0
- data/test/unit/bio/test_shell.rb +31 -0
- data/test/unit/bio/util/test_color_scheme.rb +45 -0
- data/test/unit/bio/util/test_contingency_table.rb +106 -0
- data/test/unit/bio/util/test_sirna.rb +258 -0
- 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
|
+
|