bio 1.5.2 → 1.6.0.pre.20181210
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +12 -11
- data/ChangeLog +14 -3106
- data/{gemfiles/Gemfile.travis-ruby2.2 → Gemfile} +0 -1
- data/KNOWN_ISSUES.rdoc +0 -5
- data/README.rdoc +11 -18
- data/RELEASE_NOTES.rdoc +34 -291
- data/Rakefile +13 -9
- data/appveyor.yml +21 -0
- data/bioruby.gemspec +7 -78
- data/bioruby.gemspec.erb +8 -27
- data/doc/ChangeLog-1.5.0 +2919 -0
- data/doc/RELEASE_NOTES-1.5.0.rdoc +285 -0
- data/doc/Tutorial.rd +6 -108
- data/doc/Tutorial.rd.html +19 -98
- data/gemfiles/Gemfile.travis-jruby1.8 +3 -5
- data/gemfiles/Gemfile.travis-jruby1.9 +0 -3
- data/gemfiles/Gemfile.travis-rbx +0 -1
- data/gemfiles/Gemfile.travis-ruby1.8 +4 -4
- data/gemfiles/Gemfile.travis-ruby1.9 +0 -1
- data/gemfiles/prepare-gemspec.rb +4 -0
- data/lib/bio.rb +0 -10
- data/lib/bio/data/codontable.rb +99 -3
- data/lib/bio/io/togows.rb +5 -5
- data/lib/bio/version.rb +6 -8
- data/sample/test_restriction_enzyme_long.rb +1 -1
- data/test/unit/bio/data/test_codontable.rb +3 -0
- metadata +11 -77
- data/bin/bioruby +0 -47
- data/bin/br_biofetch.rb +0 -71
- data/bin/br_bioflat.rb +0 -293
- data/bin/br_biogetseq.rb +0 -45
- data/bin/br_pmfetch.rb +0 -422
- data/lib/bio/db/biosql/biosql_to_biosequence.rb +0 -78
- data/lib/bio/db/biosql/sequence.rb +0 -444
- data/lib/bio/db/phyloxml/phyloxml.xsd +0 -582
- data/lib/bio/db/phyloxml/phyloxml_elements.rb +0 -1197
- data/lib/bio/db/phyloxml/phyloxml_parser.rb +0 -1001
- data/lib/bio/db/phyloxml/phyloxml_writer.rb +0 -227
- data/lib/bio/io/biosql/ar-biosql.rb +0 -257
- data/lib/bio/io/biosql/biosql.rb +0 -39
- data/lib/bio/io/biosql/config/database.yml +0 -21
- data/lib/bio/io/sql.rb +0 -79
- data/lib/bio/shell.rb +0 -44
- data/lib/bio/shell/core.rb +0 -578
- data/lib/bio/shell/demo.rb +0 -146
- data/lib/bio/shell/interface.rb +0 -217
- data/lib/bio/shell/irb.rb +0 -94
- data/lib/bio/shell/object.rb +0 -71
- data/lib/bio/shell/plugin/blast.rb +0 -42
- data/lib/bio/shell/plugin/codon.rb +0 -218
- data/lib/bio/shell/plugin/das.rb +0 -58
- data/lib/bio/shell/plugin/emboss.rb +0 -23
- data/lib/bio/shell/plugin/entry.rb +0 -137
- data/lib/bio/shell/plugin/flatfile.rb +0 -101
- data/lib/bio/shell/plugin/midi.rb +0 -430
- data/lib/bio/shell/plugin/ncbirest.rb +0 -68
- data/lib/bio/shell/plugin/obda.rb +0 -45
- data/lib/bio/shell/plugin/psort.rb +0 -56
- data/lib/bio/shell/plugin/seq.rb +0 -248
- data/lib/bio/shell/plugin/togows.rb +0 -40
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/bioruby_generator.rb +0 -29
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_classes.rhtml +0 -4
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_log.rhtml +0 -27
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_methods.rhtml +0 -11
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_modules.rhtml +0 -4
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_variables.rhtml +0 -7
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-bg.gif +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-gem.png +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-link.gif +0 -0
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.css +0 -368
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.rhtml +0 -47
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb +0 -144
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_helper.rb +0 -47
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/commands.rhtml +0 -8
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/history.rhtml +0 -10
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/index.rhtml +0 -26
- data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/spinner.gif +0 -0
- data/lib/bio/shell/script.rb +0 -25
- data/lib/bio/shell/setup.rb +0 -108
- data/lib/bio/shell/web.rb +0 -102
- data/sample/test_phyloxml_big.rb +0 -205
- data/test/data/phyloxml/apaf.xml +0 -666
- data/test/data/phyloxml/bcl_2.xml +0 -2097
- data/test/data/phyloxml/made_up.xml +0 -144
- data/test/data/phyloxml/ncbi_taxonomy_mollusca_short.xml +0 -65
- data/test/data/phyloxml/phyloxml_examples.xml +0 -415
- data/test/unit/bio/db/biosql/tc_biosql.rb +0 -114
- data/test/unit/bio/db/biosql/ts_suite_biosql.rb +0 -8
- data/test/unit/bio/db/test_phyloxml.rb +0 -821
- data/test/unit/bio/db/test_phyloxml_writer.rb +0 -334
- data/test/unit/bio/shell/plugin/test_seq.rb +0 -187
- data/test/unit/bio/test_shell.rb +0 -20
@@ -1,101 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = bio/shell/plugin/flatfile.rb - plugin for flatfile database
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright (C) 2005
|
5
|
-
# Toshiaki Katayama <k@bioruby.org>
|
6
|
-
# License:: The Ruby License
|
7
|
-
#
|
8
|
-
# $Id: flatfile.rb,v 1.13 2007/04/05 23:45:11 trevor Exp $
|
9
|
-
#
|
10
|
-
|
11
|
-
module Bio::Shell
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def flatfile(filename)
|
16
|
-
if block_given?
|
17
|
-
Bio::FlatFile.auto(filename) do |flat|
|
18
|
-
flat.each do |entry|
|
19
|
-
yield flat.entry_raw
|
20
|
-
end
|
21
|
-
end
|
22
|
-
else
|
23
|
-
entry = ''
|
24
|
-
Bio::FlatFile.auto(filename) do |flat|
|
25
|
-
flat.next_entry
|
26
|
-
entry = flat.entry_raw
|
27
|
-
end
|
28
|
-
return entry
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def flatauto(filename)
|
33
|
-
if block_given?
|
34
|
-
Bio::FlatFile.auto(filename) do |flat|
|
35
|
-
flat.each do |entry|
|
36
|
-
yield entry
|
37
|
-
end
|
38
|
-
end
|
39
|
-
else
|
40
|
-
entry = ''
|
41
|
-
Bio::FlatFile.auto(filename) do |flat|
|
42
|
-
entry = flat.next_entry
|
43
|
-
end
|
44
|
-
return entry
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def flatparse(entry)
|
49
|
-
if cls = Bio::FlatFile.autodetect(entry)
|
50
|
-
return cls.new(entry)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def flatfasta(fastafile, *flatfiles)
|
55
|
-
puts "Saving fasta file (#{fastafile}) ... "
|
56
|
-
File.open(fastafile, "w") do |fasta|
|
57
|
-
flatfiles.each do |flatfile|
|
58
|
-
puts " converting -- #{flatfile}"
|
59
|
-
Bio::FlatFile.auto(flatfile) do |flat|
|
60
|
-
flat.each do |entry|
|
61
|
-
header = "#{entry.entry_id} #{entry.definition}"
|
62
|
-
fasta.puts entry.seq.to_fasta(header, 50)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
puts "done"
|
68
|
-
end
|
69
|
-
|
70
|
-
def flatindex(dbname, *flatfiles)
|
71
|
-
begin
|
72
|
-
dir = Bio::Shell.create_flat_dir(dbname)
|
73
|
-
print "Creating BioFlat index (#{dir}) ... "
|
74
|
-
bdb = format = options = nil
|
75
|
-
Bio::FlatFileIndex.makeindex(bdb, dir, format, options, *flatfiles)
|
76
|
-
puts "done"
|
77
|
-
rescue
|
78
|
-
warn "Error: Failed to create index (#{dir}) : #{$!}"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def flatsearch(dbname, keyword)
|
83
|
-
dir = Bio::Shell.find_flat_dir(dbname)
|
84
|
-
unless dir
|
85
|
-
warn "Error: Failed to open database (#{dbname})"
|
86
|
-
return
|
87
|
-
end
|
88
|
-
entry = ''
|
89
|
-
Bio::FlatFileIndex.open(dir) do |db|
|
90
|
-
if results = db.include?(keyword)
|
91
|
-
results.each do |entry_id|
|
92
|
-
entry << db.search_primary(entry_id).to_s
|
93
|
-
end
|
94
|
-
else
|
95
|
-
warn "Error: No hits found in #{dbname} (#{keyword})"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
return entry
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
@@ -1,430 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# = bio/shell/plugin/midi.rb - Sequence to MIDI converter
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright (C) 2003, 2005
|
5
|
-
# Natsuhiro Ichinose <ichinose@genome.ist.i.kyoto-u.ac.jp>,
|
6
|
-
# Toshiaki Katayama <k@bioruby.org>
|
7
|
-
# License:: The Ruby License
|
8
|
-
#
|
9
|
-
# $Id: midi.rb,v 1.9 2007/04/05 23:35:41 trevor Exp $
|
10
|
-
#
|
11
|
-
|
12
|
-
#--
|
13
|
-
# *TODO*
|
14
|
-
# - add "Ohno" style
|
15
|
-
# - add a accessor to drum pattern
|
16
|
-
# - add a new feature to select music style (pop, trans, ryukyu, ...)
|
17
|
-
# - what is the base?
|
18
|
-
#++
|
19
|
-
|
20
|
-
class Bio::Sequence::NA
|
21
|
-
|
22
|
-
class MidiTrack
|
23
|
-
|
24
|
-
MidiProg = [
|
25
|
-
"Acoustic Grand Piano",
|
26
|
-
"Bright Acoustic Piano",
|
27
|
-
"Electric grand Piano",
|
28
|
-
"Honky Tonk Piano",
|
29
|
-
"Eiectric Piano 1",
|
30
|
-
"Electric Piano 2",
|
31
|
-
"Harpsichord",
|
32
|
-
"Clavinet",
|
33
|
-
"Celesra",
|
34
|
-
"Glockenspiel",
|
35
|
-
"Music Box",
|
36
|
-
"Vibraphone",
|
37
|
-
"Marimba",
|
38
|
-
"Xylophone",
|
39
|
-
"Tubular bells",
|
40
|
-
"Dulcimer",
|
41
|
-
"Drawbar Organ",
|
42
|
-
"Percussive Organ",
|
43
|
-
"Rock Organ",
|
44
|
-
"Church Organ",
|
45
|
-
"Reed Organ",
|
46
|
-
"Accordion",
|
47
|
-
"Harmonica",
|
48
|
-
"Tango Accordion",
|
49
|
-
"Nylon Accustic Guitar",
|
50
|
-
"Steel Acoustic Guitar",
|
51
|
-
"Jazz Electric Guitar",
|
52
|
-
"Ciean Electric Guitar",
|
53
|
-
"Muted Electric Guitar",
|
54
|
-
"Overdrive Guitar",
|
55
|
-
"Distorted Guitar",
|
56
|
-
"Guitar Harmonics",
|
57
|
-
"Acoustic Bass",
|
58
|
-
"Electric Fingered Bass",
|
59
|
-
"Electric Picked Bass",
|
60
|
-
"Fretless Bass",
|
61
|
-
"Slap Bass 1",
|
62
|
-
"Slap Bass 2",
|
63
|
-
"Syn Bass 1",
|
64
|
-
"Syn Bass 2",
|
65
|
-
"Violin",
|
66
|
-
"Viola",
|
67
|
-
"Cello",
|
68
|
-
"Contrabass",
|
69
|
-
"Tremolo Strings",
|
70
|
-
"Pizzicato Strings",
|
71
|
-
"Orchestral Harp",
|
72
|
-
"Timpani",
|
73
|
-
"String Ensemble 1",
|
74
|
-
"String Ensemble 2 (Slow)",
|
75
|
-
"Syn Strings 1",
|
76
|
-
"Syn Strings 2",
|
77
|
-
"Choir Aahs",
|
78
|
-
"Voice Oohs",
|
79
|
-
"Syn Choir",
|
80
|
-
"Orchestral Hit",
|
81
|
-
"Trumpet",
|
82
|
-
"Trombone",
|
83
|
-
"Tuba",
|
84
|
-
"Muted Trumpet",
|
85
|
-
"French Horn",
|
86
|
-
"Brass Section",
|
87
|
-
"Syn Brass 1",
|
88
|
-
"Syn Brass 2",
|
89
|
-
"Soprano Sax",
|
90
|
-
"Alto Sax",
|
91
|
-
"Tenor Sax",
|
92
|
-
"Baritone Sax",
|
93
|
-
"Oboe",
|
94
|
-
"English Horn",
|
95
|
-
"Bassoon",
|
96
|
-
"Clarinet",
|
97
|
-
"Piccolo",
|
98
|
-
"Flute",
|
99
|
-
"Recorder",
|
100
|
-
"Pan Flute",
|
101
|
-
"Bottle Blow",
|
102
|
-
"Shakuhachi",
|
103
|
-
"Whistle",
|
104
|
-
"Ocarina",
|
105
|
-
"Syn Square Wave",
|
106
|
-
"Syn Sawtooth Wave",
|
107
|
-
"Syn Calliope",
|
108
|
-
"Syn Chiff",
|
109
|
-
"Syn Charang",
|
110
|
-
"Syn Voice",
|
111
|
-
"Syn Fifths Sawtooth Wave",
|
112
|
-
"Syn Brass & Lead",
|
113
|
-
"New Age Syn Pad",
|
114
|
-
"Warm Syn Pad",
|
115
|
-
"Polysynth Syn Pad",
|
116
|
-
"Choir Syn Pad",
|
117
|
-
"Bowed Syn Pad",
|
118
|
-
"Metal Syn Pad",
|
119
|
-
"Halo Syn Pad",
|
120
|
-
"Sweep Syn Pad",
|
121
|
-
"SFX Rain",
|
122
|
-
"SFX Soundtrack",
|
123
|
-
"SFX Crystal",
|
124
|
-
"SFX Atmosphere",
|
125
|
-
"SFX Brightness",
|
126
|
-
"SFX Goblins",
|
127
|
-
"SFX Echoes",
|
128
|
-
"SFX Sci-fi",
|
129
|
-
"Sitar",
|
130
|
-
"Banjo",
|
131
|
-
"Shamisen",
|
132
|
-
"Koto",
|
133
|
-
"Kalimba",
|
134
|
-
"Bag Pipe",
|
135
|
-
"Fiddle",
|
136
|
-
"Shanai",
|
137
|
-
"Tinkle Bell",
|
138
|
-
"Agogo",
|
139
|
-
"Steel Drums",
|
140
|
-
"Woodblock",
|
141
|
-
"Taiko Drum",
|
142
|
-
"Melodic Tom",
|
143
|
-
"Syn Drum",
|
144
|
-
"Reverse Cymbal",
|
145
|
-
"Guitar Fret Noise",
|
146
|
-
"Breath Noise",
|
147
|
-
"Seashore",
|
148
|
-
"Bird Tweet",
|
149
|
-
"Telephone Ring",
|
150
|
-
"Helicopter",
|
151
|
-
"Applause",
|
152
|
-
"Gun Shot"
|
153
|
-
]
|
154
|
-
|
155
|
-
Styles = {
|
156
|
-
# "Ohno" => {
|
157
|
-
# # http://home.hiroshima-u.ac.jp/cato/bunkakoryuron.html
|
158
|
-
# },
|
159
|
-
"Ichinose" => {
|
160
|
-
:tempo => 120,
|
161
|
-
:scale => [0, 2, 4, 5, 7, 9, 11],
|
162
|
-
:tones => [
|
163
|
-
{:prog => 9, :base => 60, :range => 2},
|
164
|
-
{:prog => 13, :base => 48, :range => 2},
|
165
|
-
{:prog => 41, :base => 48, :range => 2},
|
166
|
-
{:prog => 44, :base => 36, :range => 2},
|
167
|
-
]
|
168
|
-
},
|
169
|
-
"Okinawan" => {
|
170
|
-
:tempo => 180,
|
171
|
-
:scale => [0,4,5,7,11],
|
172
|
-
:tones => [
|
173
|
-
{:prog => MidiProg.index("Harpsichord"), :base => 60, :range => 2},
|
174
|
-
{:prog => MidiProg.index("Dulcimer"), :base => 48, :range => 2},
|
175
|
-
{:prog => MidiProg.index("Fretless Base"), :base => 36, :range => 1},
|
176
|
-
]
|
177
|
-
},
|
178
|
-
"Major" => {
|
179
|
-
:scale => [0,2,4,5,7,9,11],
|
180
|
-
},
|
181
|
-
"Minor" => {
|
182
|
-
:scale => [0,2,3,5,7,9,10],
|
183
|
-
},
|
184
|
-
"Harmonic minor" => {
|
185
|
-
:scale => [0,2,3,5,7,9,11],
|
186
|
-
},
|
187
|
-
"Whole tone" => {
|
188
|
-
:scale => [0,2,4,6,8,10],
|
189
|
-
},
|
190
|
-
"Half tone" => {
|
191
|
-
:scale => [0,1,2,3,4,5,6,7,8,9,10,11],
|
192
|
-
},
|
193
|
-
"Indian" => {
|
194
|
-
:scale => [0,1,4,5,7,8,11],
|
195
|
-
},
|
196
|
-
"Arabic" => {
|
197
|
-
:scale => [0,2,3,6,7,8,11],
|
198
|
-
},
|
199
|
-
"Spanish" => {
|
200
|
-
:scale => [0,1,3,4,5,7,8,10],
|
201
|
-
},
|
202
|
-
"Japanese" => {
|
203
|
-
:scale => [0,2,5,7,9],
|
204
|
-
},
|
205
|
-
}
|
206
|
-
|
207
|
-
def initialize(channel = 0, program = nil, base = nil, range = nil, scale = nil)
|
208
|
-
@channel = channel & 0xff
|
209
|
-
@program = program || 0
|
210
|
-
@base = base || 60
|
211
|
-
@range = range || 2
|
212
|
-
@scale = scale || [0, 2, 4, 5, 7, 9, 11]
|
213
|
-
|
214
|
-
@tunes = []
|
215
|
-
@tune = 0
|
216
|
-
@code = []
|
217
|
-
@time = 0
|
218
|
-
|
219
|
-
@range.times do |i|
|
220
|
-
@scale.each do |c|
|
221
|
-
@tunes.push c + i * 12
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
@ttype = {
|
226
|
-
'aa' => 1, 'at' => 0, 'ac' => 3, 'ag' => -1,
|
227
|
-
'ta' => 0, 'tt' => -1, 'tc' => 1, 'tg' => -2,
|
228
|
-
'ca' => 2, 'ct' => 1, 'cc' => 2, 'cg' => 6,
|
229
|
-
'ga' => -1, 'gt' => -3, 'gc' => 0, 'gg' => -2,
|
230
|
-
}
|
231
|
-
@dtype = [
|
232
|
-
{ 'aa' => 2, 'at' => 4, 'ac' => 4, 'ag' => 2,
|
233
|
-
'ta' => 2, 'tt' => 4, 'tc' => 4, 'tg' => 2,
|
234
|
-
'ca' => 2, 'ct' => 3, 'cc' => 1, 'cg' => 2,
|
235
|
-
'ga' => 1, 'gt' => 2, 'gc' => 2, 'gg' => 3,
|
236
|
-
},
|
237
|
-
{ 'aa' => 3, 'at' => 3, 'ac' => 2, 'ag' => 3,
|
238
|
-
'ta' => 3, 'tt' => 3, 'tc' => 2, 'tg' => 2,
|
239
|
-
'ca' => 3, 'ct' => 2, 'cc' => 1, 'cg' => 1,
|
240
|
-
'ga' => 1, 'gt' => 1, 'gc' => 1, 'gg' => 1,
|
241
|
-
},
|
242
|
-
{ 'aa' => 2, 'at' => 2, 'ac' => 2, 'ag' => 2,
|
243
|
-
'ta' => 1, 'tt' => 1, 'tc' => 2, 'tg' => 2,
|
244
|
-
'ca' => 2, 'ct' => 2, 'cc' => 2, 'cg' => 3,
|
245
|
-
'ga' => 2, 'gt' => 2, 'gc' => 3, 'gg' => 1,
|
246
|
-
},
|
247
|
-
{ 'aa' => 1, 'at' => 1, 'ac' => 1, 'ag' => 1,
|
248
|
-
'ta' => 1, 'tt' => 1, 'tc' => 1, 'tg' => 1,
|
249
|
-
'ca' => 1, 'ct' => 1, 'cc' => 1, 'cg' => 3,
|
250
|
-
'ga' => 1, 'gt' => 1, 'gc' => 1, 'gg' => 1,
|
251
|
-
},
|
252
|
-
]
|
253
|
-
|
254
|
-
@code.concat [0x00, 0xc0 | (@channel & 0xff)]
|
255
|
-
@code.concat icode(@program & 0xff, 1)
|
256
|
-
end
|
257
|
-
|
258
|
-
def icode(num, n)
|
259
|
-
code = []
|
260
|
-
n.times do |i|
|
261
|
-
code.push num & 0xff
|
262
|
-
num >>= 8
|
263
|
-
end
|
264
|
-
code.reverse
|
265
|
-
end
|
266
|
-
|
267
|
-
def rcode(num)
|
268
|
-
code = []
|
269
|
-
code.push num & 0x7f
|
270
|
-
while num > 0x7f
|
271
|
-
num >>= 7
|
272
|
-
code.push num & 0x7f | 0x80
|
273
|
-
end
|
274
|
-
code.reverse
|
275
|
-
end
|
276
|
-
|
277
|
-
def c2s(code)
|
278
|
-
ans = ""
|
279
|
-
code.each do |c|
|
280
|
-
ans += c.chr
|
281
|
-
end
|
282
|
-
ans
|
283
|
-
end
|
284
|
-
|
285
|
-
def push(s)
|
286
|
-
tt = @time % 4
|
287
|
-
t = @ttype[s[0, 2]]
|
288
|
-
d = @dtype[tt][s[2, 2]]
|
289
|
-
if !t.nil? && !d.nil?
|
290
|
-
@tune += t
|
291
|
-
@tune %= @tunes.length
|
292
|
-
if tt == 0
|
293
|
-
vel = 90
|
294
|
-
elsif tt == 1 && d > 1
|
295
|
-
vel = 100
|
296
|
-
elsif tt == 2
|
297
|
-
vel = 60
|
298
|
-
else
|
299
|
-
vel = 50
|
300
|
-
end
|
301
|
-
@code.concat rcode(1)
|
302
|
-
@code.concat [0x90 | @channel, @tunes[@tune] + @base, vel]
|
303
|
-
@code.concat rcode(240 * d)
|
304
|
-
@code.concat [0x80 | @channel, @tunes[@tune] + @base, 0]
|
305
|
-
@time += d
|
306
|
-
end
|
307
|
-
end
|
308
|
-
|
309
|
-
def push_silent(d)
|
310
|
-
@code.concat rcode(1)
|
311
|
-
@code.concat [0x90 | @channel, 0, 0]
|
312
|
-
@code.concat rcode(240 * d)
|
313
|
-
@code.concat [0x80 | @channel, 0, 0]
|
314
|
-
@time += d;
|
315
|
-
end
|
316
|
-
|
317
|
-
def encode
|
318
|
-
ans ="MTrk"
|
319
|
-
ans += c2s(icode(@code.length + 4, 4))
|
320
|
-
ans += c2s(@code)
|
321
|
-
ans += c2s([0x00, 0xff, 0x2f, 0x00])
|
322
|
-
ans
|
323
|
-
end
|
324
|
-
|
325
|
-
def header(num, tempo = 120)
|
326
|
-
ans = "MThd"
|
327
|
-
ans += c2s(icode(6, 4))
|
328
|
-
ans += c2s(icode(1, 2))
|
329
|
-
ans += c2s(icode(num + 1, 2))
|
330
|
-
ans += c2s(icode(480, 2))
|
331
|
-
ans += "MTrk"
|
332
|
-
ans += c2s(icode(11, 4))
|
333
|
-
ans += c2s([0x00, 0xff, 0x51, 0x03])
|
334
|
-
ans += c2s(icode(60000000 / tempo, 3))
|
335
|
-
ans += c2s([0x00, 0xff, 0x2f, 0x00])
|
336
|
-
ans
|
337
|
-
end
|
338
|
-
|
339
|
-
end # MidiTrack
|
340
|
-
|
341
|
-
|
342
|
-
# style:
|
343
|
-
# Hash of :tempo, :scale, :tones
|
344
|
-
# scale:
|
345
|
-
# C C# D D# E F F# G G# A A# B
|
346
|
-
# 0 1 2 3 4 5 6 7 8 9 10 11
|
347
|
-
# tones:
|
348
|
-
# Hash of :prog, :base, :range -- tone, vol? or len?, octaves
|
349
|
-
# drum:
|
350
|
-
# true (with rhythm part), false (without rhythm part)
|
351
|
-
def to_midi(style = {}, drum = true)
|
352
|
-
default = MidiTrack::Styles["Ichinose"]
|
353
|
-
if style.is_a?(String)
|
354
|
-
style = MidiTrack::Styles[style] || default
|
355
|
-
end
|
356
|
-
tempo = style[:tempo] || default[:tempo]
|
357
|
-
scale = style[:scale] || default[:scale]
|
358
|
-
tones = style[:tones] || default[:tones]
|
359
|
-
|
360
|
-
track = []
|
361
|
-
|
362
|
-
tones.each_with_index do |tone, i|
|
363
|
-
ch = i
|
364
|
-
ch += 1 if i >= 9 # skip rythm track
|
365
|
-
track.push MidiTrack.new(ch, tone[:prog], tone[:base], tone[:range], scale)
|
366
|
-
end
|
367
|
-
|
368
|
-
if drum
|
369
|
-
rhythm = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
|
370
|
-
track.push(MidiTrack.new(9, 0, 35, 2, rhythm))
|
371
|
-
end
|
372
|
-
|
373
|
-
cur = 0
|
374
|
-
window_search(4) do |s|
|
375
|
-
track[cur % track.length].push(s)
|
376
|
-
cur += 1
|
377
|
-
end
|
378
|
-
|
379
|
-
track.each do |t|
|
380
|
-
t.push_silent(12)
|
381
|
-
end
|
382
|
-
|
383
|
-
ans = track[0].header(track.length, tempo)
|
384
|
-
track.each do |t|
|
385
|
-
ans += t.encode
|
386
|
-
end
|
387
|
-
return ans
|
388
|
-
end
|
389
|
-
|
390
|
-
end
|
391
|
-
|
392
|
-
|
393
|
-
module Bio::Shell
|
394
|
-
|
395
|
-
private
|
396
|
-
|
397
|
-
def midifile(filename, seq, *args)
|
398
|
-
begin
|
399
|
-
print "Saving MIDI file (#{filename}) ... "
|
400
|
-
File.open(filename, "w") do |file|
|
401
|
-
file.puts seq.to_midi(*args)
|
402
|
-
end
|
403
|
-
puts "done"
|
404
|
-
rescue
|
405
|
-
warn "Error: Failed to save (#{filename}) : #{$!}"
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
end
|
410
|
-
|
411
|
-
|
412
|
-
if $0 == __FILE__
|
413
|
-
|
414
|
-
# % for i in file*
|
415
|
-
# do
|
416
|
-
# ruby -r bio bio/shell/plugin/midi.rb $i ${i}.mid
|
417
|
-
# done
|
418
|
-
|
419
|
-
include Bio::Shell
|
420
|
-
|
421
|
-
seq_file = ARGV.shift
|
422
|
-
mid_file = ARGV.shift
|
423
|
-
|
424
|
-
Bio::FlatFile.auto(seq_file) do |ff|
|
425
|
-
ff.each do |f|
|
426
|
-
midifile(mid_file, f.naseq[0..1000])
|
427
|
-
end
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|