Module Bio::Alignment::SiteMethods
In: lib/bio/alignment.rb  (CVS)

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.

Methods

Included Modules

PropertyMethods

Constants

IUPAC_NUC = [ %w( t u ), %w( m a c ), %w( r a g ), %w( w a t u ), %w( s c g ), %w( y c t u ), %w( k g t u ), %w( v a c g m r s ), %w( h a c t u m w y ), %w( d a g t u r w k ), %w( b c g t u s y k ), %w( n a c g t u m r w s y k v h d b )   IUPAC nucleotide groups. Internal use only.
StrongConservationGroups = %w(STA NEQK NHQK NDEQ QHRK MILV MILF HY FYW).collect { |x| x.split('').sort }   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 = %w(CSA ATV SAG STNK STPA SGND SNDEQK NDEQHK NEQHRK FVLIM HFY).collect { |x| x.split('').sort }   Table of weakly conserved amino-acid groups.

Please refer StrongConservationGroups document for the origin of the table.

Public Instance methods

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

[Source]

# 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

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

[Source]

# 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

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

[Source]

# File lib/bio/alignment.rb, line 164
      def has_gap?
        (find { |x| is_gap?(x) }) ? true : false
      end

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

[Source]

# 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

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

[Source]

# 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

Removes gaps in the site. (destructive method)

[Source]

# 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

[Validate]