Class: Bio::Hello
- Inherits:
-
Object
- Object
- Bio::Hello
- Defined in:
- lib/bio-hello.rb
Instance Attribute Summary collapse
-
#aa ⇒ Object
readonly
Returns the value of attribute aa.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#na ⇒ Object
readonly
Returns the value of attribute na.
Class Method Summary collapse
Instance Method Summary collapse
- #aaseq(string = "") ⇒ Object
-
#codon_table ⇒ Object
ad hoc modifications to support 26 alphabets (only confirmed with the codon table 1).
- #decode(string = nil) ⇒ Object
- #encode(string = nil) ⇒ Object
- #helix(string = nil) ⇒ Object
-
#initialize(string = nil) ⇒ Hello
constructor
A new instance of Hello.
- #naseq(string) ⇒ Object
Constructor Details
#initialize(string = nil) ⇒ Hello
Returns a new instance of Hello.
72 73 74 75 76 |
# File 'lib/bio-hello.rb', line 72 def initialize(string = nil) @message = string || "HELLO*BIORUBY" @aa = aaseq(@message) @ct = codon_table end |
Instance Attribute Details
#aa ⇒ Object (readonly)
Returns the value of attribute aa.
70 71 72 |
# File 'lib/bio-hello.rb', line 70 def aa @aa end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
70 71 72 |
# File 'lib/bio-hello.rb', line 70 def @message end |
#na ⇒ Object (readonly)
Returns the value of attribute na.
70 71 72 |
# File 'lib/bio-hello.rb', line 70 def na @na end |
Class Method Details
.decode(string) ⇒ Object
138 139 140 |
# File 'lib/bio-hello.rb', line 138 def self.decode(string) self.new.decode(string) end |
.encode(string) ⇒ Object
134 135 136 |
# File 'lib/bio-hello.rb', line 134 def self.encode(string) self.new.encode(string) end |
Instance Method Details
#aaseq(string = "") ⇒ Object
104 105 106 107 |
# File 'lib/bio-hello.rb', line 104 def aaseq(string = "") aa = string.upcase.gsub(/[^A-Z]+/, ' ').strip.tr(' ', '*') Bio::Sequence::AA.new(aa) end |
#codon_table ⇒ Object
ad hoc modifications to support 26 alphabets (only confirmed with the codon table 1)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bio-hello.rb', line 80 def codon_table ct = Bio::CodonTable.copy(1) # O Pyl pyrrolysine ct['tag'] = 'O' # U Sec selenocysteine ct['tga'] = 'U' # B Asx asparagine/aspartic acid [DN] ct['nac'] = 'B' # can be 'uac' (Y) or 'cac' (H) but please omit. # J Xle isoleucine/leucine [IL] ct['ctn'] = 'J' # should also include 'tt[ag]' (L), 'at[tca]' (I). # Z Glx glutamine/glutamic acid [EQ] ct['nag'] = 'Z' # can be 'aag' (K) or 'tag' (*/O) but please omit. # X Xaa unknown [A-Z] ct['nnn'] = 'X' return ct end |
#decode(string = nil) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/bio-hello.rb', line 126 def decode(string = nil) if string @na = Bio::Sequence::NA.new(string) end aa = @na.translate(1, @ct) @aa = Bio::Sequence::AA.new(aa) end |
#encode(string = nil) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/bio-hello.rb', line 117 def encode(string = nil) if string @message = string @aa = aaseq(string) end na = @aa.split(//).map{|a| @ct.revtrans(a).first}.join @na = Bio::Sequence::NA.new(na) end |
#helix(string = nil) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/bio-hello.rb', line 142 def helix(string = nil) if string @na = naseq(string) end dna = @na.clone len = @na.length if len < 16 dna += 'n' * (16 - len) end pairs = [ [5, 0], [4, 2], [3, 3], [2, 4], [1, 4], [0, 3], [0, 2], [1, 0] ] count = 0 dna.window_search(16, 16) do |subseq| pairs.each_with_index do |ij, x| count += 1 break if count > len base = subseq[x, 1] puts ' ' * ij[0] + base + '-' * ij[1] + base.complement end pairs.reverse.each_with_index do |ij, x| count += 1 break if count > len base = subseq[x + 8, 1] puts ' ' * ij[0] + base.complement + '-' * ij[1] + base end end return "" end |