bio-hello 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/biohello.rb +175 -0
- data/bio-hello.gemspec +70 -0
- data/lib/bio-hello.rb +178 -0
- data/test/helper.rb +18 -0
- data/test/test_bio-hello.rb +7 -0
- metadata +155 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem "bio", ">= 1.4.1"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
bio (1.4.1)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.8.7)
|
11
|
+
rcov (0.9.9)
|
12
|
+
shoulda (2.11.3)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bio (>= 1.4.1)
|
19
|
+
bundler (~> 1.0.0)
|
20
|
+
jeweler (~> 1.5.2)
|
21
|
+
rcov
|
22
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Toshiaki Katayama
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= bio-hello
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to bio-hello
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Toshiaki Katayama. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "bio-hello"
|
16
|
+
gem.homepage = "http://github.com/ktym/bioruby-hello"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Hello World plugin for the BioRuby (just for fun :-)}
|
19
|
+
gem.description = %Q{Encode any message string into a DNA sequence}
|
20
|
+
gem.email = "k@bioruby.org"
|
21
|
+
gem.authors = ["Toshiaki Katayama"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "bio-hello #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/biohello.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# = Bio::Hello -- Hello World plugin for the BioRuby (just for fun :-)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright (C) 2010 Toshiaki Katayama <mailto:k at bioruby dot org>
|
6
|
+
# License:: Distributes under the same terms as Ruby
|
7
|
+
# Site:: https://github.com/ktym/bioruby-hello
|
8
|
+
#
|
9
|
+
# == USAGE (AS A COMMAND)
|
10
|
+
#
|
11
|
+
# Usage:
|
12
|
+
# % biohello.rb [options...] string
|
13
|
+
# % biohello.rb [options...] file
|
14
|
+
#
|
15
|
+
# Options:
|
16
|
+
# -e or --encode
|
17
|
+
# Encode the given string or file contents as a DNA sequence. (default)
|
18
|
+
# -d or --decode
|
19
|
+
# Decode a DNA encoded string.
|
20
|
+
# -x or --helix
|
21
|
+
# Show a DNA double strand helix in ASCII art.
|
22
|
+
# -c or --code
|
23
|
+
# Show the BioRuby code snippet.
|
24
|
+
# -h or --help
|
25
|
+
# Print this help message.
|
26
|
+
#
|
27
|
+
# Examples:
|
28
|
+
# % biohello.rb file
|
29
|
+
# % biohello.rb -e file
|
30
|
+
# % biohello.rb -d file
|
31
|
+
#
|
32
|
+
# % biohello.rb "BioRuby is fun"
|
33
|
+
# % biohello.rb -e "BIORUBY*IS*FUN"
|
34
|
+
# % biohello.rb -d "nacatatagagatganactattaaataagttaattttgaaat"
|
35
|
+
#
|
36
|
+
# % biohello.rb -x "I love you"
|
37
|
+
# % biohello.rb -x -e "I*LOVE*YOU"
|
38
|
+
# % biohello.rb -x -d "atataattataggtagaataatattagtga"
|
39
|
+
#
|
40
|
+
# % biohello.rb -c "A happy new year"
|
41
|
+
# % biohello.rb -c -e "A*HAPPY*NEW*YEAR"
|
42
|
+
# % biohello.rb -c -d "gcataacatgcacctccttattaaaatgaatggtaatatgaagcaaga"
|
43
|
+
#
|
44
|
+
# TODO:
|
45
|
+
# * Generate a postcard image :-)
|
46
|
+
#
|
47
|
+
|
48
|
+
require 'rubygems'
|
49
|
+
require 'bio-hello'
|
50
|
+
require 'getoptlong'
|
51
|
+
|
52
|
+
def show_usage
|
53
|
+
prog = File.basename($0)
|
54
|
+
usage = %Q[
|
55
|
+
Usage:
|
56
|
+
% #{prog} \[options...\] string
|
57
|
+
% #{prog} \[options...\] file
|
58
|
+
|
59
|
+
Options:
|
60
|
+
-e or --encode
|
61
|
+
Encode the given string or file contents as a DNA sequence. (default)
|
62
|
+
-d or --decode
|
63
|
+
Decode a DNA encoded string.
|
64
|
+
-x or --helix
|
65
|
+
Show a DNA double strand helix in ASCII art.
|
66
|
+
-c or --code
|
67
|
+
Show the BioRuby code snippet.
|
68
|
+
-h or --help
|
69
|
+
Print this help message.
|
70
|
+
|
71
|
+
Examples:
|
72
|
+
% #{prog} file
|
73
|
+
% #{prog} -e file
|
74
|
+
% #{prog} -d file
|
75
|
+
|
76
|
+
% #{prog} "BioRuby is fun"
|
77
|
+
% #{prog} -e "BIORUBY*IS*FUN"
|
78
|
+
% #{prog} -d "nacatatagagatganactattaaataagttaattttgaaat"
|
79
|
+
|
80
|
+
% #{prog} -x "I love you"
|
81
|
+
% #{prog} -x -e "I*LOVE*YOU"
|
82
|
+
% #{prog} -x -d "atataattataggtagaataatattagtga"
|
83
|
+
|
84
|
+
% #{prog} -c "A happy new year"
|
85
|
+
% #{prog} -c -e "A*HAPPY*NEW*YEAR"
|
86
|
+
% #{prog} -c -d "gcataacatgcacctccttattaaaatgaatggtaatatgaagcaaga"
|
87
|
+
|
88
|
+
]
|
89
|
+
puts usage
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
|
93
|
+
$opts = Hash.new
|
94
|
+
|
95
|
+
args = GetoptLong.new(
|
96
|
+
[ '--encode', '-e', GetoptLong::NO_ARGUMENT ],
|
97
|
+
[ '--decode', '-d', GetoptLong::NO_ARGUMENT ],
|
98
|
+
[ '--helix', '-x', GetoptLong::NO_ARGUMENT ],
|
99
|
+
[ '--code', '-c', GetoptLong::NO_ARGUMENT ],
|
100
|
+
[ '--help', '-h', GetoptLong::NO_ARGUMENT ]
|
101
|
+
)
|
102
|
+
|
103
|
+
args.each_option do |name, value|
|
104
|
+
case name
|
105
|
+
when /--encode/
|
106
|
+
$opts[:encode] = true
|
107
|
+
when /--decode/
|
108
|
+
$opts[:decode] = true
|
109
|
+
when /--code/
|
110
|
+
$opts[:code] = true
|
111
|
+
when /--helix/
|
112
|
+
$opts[:helix] = true
|
113
|
+
when /--help/
|
114
|
+
show_usage
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def process(string)
|
119
|
+
if $opts[:decode]
|
120
|
+
puts $hello.decode(string)
|
121
|
+
else # default incl. $opts[:encode]
|
122
|
+
puts $hello.encode(string)
|
123
|
+
end
|
124
|
+
if $opts[:helix]
|
125
|
+
puts
|
126
|
+
puts $hello.helix(string)
|
127
|
+
end
|
128
|
+
if $opts[:code]
|
129
|
+
puts
|
130
|
+
puts %Q[% ruby -rubygems -r bio -e 'p Bio::Sequence::NA.new("#{$hello.na}").translate']
|
131
|
+
puts %Q[ ==> "#{$hello.aa}"]
|
132
|
+
puts
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
$hello = Bio::Hello.new
|
138
|
+
|
139
|
+
message = ARGV.first
|
140
|
+
|
141
|
+
if message and ! File.file?(message)
|
142
|
+
process(message)
|
143
|
+
else
|
144
|
+
ARGF.each do |line|
|
145
|
+
process(line)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
=begin
|
152
|
+
|
153
|
+
hello = Bio::Hello.new(message)
|
154
|
+
|
155
|
+
puts hello.encode
|
156
|
+
puts Bio::Sequence::NA.new(hello.encode).translate
|
157
|
+
puts hello.decode(hello.encode)
|
158
|
+
|
159
|
+
aa = "BIO*RUBY*IS*FUN"
|
160
|
+
puts dna = hello.encode(aa)
|
161
|
+
puts hello.helix(aa)
|
162
|
+
puts hello.decode(dna)
|
163
|
+
puts hello.helix(dna)
|
164
|
+
|
165
|
+
puts Bio::Hello.encode("I*LOVE*YOU")
|
166
|
+
puts Bio::Hello.decode("atataattataggtagaataatattagtga")
|
167
|
+
|
168
|
+
ARGF.each do |line|
|
169
|
+
puts hello.encode(line)
|
170
|
+
end
|
171
|
+
|
172
|
+
=end
|
173
|
+
|
174
|
+
|
175
|
+
|
data/bio-hello.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{bio-hello}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Toshiaki Katayama"]
|
12
|
+
s.date = %q{2010-12-31}
|
13
|
+
s.default_executable = %q{biohello.rb}
|
14
|
+
s.description = %q{Encode any message string into a DNA sequence}
|
15
|
+
s.email = %q{k@bioruby.org}
|
16
|
+
s.executables = ["biohello.rb"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/biohello.rb",
|
30
|
+
"bio-hello.gemspec",
|
31
|
+
"lib/bio-hello.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_bio-hello.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/ktym/bioruby-hello}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{Hello World plugin for the BioRuby (just for fun :-)}
|
40
|
+
s.test_files = [
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_bio-hello.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
53
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<bio>, [">= 1.4.1"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
s.add_dependency(%q<bio>, [">= 1.4.1"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
s.add_dependency(%q<bio>, [">= 1.4.1"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/lib/bio-hello.rb
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
#
|
2
|
+
# = Bio::Hello -- Hello World plugin for the BioRuby (just for fun :-)
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2010 Toshiaki Katayama <mailto:k at bioruby dot org>
|
5
|
+
# License:: Distributes under the same terms as Ruby
|
6
|
+
# Site:: https://github.com/ktym/bioruby-hello
|
7
|
+
#
|
8
|
+
# == USAGE (AS A LIBRARY)
|
9
|
+
#
|
10
|
+
# The Bio::Hello class accepts your message as an amino acid sequence
|
11
|
+
# and encodes it as a DNA sequence.
|
12
|
+
#
|
13
|
+
# As this http://twitter.com/#!/OrthoNormalRuss/status/19117017042784256
|
14
|
+
# example shows,
|
15
|
+
#
|
16
|
+
# seq = Bio::Sequence::NA.new("ATGGAGCGTCGTTATTAATGTCATCGTATTTCTACTATGGCTTCT")
|
17
|
+
# puts seq.translate
|
18
|
+
#
|
19
|
+
# the translation itself is originally supported by the BioRuby library,
|
20
|
+
# however, this plugin provides both encoding and decoding of the message.
|
21
|
+
#
|
22
|
+
# Reverse translation of a given string into a DNA sequence can be done
|
23
|
+
# by the following script
|
24
|
+
#
|
25
|
+
# require 'rubygems'
|
26
|
+
# require 'bio'
|
27
|
+
#
|
28
|
+
# ct = Bio::CodonTable[1]
|
29
|
+
# aa = Bio::Sequence::AA("A*HAPPY*NEW*YEAR")
|
30
|
+
# na = aa.split(//).map{|a| ct.revtrans(a).first}.join
|
31
|
+
#
|
32
|
+
# and can be confirmed by the following bioruby shell session.
|
33
|
+
#
|
34
|
+
# bioruby> ct = codontable(1)
|
35
|
+
# bioruby> aa = getseq("A*HAPPY*NEW*YEAR")
|
36
|
+
# ==> A*HAPPY*NEW*YEAR
|
37
|
+
# bioruby> na = aa.split(//).map{|a| ct.revtrans(a).first}.join
|
38
|
+
# ==> "gcataacatgcacctccttattaaaatgaatggtaatatgaagcaaga"
|
39
|
+
#
|
40
|
+
# However, this method won't work for "I*LOVE*YOU" as the message contains
|
41
|
+
# abnormal amino acids like pyrrolysine and selenocysteine.
|
42
|
+
#
|
43
|
+
# Therefore, this plugin also provides ad hoc support for all 26 alphabets,
|
44
|
+
# which enables you to encode any message as a DNA sequence.
|
45
|
+
#
|
46
|
+
# Bio::Hello.encode() and Bio::Hello.decode() can be used as class methods.
|
47
|
+
#
|
48
|
+
# puts Bio::Hello.encode("I*LOVE*YOU")
|
49
|
+
# puts Bio::Hello.decode("atataattataggtagaataatattagtga")
|
50
|
+
#
|
51
|
+
# You can also instantiate the Bio::Hello object to reduce the initialization cost.
|
52
|
+
#
|
53
|
+
# hello = Bio::Hello.new(string)
|
54
|
+
# puts hello.encode
|
55
|
+
#
|
56
|
+
# puts hello.encode("BIO*RUBY*IS*FUN")
|
57
|
+
#
|
58
|
+
# ARGF.each do |line|
|
59
|
+
# puts hello.encode(line)
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
|
63
|
+
require 'rubygems'
|
64
|
+
require 'bio'
|
65
|
+
|
66
|
+
module Bio
|
67
|
+
|
68
|
+
class Hello
|
69
|
+
|
70
|
+
attr_reader :message, :na, :aa
|
71
|
+
|
72
|
+
def initialize(string = nil)
|
73
|
+
@message = string || "HELLO*BIORUBY"
|
74
|
+
@aa = aaseq(@message)
|
75
|
+
@ct = codon_table
|
76
|
+
end
|
77
|
+
|
78
|
+
# ad hoc modifications to support 26 alphabets
|
79
|
+
# (only confirmed with the codon table 1)
|
80
|
+
def codon_table
|
81
|
+
ct = Bio::CodonTable.copy(1)
|
82
|
+
|
83
|
+
# O Pyl pyrrolysine
|
84
|
+
ct['tag'] = 'O'
|
85
|
+
|
86
|
+
# U Sec selenocysteine
|
87
|
+
ct['tga'] = 'U'
|
88
|
+
|
89
|
+
# B Asx asparagine/aspartic acid [DN]
|
90
|
+
ct['nac'] = 'B' # can be 'uac' (Y) or 'cac' (H) but please omit.
|
91
|
+
|
92
|
+
# J Xle isoleucine/leucine [IL]
|
93
|
+
ct['ctn'] = 'J' # should also include 'tt[ag]' (L), 'at[tca]' (I).
|
94
|
+
|
95
|
+
# Z Glx glutamine/glutamic acid [EQ]
|
96
|
+
ct['nag'] = 'Z' # can be 'aag' (K) or 'tag' (*/O) but please omit.
|
97
|
+
|
98
|
+
# X Xaa unknown [A-Z]
|
99
|
+
ct['nnn'] = 'X'
|
100
|
+
|
101
|
+
return ct
|
102
|
+
end
|
103
|
+
|
104
|
+
def aaseq(string = "")
|
105
|
+
aa = string.upcase.gsub(/[^A-Z]+/, ' ').strip.tr(' ', '*')
|
106
|
+
Bio::Sequence::AA.new(aa)
|
107
|
+
end
|
108
|
+
|
109
|
+
def naseq(string)
|
110
|
+
if Bio::Sequence.guess(string) == Bio::Sequence::NA
|
111
|
+
dna = Bio::Sequence::NA.new(string)
|
112
|
+
else
|
113
|
+
dna = encode(string)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def encode(string = nil)
|
118
|
+
if string
|
119
|
+
@message = string
|
120
|
+
@aa = aaseq(string)
|
121
|
+
end
|
122
|
+
na = @aa.split(//).map{|a| @ct.revtrans(a).first}.join
|
123
|
+
@na = Bio::Sequence::NA.new(na)
|
124
|
+
end
|
125
|
+
|
126
|
+
def decode(string = nil)
|
127
|
+
if string
|
128
|
+
@na = Bio::Sequence::NA.new(string)
|
129
|
+
end
|
130
|
+
aa = @na.translate(1, @ct)
|
131
|
+
@aa = Bio::Sequence::AA.new(aa)
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.encode(string)
|
135
|
+
self.new.encode(string)
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.decode(string)
|
139
|
+
self.new.decode(string)
|
140
|
+
end
|
141
|
+
|
142
|
+
def helix(string = nil)
|
143
|
+
if string
|
144
|
+
@na = naseq(string)
|
145
|
+
end
|
146
|
+
dna = @na.clone
|
147
|
+
len = @na.length
|
148
|
+
|
149
|
+
if len < 16
|
150
|
+
dna += 'n' * (16 - len)
|
151
|
+
end
|
152
|
+
|
153
|
+
pairs = [ [5, 0], [4, 2], [3, 3], [2, 4],
|
154
|
+
[1, 4], [0, 3], [0, 2], [1, 0] ]
|
155
|
+
|
156
|
+
count = 0
|
157
|
+
dna.window_search(16, 16) do |subseq|
|
158
|
+
pairs.each_with_index do |ij, x|
|
159
|
+
count += 1
|
160
|
+
break if count > len
|
161
|
+
base = subseq[x, 1]
|
162
|
+
puts ' ' * ij[0] + base + '-' * ij[1] + base.complement
|
163
|
+
end
|
164
|
+
pairs.reverse.each_with_index do |ij, x|
|
165
|
+
count += 1
|
166
|
+
break if count > len
|
167
|
+
base = subseq[x + 8, 1]
|
168
|
+
puts ' ' * ij[0] + base.complement + '-' * ij[1] + base
|
169
|
+
end
|
170
|
+
end
|
171
|
+
return ""
|
172
|
+
end
|
173
|
+
|
174
|
+
end # class Hello
|
175
|
+
|
176
|
+
end # module Bio
|
177
|
+
|
178
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'bio-hello'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bio-hello
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Toshiaki Katayama
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-31 00:00:00 +09:00
|
19
|
+
default_executable: biohello.rb
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
name: shoulda
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
name: bundler
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
version: 1.0.0
|
50
|
+
requirement: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
type: :development
|
53
|
+
prerelease: false
|
54
|
+
name: jeweler
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 7
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 5
|
64
|
+
- 2
|
65
|
+
version: 1.5.2
|
66
|
+
requirement: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
name: rcov
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirement: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
name: bio
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 5
|
91
|
+
segments:
|
92
|
+
- 1
|
93
|
+
- 4
|
94
|
+
- 1
|
95
|
+
version: 1.4.1
|
96
|
+
requirement: *id005
|
97
|
+
description: Encode any message string into a DNA sequence
|
98
|
+
email: k@bioruby.org
|
99
|
+
executables:
|
100
|
+
- biohello.rb
|
101
|
+
extensions: []
|
102
|
+
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.rdoc
|
106
|
+
files:
|
107
|
+
- .document
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.rdoc
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- bin/biohello.rb
|
115
|
+
- bio-hello.gemspec
|
116
|
+
- lib/bio-hello.rb
|
117
|
+
- test/helper.rb
|
118
|
+
- test/test_bio-hello.rb
|
119
|
+
has_rdoc: true
|
120
|
+
homepage: http://github.com/ktym/bioruby-hello
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
requirements: []
|
147
|
+
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 1.3.7
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: Hello World plugin for the BioRuby (just for fun :-)
|
153
|
+
test_files:
|
154
|
+
- test/helper.rb
|
155
|
+
- test/test_bio-hello.rb
|