File: demo.rb

package info (click to toggle)
ruby-bio 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,480 kB
  • ctags: 9,428
  • sloc: ruby: 74,117; xml: 3,383; makefile: 17; perl: 13; sh: 1
file content (146 lines) | stat: -rw-r--r-- 5,015 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#
# = bio/shell/demo.rb - demo mode for the BioRuby shell
#
# Copyright::   Copyright (C) 2006
#               Toshiaki Katayama <k@bioruby.org>
# License::     The Ruby License
#
# $Id: demo.rb,v 1.4 2007/04/05 23:35:41 trevor Exp $
#

module Bio::Shell

  private

  def demo(part = nil)
    demo = Demo.new
    if part
      demo.send(part)
    else
      demo.all
    end
  end

  class Demo

    def initialize
      @bind = Bio::Shell.cache[:binding]
    end

    def all
      sequence &&
      entry &&
      shell &&
      pdb &&
      true
    end

    def tutorial
    end

    def aldh2
    end

    def mito
      run(%q[entry = getent("data/kumamushi.gb")], "Load kumamushi gene from GenBank database entry ...", false) &&
      run(%q[disp entry], "Check the contents ...", false) &&
      run(%q[kuma = flatparse(entry)], "Parse the database entry ...", true) &&
      run(%q[web], "Start BioRuby on Rails...", false) &&
      run(%q[puts kuma.entry_id], "Extract entry ID ...", false) &&
      run(%q[puts kuma.definition], "Extract definition ...", false) &&
      run(%q[gene = kuma.seq], "Extract DNA sequence of the gene ...", true) &&
      run(%q[doublehelix(gene)], "Show the sequence in ascii art ...", false) &&
      run(%q[seqstat(gene)], "Statistics of the gene ...", false) &&
      run(%q[config :color], "Change to color mode...", false) &&
      run(%q[seqstat(gene)], "Statistics of the gene ...", false) &&
      #run(%q[codontable], "Codontalble ...", false) &&
      run(%q[protein = gene.translate], "Translate DNA into protein ...", true) &&
      run(%q[comp = protein.composition], "Composition of the amino acids ...", false) &&
      run(%q[pp comp], "Check the composition ...", false) &&
      run(%q[puts protein.molecular_weight], "Molecular weight ...", false) &&
      run(%q[midifile("data/kumamushi.mid", gene)], "Gene to music ...", false) &&
      run(%q[`open "data/kumamushi.mid"`], "Let's listen ...", false) &&
      true
    end

    def sequence
      run(%q[dna = getseq("atgc" * 100)], "Generating DNA sequence ...", true) &&
      run(%q[doublehelix dna], "Double helix representation", false) &&
      run(%q[protein = dna.translate], "Translate DNA into Protein ...", true) &&
      run(%q[protein.molecular_weight], "Calculating molecular weight ...", true) &&
      run(%q[protein.composition], "Amino acid composition ...", true) &&
      true
    end

    def entry
      run(%q[kuma = getobj("gb:AF237819")], "Obtain an entry from GenBank database", false) &&
      run(%q[kuma.definition], "Definition of the entry", true) &&
      run(%q[kuma.naseq], "Sequence of the entry", true) &&
      run(%q[kuma.naseq.translate], "Translate the sequence to protein", true) &&
      run(%q[midifile("data/AF237819.mid", kuma.naseq)], "Generate gene music ...", false) &&
      true
    end

    def shell
      run(%q[pwd], "Show current working directory ...", false) &&
      run(%q[dir], "Show directory contents ...", false) &&
      run(%q[dir "shell/session"], "Show directory contents ...", false) &&
      true
    end

    def pdb
      run(%q[ent_1bl8 = getent("pdb:1bl8")], "Retrieving PDB entry 1BL8 ...", false) &&
      run(%q[head ent_1bl8], "Head part of the entry ...", false) &&
      run(%q[savefile("1bl8.pdb", ent_1bl8)], "Saving the original entry in file ...", false) &&
      run(%q[disp "data/1bl8.pdb"], "Look through the entire entry ...", false) &&
      run(%q[pdb_1bl8 = flatparse(ent_1bl8)], "Parsing the entry ...", false) &&
      run(%q[pdb_1bl8.entry_id], "Showing the entry ID ...", true) &&
      run(%q[pdb_1bl8.each_heterogen { |heterogen| p heterogen.resName }], "Showing each heterogen object ...", false) &&
      true
    end

    def pdb_hetdic
#      run(%q[het_dic = open("http://deposit.pdb.org/het_dictionary.txt").read],
#          "Retrieving the het_dic database ...", false) &&
#      run(%q[savefile("data/het_dictionary.txt", het_dic)],
#          "Saving the file ... ", false) &&
      run(%q[het_dic.size], "Bytes of the file ...", true) &&
      run(%q[disp "data/het_dictionary.txt"], "Take a look on the contents ...", true) &&
      run(%q[flatindex("het_dic", "data/het_dictionary.txt")],
          "Creating index to make the seaarchable database ...", false) &&
      run(%q[ethanol = flatsearch("het_dic", "EOH")], "Search an ethanol entry ...", true) &&
      run(%q[osake = flatparse(ethanol)], "Parse the entry ...", true) &&
      run(%q[osake.conect], "Showing connect table (conect) of the molecule ...", true) &&
      true
    end

    private

    def run(cmd, msg, echo)
      comment(msg)
      splash(cmd)
      result = eval(cmd, @bind)
      if echo
        pp result
      end
      continue?
    end

    def comment(msg)
      puts "### #{msg}"
    end

    def splash(msg)
      Bio::Shell.splash_message_action("bioruby> #{msg}")
      print "bioruby> #{msg}"
      gets
    end

    def continue?
      Bio::Shell.ask_yes_or_no("Continue? [y/n] ")
    end

  end

end