module Bio::Alignment::SiteMethods

Bio::Alignment::SiteMethods is a set of methods for Bio::Alignment::Site. It can also be used for extending an array of single-letter strings.

Constants

IUPAC_NUC

IUPAC nucleotide groups. Internal use only.

StrongConservationGroups

Table of strongly conserved amino-acid groups.

The value of the tables are taken from BioPerl (Bio/SimpleAlign.pm in BioPerl 1.0), and the BioPerl's document says that it is taken from Clustalw documentation and

These are all the positively scoring groups that occur in the 
Gonnet Pam250 matrix. The strong and weak groups are 
defined as strong score >0.5 and weak score =<0.5 respectively.
WeakConservationGroups

Table of weakly conserved amino-acid groups.

Please refer StrongConservationGroups document for the origin of the table.

Public Instance Methods

consensus_iupac() click to toggle source

Returns an IUPAC consensus base for the site. If consensus is found, eturns a single-letter string. If not, returns nil.

# File lib/bio/alignment.rb, line 218
def consensus_iupac
  a = self.collect { |x| x.downcase }.sort.uniq
  if a.size == 1 then
    case a[0]
    when 'a', 'c', 'g', 't'
      a[0]
    when 'u'
      't'
    else
      IUPAC_NUC.find { |x| a[0] == x[0] } ? a[0] : nil
    end
  elsif r = IUPAC_NUC.find { |x| (a - x).size <= 0 } then
    r[0]
  else
    nil
  end
end
consensus_string(threshold = 1.0) click to toggle source

Returns consensus character of the site. If consensus is found, eturns a single-letter string. If not, returns nil.

# File lib/bio/alignment.rb, line 181
def consensus_string(threshold = 1.0)
  return nil if self.size <= 0
  return self[0] if self.sort.uniq.size == 1
  h = Hash.new(0)
  self.each { |x| h[x] += 1 }
  total = self.size
  b = h.to_a.sort do |x,y|
    z = (y[1] <=> x[1])
    z = (self.index(x[0]) <=> self.index(y[0])) if z == 0
    z
  end
  if total * threshold <= b[0][1] then
    b[0][0]
  else
    nil
  end
end
has_gap?() click to toggle source

If there are gaps, returns true. Otherwise, returns false.

# File lib/bio/alignment.rb, line 164
def has_gap?
  (find { |x| is_gap?(x) }) ? true : false
end
match_line_amino(opt = {}) click to toggle source

Returns the match-line character for the site. This is amino-acid version.

# File lib/bio/alignment.rb, line 258
def match_line_amino(opt = {})
  # opt[:match_line_char]   ==> 100% equal    default: '*'
  # opt[:strong_match_char] ==> strong match  default: ':'
  # opt[:weak_match_char]   ==> weak match    default: '.'
  # opt[:mismatch_char]     ==> mismatch      default: ' '
  mlc = (opt[:match_line_char]   or '*')
  smc = (opt[:strong_match_char] or ':')
  wmc = (opt[:weak_match_char]   or '.')
  mmc = (opt[:mismatch_char]     or ' ')
  a = self.collect { |c| c.upcase }.sort.uniq
  a.extend(SiteMethods)
  if a.has_gap? then
    mmc
  elsif a.size == 1 then
    mlc
  elsif StrongConservationGroups.find { |x| (a - x).empty? } then
    smc
  elsif WeakConservationGroups.find { |x| (a - x).empty? } then
    wmc
  else
    mmc
  end
end
match_line_nuc(opt = {}) click to toggle source

Returns the match-line character for the site. This is nucleic-acid version.

# File lib/bio/alignment.rb, line 284
def match_line_nuc(opt = {})
  # opt[:match_line_char]   ==> 100% equal    default: '*'
  # opt[:mismatch_char]     ==> mismatch      default: ' '
  mlc = (opt[:match_line_char]   or '*')
  mmc = (opt[:mismatch_char]     or ' ')
  a = self.collect { |c| c.upcase }.sort.uniq
  a.extend(SiteMethods)
  if a.has_gap? then
    mmc
  elsif a.size == 1 then
    mlc
  else
    mmc
  end
end
remove_gaps!() click to toggle source

Removes gaps in the site. (destructive method)

# File lib/bio/alignment.rb, line 169
def remove_gaps!
  flag = nil
  self.collect! do |x|
    if is_gap?(x) then flag = self; nil; else x; end
  end
  self.compact!
  flag
end