bio-shell 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,146 @@
1
+ #
2
+ # = bio/shell/demo.rb - demo mode for the BioRuby shell
3
+ #
4
+ # Copyright:: Copyright (C) 2006
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: The Ruby License
7
+ #
8
+ # $Id: demo.rb,v 1.4 2007/04/05 23:35:41 trevor Exp $
9
+ #
10
+
11
+ module Bio::Shell
12
+
13
+ private
14
+
15
+ def demo(part = nil)
16
+ demo = Demo.new
17
+ if part
18
+ demo.send(part)
19
+ else
20
+ demo.all
21
+ end
22
+ end
23
+
24
+ class Demo
25
+
26
+ def initialize
27
+ @bind = Bio::Shell.cache[:binding]
28
+ end
29
+
30
+ def all
31
+ sequence &&
32
+ entry &&
33
+ shell &&
34
+ pdb &&
35
+ true
36
+ end
37
+
38
+ def tutorial
39
+ end
40
+
41
+ def aldh2
42
+ end
43
+
44
+ def mito
45
+ run(%q[entry = getent("data/kumamushi.gb")], "Load kumamushi gene from GenBank database entry ...", false) &&
46
+ run(%q[disp entry], "Check the contents ...", false) &&
47
+ run(%q[kuma = flatparse(entry)], "Parse the database entry ...", true) &&
48
+ run(%q[web], "Start BioRuby on Rails...", false) &&
49
+ run(%q[puts kuma.entry_id], "Extract entry ID ...", false) &&
50
+ run(%q[puts kuma.definition], "Extract definition ...", false) &&
51
+ run(%q[gene = kuma.seq], "Extract DNA sequence of the gene ...", true) &&
52
+ run(%q[doublehelix(gene)], "Show the sequence in ascii art ...", false) &&
53
+ run(%q[seqstat(gene)], "Statistics of the gene ...", false) &&
54
+ run(%q[config :color], "Change to color mode...", false) &&
55
+ run(%q[seqstat(gene)], "Statistics of the gene ...", false) &&
56
+ #run(%q[codontable], "Codontalble ...", false) &&
57
+ run(%q[protein = gene.translate], "Translate DNA into protein ...", true) &&
58
+ run(%q[comp = protein.composition], "Composition of the amino acids ...", false) &&
59
+ run(%q[pp comp], "Check the composition ...", false) &&
60
+ run(%q[puts protein.molecular_weight], "Molecular weight ...", false) &&
61
+ run(%q[midifile("data/kumamushi.mid", gene)], "Gene to music ...", false) &&
62
+ run(%q[`open "data/kumamushi.mid"`], "Let's listen ...", false) &&
63
+ true
64
+ end
65
+
66
+ def sequence
67
+ run(%q[dna = getseq("atgc" * 100)], "Generating DNA sequence ...", true) &&
68
+ run(%q[doublehelix dna], "Double helix representation", false) &&
69
+ run(%q[protein = dna.translate], "Translate DNA into Protein ...", true) &&
70
+ run(%q[protein.molecular_weight], "Calculating molecular weight ...", true) &&
71
+ run(%q[protein.composition], "Amino acid composition ...", true) &&
72
+ true
73
+ end
74
+
75
+ def entry
76
+ run(%q[kuma = getobj("gb:AF237819")], "Obtain an entry from GenBank database", false) &&
77
+ run(%q[kuma.definition], "Definition of the entry", true) &&
78
+ run(%q[kuma.naseq], "Sequence of the entry", true) &&
79
+ run(%q[kuma.naseq.translate], "Translate the sequence to protein", true) &&
80
+ run(%q[midifile("data/AF237819.mid", kuma.naseq)], "Generate gene music ...", false) &&
81
+ true
82
+ end
83
+
84
+ def shell
85
+ run(%q[pwd], "Show current working directory ...", false) &&
86
+ run(%q[dir], "Show directory contents ...", false) &&
87
+ run(%q[dir "shell/session"], "Show directory contents ...", false) &&
88
+ true
89
+ end
90
+
91
+ def pdb
92
+ run(%q[ent_1bl8 = getent("pdb:1bl8")], "Retrieving PDB entry 1BL8 ...", false) &&
93
+ run(%q[head ent_1bl8], "Head part of the entry ...", false) &&
94
+ run(%q[savefile("1bl8.pdb", ent_1bl8)], "Saving the original entry in file ...", false) &&
95
+ run(%q[disp "data/1bl8.pdb"], "Look through the entire entry ...", false) &&
96
+ run(%q[pdb_1bl8 = flatparse(ent_1bl8)], "Parsing the entry ...", false) &&
97
+ run(%q[pdb_1bl8.entry_id], "Showing the entry ID ...", true) &&
98
+ run(%q[pdb_1bl8.each_heterogen { |heterogen| p heterogen.resName }], "Showing each heterogen object ...", false) &&
99
+ true
100
+ end
101
+
102
+ def pdb_hetdic
103
+ # run(%q[het_dic = open("http://deposit.pdb.org/het_dictionary.txt").read],
104
+ # "Retrieving the het_dic database ...", false) &&
105
+ # run(%q[savefile("data/het_dictionary.txt", het_dic)],
106
+ # "Saving the file ... ", false) &&
107
+ run(%q[het_dic.size], "Bytes of the file ...", true) &&
108
+ run(%q[disp "data/het_dictionary.txt"], "Take a look on the contents ...", true) &&
109
+ run(%q[flatindex("het_dic", "data/het_dictionary.txt")],
110
+ "Creating index to make the seaarchable database ...", false) &&
111
+ run(%q[ethanol = flatsearch("het_dic", "EOH")], "Search an ethanol entry ...", true) &&
112
+ run(%q[osake = flatparse(ethanol)], "Parse the entry ...", true) &&
113
+ run(%q[osake.conect], "Showing connect table (conect) of the molecule ...", true) &&
114
+ true
115
+ end
116
+
117
+ private
118
+
119
+ def run(cmd, msg, echo)
120
+ comment(msg)
121
+ splash(cmd)
122
+ result = eval(cmd, @bind)
123
+ if echo
124
+ pp result
125
+ end
126
+ continue?
127
+ end
128
+
129
+ def comment(msg)
130
+ puts "### #{msg}"
131
+ end
132
+
133
+ def splash(msg)
134
+ Bio::Shell.splash_message_action("bioruby> #{msg}")
135
+ print "bioruby> #{msg}"
136
+ gets
137
+ end
138
+
139
+ def continue?
140
+ Bio::Shell.ask_yes_or_no("Continue? [y/n] ")
141
+ end
142
+
143
+ end
144
+
145
+ end
146
+
@@ -0,0 +1,217 @@
1
+ #
2
+ # = bio/shell/interface.rb - core user interface of the BioRuby shell
3
+ #
4
+ # Copyright:: Copyright (C) 2005
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: The Ruby License
7
+ #
8
+ #
9
+
10
+ module Bio::Shell
11
+
12
+ private
13
+
14
+ ### work space
15
+
16
+ def ls
17
+ bind = Bio::Shell.cache[:binding]
18
+ list = eval("local_variables", bind).reject { |x|
19
+ eval(x, bind).nil?
20
+ }
21
+ puts list.inspect
22
+ return list
23
+ end
24
+
25
+ def rm(name)
26
+ bind = Bio::Shell.cache[:binding]
27
+ list = eval("local_variables", bind).reject { |x|
28
+ eval(x, bind).nil?
29
+ }
30
+ begin
31
+ if list.include?(name.to_s)
32
+ eval("#{name} = nil", bind)
33
+ else
34
+ raise
35
+ end
36
+ rescue
37
+ warn "Usage: rm :var or rm 'var' (rm var is not valid)"
38
+ end
39
+ end
40
+
41
+ ### script
42
+
43
+ def script(mode = nil)
44
+ Bio::Shell.script(mode)
45
+ end
46
+
47
+ ### object
48
+
49
+ def reload_object
50
+ Bio::Shell.load_object
51
+ end
52
+
53
+ ### plugin
54
+
55
+ def reload_plugin
56
+ Bio::Shell.load_plugin
57
+ end
58
+
59
+ ### config
60
+
61
+ def config(mode = :show, *opts)
62
+ case mode
63
+ when :show, "show"
64
+ Bio::Shell.config_show
65
+ when :echo, "echo"
66
+ Bio::Shell.config_echo
67
+ when :color, "color"
68
+ Bio::Shell.config_color
69
+ when :splash, "splash"
70
+ Bio::Shell.config_splash
71
+ when :pager, "pager"
72
+ Bio::Shell.config_pager(*opts)
73
+ when :message, "message"
74
+ Bio::Shell.config_message(*opts)
75
+ else
76
+ puts "Invalid mode (#{mode}) - :show, :echo, :color, :splash, :massage"
77
+ end
78
+ end
79
+
80
+ def reload_config
81
+ Bio::Shell.load_config
82
+ end
83
+
84
+ ### pager
85
+
86
+ def pager(cmd = nil)
87
+ unless Bio::Shell.config[:pager]
88
+ cmd ||= ENV['PAGER']
89
+ end
90
+ Bio::Shell.config_pager(cmd)
91
+ puts "Pager is set to '#{cmd ? cmd : 'off'}'"
92
+ end
93
+
94
+ def disp(*objs)
95
+ # The original idea is from http://sheepman.parfait.ne.jp/20050215.html
96
+ if cmd = Bio::Shell.config[:pager]
97
+ pg = IO.popen(cmd, "w")
98
+ begin
99
+ stdout_save = STDOUT.clone
100
+ STDOUT.reopen(pg)
101
+ objs.each do |obj|
102
+ if obj.is_a?(String)
103
+ if File.exist?(obj)
104
+ system("#{cmd} #{obj}")
105
+ else
106
+ obj.display
107
+ end
108
+ else
109
+ pp obj
110
+ end
111
+ end
112
+ ensure
113
+ STDOUT.reopen(stdout_save)
114
+ stdout_save.close
115
+ pg.close
116
+ end
117
+ else
118
+ objs.each do |obj|
119
+ if obj.is_a?(String)
120
+ obj.display
121
+ else
122
+ pp obj
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ def head(arg, num = 10)
129
+ str = ""
130
+ if File.exist?(arg)
131
+ File.open(arg) do |file|
132
+ num.times do
133
+ if line = file.gets
134
+ str << line
135
+ end
136
+ end
137
+ end
138
+ else
139
+ arg.to_s.each_with_index do |line, i|
140
+ break if i >= num
141
+ str << line
142
+ end
143
+ end
144
+ puts str
145
+ return str
146
+ end
147
+
148
+ ### file save
149
+
150
+ def savefile(file, *objs)
151
+ datadir = Bio::Shell.data_dir
152
+ message = "Save file '#{file}' in '#{datadir}' directory? [y/n] "
153
+ if ! file[/^#{datadir}/] and Bio::Shell.ask_yes_or_no(message)
154
+ file = File.join(datadir, file)
155
+ end
156
+ if File.exist?(file)
157
+ message = "Overwrite existing '#{file}' file? [y/n] "
158
+ if ! Bio::Shell.ask_yes_or_no(message)
159
+ puts " ... save aborted."
160
+ return
161
+ end
162
+ end
163
+ begin
164
+ print "Saving file (#{file}) ... "
165
+ File.open(file, "w") do |f|
166
+ objs.each do |obj|
167
+ f.puts obj.to_s
168
+ end
169
+ end
170
+ puts "done"
171
+ rescue
172
+ warn "Error: Failed to save (#{file}) : #{$!}"
173
+ end
174
+ end
175
+
176
+ ### file system
177
+
178
+ def cd(dir = ENV['HOME'])
179
+ if dir
180
+ Dir.chdir(dir)
181
+ end
182
+ puts Dir.pwd.inspect
183
+ end
184
+
185
+ def pwd
186
+ puts Dir.pwd.inspect
187
+ end
188
+
189
+ def dir(file = nil)
190
+ if file
191
+ if File.directory?(file)
192
+ files = Dir.glob("#{file}/*")
193
+ else
194
+ files = Dir.glob(file)
195
+ end
196
+ else
197
+ files = Dir.glob("*")
198
+ end
199
+ if files
200
+ str = " UGO Date Byte File\n"
201
+ str << "------ ------------------------------ ----------- ------------\n"
202
+ files.sort.each { |f|
203
+ stat = File.lstat(f)
204
+ mode = format("%6o", stat.mode)
205
+ date = stat.mtime
206
+ byte = stat.size
207
+ name = f.inspect
208
+ str << format("%s %30s%13d %s\n", mode, date, byte, name)
209
+ }
210
+ puts str
211
+ return files.sort
212
+ end
213
+ end
214
+
215
+ end
216
+
217
+
@@ -0,0 +1,94 @@
1
+ #
2
+ # = bio/shell/irb.rb - CUI for the BioRuby shell
3
+ #
4
+ # Copyright:: Copyright (C) 2006
5
+ # Toshiaki Katayama <k@bioruby.org>
6
+ # License:: The Ruby License
7
+ #
8
+ #
9
+
10
+ module Bio::Shell
11
+
12
+ class Irb
13
+
14
+ def initialize
15
+ require 'irb'
16
+ begin
17
+ require 'irb/completion'
18
+ Bio::Shell.cache[:readline] = true
19
+ rescue LoadError
20
+ Bio::Shell.cache[:readline] = false
21
+ end
22
+ IRB.setup(nil)
23
+ setup_irb
24
+ start_irb
25
+ end
26
+
27
+ def start_irb
28
+ Bio::Shell.cache[:irb] = IRB::Irb.new
29
+
30
+ # needed for method completion
31
+ IRB.conf[:MAIN_CONTEXT] = Bio::Shell.cache[:irb].context
32
+
33
+ # store binding for evaluation
34
+ Bio::Shell.cache[:binding] = IRB.conf[:MAIN_CONTEXT].workspace.binding
35
+
36
+ # overwrite gets to store history with time stamp
37
+ io = IRB.conf[:MAIN_CONTEXT].io
38
+ io.class.class_eval do
39
+ alias_method :irb_original_gets, :gets
40
+ end
41
+
42
+ def io.gets
43
+ line = irb_original_gets
44
+ if line
45
+ Bio::Shell.store_history(line)
46
+ end
47
+ return line
48
+ end
49
+
50
+ if File.exist?("./config/boot.rb")
51
+ require "./config/boot"
52
+ require "./config/environment"
53
+ #require 'commands/console'
54
+ end
55
+ end
56
+
57
+ def setup_irb
58
+ # set application name
59
+ IRB.conf[:AP_NAME] = 'bioruby'
60
+
61
+ # change prompt for bioruby
62
+ $_ = Bio::Shell.colors
63
+ IRB.conf[:PROMPT][:BIORUBY_COLOR] = {
64
+ :PROMPT_I => "bio#{$_[:ruby]}ruby#{$_[:none]}> ",
65
+ :PROMPT_S => "bio#{$_[:ruby]}ruby#{$_[:none]}%l ",
66
+ :PROMPT_C => "bio#{$_[:ruby]}ruby#{$_[:none]}+ ",
67
+ :RETURN => " ==> %s\n"
68
+ }
69
+ IRB.conf[:PROMPT][:BIORUBY] = {
70
+ :PROMPT_I => "bioruby> ",
71
+ :PROMPT_S => "bioruby%l ",
72
+ :PROMPT_C => "bioruby+ ",
73
+ :RETURN => " ==> %s\n"
74
+ }
75
+ if Bio::Shell.config[:color]
76
+ IRB.conf[:PROMPT_MODE] = :BIORUBY_COLOR
77
+ else
78
+ IRB.conf[:PROMPT_MODE] = :BIORUBY
79
+ end
80
+
81
+ # echo mode (uncomment to off by default)
82
+ #IRB.conf[:ECHO] = Bio::Shell.config[:echo] || false
83
+
84
+ # irb/input-method.rb >= v1.5 (not in 1.8.2)
85
+ #IRB.conf[:SAVE_HISTORY] = 100000
86
+
87
+ # not nicely works
88
+ #IRB.conf[:AUTO_INDENT] = true
89
+ end
90
+
91
+ end # Irb
92
+
93
+ end
94
+