class Bio::Hello

Attributes

aa[R]
message[R]
na[R]

Public Class Methods

decode(string) click to toggle source
# File lib/bio-hello.rb, line 138
def self.decode(string)
  self.new.decode(string)
end
encode(string) click to toggle source
# File lib/bio-hello.rb, line 134
def self.encode(string)
  self.new.encode(string)
end
new(string = nil) click to toggle source
# File lib/bio-hello.rb, line 72
def initialize(string = nil)
  @message = string || "HELLO*BIORUBY"
  @aa = aaseq(@message)
  @ct = codon_table
end

Public Instance Methods

aaseq(string = "") click to toggle source
# 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() click to toggle source

ad hoc modifications to support 26 alphabets (only confirmed with the codon table 1)

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
naseq(string) click to toggle source
# File lib/bio-hello.rb, line 109
def naseq(string)
  if Bio::Sequence.guess(string) == Bio::Sequence::NA
    dna = Bio::Sequence::NA.new(string)
  else
    dna = encode(string)
  end
end